16×2点阵字符型LCD模块Keil C51驱动程序
#i nclude
#define uchar unsigned char
idata char flag0 ;
idata char flag1 ;
idata char flag2 ;
idata char flag3 ;
idata char flag4 ;
idata char flag5 ;
idata char flag6 ;
idata char flag7 ;
sbit RS=P2^3;
sbit RW=P2^4;
sbit LCDE=P2^5;
sbit big=P3^2;
sbit fd=P3^3;
unsigned char line1[16],line2[16];
unsigned char code cgram1[64]={0x00,0x1f,0x12,0x09,0x1f,0x11,0x01,0x0f,
0x1e,0x04,0x04,0x08,0x1f,0x01,0x00,0x1e,
0x02,0x03,0x06,0x05,0x04,0x09,0x09,0x12,
0x00,0x1c,0x04,0x08,0x10,0x18,0x04,0x07,
0x00,0x0f,0x09,0x09,0x0f,0x09,0x09,0x0f,0x00,0x1c,0x04,0x04,0x1c,0x04,0x04,0x1c,
0x00,0x04,0x14,0x14,0x14,0x04,0x04,0x03,0x00,0x12,0x13,0x11,0x01,0x04,0x04,0x1c};/
void delay5ms()
{
register int i;
for (i=0;i<1000;i++)
;
}
void delay50us()
{
register int i;
for (i=0;i<20;i++)
;
}
wr_com(unsigned char comm)
{
LCDE=0;
RS=0;
RW=0;
LCDE=1;
P0=comm;
RS=0;
RW=0;
LCDE=0;
}
wr_data(unsigned char dat)
{
LCDE=0;
RS=0;
RW=0;
RS=1;