This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

16x2 LCD problem

Hi,

I am facing some problem in LCD interfacing. Im displaying some characters like "ABCDEX"   4bit mode on TIVAC123GH6PM. It works fine  for some time after that start showing some garbage characters.what can be problem. Also I tested with single character like 'A' it display fine but when I replaced it with 'W' it shows some garbage character. some more characters like 'G' ,'K' also shows garbage. What can be problem.It LCD got corrupted?Also LCD Back-light flickering.

Here is code:


//PB0-3 signal output
//PB4-7 command in/out, data in/out
void PortB_Init(void)
{
SYSCTL_RCGCGPIO_R = 0X02;
while((SYSCTL_PRGPIO_R & 0x02)==0);
GPIO_PORTB_LOCK_R = 0X4C4F434B;
GPIO_PORTB_CR_R = 0xFF;
GPIO_PORTB_AMSEL_R = 0x00;
GPIO_PORTB_AFSEL_R = 0x00;
GPIO_PORTB_PCTL_R = 0X00000000;
GPIO_PORTB_DIR_R = 0xFF;
GPIO_PORTB_DEN_R = 0xFF;
}

void LCD_WriteNibble(uint8_t data,unsigned char control)
{

while(1)
{
//if(LCD_Busy() == 0)
break;
}

GPIO_PORTB_DIR_R = 0xFF; //make portB dir output
data &= 0xF0; //get data bits
control &= 0x0F; //get control bits
GPIO_PORTB_DATA_R = data|control; //data part hinibble
GPIO_PORTB_DATA_R = data|control|EN; //EN=1,RS=0,RW=0
msDelay(2);
GPIO_PORTB_DATA_R &= 0xF0; //EN=0
GPIO_PORTB_DATA_R = 0;
}
void LCD_Write(uint32_t data)
{
LCD_WriteNibble(data & 0xF0,RS); //hiniible data
LCD_WriteNibble(data << 4,RS); //lownibble data
}

void LCD_Command(uint8_t cmd)
{
LCD_WriteNibble(cmd & 0xF0,0); //hiniible command
LCD_WriteNibble(cmd << 4,0); //low nibble of command

if(cmd < 4)
msDelay(2);// 2 milisec delay
else
usDelay(40);
}


void LCD_Init(void)
{
PortB_Init(); //initialize port

msDelay(20); //LCD initialization
LCD_WriteNibble(0x30,0);
msDelay(20);
LCD_WriteNibble(0x30,0);
msDelay(20);
LCD_WriteNibble(0x30,0);
msDelay(20);
LCD_WriteNibble(0x20,0); // use 4-bit data mode
usDelay(40);

LCD_Command(0x28); //set 4-bit data,2-line,5x7 font
LCD_Command(0x05); //move cursor left after write a character
LCD_Command(0x01); //clear screen .move cursor to home
LCD_Command(0x0F); //turn on Display,cursor blinking

}

int main(void)
{
LCD_Init();
while(1)
{
LCD_Command(0x01); //clear screen .move cursor to home
LCD_Command(0x8F); //lcd cursor location
//LCD_Command(0x0C); //Display on cursor off

msDelay(500);//500milisec delay

LCD_Write('A');msDelay(100);
LCD_Write('B');msDelay(100);
LCD_Write('C');msDelay(100);
LCD_Write('D');msDelay(100);
LCD_Write('E');msDelay(100);
LCD_Write('F');msDelay(100);
LCD_Write('X');msDelay(100);
LCD_Write('Y');msDelay(100);
LCD_Write('Z');msDelay(100);

msDelay(500);

}

}

Please help in this regard.

Thanks,

