#include #include "Robostix.h" #include "timer0.h" volatile ticks_t overflow0 = 0; void (*timer0_handler)(ticks_t ticks) = 0; #define TCCR0_INIT 0x0F // 0x0 0 0 0 1 1 1 1 #define TIMSK_INIT 0x02 #define COUNT_TOP 156 /** * This will fire every 10msec as set in init_timer0, it will also call * any assigned function to allow user specific processing */ ISR(TIMER0_COMP_vect) { overflow0++; if (timer0_handler) { timer0_handler(overflow0); } } void delay_10ms() { uint8_t prev = overflow0; while (prev == overflow0); } void delay_100ms(uint8_t num) { while (num--) { int8_t i; for(i = 0; i < 10; i++) { delay_10ms(); } } } void init_timer0(void (*func)(ticks_t ticks)) { /* Assign handler */ timer0_handler = func; /* Set the timer to use with a prescaler of */ TCCR0 = TCCR0_INIT; // Set "TOP" counter value. OCR0 = COUNT_TOP; /* Enable interrupt */ TIMSK |= TIMSK_INIT; }