#include
#define uchar unsigned char
#define uint unsigned int
#define LCDLCDDisp_off 0x3e
#define LCDLCDDisp_on 0x3f
#define Page_Add 0xb8
#define LCDCol_Add 0x40
#define Start_Line 0xC0
#define data_ora P0
sbit LCDMcs=P2^1;//H-选择右半屏信号
sbit LCDScs=P2^2; //H-选择左半屏信号
sbit RESET=P2^3;//低电平复位
sbit LCDDi=P2^4;
sbit LCDRW=P2^5;
sbit LCDEnable=P2^6;
uchar code Hz_xu[]=
{
0x02,0xF2,0x12,0x12,0x1E,0x00,0x80,0x80,0xFF,0xA0,0x90,0x88,0x86,0x84,0x80,0x00,
0x01,0x03,0x41,0x81,0x7F,0x00,0x00,0x40,0xFF,0x40,0x23,0x0C,0x10,0x60,0x20,0x00
};
uchar code jia[]=
{
0x00,0x02,0x02,0xE2,0xAA,0xAA,0xAA,0xAF,0xAA,0xAA,0xAA,0xE2,0x02,0x02,0x00,0x00,
0x82,0x4A,0x2A,0x1E,0x4B,0x8A,0x7A,0x02,0x02,0x7B,0x4A,0x4A,0x7A,0x02,0x02,0x00
};
uchar code de[]=
{
0x10,0x88,0xE4,0x3B,0x12,0x04,0xF4,0x94,0xF4,0x9F,0x94,0xF4,0x94,0xF4,0x04,0x00,
0x01,0x00,0xFF,0x00,0x42,0x3A,0x02,0x3A,0x42,0x4A,0x52,0x42,0x62,0x0A,0x32,0x00
};
void LCDdelay(uint t)
{ uint i,j;
for(i=0;i for(j=0;j<10;j++)
;
}
void CheckState()
{
uchar dat,DATA;
LCDDi=0;//Di=0,表示DB7-DB0为显示指令数据
LCDRW=1;//RW=1,表示数据被读到DB7-DB0
do
{
DATA=0x00;
LCDEnable=1;
LCDdelay(2);
dat=DATA;
LCDEnable=0;
dat=0x80&dat;//仅当第七位为0时菜可操作(判断BUSY信号)
}
while(!(dat==0x00));
}
void write_com(uchar cmdcode)
{
CheckState(); //检查是否忙
LCDDi=0;
LCDRW=0;
P0=cmdcode;
LCDdelay(2);
LCDEnable=1;
LCDdelay(2);
LCDEnable=0;
}
void inti_lcd()
{
LCDdelay(100);
LCDMcs=1; //关闭两屏
LCDScs=1;
LCDdelay(100);
write_com(LCDLCDDisp_off); //关屏
write_com(Page_Add+0); //设置页地址
write_com(Start_Line+0);//设置起始行
write_com(LCDCol_Add+0); //设置起始列
write_com(LCDLCDDisp_on); //开屏
}
void write_data(uchar LCDDispdata)
{
CheckState(); //检查是否忙
LCDDi=1;
LCDRW=0;
P0=LCDDispdata;
LCDdelay(2);
LCDEnable=1;
LCDdelay(2);
LCDEnable=0;
}
void Clr_Scr() //清楚LCD内存程序{
{
uchar j,k;
LCDMcs=0; //打开两屏
LCDScs=0;
write_com(Page_Add+0);
write_com(LCDCol_Add+0);
for(k=0;k<8;k++)
{write_com(Page_Add+k);
for(j=0;j<64;j++)
{
write_com(LCDCol_Add+j);
write_data(0x00);//控制列数0-63,共64列,列表地址自动加1
}
}
}
void hz_LCDDisp16(uchar page,uchar column,uchar code*hzk)
{
uchar j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+page+j);
write_com(LCDCol_Add+column);
for(i=0;i<16;i++)
write_data(hzk[16*j+i]);
}
}
void main()
{
inti_lcd();
while(1)
{
Clr_Scr();
// LCDdelay(500);
LCDMcs=1;
LCDScs=0; //左屏开显示
hz_LCDDisp16(0,32,Hz_xu);//为某个汉字的首地址
LCDMcs=0;//右屏开显示
LCDScs=1;
hz_LCDDisp16(2,0,jia);
hz_LCDDisp16(2,16,de);
LCDdelay(500);
}
}