#include <REGX51.H>
#include <string.h>
#define LCDdata P2
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
sbit BF=0xA7;
void delay(long time)
{long n;
for(n=0;n<time;n++)
{
;
}
}
void lcd_wait()
{long n=0;
E=1;
RS=0; //ghi lenh
RW=1; // doc dl
LCDdata=0xff;
while(BF) // bit ban
{n++;if(n>100)break;
}
E=0;
RW=0;
}
void lcd_control(unsigned char x)
{E=1;
RS=0;
RW=0;
LCDdata=x;
E=0;
lcd_wait();
}
void lcd_init()
{
lcd_control(0x30);
lcd_control(0x30);
lcd_control(0x30);
lcd_control(0x38);
lcd_control(0x0c);
lcd_control(0x06);
lcd_control(0x01);
}
void lcd_writedata(unsigned char c)
{
RS=1;
RS=0;
LCDdata=c;
E=1;
E=0;
delay(1000);
}
void lcd_write()
{unsigned char i;
E=1;
RS=1;
RW=0;
LCDdata=i;
E=0;
lcd_wait();
}
void lcd_puts(unsigned char *s)
{
while (*s)
{
lcd_writedata(*s);
s++;
}
}
#include <string.h>
#define LCDdata P2
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
sbit BF=0xA7;
void delay(long time)
{long n;
for(n=0;n<time;n++)
{
;
}
}
void lcd_wait()
{long n=0;
E=1;
RS=0; //ghi lenh
RW=1; // doc dl
LCDdata=0xff;
while(BF) // bit ban
{n++;if(n>100)break;
}
E=0;
RW=0;
}
void lcd_control(unsigned char x)
{E=1;
RS=0;
RW=0;
LCDdata=x;
E=0;
lcd_wait();
}
void lcd_init()
{
lcd_control(0x30);
lcd_control(0x30);
lcd_control(0x30);
lcd_control(0x38);
lcd_control(0x0c);
lcd_control(0x06);
lcd_control(0x01);
}
void lcd_writedata(unsigned char c)
{
RS=1;
RS=0;
LCDdata=c;
E=1;
E=0;
delay(1000);
}
void lcd_write()
{unsigned char i;
E=1;
RS=1;
RW=0;
LCDdata=i;
E=0;
lcd_wait();
}
void lcd_puts(unsigned char *s)
{
while (*s)
{
lcd_writedata(*s);
s++;
}
}
Comment