Blink a LED using a counter compare-match flag
#include BOARD_H
#define COUNTER counter0
#define CLKDIV 64
#define COMPARE compare0
#define PERIOD 0.5
int main ( )
{
hwa( configure, PIN_LED, mode, digital_output );
clock, ioclk / CLKDIV,
direction, up_loop,
bottom, 0,
top, max );
hwa( write, (COUNTER,COMPARE), 0.001 * HW_SYSHZ / CLKDIV );
static uint8_t n ;
for(;;) {
if (
hw( read, (COUNTER,COMPARE,irq) ) ) {
hw( clear, (COUNTER,COMPARE,irq) );
n++ ;
if ( n >= (uint8_t)(0.5 + 1.0*PERIOD/0.001/2.0+0.5) ) {
n = 0 ;
}
}
}
}