/*----------------------------------------------------------------------------*/ #define GPIO_BASE 0x20200000 #define GPIO_FSEL 0x00 #define GPIO_FSET 0x07 #define GPIO_FCLR 0x0A #define GPIO_ACT_LED 47 /*----------------------------------------------------------------------------*/ /** 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) /*----------------------------------------------------------------------------*/ /** volatile coz -O2 compiler option would otherwise kill them? */ volatile unsigned int *gpio, loop; /*----------------------------------------------------------------------------*/ void main(void) { /** point to gpio access register */ gpio = (unsigned int*) GPIO_BASE; /** configure gpio as output */ gpio_output(GPIO_ACT_LED); /** main loop */ while(1) { /** clear pin! */ gpio_clr(GPIO_ACT_LED); /** delay a bit to allow us see the blink! */ for(loop=0;loop<0x200000;loop++); /** set pin! */ gpio_set(GPIO_ACT_LED); /** delay a bit to allow us see the blink! */ for(loop=0;loop<0x200000;loop++); } } /*----------------------------------------------------------------------------*/