Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] special functions in keypad

Status
Not open for further replies.

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
how to add special functions like delete,enter,uparrow, down arrow pls help me
 

Hi,

Your question is not clear...

You need some keys.. and the code for the special function keys.Usually sent by a HID via usb.

Klaus
 

If you need to expand the keypad, add extra rows or columns and scan them in the same way as normal.

The keypad simply returns a number representing the key position, how that number is used will depend on your application. Cursor control and delete implies you have an array of data to move through, maybe text or maybe it is to control XY axis of a machine. All you have to do is code the required function to operate when it sees the number from the keypad.

Brian.
 

if the keypad has a # key you can use that to to select another set of operations, e.g. # then 1 is delete, etc
 

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
 

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
what processor and language are you using?
can you post the code you have so far?
in C usually one would use a switch, e.g.
Code:
switch (key)
{
  case 'E': uparrow(); break;
  case 'D': delete(); break;


}
where delete() etc are functions to perform the required operation
 

here is my program pls go through of it and suggest me

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;
}



this program performs only 0-9 numbers on lcd.when i press last two buttons to perform count operation only up count is displaying.no down count.when i press 0 it displays 0 like wise.. when i press up arrow the count should automatically increase.
 
Last edited by a moderator:

Thats because you call the down count function on both the keys! Checking the key state a second time in the count() function is not safe as the key may have been released by then or be bouncing. I'm also not sure about all the checks for the column value being zero in the key scan routine, is this really what you want to do? Wouldn't it be better to check if one of the columns was '1'?

You need to add a function to count up or better still, pass +1 and -1 as parameters to the Count function and add them to the total already there.

Suggestion: after using each 'lcddata()' call you add a delay, why not add a single delay at the end of that function before returning?

Brian.
 

Could you explain why your program is not hanging in the 'while(1)' loops you have sprinkled your code with?

In the 'main()' it is ok, but why use it in the 'count()' function?
 

then what to do suggest me the corrections
 

1. Start by flowcharting exactly what you want to do. It isn't easy to see what you are trying to achieve at the moment, especially as it has no comments.

2. Simplify the code so it's easier to debug. For example, every 'lcddata' is preceeded with 'lcdcmd(0x80)' so remove it from the main code and add it to the start of the 'lcddata' function instead.

3. Similarly, in almost (but not all) cases you call a delay function after 'lcddata', if you move the call inside the 'lcddata' function it will make your code much simpler.

4. Fully decode the keypad and only then act upon the number it returns. Reading it again later in the code does not guarantee the same key is still pressed and with most keypads there is significant contact bounce so you may react to the first closure then miss it altogether as you move down the code.

5. I'm not sure what the n[] array does. If it's just to convert the index to ASCII, simply add '0' (character zero) to the index to get the same result.

Brian.
 

i am creating a display on lcd like 1234567890.ok.i want my cursor to move /shift left and give the data of the present cursor value.if here i press up arrow the 0 should increment from (0-9) for selection insted of pressing individual 1,2,3 buttons
 

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.
 

please give me code for these functions



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.
 

Without knowing more about your application and your compiler that is difficult to do. Here is some 'psuedo code' for you to adapt, it will probably not work as it is:


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
}



You may want to check the selected digit is within a sensible range before incrementing or decrementing it.
Sorry for not formating the lines very well - it's difficult to do on a mobile phone!

Brian.
 
Last edited by a moderator:
i am defining a array a[n]=123456;the same is displayed on lcd also. the problem here is if i give n=0; a[n]++;the position of the a[0] is incrementing and displaying but now i want to move to next digit to increment i.e.a[1],a[2],like that give code for this how to increment one by one and display on lcd.
 

Code:
	#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
add a macro like this
and you detect 'A' in keypad use one macro and you detect 'B' use another.

- - - Updated - - -

similarly if you are try for up and down arrow it depends on you lcd length and the place of the row.
for eg if is 20 x 4 lcd display cursor moves from 1 st line to 3 rd line then back to 2 nd line then 4 th line.
write a loop based on the line you are in lcd. x will be fix as 20.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top