- This topic has 2 replies, 3 voices, and was last updated 10 years, 3 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › Want Help about coding the 16*2 interfacing to lcd for sending the numeric data
This is code to send numeric data on 16*2 lcd using the 8051 plz explain it
void lcd_data(unsigned int i) //Function to send data on LCD
{ int p;
int k=0;
while(i>0)
{
num[k]=i%10;
i=i/10;
k++;
}
k--;
for (p=k;p>=0;p--)
{
c=num[p]+48;
lcd_data_pin = c;
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}
Hi Awais,
I can give you some clues regarding the logic used,
These two lines are the key,
num[k]=i%10;
This will store the value in the unit place of 'i' to 'k' the variable in 'num'
For example if i = 1234, the value of num [k] will be '4'.
Since to diaplay a value like '4' in the lcd we need to convert it to its ascii value first, the following statement does the same,
c=num[p]+48;
Remember ’48’ is the ascii value of ‘0’. (zero)
to display anything on LCD first it must be converted into ASCII
e.g. to display A you have to send its ASCII value 40h
to display a you have to send its ASCII value 63h
to display any number 0 to 9 send 30h to 39h
like wise
the given function first saparate all the digits of any number (eg 254 = 2, 5, 4)
then it converts all number into ASCII by adding 30h = 48 d