#include<reg51.h>
#define port P1 /* Data pins connected to port P1 */
sbit RS = P2^0; /* RS pin connected to pin 0 of port P2 */
sbit RW = P2^1; /* RW pin connected to pin 1 of port P2 */
sbit EN = P2^2; /* EN pin connected to pin 2 of port P2 */
void DelayUs(unsigned int wait);
void DelayMs(unsigned int wait);
void LCD_Command(unsigned char cmd);
void LCD_Data(unsigned char Data);
void LCD_init();
/* functions for delay */
void DelayUs(unsigned int wait)
{
wait >>= 3;
while(wait--);
}
void DelayMs(unsigned int wait)
{
while(wait--)
DelayUs(1000);
}
/* Function to send command instruction to LCD */
void LCD_Command(unsigned char cmd)
{
port = cmd;
RS=0;
RW=0;
EN=1;
DelayMs(5);
EN=0;
}
/*Function to send display dato LCD */
void LCD_Data(unsigned char Data)
{
port = Data;
RS=1;
RW=0;
EN=1;
DelayMs(5);
EN=0;
}
/* Function to prepare the LCD */
void LCD_init()
{
LCD_Command(0x38);
DelayMs(15);
LCD_Command(0x0c);
DelayMs(15);
LCD_Command(0x01);
DelayMs(15);
LCD_Command(0x81);
DelayMs(15);
}
//Function to send string to LCD
void Putch(const char *Message)
{
while(*Message != 0)
LCD_Data(*Message++);
}
void PutMessage(const char *Message)
{
Putch((const char *) Message);
}
void LcdGoto(unsigned char x, unsigned char y)
{
x += 0x80;
if(y==1) x+=0x40;
LCD_Command(x);
}
void main(void)
{
LCD_init();
while(1)
{
LcdGoto(1,1);
PutMessage("Hello");
LcdGoto(1,2);
PutMessage("Forum");
}
}