联系人:刘小姐,李小姐,王小姐
Tel:010-62000662,62051209
Fax:010-82036512
Mobile:13701081790
Email:bjqingda@126.com
Web:www.tsingtek.com
QQ:453189731
微信:13701081790
地址:北京市海淀区花园东路32号花园公寓A402室液晶模块HG128641与8051单片机应用示例-2
液晶模块HG128641与8051单片机应用示例-2 接上一篇
四‘、液晶模块HG128641与8051单片机连接电路图:
五、HG128641与8051单片机示例程序(写指令写数据等主要子程序)
/************
延时子程序
*****************/
void Delay(uint t)
{uint i,j;
for(i=0;i<t;i++)
for(j=0;j<305;j++)
_nop_();_nop_();_nop_();_nop_();
}
/***********
忙判断子程序
************/
void Busy()
{
A0=0;
RW=1;
buslcd=0xff;
E=1;
_nop_();
while(buslcd&0x80);
E=0;
_nop_();
}
/*********************
写入左半屏指令 子程序
**********************/
void Writecom1(uchar wcom)
{
CS1=1;CS2=0;
Busy();
buslcd=wcom;
A0=0;
RW=0;
E=1;
_nop_();
E=0;
_nop_();}
/*********************
写入左半屏数据 子程序
**********************/
void Writedata1(uchar wdata)
{
CS1=1;CS2=0;
Busy();
buslcd=wdata;
A0=1;
RW=0;
E=1;
_nop_();
E=0;
_nop_();}
/*********************
写入右半屏指令 子程序
***********************/
void Writecom2(uchar wcom)
{
CS1=0;CS2=1;
Busy();
buslcd=wcom;
A0=0;
RW=0;
E=1;
_nop_();
E=0;
_nop_();}
/************************
写入右半屏数据 子程序
*************************/
void Writedata2(uchar wdata)
{
CS1=0;CS2=1;
Busy();
buslcd=wdata;
A0=1;
RW=0;
E=1;
_nop_();
E=0;
_nop_();}
/*********************
读出左半屏数据 子程序
**********************/
uchar Readdata1()
{
uchar rdata;
CS1=1;CS2=0;
Busy();
A0=1;
RW=1;
E=1;
rdata=buslcd;
_nop_();_nop_();_nop_();
E=0;
_nop_();
return rdata;
}
/**********************
读出右半屏数据 子程序
****************************/
uchar Readdata2()
{
uchar rdata;
CS1=0;CS2=1;
Busy();
A0=1;
RW=1;
E=1;
rdata=buslcd;
_nop_();_nop_();_nop_();
E=0;
_nop_();
return rdata;
}
/*********************
清屏子程序
****************************/
void Clear(void)
{uchar i,j;
for(i=0;i<8;i++)
{Writecom1(0xb8+i);Writecom1(0x40);
Writecom2(0xb8+i);;Writecom2(0x40);
for(j=0;j<64;j++)
{Writedata1(0);Writedata2(0);}}
}
/**********************
液晶初始化子程序
***********************/
void INT()
{
Delay(3);
Writecom1(0x3f);
Writecom2(0x3f);
Writecom1(0xc0);
Writecom2(0xc0);
Writecom1(0xb8);
Writecom2(0xb8);
Writecom1(0x40);
Writecom2(0x40);
Clear();
}