main.c 2.06 KB
#include <stdint.h>
#include <stdbool.h>

#define PB_PER		(*((volatile uint32_t*)0xFFFFF400))
#define PB_OER		(*((volatile uint32_t*)0xFFFFF410))
#define PB_SODR		(*((volatile uint32_t*)0xFFFFF430))
#define PB_CODR		(*((volatile uint32_t*)0xFFFFF434))
#define PB_PDSR		(*((volatile uint32_t*)0xFFFFF43C))

#define PC_PER		(*((volatile uint32_t*)0xFFFFF600))
#define PC_ODR		(*((volatile uint32_t*)0xFFFFF614))
#define PC_OER		(*((volatile uint32_t*)0xFFFFF610))
#define PC_SODR		(*((volatile uint32_t*)0xFFFFF630))
#define PC_CODR		(*((volatile uint32_t*)0xFFFFF634))
#define PC_PDSR		(*((volatile uint32_t*)0xFFFFF63C))
#define PC_PUER		(*((volatile uint32_t*)0xFFFFF664))

#define PMC_PCER	(*((volatile uint32_t*)0xFFFFFC10))

#define CLK_PIO_CDE	4

#define	DS1	(1 << 8)	//PB8
#define	DS2	(1 << 29)	//PC29

#define BT2	(1 << 4)	//PC4
#define BT1	(1 << 5)	//PC5

void delay_ms (int delay)
{
    volatile uint64_t DelayStep;
    for(DelayStep = 0; DelayStep < 100000*delay; DelayStep++);
}

void ConfigureLEDs (void)
{
	PB_PER = DS1;
	PC_PER = DS2;
	PB_OER = DS1;
	PC_OER = DS2;
	PB_SODR = DS1;
	PC_SODR = DS2;
}


void ConfigureButtons (void)
{
	PMC_PCER = 1 << CLK_PIO_CDE;    
	PC_PER = BT1 | BT2;
	PC_ODR = BT1 | BT2;
	PC_PUER = BT1 | BT2;
}

int main(void)
{
	int Decimator=0;
	ConfigureLEDs();
	ConfigureButtons();
#if 0    
	PMC_PCER = 1 << PER_ID_PBIOC_TO_PIOE;    
    PB_PER = DS1; //PIO enable register
//    PB_PDR = 0xffffffff; //PIO disable register

    PB_OER = DS1; //PIO controller output enable register
    PC_PER = DS2 | BT1 | BT2; //PIO enable register
    PC_OER = DS2; //PIO controller output enable register
    PC_ODR = BT1 | BT2;
    PC_PUER = BT1 | BT2;
#endif

  while(true)
  {
	for (Decimator=0; Decimator<100; Decimator++)
	{
		if((PC_PDSR & BT1) == 0)
        		PB_SODR = DS1;

    		if((PC_PDSR & BT2) == 0)
        		PB_CODR = DS1;
		delay_ms(10);
	}
    	
	PC_CODR = DS2;

	for (Decimator=0; Decimator<100; Decimator++)
	{
		if((PC_PDSR & BT1) == 0)
        		PB_SODR = DS1;

    		if((PC_PDSR & BT2) == 0)
        		PB_CODR = DS1;
		delay_ms(10);
	}

	PC_SODR = DS2;
  }
}