/*----------------------------------------------------------------------------*/ #define GPIO_BASE 0x20200000 #define GPIO_FSEL 0x00 #define GPIO_FSET 0x07 #define GPIO_FCLR 0x0A #define GPIO_FGET 0x0D //*----------------------------------------------------------------------------*/ #define MY_LED 47 #define MY_SWITCH 3 /*----------------------------------------------------------------------------*/ /** using macros :p */ #define gpio_output(x) gpio[GPIO_FSEL+(x/10)]=1<<(x%10)*3 #define gpio_clr(x) gpio[GPIO_FCLR+(x/32)]=1<<(x%32) #define gpio_set(x) gpio[GPIO_FSET+(x/32)]=1<<(x%32) #define gpio_get(x) (gpio[GPIO_FGET+(x/32)]&(1<<(x%32))) /*----------------------------------------------------------------------------*/ volatile unsigned int *gpio; /*----------------------------------------------------------------------------*/ void main(void) { /** base register address */ gpio = (unsigned int*) GPIO_BASE; /** configure gpio as output, by default it is an input pin */ gpio_output(MY_LED); /** main loop */ while(1) { if(gpio_get(MY_SWITCH)) gpio_set(MY_LED); else gpio_clr(MY_LED); } } /*----------------------------------------------------------------------------*/