#### eessoo

Joined Jan 29, 2012
23
Instead of a switch statement in keypad( ), use an array, a look-up-table.
This is much more simple and efficient.
the maximum value is 100
WOW very good idea on the array

i tested it
it give the same output ,wrong output
if i type 13.3 it gives output 10

#### eessoo

Joined Jan 29, 2012
23
one solution is to accumulate the number as an integer. When the "." is pressed, accumulate a power of 10 value and do the division after "ENTER" is pressed.
i don't understand that part

Last edited:

#### MrChips

Joined Oct 2, 2009
30,442
Please post the complete program code.

#### eessoo

Joined Jan 29, 2012
23
Rich (BB code):
int keypad[]={0,55,56,57,0,52,53,54,0,49,50,51,0,13,48,46,0} ;
int key=0;
float x;
int h=10;
char txt[15];
float kpt=0;

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

void main() {

lcd_init();
while(1)
{
do
while(!key);
if(key==13)
{
lcd_cmd(_lcd_clear);
break;
}

else if(key==46)
{
while(1)
{lcd_chr_cp(key);
do
while(!key);
kpt=((key-48)/10)+kpt;

if(key==13)
{lcd_cmd(_lcd_clear);
goto finaly;}

}
break;
}
else if(key!=13)
{lcd_chr_cp(key);
kpt=kpt*10+(key-48);}
}
finaly:
floattostr(kpt,txt);
Lcd_Out_CP(txt);
}

#### eessoo

Joined Jan 29, 2012
23
I FINALLY FIXED IT (i didn't really fix it, i just change some things)
Rich (BB code):
int keypad[]={0,55,56,57,0,52,53,54,0,49,50,51,0,13,48,46,0} ;
int key=0;
float x;
int h=10;
char txt[15];
float kpt=0;
int dot=0;

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

void main() {

lcd_init();
while(1)
{
do
while(!key);
if(key==13)
{
lcd_cmd(_lcd_clear);
break;
}

else if(key==46)
{  lcd_chr_cp(key);
dot=1;
}
else
{lcd_chr_cp(key);
kpt=kpt*10+(key-48);}

}
if (dot==1)
{kpt=(kpt/10);
}
finaly:
floattostr(kpt,txt);
Lcd_Out_CP(txt);
}
now help me figure out a way to make the user add more than one number after the Dot

thanks MrChips

Last edited:

#### MrChips

Joined Oct 2, 2009
30,442
Ok. When you set dot = 1, set divisor = 1,
Every time a digit is pressed when dot == 1, multiply the divisor by 10.
When ENTER is pressed divide the results by the divisor.

(What do you do if the dot is pressed more than once? Error checking is always the most tedious part of any program.)