📄 lcm.c
字号:
//The command of LCM24064ZK
#include <LCM.h>
#include <ADC0816.H>
#include <DIGITAL.H>
sbit Busy = P1^3;
sbit IntLcm = P1^7;
//a subroutine to write command register at 'x' with the content 'y'
void Set(uchar x,uchar y)
{
while(Busy!=0);
LcmCmd = x;
while(Busy!=0);
LcmData = y;
}
// a subroutine to read command register at 'x'
uchar LcmStatus(uchar x)
{
while(Busy!=0);
LcmCmd = x;
while(Busy!=0);
return LcmData;
}
// to write data 'x' to LCM data bus
void Write(uchar x)
{
while(Busy!=0);
LcmData = x;
}
// to read data from LCM data bus
/*uchar Read()
{
while(Busy!=0);
return LcmData;
}*/
// set cursor position at segment 'x',common 'y' 左上角为(0,0) 右下角为(14,3)
void sc(uchar x,uchar y)
{
x*=2; //x以16象素为一单位
y*=16; //y以16象素为一单位
Set(0x60,x);
Set(0x70,y);
}
// display a chinese character in the cursor position defined before 输入的是区位码!!
void ch(uint gbcode)
{
uchar a,b;
a=gbcode/100+0xa0; //当gbcode是区位码时,要分别将高8位码和低8位码加上0XA0才能得到正确的内码
b=gbcode%100+0xa0;
Write(a);
Write(b);
}
void SetDisplayWindow(right,bottom,left,top)
{
Set(0x28,right);
Set(0x38,bottom);
Set(0x48,left);
Set(0x58,top);
}
void SetActiveWindow(right,bottom,left,top)
{
Set(0x20,right);
Set(0x30,bottom);
Set(0x40,left);
Set(0x50,top);
}
void InitDisp()
{
Set(0x00,0xcd); //电源模式正常,软体重置无作用,禁能自动重置功能,文字模式,荧幕显示开启,无闪烁,无反白
Set(0x08,0x73); //CLK_OUT使能 工作视窗 中断和忙碌位元的电位高电位动作 8MHZ时脉
Set(0x10,0x2b); //当资料读出DDRAM时光标不自动移位 中/英文字不对齐 正相储存当前资料于DDRAM 非粗体字 当资料写入DDRAM时光标自动移位 光标显示off 光标闪烁 光标宽度会随着输入的资料而变动
//cursor off:0x2b,cursor on:0x2f
Set(0x80,32); //屏幕的刷新率出厂时为64HZ,即更新时间为15.625ms,要想光标闪烁时间为500ms,则应该设置500/15.625=32
Set(0x18,0xf0); //光标高度为16象素 行距为0象素
SetDisplayWindow(29,63,0,0); //设置LCD面板大小 240/8-1=29,64-1=63
SetActiveWindow(29,63,0,0); //设置工作视窗大小 到达边界时自动换行
sc(0,0); //光标位置
Set(0x90,65); //Shift Clock Control Register
Set(0xa0,0x00); //禁能BUSY去产生中断输出 触摸屏中断屏蔽
Set(0xd0,0x30); //LCD Contrast Control Register,低五位为电流值
Set(0xe0,0x00); //当寄存器[F0h]的bit3为'1',控制器内部将自动读取本寄存器[E0h]的Data,然后全部填写到DDRAM内,之后寄存器[F0h]的bit3被清除为'0'
Set(0xf0,0xa0); //使能字型ROM的转换 选择内部字型ROM 选择简体字型 不开始重复写入REG[E0h]的资料到DDRAM 输入GB/BIG5码输出为中文字 ASCII选择区块0
}
void ASCON()
{
Set(0xf0,0xa4);//设定将要输入ASC码
}
void ASCOFF()
{
Set(0xf0,0xa0);//中文
}
void CON()
{
Set(0x10,0x2f); //show cursor
}
void COFF()
{
Set(0x10,0x2b); //hide cursor
}
void ClearDisp()
{
uchar i;
i=60;
COFF(); //hide cursor
ASCOFF(); //中文模式
while(i--) ch(101); //240*64的屏幕能显示16*16的汉字60个,清屏就是将整屏写入空格
}
void ShowMainScreen() //显示主界面
{
ClearDisp();
sc(0,0);
ch(3975);ch(4901);ch(5281);ch(1866);ch(4252);ch(2252);ch(4783);ch(135);ch(260);ch(4293);ch(3061);ch(4846);ch(1941);ch(3887);ch(101);
ch(101);ch(257);ch(2789);ch(5528);ch(3821);ch(3442);ch(5220);ch(101);ch(261);ch(4763);ch(4852);ch(2187);ch(3821);ch(5220);ch(101);
ch(101);ch(258);ch(8225);ch(2079);ch(3768);ch(2171);ch(3887);ch(101);ch(262);ch(3255);ch(2079);ch(2951);ch(4253);ch(2790);ch(101);
ch(101);ch(259);ch(3658);ch(2208);ch(1774);ch(3887);ch(101);ch(101);ch(263);ch(2014);ch(3158);ch(2504);ch(5587);ch(101);ch(101);
sc(0,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -