code:-
LCD.h
sbit rs = P0^0;
sbit rw = P0^1;
sbit en = P0^2;
void delay(unsigned int dela)
{
unsigned int l,mm;
for(mm=0;mm<100;mm++)
for(l=0;l<dela;l++);
}
void lcdcmd(unsigned char cmd)
{
P2 = cmd;
rs = 0;
rw = 0;
en = 1;
delay(15);
en = 0;
delay(150);
}
void datawrt_lcd(unsigned char datas)
{
P2 = datas;
rs = 1;
rw = 0;
en = 1;
delay(15);
en = 0;
delay(150);
}
void display_lcd(unsigned int row, unsigned int colum, unsigned char *lcdstr)
{
if(row==1)
{
lcdcmd(0x80 + colum);
}
else if(row==2)
{
lcdcmd(0xc0 + colum);
}
while (*lcdstr !='\0')
{
datawrt_lcd(*lcdstr);
lcdstr++;
}
}
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0C);
lcdcmd(0x01);
lcdcmd(0x80);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
main.c
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<reg51.h>
#include "lcd.h"
void main()
{
lcd_init();
while(1)
{
display_lcd(1,4,"Hello World!");
}
}
Comments
Post a Comment