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

#define PA_PER		(*((volatile uint32_t*)0xFFFFF200))
#define PA_OER		(*((volatile uint32_t*)0xFFFFF210))
#define PA_SODR		(*((volatile uint32_t*)0xFFFFF230))
#define PA_CODR		(*((volatile uint32_t*)0xFFFFF234))
#define PA_PDSR		(*((volatile uint32_t*)0xFFFFF23C))


#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 PER_ID_PBIOC_TO_PIOE	4

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

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

void _exit(int c){while(1);};

void dabt_handler(){};
void pabt_handler(){};
void dbgu_print_ascii(){};;

void delay(void)
{
    volatile uint64_t i;
    for(i = 0; i < 100000000; i++);
}

int main(void)
{
    PMC_PCER = 1 << PER_ID_PBIOC_TO_PIOE;

    PA_PER = 0x23; //PIO enable register
    PA_OER = 0x54; //PIO controller output enable register


    PB_PER = DS1; //PIO enable 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;
    while(true)
    {
    delay();
    /*
    PB_SODR = DS1;
    PC_CODR = DS2;
    delay();
    PB_CODR = DS1;
    PC_SODR = DS2;
    delay();
    */
    if(PC_PDSR & BT1)
        PB_SODR = DS1;
    else
        PB_CODR = DS1;
    if(PC_PDSR & BT2)
        PC_SODR = DS2;
    else
        PC_CODR = DS2;
    }
}