pic 16f877A
keypad 16
i want the program to read from the user the input and put it back on the lcd
so far if i input 53.1 the program send out 5331.999
or 20.1 it gives 2001.999
but it works fine with out the (.)
here is the program
(part of it) the other part is taking the percentage the the user enter and so some calculation to it
please explain your self in details coz i'm not very good in english
int key=0;
int kp1;
float x;
int h=10;
int kp2=0;
float kp=0;
float blue ,red ,green;
char txt[3];
float e;
int keypad(int key)
{
switch (key)
{case 9:
key=49;
kp1=1;
break;
case 10:
key=50;
kp1=2;
break;
case 11:
key=51;
kp1=3;
break;
case 5:
key=52;
kp1=4;
break;
case 6:
key=53;
kp1=5;
break;
case 7:
key=54;
kp1=6;
break;
case 1:
key=55;
kp1=7;
break;
case 2:
key=56;
kp1=8;
break;
case 3:
key=57;
kp1=9;
break;
case 14:
key=48;
kp1=0;
break;
case 15:
key=46;
}
return (key);
}
char keypadPort at PORTD;
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
keypad 16
i want the program to read from the user the input and put it back on the lcd
so far if i input 53.1 the program send out 5331.999
or 20.1 it gives 2001.999
but it works fine with out the (.)
here is the program
(part of it) the other part is taking the percentage the the user enter and so some calculation to it
please explain your self in details coz i'm not very good in english
int key=0;
int kp1;
float x;
int h=10;
int kp2=0;
float kp=0;
float blue ,red ,green;
char txt[3];
float e;
int keypad(int key)
{
switch (key)
{case 9:
key=49;
kp1=1;
break;
case 10:
key=50;
kp1=2;
break;
case 11:
key=51;
kp1=3;
break;
case 5:
key=52;
kp1=4;
break;
case 6:
key=53;
kp1=5;
break;
case 7:
key=54;
kp1=6;
break;
case 1:
key=55;
kp1=7;
break;
case 2:
key=56;
kp1=8;
break;
case 3:
key=57;
kp1=9;
break;
case 14:
key=48;
kp1=0;
break;
case 15:
key=46;
}
return (key);
}
char keypadPort at PORTD;
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
Rich (BB code):
void main() {
Keypad_Init();
lcd_init();
while(1)
{
do
key=keypad_key_click();
while(!key);
key=keypad(key);
if(key==13) \\if the use enter (enter)
{
lcd_cmd(_lcd_clear);
break;
}
else if(key==15) \\if the user enter '.'
{
while(1)
{lcd_chr_cp(key);
do
key=keypad_key_click();
while(!key);
key=keypad(key);
kp=kp1/10+kp;
if(key==13) \\ if the user use Enter
{lcd_cmd(_lcd_clear);
break;}
}
break;
}
else
{lcd_chr_cp(key);
kp=kp*10+kp1;}
}
floattostr(kp,txt);
Lcd_Out_CP(txt);
}
Last edited: