pranavm1502
Newbie level 6
Hi,
I am having problem getting LCD work with this code:
I am having problem getting LCD work with this code:
Code:
// Program to display text on 16x2 LCD using PIC18F4550 Microcontroller
#include <p18f4550.h>
//LCD Control pins
#define rs LATEbits.LATE0
#define rw LATEbits.LATE1
#define en LATEbits.LATE2
//LCD Data pins
#define lcdport LATD
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char data[20]="CheckThisOut";
unsigned int i=0;
void lcd_ini()
{
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
}
void Delay_ms(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<760;j++);
}
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTD
rs=0;
rw=0;
en=1;
Delay_ms(10);
en=0;
}
void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
}
void main(void)
{
ADCON1=0x0F;
TRISE=0; // Configure Port E as output port
LATE=0;
TRISD=0; // Configure Port D as output port
LATD=0;
lcd_ini(); // LCD initialization
while(data[i]!='\0')
{
lcddata(data[i]); // Call lcddata function to send characters
// one by one from "data" array
i++;
Delay_ms(300);
}
}