Serial interface LCD-09395 ATMEGA328

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

 

I working in a school project and I need to print two informations on the LCD.

First line: TARGET: (value entered by the user) PSI

Second line: MEASURED (value measured) PSI.

The code is working as desired when I use the putty to check the results. However, when I connect the LCD, the text keep scrolling and I can't read it properly. I found at the LCD manual the control character and commands to set the cursor position. My question is, how I can tell to the LCD microcontroller the information is a command and not a data to display? The printByte does not work.

I'm using the ATMEGA328P and LCD serial enabled 09395. 

Follow a piece of my code:

    printByte(0xFE);                        //control character from LCD manual
    printByte(0x80);                        //Set cursor position from LCD manual
    printString("Measure: ");
    printInt(pressure);                     //Pressure read PSI
    printString(" PSI");
    printString("\n\r ");
    printByte(0xFE);                        //control character
    printByte(0xC0);                       //Set cursor position 1,0
    printString("TARGET: ");
    printInt(pressureSet);               //User pressure set 
    printString(" PSI");
    printString("\n\r ");

 

Thanks a lot for your attention.

 

Ramon

This topic has a solution.
Last Edited: Tue. Feb 25, 2020 - 10:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure you don't mean LCD-09395 (that is with an added 9) that is:

 

https://www.sparkfun.com/products/9395

 

But yeah, if you have a 2 line LCD you can't do the same as you do with a UART terminal (where there's virtually infinite "scroll back") so you can't really use "\r\n" at all. Instead most LCD have the concept of LCDgotXY() that you use before each item you print. So if you are going to print at the start of the first line you might goto(0,0) (could be 1,1 depending on the counting ordinals) and if you wanted the next thing in column 10 on that same line you might goto(10, 0). then to get onto the next line perhaps goto(0, 1) and in column 8 on that line goto(8, 1) etc etc

 

While "\r\n" (start of line then down onto next line" might work once if you happen to be towards the end of the first of the 2 LCD lines then after that it generally will just mean "scroll everything up so the top line scrolls off the top". Not what you want.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You did not show us your USART init code, but if it is not sending 8 bit data, i.e. such as 7N1, then 8 bit characters will not be sent correctly so the "command" byte 0xFE will be sent as 0x7E.

By any chance did you init your USART as 7 bit data size?

Jim

 

 

 

 

 

Last Edited: Thu. Feb 20, 2020 - 08:06 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks all for your attention. Each one of had very good points. the code is working now as supposed to be. I just would like to share the solution.  Basically what  I was looking for is the function transmitByte. 

 

Thanks again

 

Ramon 

 

  void transmitByte(uint8_t data) {
                                     /* Wait for empty transmit buffer */
  loop_until_bit_is_set(UCSR0A, UDRE0);
  UDR0 = data;                                            /* send data */
}
 

    transmitByte(0xFE);                        //Control Char
    transmitByte(0x80);                        //Set position
    printString("Measure: ");
    printInt(pressure);
    printString(" PSI");

    transmitByte(0xFE);                        //Control Char
    transmitByte(0xC0);                        //Set position
    printString("Desired: ");
    printInt(pressureSet);    
    printString(" PSI");