Blink a LED using a counter compare interrupt
#include BOARD_H
#define COUNTER counter0
#define CLKDIV 64
#define COUNTMODE up_loop
#define COMPARE compare0
#define PERIOD 0.5
#define STRCMP(s1,s2) __builtin_strcmp(s1,s2)
HW_ISR( (COUNTER,COMPARE,irq) )
{
static uint8_t n ;
n++ ;
if ( n >= (uint8_t)(0.5 + 1.0 * 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, max );
if ( !STRCMP(
HW_Q(COUNTMODE),
"updown_loop") )
hwa( write, (COUNTER,COMPARE), 0.5 + 0.001*HW_SYSHZ/CLKDIV/2 );
else
hwa( write, (COUNTER,COMPARE), 0.5 + 0.001*HW_SYSHZ/CLKDIV );
hwa( enable, (COUNTER,COMPARE,irq) );
hw( enable, interrupts );
for(;;)
}