scorrpeio
Full Member level 5
Hello,
I have connected 16x2 LCD module to PIC18F4520.
Pin configuration->
EN - RA1
RW- RA2
RS - RA3
D4-D7 - RD4-RD7
I have written this code...
I took this link as reference...
LCD Commands and Instructions: LCD Tutorial for interfacing with Microcontrollers : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes
However, when I see output on screen, the 4-5 vertical lines blink 2 times and then nothing happens.
As per the code, i should get the blinking cursor. This is my first time to program LCD, so no idea if I am doing rite or wrong.
Can you please tell me, where did I do mistake?
I have connected 16x2 LCD module to PIC18F4520.
Pin configuration->
EN - RA1
RW- RA2
RS - RA3
D4-D7 - RD4-RD7
I have written this code...
Code:
void InitialiseDisplay(void)
{
ResetDisplay();
SendCommandToLCD(0x28); //4 bit interface 2 line First Initialise
Delay(1);
SendCommandToLCD(0x0C); //Display cursor off
Delay(1);
SendCommandToLCD(0x06); //Entry Mode
Delay(1);
SendCommandToLCD(0x0F);
Delay(1);
}
void ResetDisplay( void )
{
Delay(10);
TRISA = 0x00; //Set RA1 - RA3 as o/p
TRISD = 0x00; //Set port D as o/p
Delay(1);
PIN_ENABLE_LCD = 0;
PIN_RW_LCD = 0;
PIN_RS_LCD = 0;
//SendCommandToLCD(0x02);
SendCommandToLCD(0x03); //First Initialise
Delay(10);
SendCommandToLCD(0x03); //Second Initialise
Delay(1);
SendCommandToLCD(0x03); //Third Initialise
Delay(1);
SendCommandToLCD(0x02);
Delay(1);
}
void SendCommandToLCD( unsigned int uiCommand )
{
DATA_LCD = uiCommand >> 4; //Send MSB nibble
PIN_ENABLE_LCD = 1;
//Delay(15);
PIN_ENABLE_LCD = 0;
DATA_LCD = uiCommand & 0x0F; //Send LSB nibble
PIN_ENABLE_LCD = 1;
//Delay(15);
PIN_ENABLE_LCD = 0;
Delay(1);
}
void SendDataToLCD ( unsigned int uiData )
{
DATA_LCD = uiData >> 4; //Send MSB nibble
PIN_RS_LCD = 1;
PIN_ENABLE_LCD = 1;
PIN_ENABLE_LCD = 0;
PIN_RS_LCD = 0;
DATA_LCD = uiData & 0x0F; //Send LSB nibble
PIN_RS_LCD = 1;
PIN_ENABLE_LCD = 1;
PIN_ENABLE_LCD = 0;
PIN_RS_LCD = 0;
Delay(1);
}
void Delay ( unsigned int uiIndex1 )
{
unsigned int uiIndex;
for( uiIndex = 1000; uiIndex > 0; uiIndex-- )
{
for( ; uiIndex1 > 0; uiIndex1-- )
{
//do nothing
}
}
}
I took this link as reference...
LCD Commands and Instructions: LCD Tutorial for interfacing with Microcontrollers : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes
However, when I see output on screen, the 4-5 vertical lines blink 2 times and then nothing happens.
As per the code, i should get the blinking cursor. This is my first time to program LCD, so no idea if I am doing rite or wrong.
Can you please tell me, where did I do mistake?