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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/02/15 04:20
Read: times


 
#190511 - Sorry about the delay...
Responding to: ???'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            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      

Back to Subject List