kalyaniupen
Junior Member level 2
- Joined
- Jul 25, 2014
- Messages
- 21
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,468
what processor and language are you using?i am writing a 4x4 keypad program.in that i am getting output of 0-9 numbers but for the remaining keys i had assigned as 'E' key- has to perform up arrow/up count operation
'F'key -has to perform downarrow/down count operation
'D'key-has to perform delete operation like that...help me out
switch (key)
{
case 'E': uparrow(); break;
case 'D': delete(); break;
}
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 #include<reg51.h> #define lcdport P2 sbit rs=P3^7; sbit en=P3^5; sbit r1=P1^0; sbit r2=P1^1; sbit r3=P1^2; sbit r4=P1^3; sbit c1=P1^4; sbit c2=P1^5; sbit c3=P1^6; sbit c4=P1^7; void lcdcmd(char); void lcddata(char); void delay(unsigned int); void lcdstring(char *); void lcdint(); void scankey(); void count(); void main() { lcdint(); lcdstring("welcome to keypad"); lcdcmd(0xc0); lcdstring("press any key:"); P1=0xf0; delay(10); lcdcmd(0x01); lcdcmd(0x02); while(1) { scankey(); } } void scankey() { r1=0,r2=1,r3=1,r4=1; if(c1==0){lcdcmd(0x80);lcddata('1');delay(100);} if(c2==0){lcdcmd(0x80);lcddata('2');delay(100);} if(c3==0){lcdcmd(0x80);lcddata('3');delay(100);} if(c4==0){lcdcmd(0x80);lcddata('4');delay(100);} r2=0,r1=1,r3=1,r4=1; if(c1==0){lcdcmd(0x80);lcddata('5');delay(100);} if(c2==0){lcdcmd(0x80);lcddata('6');delay(100);} if(c3==0){lcdcmd(0x80);lcddata('7');delay(100);} if(c4==0){lcdcmd(0x80);lcddata('8');delay(100);} r3=0,r1=1,r2=1,r4=1; if(c1==0){lcdcmd(0x80);lcddata('9');delay(100);} if(c2==0){lcdcmd(0x80);lcddata('0');delay(100);} if(c3==0){lcdcmd(0x80);lcddata('A');delay(100);} if(c4==0){lcdcmd(0x80);lcddata('B');delay(100);} r4=0,r1=1,r2=1,r3=1; if(c1==0){lcdcmd(0x80);lcddata('C');delay(100);} if(c2==0){lcdcmd(0x80);lcddata('D');delay(100);} if(c3==0){count();delay(100);} if(c4==0){count();delay(100);} } void count() { int m=-1; int b; unsigned char n[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39}; if((r4==0)&&(c3==0)) { while(1) { if(m==9) { lcdcmd(0x80); lcddata(n[b]); } else if((r4==0)&&(c3==0)) { m=m+1; b=m%10; lcdcmd(0x80); lcddata(n[b]); delay(100); } } } if((r4==0)&&(c4==0)) { int m=10; while(1) { if(m==0) { lcdcmd(0x80); lcddata(n[b]); } else if((r4==0)&&(c4==0)) { m=m-1; b=m%10; lcdcmd(0x80); lcddata(n[b]); delay(100); } } } } void delay(unsigned int time) { int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++); } void lcdint() { lcdcmd(0x38); lcdcmd(0x01); lcdcmd(0x0c); lcdcmd(0x80); lcdcmd(0x0e); } void lcdcmd(char value) { lcdport=value; rs=0; en=1; delay(10); en=0; } void lcdstring(char *p) { while(*p!='\0') { lcddata(*p); delay(10); p++; } } void lcddata(char value) { lcdport=value; rs=1; en=1; delay(10); en=0; }
The easiest method in that case is to use the LCD only as a display device, do not try to read back the characters on it at all. Instead, keep a copy of the displayed line in system memory and after each 'edit' you make, copy it all back to the LCD.
The <- and -> keys should subtract or add to a pointer to the data in memory and also send cursor left or right commands to the LCD. This will make the display appear to show you are selecting the desired character but in reality you are selecting it in the copy held in memory.
The up and down keys simply increment or decrement the value in the selected location in memory then copy the memory to the LCD.
Brian.
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 #define LCD_CHARS_PER_LINE 20 // put the number of characters per line your LCD uses. char LCDLineOfDigits[LCD_CHARS_PER_LINE]; // where the line you will display is stored char PointerToDigit = 0; // position in that line you want to edit // call this when the left arrow key is pressed void CursorLeft() { if(PointerToDigit >0) { PointerToDigit--; // check you don't go back beyond 1st position LCDCmd(whatever your LCD cursor left command is); } } // call this when the right arrow key is pressed void CursorRight() { if(PointerToDigit < LCD_CHARS_PER_LINE) { PointerToDigit++; // check you don't fall off the end LCDCmd(whatever your LCD cursor right command is); } } // call this when the up arrow is pressed void UpArrow() { LCDLineOFDigits[PointerToDigit]++; // add 1 to the digit you selected LCDString(LCDLineOfDigits); // re-display the line on the LCD } // call this when the down arrow is pressed void DownArrow() { LCDLineOFDigits[PointerToDigit]--; // subtract 1 from the digit you selected LCDString(LCDLineOfDigits); // re-display the line on the LCD }
#define MoveRight(x) { unsigned char _dcnt = x; \
while(_dcnt-- != 0) \
lcdcmd(0b00010100); } \\ lcd command for cursor to move right
#define MoveLeft(x) { unsigned char _dcnt = x; \
while(_dcnt-- != 0) \
lcdcmd(0b00010000); } \\ lcd command for cursor to move letf
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?