|
|
View previous topic :: View next topic |
Author |
Message |
sudu
Joined: 23 May 2004 Posts: 7
|
How to display enter button value in LCD |
Posted: Mon Sep 13, 2004 8:17 am |
|
|
Hi all
could anyone help me to solve my problem. I'm beginner in this PIC programming. what i want to do is display back button value into LCD.
let says, when i enter button no 1, it will display 1 at LCD. and then when i continue with button 4 then A. it will show "14A" at LCD. how can i do that?.. hope anyone can help me.
below is my code. but it only display current button value that i was enter and did'nt store my previous entered button value.
Code: | #include <18F452.h>
#Fuses HS,NOPROTECT,NOBROWNOUT,NOWDT,PUT,NODEBUG,NOLVP
#use delay( clock=9830400 )
#include <math.h>
#include "Lcd.c"
// Keypad Layout
// 1 2 3 A
// 4 5 6 B
// 7 8 9 C
// * 0 # D
struct keypad_pin_map
{
int key: 4;
int row: 4;
} PortC;
#Byte PortC = 0xF82
#Byte PortD = 0xF83
#use fast_io( C )
#use fast_io( D )
struct Keypad_pin_map const WR = {0,0};
struct Keypad_pin_map const RD = {15,0};
//'1'=17, '2'=18, '3'=20, 'A'=24
//'4'=33, '5'=34, '6'=36, 'B'=40
//'7'=65, '8'=66, '9'=68, 'C'=72
//'*'=129 '0'=130 '#'=132 'D'=136
char decodeKey_Pad(int keyPadData)
{
switch (keyPadData)
{
case 17: return('1');
break;
case 18: return('2');
break;
case 20: return('3');
break;
case 24: return('A');
break;
case 33: return('4');
break;
case 34: return('5');
break;
case 36: return('6');
break;
case 40: return('B');
break;
case 65: return('7');
break;
case 66: return('8');
break;
case 68: return('9');
break;
case 72: return('C');
break;
case 129: return('E'); //* = E, esc
break;
case 130: return('0');
break;
case 132: return('R'); //# = R, return
break;
case 136: return('D');
break;
}
}
byte ReadKeyPad()
{
byte i,k,l,Res;
Res = 0;
for (i=0; i<4; i++)
{
Set_Tris_C( WR );
PortC.Key = 0;
PortC.Row = exp(i*log(2));
delay_us(50);
Set_Tris_C( RD );
k = PortC.Key;
l = exp((4+i)*log(2));
if( k!= 0) { Res = k|l; }
}
return Res;
}
void main()
{
byte c;
int keyPad_Data;
lcd_init();
lcd_putc("\f welcome \n" );
lcd_putc( " Your Display " );
delay_ms(1000);
while(1)
{
keyPad_Data = ReadKeyPad();
c = decodeKey_Pad(keyPad_Data);
if (c != 0) printf(lcd_putc, "\f%u", c );
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 13, 2004 12:35 pm |
|
|
All you want to do is to display a keypress on the LCD.
Why don't you just use the CCS drivers that come with the compiler ?Then it would work. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Sep 13, 2004 3:24 pm |
|
|
As PCM Programmer told you, use the generic keypad driver KBDD.C
to handle the keypad.
I guess that you are trying to operate arithmetically while scanning the
keypad, wich is not an easy task for a beginner. First try to get the
pressed key and then apply your arithmetics.
FYI, the function exp(value) return a float, so read carefully
the help.
Quote: |
PortC.Row = exp(i*log(2));
|
Humberto |
|
|
sudu
Joined: 23 May 2004 Posts: 7
|
|
Posted: Mon Sep 13, 2004 7:05 pm |
|
|
hi there,
thank for your feedback
finally, i can display keypress in LCD without override previous keypress.
just simple mistake in printf
Code: | printf(lcd_putc, "\f%u", c ); |
i change it to
Code: | printf(lcd_putc, "%u", c ); |
without \f.
another problems is how can i get value in LCD to manipulate.
eg:
lets says i want to use this LCD in menu function. when user enter their menu using keypad, for example enter 1234. How can i get that number 1234 and manipulate it in my menu function. is there any way to do that?.
thank for your help.
sorry for my bad english. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 13, 2004 9:31 pm |
|
|
Well if you are getting the number and displaying it, then you have the number. It really depends on what you are trying to do. You could store the data into a string and then convert that string back to a number. You could store the key press as a number. When the next number is pressed, multiply the previous result by 10 and add the new number. |
|
|
pixie Guest
|
Lcd.c |
Posted: Tue Dec 14, 2004 7:37 am |
|
|
Hello, I'm trying to resolve the same problem, could you put the librarie Lcd.c used with the 18F452 PIC.
Thank You Very Much. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|