i have the following code for writing to the LCD as below:
Code:
/* Write text data in term of 4-bit at a time to LCD */
void W_data_4bit (char x)
{
LCD_RW = 0; // Logic ‘0’
LCD_RS = 1; // Logic ‘1’
LCD_TEMP = x; // Store text data
LCD_TEMP >>= 4; // Send upper nibble of text data
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay1KTCYx(1); // 1ms delay
LCD_E = 0; // Logic ‘0’
Delay1KTCYx(1); // 1ms delay
LCD_TEMP = x; // Store text data
LCD_TEMP &= 0x0f; // Send lower nibble of text data
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay1KTCYx(1); // 1ms delay
LCD_E = 0; // Logic ‘0’
Delay1KTCYx(1); // 1ms delay
}
I understand it has to be sent in a byte to the LCD for display and my ADC values has to be in ASCII code.
Hence my coding below to send out the ASCII code for display
Code:
itoa(t,Buffer); // Convert number in variable t to a string and store in variable Buffer
for (i = 0; i < 4; i++)
{
W_data_4bit(Buffer[i]);
}
Unfortunately, my LCD is not displaying anything so i suspect my coding somewhere is wrong but i cant pinpoint where is the mistake.
I understand it is tedious but are you able to help me look through for errors ?
Thank you very much.
Yes, i am able to see "Hello World" when it is stored as a const rom char MESS[12] = "Hello World"
I am rather new to programming so my explanations may not be as clear and concise.
I seek your understanding but pls do guide me along. Thanks.
I will try out your short test when i get home after work and i will post my results after that.
For info, this was the sample prog i used to output my "Hello World" which is also the one i tweaked to output my temperature reading.
Code:
const rom char MESS[12] = "Hello World";
void main(){
ADCON1 = 0x0F; // Set Port A & E as digital I/O
TRISA = 0b11110001; // bit 1, 2 & 3 of Port A as output
TRISD = 0; // Port D as output
Init_LCD(); // Init LCD 4-bit interface, multiple line
for (i = 0; i < 11; i++) // Output message to LCD
W_data_4bit(MESS[i]); // Write individual character to LCD
while(1); // Endless loop
}
All is based on your affirmation: it's working with Hello World test....
It doesn't works with 1023 !!!
I don't undertsand why, because caracteres are in ROM area like you message Hello World.
The only difference with your working example ,is that you didn't used ligne positionning on LCD
Just writing after init_LCD..
try again to wrtite 1023 without using "W_ctr_4bit(0x80);" in the loop
maybe this function point outside of memory area display.
The other difference i saw in your previous test
is using RAM buffer
Store your adc result to floating point variable instead of integer variable. If number is 25.345 then multiply it with 1000 to get 25345 then subtract 25000 from 25345 to get 345 then convert 25 and 345 to string and display on lcd.
Lets say i just want to put the temperature at 25.3, so i will multiply by 10 to get 253.
Code:
unsigned float t=0;
val = ADRESH & 0xff;
t = ((val/255.0) * 500);
t = t *10; // 253
t = ?? // So how do i subtract 250 here since it wont be 250 everytime ??
itoa(t,Buffer); // Using my method to show on LCD, how do i convert to 25 and 3 to ascii and then show on LCD ??
for (i = 0; i < 4; i++)
{
W_data_4bit(Buffer[i]);
Delay1KTCYx(5);
}
I can understand the method but i have difficulty adapting it in terms of coding.
Are you able to help me ?