Hi guys
I am learning C18 and trying to get a HD44780 LCD display working, like I have done millions of times in assembly (well, maybe not millions).
First up, here's the code:
The Pulse_E and LCD_Delay routines:
I am running the PIC at 64MHz (overclocked). However even when I use the internal oscillator @ 1MHz, it still doesn't work.
Although if I put breakpoints on 'LCD_E = 0' and 'LCD_E = 1' in the Pulse_E routine and step between breakpoints by hand, it works.
I have read the data sheet and tried following all of the timing requirements (including data setup time, E cycle and pulse time, and delay between commands) but have no idea why this one is playing up
I have tried more than 1 screen and the result is the same (unfortunately).
If anybody can see my (possibly glaring) mistake, can you point it out and put me out of my misery please
I am learning C18 and trying to get a HD44780 LCD display working, like I have done millions of times in assembly (well, maybe not millions).
First up, here's the code:
Code:
LCD_E = 1; // Sets the enable line (the default idle state)
Delay10KTCYx(160); // Waits 100 milliseconds to make sure the LCD is powered on properly
LCD_Port = LCD_Port & 0b11110000; //Clears the bits of the LCD data port
LCD_Port = LCD_Port + 3; // Puts the first initialisation data onto the port
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
Pulse_E();
LCD_Delay();
Pulse_E();
LCD_Delay();
LCD_Port = LCD_Port - 1;
Nop();
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 8;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 0;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 8;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 0;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 1;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 0;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
LCD_Port = 4;
Nop();
Nop();
Nop();
Nop();
Pulse_E();
LCD_Delay();
The Pulse_E and LCD_Delay routines:
Code:
void Pulse_E(){ // Pulses the LCD Enable line
LCD_E = 0;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
LCD_E = 1;
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void LCD_Delay(){
Delay10KTCYx(8); // Equal to about 5 milliseconds with a 64MHz clock
}
I am running the PIC at 64MHz (overclocked). However even when I use the internal oscillator @ 1MHz, it still doesn't work.
Although if I put breakpoints on 'LCD_E = 0' and 'LCD_E = 1' in the Pulse_E routine and step between breakpoints by hand, it works.
I have read the data sheet and tried following all of the timing requirements (including data setup time, E cycle and pulse time, and delay between commands) but have no idea why this one is playing up
I have tried more than 1 screen and the result is the same (unfortunately).
If anybody can see my (possibly glaring) mistake, can you point it out and put me out of my misery please