Dheeraj

  • Hello Dheeraj,

    Which LCD panel is this? Also when writing the data to the LCD Panel can you confirm what is being written on the LCD bus?
  • Dheeraj Saxena said:
    ... tested with single character like 'A' displays fine - when replaced with 'W' it shows garbage .   Characters like 'G' ,'K' also show garbage.   What can be problem?

    Have you opened an ASCII Character Table and looked to see what's "common" between "W, G & K?"   It is likely that you've got a bad connection or intermittent which prevents the proper bits from reaching the Lcd connector.    Finding the "common bit" should resolve your issue.

    When you report "random characters arriving - after some time" that may be the result of "noise" (which is far more noted when "4 bit mode is chosen" or may be your program (inadvertently) toggling the "E" line.   Whatever is on the 4 bit Lcd bus (D7-D4) at the time of the "E" pulse will appear upon the display.

    For most applications the "saving" of 4 GPIO can not be justified by the additional pain/suffering you'll incur - both now AND into the future...

  • Hello cb1

    I suspect it to be less of intermittent, but more on (a) Bad connection and/or (b) misconfiguration of the panel.
  • As always - poster's use of, "4 Bit Text Lcd Mode" subjects he/she to endless "Pain/Suffering."

    Never is the "desire to save 4 GPIO" explained nor justified...

  • Hello Amit,

    I am using RG1602A v2.0 LCD panel. In debug mode it works fine whatever data comes on bus got written on LCD,even in free run mode also works fine for sometime like 5-10 min but after that start giving problem.

    Earlier i used 8 bit mode with upper line fixed and lower line moving it working fine,but 4bit mode giving problem.

    Regards,

    Dheeraj

  • Hello Dheeraj

    It suggests that (a) there is a problem with the LCD panel for 4-bit mode and/or (b) there is some configuration that has not been done correctly.

    To be able to debug the issue, you would need to monitor the configuration in 4-bit mode using an LA and see if they are expected as per the datasheet of the LCD panel.
  • Dheeraj Saxena said:
    Earlier i used 8 bit mode with upper line fixed and lower line moving it working fine,but 4bit mode giving problem.

    That's quite common - and results from the unwanted clocking of the "E" strobe line - via noise or program glitch.

    The best cure for such is:

    • add proper filter to the "E" signal line - as close as possible to that Lcd pin
    • periodically re-initialize the display - which restores proper operation - especially helpful to the uber-demanding "4 bit mode!"

    Eight bit mode - along w/being faster & much easier to code - is NOT DOOMED to suffer, "Nibble Offset" which frequently plagues "4 Bit or Bust" users...

  • Hi,

    Some comments about your code and problems:

    1) You do not need to unlock anything on port B; only port F or D need such, for special NMI pins.

    2) set starting address of display RAM (DDRAM) at 0x80 for the first line and 0xC0 for the second line. Seems you write twice on the same location, so the display RAM is normally garbage. Take into account you have an clear screen command to use after writing on both lines. Do write your own function to clear a single line - it is a simple for loop to write 0x20 (blank) character, 16 times.

    3) your display is a +5V one, according to the data sheet.

  • Thanks,
    I'm in training so learning both DRA & API methods to understand how h/w behaves.
    As per suggestion I periodically re-initialised LCD and also added 1us delay in between writing nibble and 'E' strobe disable/enable.
    so now its working fine not giving strange characters even the missing letter 'W' 'G' etc coming properly.
    Still could not understood when using portF LED flash and PortB for LCD display why it is not working properly as they are two separate port so how they affecting.
    When initialised portF and LCD outside while loop than it does not work.which ever initialised first outside is used first indiside while loop works only once.
    i.e.
    portF_Init()
    LCD_Init()
    while(1)
    {
    flash_led; //this runs once only
    Display_LCD //this runs but gives fault on data &= 0xF0; in code mentioned in previous mail..
    }
    also if i reverse i.e. first do LCD_Init() then portF_Init() nothing works.
    Similarly if I initialise LCD first and inside while loop use LCD Display first then display happens only once.
    For continuous working I have to initialise both portF_Init() and LCD_Init() just before use.

    Regards,
    Dheeraj
  • Hi,

    Good to know you started thinking/learning APi. Suggest to start also reading the user manual,  GPIO chapter - try to understand bit-banging operation - this allows you to set/clear a bit or a group of bits of a port without disturbing the others - useful for toggling E line.

    Your posted void LCD_Write(uint32_t data) function could be wrong or acting wrong - the two line inside uses a "RS" parameter which may be wrong. Add a second parameter to your above function to reflect what you mean.

    Suggest also that after the two nibbles written add a small delay, start with 40us, some users reported to uses up to 80us, depends on LCD brand.