tmr0.h (807B)
1 #ifndef _TMR0_H_ 2 #define _TMR0_H_ 3 4 #include "extern.h" 5 6 #define TMR0_CLK0 (0 << 5) /* Use the CLK0 pin */ 7 /* 8 * Bit 3 assigns the prescalar to TMR0. 9 * Bits 0-2 of OPTION_REG indicate the prescalar value. In this case, 10 * 111 indicates a prescalar value of 256. 11 */ 12 #define TMR0_PRESCALAR_256 0b0111 13 /* 14 * We want 1ms delay @ 16Mhz with 64 prescalar, the formula is: 15 * 16 * 256 - ((delay * (fosc / 1000)) / (prescalar * 4)) = 17 * 256 - ((1 * (16000000 / 1000)) / (256 * 4)) = 18 * 256 - ((1 * 16000) / (256 * 4)) = ~240 19 * 20 * sdcc thinks there's an overflow here (hint: he's wrong)... 21 */ 22 #define TMR0_DELAY (256 - ((1 * (_XTAL_FREQ / 1000)) / (256 * 4))) 23 24 typedef void (*ev_handler)(void); 25 26 void tmr0_init(void); 27 void tmr0_delay_ms(uint16_t); 28 int tmr0_set_event(ev_handler, uint16_t); 29 30 #endif /* _TMR0_H_ */