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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Raghunathan
06/01/15 22:20
Read: 691 times
Chennai
India


 
#190511 - Sorry about the delay...
Responding to: Konstantinos L. Angelis's previous message
Thanks Angelis. I was checking for responses for a few days and then stopped and managed to get a routine from my old archives which is now working - unfortunately it was a text file and had no author reference - quite possible I got it from this forum also. Any comments on this code ??
....
#define KEY_INPUT1  P1
unsigned char key_state;
unsigned char key_press ;
....
....

// T0 is set for 10ms interval generation. Used for debounce of all DIs
 
void Timer0_ISR(void) interrupt 1                // Basic 10ms interrupt for the program
{
  static char ct0, ct1; 
  char i;
  TR0     = 0;                                  // Stop T0 timer
  TL0     = (65535UL-18518UL);                  // Load  TMR0 registers (18518 x 0.54us = 10ms)
  TH0     = (65535UL-18518UL) >> 8;
	
// Debounce routine... returns with valid keypress only if stable for four consequtive calls 
	
   i = key_state ^ ~KEY_INPUT1;                // key changed ?
   ct0 = ~( ct0 & i );                         // reset or count ct0
   ct1 = ct0 ^ ct1 & i;                        // reset or count ct1
   i &= ct0 & ct1;                             // count until roll over ?
   key_state ^= i;                             // then toggle debounced state
   key_press |= key_state & i;                 // 0->1: key press detect
   TR0     = 1;                                // ISR over. Start T0
}
//=========================

//Reading the key press .. To read one, many or all 8 keys, the get_key_press() dose the job. 
// Argument is the mask for key you want to read. 

unsigned char get_key_press( unsigned char key_mask )
{
  EA = 0;
  key_mask &= key_press;                         // read key(s)
  key_press ^= key_mask;                         // clear key(s)
  EA = 1;
  return key_mask;
}
//============================	 


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