Blink a LED using a counter overflow interrupt
#include BOARD_H
#define COUNTER counter0
#define CLKDIV 64
#define COUNTMODE up_loop
#define PERIOD 0.5
#define STRCMP(s1,s2) __builtin_strcmp(s1,s2)
HW_ISR( (COUNTER,irq,overflow) )
{
static uint8_t n ;
n++ ;
if ( n >= (uint8_t)(PERIOD / 2.0 / 0.001) ) {
n = 0 ;
}
}
int main ( )
{
hwa( configure, PIN_LED, mode, digital_output );
sleep, enabled,
sleep_mode, idle );
clock, ioclk / CLKDIV,
direction, COUNTMODE,
bottom, 0,
top, compare0
);
if ( !STRCMP(
HW_Q(COUNTMODE),
"updown_loop") )
hwa( write, (COUNTER,compare0), 0.5 + 0.001 * HW_SYSHZ / CLKDIV / 2 );
else
hwa( write, (COUNTER,compare0), 0.5 + 0.001 * HW_SYSHZ / CLKDIV );
hwa( enable, (COUNTER,irq,overflow) );
hw( enable, interrupts );
for(;;)
}