scorrpeio
Full Member level 5
Hi...
I have interfaced the LCD with PIC18F4520 as...
EN - RA1
RW- RA2
RS - RA3
D4-D7 - RD0-RD3
The code I wrote, goes as follows...
I have called InitialiseDisplay() function in the main().
However, when I see the output on the screen...I could see this... ||| ||
blinks for few seconds and the disappears and then nothing happens.
I have sent the command of blinking cursor...so it keeps on blinking on the screen, but it seems that there is bug in the code.
Can anyone plz tell me what goes wrong with this code?
I have interfaced the LCD with PIC18F4520 as...
EN - RA1
RW- RA2
RS - RA3
D4-D7 - RD0-RD3
The code I wrote, goes as follows...
Code:
#define PIN_ENABLE_LCD PORTAbits.RA5
#define PIN_RW_LCD PORTAbits.RA2
#define PIN_RS_LCD PORTAbits.RA3
#define DATA_LCD PORTD
void InitialiseDisplay(void)
{
ADCON1 = 0x0F; // Disable Analog INput
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;
PIN_ENABLE_LCD = 0;
Delay(1);
DATA_LCD = uiCommand & 0x0F; //Send LSB nibble
PIN_ENABLE_LCD = 1;
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;
Delay(1);
PIN_ENABLE_LCD = 0;
PIN_RS_LCD = 0;
DATA_LCD = uiData & 0x0F; //Send LSB nibble
PIN_RS_LCD = 1;
PIN_ENABLE_LCD = 1;
Delay(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 have called InitialiseDisplay() function in the main().
However, when I see the output on the screen...I could see this... ||| ||
blinks for few seconds and the disappears and then nothing happens.
I have sent the command of blinking cursor...so it keeps on blinking on the screen, but it seems that there is bug in the code.
Can anyone plz tell me what goes wrong with this code?