I have a LCD display 16x2 connected to a PIC32MX470F512L. On PIC32 I configure all the 6 pins used to interface with the LCD as open drain outputs on 5V tolerant pins, I have 4.7K pull-up on each line (DB4-DB7, EN and RS), as the hardware schematic shows.

A start up of the PIC there is at least 4 seconds (initialization of other hardware connected to the PIC) before the PIC interact with the LCD. For the initialization of the LCD I send:

0x02; /* send for 4 bit initialization of LCD */

0x28; /* 2 line, 5*7 matrix in 4-bit mode */

0x0C; /* Display on cursor off*/

0x06; /* Increment cursor (shift cursor to right)*/

0x01; /* Clear display screen*/

My clock for writing to the pins of LCD is slow speed. When I write to LCD, I set up the logical levels of the pins DB4-DB7 and RS (command/data) according to what is to be writen, wait at least 1ms, put EN (LCD clock) to 1, wait at least 1 ms, put EN to 0, wait at least 1ms before put EN to 1 again (the start of the next character/command)

I did a firmware where the PIC writes "SIMPLE TEST" on the second line of LCD after its initialization.

The behavior is:

(1) I program the PIC and when it start the code, the string "SIMPLE TEST" is shown on the LCD (picture attached)

(2) I program the PIC again and when it start the code, it doens't show the second line string ("SIMPLE TEST"), and the first line LCD is full of dots (picture attached) This is the loop: (1), (2), (1), (2), (1), (2)....

On each reset of the PIC, after each reprogramming (without change anything in code), the results are 1,2,1,2... Reseting the PIC via SoftReset() gives the same loop. One time it works, one time it does not work, in loop. What can be the reason of this, it should always work...

enter image description here

enter image description here

enter image description here

  • 1
    \$\begingroup\$ I don't have the code here but there is a "sequence" (if I recall: of three bytes) you have to send to make sure the interface is 4 bits wide. The sequence has been developed such that it works if the interface starts up in 4 or 8 bit mode. \$\endgroup\$
    – Oldfart
    Commented Feb 20, 2019 at 13:55
  • \$\begingroup\$ Does this answer your question? Hitachi HD44780 LCD works exactly 50% of the time \$\endgroup\$ Commented Aug 14, 2020 at 4:55

1 Answer 1


I found the solution. I need to send commands 0x33 and 0x32 before the commands listed in the original post. Now it's always working

  • 1
    \$\begingroup\$ Sharing what those commands do would be helpful for others. \$\endgroup\$
    – DKNguyen
    Commented Feb 20, 2019 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.