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...