| ??? 05/17/15 11:52 Read: times |
#190478 - Timer 0 ISR for Switch Debounce |
// T0 is set for 10ms interval generation. Used for Switch Debounce
void Timer0_ISR(void) interrupt 1 using 0 // Basic 10ms interrupt for the program
{
static unsigned char debounce_count = 3;
TR0 = 0; // Stop T0 timer
TL0 = (65535UL-18518UL); // Load TMR0 registers (18518 x 0.54us = 10ms)
TH0 = (65535UL-18518UL) >> 8;
if ( P1TempState == P1 )
{
--debounce_count; // If Current State of P1 is same as previous, dec, counter
if ( debounce_count < 0)
{
P1FinalState = P1TempState; // State of P1 has been same for 30ms, so valid.
debounce_count = 3 ;
}
}
else
{
debounce_count = 3; // Currenmt state of P1 not equal to previous. Reset counter.
}
TR0 = 1; // ISR over. Start T0
}
Above is an ISR to debounce switches connected to P1 port of a P89V51RD2. But does not seem to work. In the code I use it as below : if ( P1FinalState & 0x01 == 0) ...then do something. Does not seem to work as above. The T0 init is rather staright forward as below :
void init_timer0(void)
{
TMOD |= 0x01; // TMR0 in 16 bit timer mode to interrupt at 10mS intervals
TL0 = (65535UL-18518UL); // First time load of TMR0 registers ( 10000/ 0.54 = 18518 )
TH0 = (65535UL-18518UL) >> 8;
ET0 = 1 ; // Enable T0 interrupt
TR0 = 1 ; // Start Timer 0
}
Anything visibly wrong ?? Raghu |
| Topic | Author | Date |
| Timer 0 ISR for Switch Debounce | 01/01/70 00:00 | |
| I guess | 01/01/70 00:00 | |
| Yes it is enabled in MAIN. Though not shown ! | 01/01/70 00:00 | |
| unsigned < 0 | 01/01/70 00:00 | |
| :^) | 01/01/70 00:00 | |
| P1TempState init and update | 01/01/70 00:00 | |
| Sorry about the delay... | 01/01/70 00:00 | |
| the code you mentioned is from a very old thread from 8052.c | 01/01/70 00:00 | |
| Thanks to you and Michael Karas !! | 01/01/70 00:00 | |
| You are welcome!! | 01/01/70 00:00 | |
Old Stuff | 01/01/70 00:00 |



