I finally got my LCD working and now I can write anything to the LCD.
For next step, I am trying to put the value of ADC0 to LCD
I an able to get the ADC running and have verified it by putting the output to LED's on Port B. The LCD is connected on PORT D (data) and Port A (Control 1-3)
Now problem is that I am not able to tranfer ADC value to LCD. I think I am having some problem in Char to function tranfer. The code compiles fine, so I cannot debug it.
My MAIN code is
unsigned char val0;
while(1)
{
val0 = ReadAdcChannel(0);
lcd_goto(0); // select first line
lcd_puts(val0);
PORTB=val0;
}
If you need to format an integer or float value to send to a display, you can use the sprintf function that is defined in stdio.h.
Example:
Code:
#include <stdio.h>
void display_value(void)
{
unsigned int value = 22;
char buffer[16]; /* size of line on display */
sprintf(buffer, "Value is %d", value); /* Same formatting options as printf */
display_line(buffer); /* Your call to display function */
}
If you look at the character map of your display, you will find that 'T' is represented as the 8 bit number 0x54. This is the ascii code for 'T'.
The ascii code for the number 0 is 0x30 and for 1 it is 0x31. So if you take a digit and add 0x30 to it you get the ascii code for the digit.
a = 0x30 + 1;
lcd_puts(a); will display 1.
You need to convert your ADC reading value to ascii codes to display it on the lcd.
sprintf does this for you with formatting options.
If you look at the character map of your display, you will find that 'T' is represented as the 8 bit number 0x54. This is the ascii code for 'T'.
The ascii code for the number 0 is 0x30 and for 1 it is 0x31. So if you take a digit and add 0x30 to it you get the ascii code for the digit.
a = 0x30 + 1;
lcd_puts(a); will display 1.
You need to convert your ADC reading value to ascii codes to display it on the lcd.
sprintf does this for you with formatting options.
It depends on what compiler you are using.
But they should all support the basic options.
d, i Print an int as a signed decimal number.
u Print decimal unsigned int.
f, F Print a double in normal (fixed-point) notation.
x, X Print an unsigned int as a hexadecimal number. 'x' uses lower-case letters and 'X' uses upper-case.
o Print an unsigned int in octal.
s Print a character string.
c Print a char (character).
You are asking it to print a char? %c
Ask it to print a unsigned int. %u