#include <p18f46k22.h>
#include <delays.h>
#define LCD_DATA PORTD
#define LCD_RS PORTDbits.RD4
#define LCD_RW PORTDbits.RD5
#define LCD_EN PORTDbits.RD6
#define LCD_PWR PORTDbits.RD7
void Init_LCD(void);
void disCmd(unsigned char);
void disData(unsigned char);
void lcdCmd(unsigned char);
void lcdData(unsigned char);
void LCD_STROBE(void);
void string(char);
void main()
{
ADCON1 = 0x0f;
OSCCON = 0x36;
TRISD = 0;
Init_LCD();
disCmd(0x80);
string("HELLO WORLD");
disCmd(0xc0);
string("IT IS WORKING:-)");
}
//****************************************************************************************************
/* LCD display initialization */
void Init_LCD()
{
disCmd(0x02);
disCmd(0x82);
disCmd(0x60);
disCmd(0xc0);
disCmd(0x80);
disCmd(0x30);
disCmd(0x10);
}
void LCD_STROBE(void)
{
LCD_EN = 1;
Delay1KTCYx(0.001);
LCD_EN = 0;
}
void string(char q)
{
while(q)
disData(q++);
}
void disCmd(unsigned char cmdValue)
{
unsigned char cmdValue1;
cmdValue1 = PORTD;
cmdValue1 &= 0xf0;
cmdValue1 = cmdValue1 | (cmdValue & 0x0f);
lcdCmd(cmdValue1);
}
void disData(unsigned char dataValue)
{
unsigned char dataValue1;
dataValue1 = PORTD;
dataValue1 &= 0xf0;
dataValue1 = dataValue1 | (dataValue & 0x0f);
lcdData(dataValue1);
}
void lcdCmd(unsigned char cmdOut)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = (cmdOut >> 4);
LCD_STROBE();
LCD_DATA = cmdOut;
LCD_STROBE();
}
void lcdData(unsigned char dataOut)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = (dataOut >> 4);
LCD_STROBE();
LCD_DATA = dataOut;
LCD_STROBE();
}