I had post a same message before. Timer0 scan a 3*4's keypad with 10mS Interval,and var Key will be changed to a value when button be pressed or 0xff when all buttons be unprssed.Every button include 4 letters,like,one button has '1','a','b','c'and another has '2','d','e','f'. How i can realize these as a keypad on mobilephone,as press button '1' once Key == '1',and double press it quickly Key == 'a',etc?can you give me some source code for exsample? Best regards, Nanntiangumo
The first thinking as following :
void Timer0(void) interrupt 1 { if (bKeyDwF == 1 && bKeyRdyF == 1) //Twice scan finished { cCount ++; if (KeyTemp0 == KeyTemp1) // scan result being same would changed value to var Key Key = KeyTemp0; else Key = 0xff; // Or Key would be changed to NUll (0xff) bKeyFree = 0; bKeyDwF = 0; bKeyRdyF = 0; } if (bKeyDwF == 1 && bKeyRdyF == 0) //Scanning a Key the second time { KeyTemp1 = Scan(); bKeyRdyF = 1; } if (bKeyDwF == 0 && bKeyRdyF == 0) //Scanning a Key the first time { KeyTemp0 = Scan(); bKeyDwF = 1; } if (Key == 0xff ) { bFF = 1; //Set unpressed Flag; } if (Key != ETB && Key != ESC && Key != SPR && Key != PDW && Key != 0xff) { if (bLetterNum == 0) //Resolve Keys in Letter mode { if (Key != cKeyTemp) //A new Key pressed; { cKeyTemp = Key; // Key value be taken to buf; cHarKey = KBChar[Key][0]; //Return the key 's first value ; cCount = 0; } else //The same Key pressed ; { if(bFF == 1) //The same Key unpressed ; { cCount = 0; cHarKey = KBChar[Key][cKBCount]; // Return the Key 's another value if (cKBCount < 3) { cKBCount ++; } else { cKBCount = 0; } bFF = 0; //Clear unpressed Flag; } } } else if (bLetterNum == 1) //Resolve Keys in Number mode { if (Key != cKeyTemp) //A new Key pressed; { cKeyTemp = Key; cHarKey = KBChar[Key][0]; // Return the Key 's first value ; cCount = 0; } else // The same Key pressed ; { if (bFF == 1) // The same Key unpressed; { cCount = 0; if (Key == 0 || Key == 9) //Resolve mutil_value Key { if (Key == 0 ) { if (cKBCount != 0) { cHarKey = '-'; //Return the NEG symbol; } else { cHarKey = '0'; } } else if (Key == 9) { if (cKBCount != 0) { cHarKey = '.'; // Return the value point } else { cHarKey = '9'; } } if (cKBCount < 1) // The mutil_value Key counter; { cKBCount ++; } else { cKBCount = 0; } } else { cHarKey = KBChar[Key][0]; //Not mutil_value Key,return the Key 's first } //value immediately; bFF = 0; // Clear unpressed flag; } } } if (cCount == 8) //The same Key pressed 8 times { bValKey = 1; // Set the valid Key 's flag,CHARKEY would be main() taken to resolve; } } }
basic keypad code (assuping you drive columns and read rows. 1) feed all columns, if no row,: no key 2) scan columns till row active = key found 3) at exit if now_key is not = prev_key ignore 4) if 2 identical reads and result different from last key presented present key. Erik