romel_emperado
Advanced Member level 2

- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
hi all
I have problem with this keypad.. I know how to interface in MCu but I dont get the logic how do I make the keypad increement the value of x ONLY once even if we hold or press one button for a long time
in my example I use button 1 to increment the value of x but I cannot get the logic how..
see my example code... hehe.. pls help..
I have problem with this keypad.. I know how to interface in MCu but I dont get the logic how do I make the keypad increement the value of x ONLY once even if we hold or press one button for a long time
in my example I use button 1 to increment the value of x but I cannot get the logic how..
see my example code... hehe.. pls help..
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 #include <REG51.h> #define KEYPAD P2 #define display P3 sbit key = P1^7; void DelayMs(unsigned int) ; unsigned char keypad[4][3]= { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 15 , 0 , 15 } ; unsigned char get_key() { unsigned char colloc,rowloc; do { KEYPAD=0xF0; colloc=KEYPAD & 0xF0; } while(colloc ==0xF0); // if any key pressed DelayMs(1); // some delay do { colloc=KEYPAD; colloc &=0xF0; }while(colloc==0xF0); // to verify is really key pressed KEYPAD=0xFE; colloc=KEYPAD & 0xF0; if(colloc !=0xF0) { rowloc=0; goto next; } KEYPAD=0xFD; colloc=KEYPAD & 0xF0; if(colloc !=0xF0) { rowloc=1; goto next; } KEYPAD=0xFB; colloc=KEYPAD & 0xF0; if(colloc !=0xF0) { rowloc=2; goto next; } KEYPAD=0xF7; colloc=KEYPAD & 0xF0; rowloc=3; goto next; next: if (colloc==0xE0) { display = (keypad[rowloc][0]); return display; } else if(colloc==0xD0) { display=(keypad[rowloc][1]); return display; } else { display=(keypad[rowloc][2]); return display; } void main() { char x; P1 = 0; while(1) { if(get_key() == 1) { x++; if(x==2) P1=1; } } } //--------------------------------------- // Delay mS function //--------------------------------------- void DelayMs(unsigned int count) { // mSec Delay 11.0592 Mhz unsigned int i; while(count) { i = 115; while(i>0) i--; count--; } }