Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Raghunathan
05/17/15 05:52
Read: 1356 times
Chennai
India


 
#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

List of 11 messages in thread
TopicAuthorDate
Timer 0 ISR for Switch Debounce      Raghunathan      05/17/15 05:52      
   I guess      Erik Malund      05/18/15 05:59      
      Yes it is enabled in MAIN. Though not shown !       Raghunathan      05/18/15 08:42      
   unsigned < 0      Maarten Brock      05/19/15 11:39      
      :^)      Michael Karas      05/19/15 12:41      
   P1TempState init and update      KONSTANTINOS L. ANGELIS      05/21/15 02:30      
      Sorry about the delay...      Raghunathan      06/01/15 22:20      
         the code you mentioned is from a very old thread from 8052.c      KONSTANTINOS L. ANGELIS      06/02/15 00:41      
            Thanks to you and Michael Karas !!       Raghunathan      06/02/15 05:01      
               You are welcome!!      Michael Karas      06/02/15 11:51      
                  Old Stuff      Michael Karas      06/05/15 03:45      

Back to Subject List