optimize delays for better accuracy
This commit is contained in:
33
src/main.c
33
src/main.c
@ -8,7 +8,7 @@
|
||||
#include "key.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define FOSC 11059200
|
||||
#define FOSC 11583000
|
||||
|
||||
|
||||
static const char KEY_MAP[20] = {
|
||||
@ -46,19 +46,34 @@ void timer0_isr() __interrupt 1 __using 1
|
||||
INCR_NEW_KEY_I(new_key_write_i);
|
||||
new_key_empty = 0;
|
||||
}
|
||||
|
||||
//track time
|
||||
count++;
|
||||
if (count == 200){
|
||||
count = 0;
|
||||
SecCount++;
|
||||
if (SecCount == 60){
|
||||
SecCount = 0;
|
||||
min_count++;
|
||||
if (min_count == 60){
|
||||
min_count = 0;
|
||||
hour_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Call timer0_isr() 10000/sec: 0.0001 sec
|
||||
// Initialize the timer count so that it overflows after 0.0001 sec
|
||||
// THTL = 0x10000 - FOSC / 12 / 10000 = 0x10000 - 92.16 = 65444 = 0xFFA4
|
||||
void Timer0Init(void) //100us @ 11.0592MHz
|
||||
// Call timer0_isr() 200/sec: 5 ms period
|
||||
// Initialize the timer count so that it overflows after 0.01 sec
|
||||
// THTL = 0x10000 - FOSC / 200 = 0x10000 - 115830 = 7621 = 0x1DC5
|
||||
void Timer0Init(void)
|
||||
{
|
||||
// TMOD = 0; // default: 16-bit auto-reload
|
||||
// AUXR = 0; // default: traditional 8051 timer frequency of FOSC / 12
|
||||
// TMOD = 0; // default: 16-bit auto-reload
|
||||
AUXR |= 0x80; // use undivided SYSclk for timer0
|
||||
// Initial values of TL0 and TH0 are stored in hidden reload registers: RL_TL0 and RL_TH0
|
||||
TL0 = 0xA4; // Initial timer value
|
||||
TH0 = 0xFF; // Initial timer value
|
||||
TL0 = 0xC5; // Initial timer value
|
||||
TH0 = 0x1D; // Initial timer value
|
||||
TF0 = 0; // Clear overflow flag
|
||||
TR0 = 1; // Timer0 start run
|
||||
ET0 = 1; // Enable timer0 interrupt
|
||||
|
Reference in New Issue
Block a user