I have taken a code from a book to display characters on LCD. I ran this code in proteus and it is working perfectly but when I ran it on hardware but it doesn't display anything on LCD except that the back light is on. I know proteus is not 100% correct for hardware. I have been debugging it since morning but nothing got solved. I check voltages, remade the circuit, checked all connections too. Now it's getting so frustrating!
I am using pic18f4520 microcontroller and 16x2 LCD and the compiler is MPLAB. I am attaching my schematic and code here.
P.S. I have read many forums here and did everything, installed potentiometer in the circuits, resistors etc, did reset on the board, tried every possible thing but nothing happens!
This is the schematic :
https://obrazki.elektroda.pl/3234481400_1367694148.png
and here's the code :
#include<p18f4520.h>
#define ldata PORTD
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define en PORTCbits.RC2
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void MSDelay(unsigned int itime);
void main()
{
TRISD = 0;
TRISC = 0;
en = 0;
MSDelay(250);
lcdcmd(0x38);
MSDelay(250);
lcdcmd(0x0E);
MSDelay(15);
lcdcmd(0x01);
MSDelay(15);
lcdcmd(0x06);
MSDelay(15);
lcdcmd(0x80);
MSDelay(15);
lcddata('M');
MSDelay(15);
lcddata('D');
MSDelay(15);
lcddata('E');
}
void lcdcmd(unsigned char value)
{
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void lcddata(unsigned char value)
{
ldata = value;
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}
void MSDelay(unsigned int itime)
{
unsigned i,j;
for(i = 0; i<itime; i++)
for(j = 0; j<135; j++);
}