HELP PLEASE!!!keypad problem

Thread Starter

ewincxz

Joined Oct 14, 2009
3
when i key "9" twice on the keypad. it does not give me the maths value of 99. instead its is just "9" and "9" side by side.i tried using the atoi() function however it doesnt seems to work. any suggestion in which im able to key 9 twice to give me the maths value 9?

im using pic18f4550 microcontroller

im actually quite new to microcontroller
 

n9352527

Joined Oct 14, 2005
1,198
You have to do it manually. You have to check for the number of digits. For two digits, multiply the first digit by 10 and add the second digit.
 

Thread Starter

ewincxz

Joined Oct 14, 2009
3
thanks. but after i get the value how to i do the addition and subtraction between. when i try to input 2 different value and do a substraction the final answer i get on the lcd screen would be rubbish(weird symbols).
 

n9352527

Joined Oct 14, 2005
1,198
You need to convert the result to the representation of the result in ASCII. For example, a zero in binary is 0x30 in ASCII. If the number is more than one digit, for example 12, then you need to convert for two ASCII digits (0x31 followed by 0x32). These ASCII representations are the values that you need to send to the LCD.
 

Thread Starter

ewincxz

Joined Oct 14, 2009
3
how am i able to initialise the button i press to ascii value?right now im using this function to do the converting
char getkey(void)
{ char keycode;
const unsigned char lookup[] = "123F456E789DA0BC ";
while (KEY_DA==0); //wait for key to be pressed
keycode=KEY_PORT&0x0F; //read from encoder at portB,mask upper 4 bits
while (KEY_DA==1); //wait for key to be released
return(lookup[keycode]); //convert keycode to its ascii value for LCD

}
however when i do a addition the lcd will display rubbish.
 
Top