Hi, I'd really appreciate your help, this is driving me mad..
This code works sometimes, if I compile it say 4 times it will run once or twice successfully, the other times the LED's used to trace the code flow were telling me its getting to the Init code but the LCD is not displaying.
I've tried increased timing to silly numbers, I written a GH_delay_ms timer and tested it and its reasonably accurate. I've add delays all over the place without joy, I've reviewed and tried lots of code and LCD codes, but not been able to understand my errors. I've reviewed the data sheets and I'm obviously misunderstanding.
He's my test code, I've pasted it all together in case you would like to run it, thanking you in advance.
Many Thanks Geoff.
Here's a snippet, the full code is attached.
Mod edit: code tags
This code works sometimes, if I compile it say 4 times it will run once or twice successfully, the other times the LED's used to trace the code flow were telling me its getting to the Init code but the LCD is not displaying.
I've tried increased timing to silly numbers, I written a GH_delay_ms timer and tested it and its reasonably accurate. I've add delays all over the place without joy, I've reviewed and tried lots of code and LCD codes, but not been able to understand my errors. I've reviewed the data sheets and I'm obviously misunderstanding.
He's my test code, I've pasted it all together in case you would like to run it, thanking you in advance.
Many Thanks Geoff.
Here's a snippet, the full code is attached.
C:
{
GH_delay_ms(50);
// The data bits must be either a 8-bit port or the upper or
// lower 4-bits of a port. These pins are made into inputs
#ifdef BIT8 // 8-bit mode, use whole port
DATA_PORT = 0;
TRIS_DATA_PORT = 0x00;
#else // 4-bit mode
#ifdef UPPER // Upper 4-bits of the port
DATA_PORT &= 0x0f;
TRIS_DATA_PORT &= 0x0F;
#else // Lower 4-bits of the port
DATA_PORT &= 0xf0;
TRIS_DATA_PORT &= 0xF0;
#endif
#endif
TRIS_RW = 0; // All control signals made outputs
TRIS_RS = 0;
TRIS_E = 0;
RW_PIN = 0; // R/W pin made low
RS_PIN = 0; // Register select pin made low
E_PIN = 0; // Clock pin made low
// Delay for 15ms to allow for LCD Power on reset
GH_delay_ms(15);
LATAbits.LATA2 = 1;
WriteCmdXLCD(0x28);
WriteCmdXLCD(0x28);
WriteCmdXLCD(0x28);
WriteCmdXLCD(LCD_FUNCTION); // 4 bit interface, 2 lines, 5x8 font
WriteCmdXLCD(LCD_DISPLAY_OFF);
WriteCmdXLCD(LCD_CLEAR); // Clear
WriteCmdXLCD(LCD_ENTRY_MODE); // Increment, with display shift
WriteCmdXLCD(LCD_CURSOR_FWD); //
WriteCmdXLCD(LCD_DISP_ON_NO_CURSOR); // Display on and blink cursor
WriteCmdXLCD(LCD_FUNCTION); // 4 bit interface, 2 lines, 5x8 font
}
Attachments
-
42.1 KB Views: 8
Last edited by a moderator: