#include #include #include unsigned long ms_counter; #define MAXBASE 8 /* 921,583 - per ms */ void T2_ISR(void) __interrupt(5) { ms_counter++; } void InitTimer() { ms_counter = 0; SetVector(0x202B, (void*)T2_ISR); TH2 = 0xFF - 0x03; TL2 = 0xFF - 0x98; RCAP2L = TL2; RCAP2H = TH2; T2CON = 0x05; ET2 = 1; EA = 1; } unsigned long GetMsCounter() { return ms_counter; } unsigned long DTimeMs(unsigned long t0) { return ms_counter - t0; } void DelayMs(unsigned long t) { unsigned long target = ms_counter + t; while(target > ms_counter){} }