原创
ST7920汉字点阵LCD的接口程序(间接方式)
/**********************************************************
* ST7920控制器间接方式驱动程序 *
* 12832点阵 使用P0和 *
* RS,RW,E *
* 2006.1 *
**********************************************************/
/******************/
/**/
#include <reg52.h>
#include <intrins.h>
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P3^5;
unsigned char DisBuf1[17]; //第一行的显示缓冲
unsigned char DisBuf2[17]; //第二行的显示缓冲
unsigned char ReadInst() //读BF标志及AC计数器
{
unsigned char temp;
EA = 0;
RS = 0; //0:指令,1:数据
RW = 1; //0:写,1:读
E = 1;
temp = P0;
E = 0;
EA = 1;
return(temp);
}
unsigned char ReadData()
{
unsigned char temp;
EA = 0;
RS = 1; //0:指令,1:数据
RW = 1; //0:写,1:读
E = 1;
temp = P0;
E = 0;
EA = 1;
return(temp);
}
void WriteInst(unsigned char Inst)
{
EA = 0;
RS = 0; //0:指令,1:数据
RW = 0; //0:写,1:读
P0 = Inst;
E = 1;
_nop_();
E = 0;
EA = 1;
}
void WriteData(unsigned char Inst)
{
EA = 0;
RS = 1; //0:指令,1:数据
RW = 0; //0:写,1:读
P0 = Inst;
E = 1;
_nop_();
E = 0;
EA = 1;
}
void InitLCD()
{
//wait for 40mS
while(ReadInst() & 0x80); //等待BF忙标志
// {
// if(i--)break;
// }
WriteInst(0x30); //Function Set: 8bit MPU interface,基本指令集
//wait for 100uS
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(0x30); //Function Set: 8bit MPU interface,基本指令集
//wait for 37uS
while(ReadInst()& 0x80); //等待BF忙标志
// WriteInst(0x0F); //显示状态:整体显示ON,光标ON,光标反白ON
WriteInst(0x0C); //显示状态:整体显示ON,光标OFF,光标反白OFF
//wait for 100us
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(0x01); //清屏
//wait for 10mS
while(ReadInst()& 0x80); //等待BF忙标志
WriteInst(0x06); //进入点设定:光标右移,AC+1
}
void DispStr(unsigned char StartAddr,unsigned char *star)
{
unsigned char temp;
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(StartAddr|0x80);
while(*star!='\0')
{
while(ReadInst() & 0x80); //等待BF忙标志
temp = *star;
WriteData(temp);
star++;
}
}
void DisplayBuff(unsigned char line)
{
unsigned char i;
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(0x80+0x10*line);
for(i=0;i<16;i++)
{
while(ReadInst() & 0x80); //等待BF忙标志
WriteData(DisBuf[i+0x10*line]);
}
}
void DisplayBuff0() //显示第一行
{
unsigned char i;
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(0x80);
for(i=0;i<16;i++)
{
while(ReadInst() & 0x80); //等待BF忙标志
WriteData(DisBuf1);
}
}
void DisplayBuff1() //显示第二行
{
unsigned char i;
while(ReadInst() & 0x80); //等待BF忙标志
WriteInst(0x90);
for(i=0;i<16;i++)
{
while(ReadInst() & 0x80); //等待BF忙标志
WriteData(DisBuf2);
}
}
主程序调用示例
sprintf(DisBuf1,"一二三四技术公司");
sprintf(DisBuf2,"系统自检中 ");
DisplayBuff0();
DisplayBuff1();
sprintf(DisBuf1,"体积总量: m3");
sprintf(DisBuf2," %12.3f ",massflow); //体积总量
DisplayBuff0();
DisplayBuff1();
文章评论(0条评论)
登录后参与讨论