I am using timer T1 in a digital clock project and have set TH1 to 0x01F (=31) and TL1 =0x00; I supposed counting 16 interupts in this way would count 1 sec. as 256*(256-31)*16*12 = 11059200. Running the code on proteus gives an output of 48 secs in 1 min which is .8 the required speed. Where am I going Wrong?
Code: Select all
void Timer1InterruptHandler() org IVT_ADDR_ET1{//<===0
EA_bit = 0; // Clear global interrupt enable flag / seems unnecessary here
//TR1_bit = 0; // Stop Timer1
TH1 = 0x1F; // Reset Timer1 high byte <===0
//TL1 = 0x00; // Reset Timer1 low byte
Sms++;
EA_bit = 1; // Set global interrupt enable flag
//TR1_bit = 1; // Run Timer1
}
Code: Select all
TF1_bit = 0; // Timer 1 Overflow: Ensure that Timer1 interrupt flag is cleared
ET1_bit = 1; // Enable Timer1 interrupt
EA_bit = 1; // Set global interrupt enable
GATE1_bit = 0; // Clear this flag to enable Timer1 whenever TR1 bit is set (not only at input at P3.3).
C_T1_bit = 0; // Set Timer operation: Timer1 counts the divided-down system clock
// When this bit is clear the timer will be incremented every machine cycle (not event counter for P3.5)..
M11_bit = 0; // M1 of Timer 1 Mode 1(16-bit Timer/Counter)
M01_bit = 1; // M0 of Timer 1 M0 an M1 = 1&0 resp.
TR1_bit = 0; // Turn off Timer1
TH1 = 0x01F; // Set Timer1 high byte Do I have to set it back to this value?
TL1 = 0x00; // Set Timer1 low byte
cval = 16; // Or (crystal/12)/(65536-(TH1*256+Tl1));
TR1_bit = 1;
Could it be because of using 2*16 LCD. I have heard (but am not sure) that the LCD Library also makes use of internal timers.