ALL ... OK, got an inexpensive 20 x 4 line LCD off eBAY... It uses the Sitronix ST7066 controller...
Here is my XC8 programming, it works... May not be fastest or most efficient....
First, check the "busy flag". Is it clear?
void wait4BFclr(void){
byte btemp;
TRISD = 0xFF; // Set PORTD to input ...
LCD_RS = 0;
LCD_RW = 1; Nop(); Nop();
BFchk: Nop();
LCD_EN = 1; Nop(); Nop();
btemp = PORTD;
btemp &= 0x80;
LCD_EN = 0;
if (btemp == 0x80) goto BFchk;
}
HERE is the function that does the work ........................
// FUNCTION initLCD --- EIGHT bit interface .................
//
// RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
// 0 0 0 0 1 1 x x x x (0x30)
//
// 0 0 0 0 1 1 x x x x
//
// 0 0 0 0 1 1 N F x x (0x30) FUNCTION SET
// 0 0 0 0 0 0 1 0 0 0 (0x08) DISPLAY OFF
// 0 0 0 0 0 0 0 0 0 1 (0x01) DISPLAY CLEAR
// 0 0 0 0 0 0 0 1 I/D S (0x06) FUNCTION SET
//
// END of initLCD
void initLCD(void){
byte btemp;
TRISD = 0xFF; // Set PORTD to INPUT ...
//
LCD_EN = 0; LCD_RW = 0; LCD_RS = 0;
LCD_PWR = 1; BACKLIGHT = 1; // POWER on .....
LCD_PORT = 0b00110000; // INIT state, PORTD latch bits ....
//
for (btemp=0; btemp<6; btemp++) Delay_msec(20);
Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); // WAKE up time ...
writeLCDcmd(0x38); // OR 0x30
?
Delay_msec(20);
Nop(); Nop(); Nop();
//
writeLCDcmd(0x38); // DO again ...
Delay_msec(20);
Nop(); Nop(); Nop();
//
writeLCDcmd(0x38); // DO again ...
Delay_msec(20);
Nop(); Nop(); Nop();
//
writeLCDcmd(0x08); //
Delay_msec(20);
Nop(); Nop(); Nop();
//
writeLCDcmd(0x01); //
Delay_msec(20);
Nop(); Nop(); Nop();
//
writeLCDcmd(0x06); //
Delay_msec(20);
Nop(); Nop(); Nop();
//
wait4BFclr();
homeLCD();
wait4BFclr();
dispLCD();
wait4BFclr();
}
Easy to debug, and it works ....
Hope this helps ............................