I want to get two independent digits from the user and then merge them into a single byte. Like first digit is “1” ( tens place), and next is “5” (units place). I want to store it as “15” and then read it and display as “15”. The code snippet is as below :
byte numval, tYear, uYear, year ;
numval = 1;
tYear = numval<<4;
uYear = 5;
year = tYear + uYear ;
tempYear = bcdToDec(EEPROM.read(4)) ;
What is wrong with above approach ??
First - are you getting these bytes from the user as ASCII? ASCII encodes characters as numbers, as described in any ASCII table. (eg: http://www.asciitable.com/ ). So the value of the ASCII digit ‘0’ is the number 0x30 (hecadecimal), 48 (Decimal), or XLVIII (roman numnerals). THe reason I mention roman numerals is to try to help you understand that a number is not the same thing as how it is written down.
So if the user input comes to you as ASCII (which seems to be what is hapenning), you need to subtract 0x30, 48, or better yet ‘0’ from the value to get it as a numeric quantity from 0-9.
Apart from that, yes this code would appear to store it as a BCD encoded value in year. And if the lcd.print function undertands that a byte is a numeric value that it needs to expand, then the print functrion should work.
What I would tend to do, rather than giving your entire program to this board, it to make up a snippet that compiles and runs on its own. Just write a short sketch whose setup() includes the code above and whose loop() does nothing.