📄 lcd.c
字号:
//ST7920驱动的12864(串行工作方式)
/******************************************************************************
文件名 : lcd.c
模块名称:st7920 串行方式驱动12232液晶驱动
CPU: stc89c516rd+ 主频:11.0592M
******************************************************************************/
#include "lcd.h"
#include "common.h"
#include "delay.h"
uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置
};
/******************************************************************************************
* 函数名称 :SendByte
* 功能描述 :串口发送一个字节
******************************************************************************************/
void SendByte(uchar Dbyte)
{
uchar i;
for(i=0;i<8;i++)
{
SCK = 0;
Dbyte=Dbyte<<1; //左移一位
SID = CY; //移出的位给SID
SCK = 1;
SCK = 0;
}
}
/******************************************************************************************
* 函数名称 :ReceiveByte
* 功能描述 :串口接收一个字节
******************************************************************************************/
uchar ReceiveByte(void)
{
uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
/******************************************************************************************
* 函数名称 :CheckBusy
* 功能描述 :
******************************************************************************************/
void CheckBusy( void )
{
do SendByte(0xfc); //11111,RW(1),RS(0),0
while(0x80&ReceiveByte()); //BF(.7)=1 Busy
}
/******************************************************************************************
* 函数名称 :WriteCommand
* 功能描述 :
******************************************************************************************/
void WriteCommand(uchar Cbyte)
{
CS = 1;
CheckBusy();
SendByte(0xf8); //11111,RW(0),RS(0),0
SendByte(0xf0&Cbyte); //高四位
SendByte(0xf0&Cbyte<<4);//低四位(先执行<<)
CS = 0;
}
/******************************************************************************************
* 函数名称 :WriteData
* 功能描述 :
******************************************************************************************/
void WriteData(uchar Dbyte)
{
CS = 1;
CheckBusy();
SendByte(0xfa); //11111,RW(0),RS(1),0
SendByte(0xf0&Dbyte); //高四位
SendByte(0xf0&Dbyte<<4);//低四位(先执行<<)
CS = 0;
}
/******************************************************************************************
* 函数名称 :ReadData
* 功能描述 :
******************************************************************************************/
uchar ReadData(void)
{
CheckBusy();
SendByte(0xfe); //11111,RW(1),RS(1),0
return ReceiveByte();
}
/******************************************************************************************
* 函数名称 :LcmInit
******************************************************************************************/
void LcmInit(void)
{
delay_1ms(100);
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(0x03); //AC归0,不改变DDRAM内容
WriteCommand(0x0C); //显示ON,游标OFF,游标位反白OFF
WriteCommand(0x01); //清屏,AC归0
WriteCommand(0x06); //写入时,游标右移动
}
/******************************************************************************************
* 函数名称 :LcmClearTXT
* 功能描述 :文本区清RAM函数
******************************************************************************************/
void LcmClearTXT(void)
{
uchar i;
WriteCommand(0x80);//设定DDRAM地址80H
for(i=0;i<16;i++) WriteData(0x20);
WriteCommand(0x90);//设定DDRAM地址90H
for(i=0;i<16;i++) WriteData(0x20);
}
/******************************************************************************************
* 函数名称 :LcmClearBMP
* 功能描述 :图形区清RAM函数
******************************************************************************************/
/*void LcmClearBMP(void)
{
uchar i,j;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++)
{
WriteCommand(0x80|i); //行位置
WriteCommand(0x80); //列位置
for(j=0;j<16;j++)
WriteData(0);
}
} */
void ClrDis(void)
{
WriteCommand(0x01);
}
void White(uchar firstsecond)
{
WriteCommand(0x34);
if(firstsecond==0) WriteCommand(04);
else if(firstsecond==1) WriteCommand(05);
WriteCommand(0x30);
}
/******************************************************************************************
* 函数名称 :PutStr
* 功能描述 :
******************************************************************************************/
void PutStr(uchar row,uchar col,uchar *puts)
{
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(AC_TABLE[8*row+col]); //起始位置
while(*puts != '\0') //判断字符串是否显示完毕
{
if(col==8) //判断换行
{ //若不判断,则自动从第一行到第三行
col=0;
row++;
}
if(row==2) row=0; //一屏显示完,回到屏左上角
WriteCommand(AC_TABLE[8*row+col]);
WriteData(*puts); //一个汉字要写两次
puts++;
WriteData(*puts);
puts++;
col++;
}
}
/*void WriteHalf(uchar ad,uchar da)
{
WriteCommand(ad);
WriteData(da);
}*/
/******************************************************************************************
* 函数名称 :PutBMP
* 功能描述 :
******************************************************************************************/
/*void PutBMP(uchar *puts)
{
uint x=0;
uchar i,j;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++) //12864实际为256x32
{
WriteCommand(0x80|i); //行位置
WriteCommand(0x80); //列位置
for(j=0;j<16;j++) //256/8=32 byte
{ //列位置每行自动增加
WriteData(puts[x]);
x++;
}
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -