📄 glcd.c
字号:
#include "Global.h"
#include "Hzlib.h"
///////////////////////////////////////////////////////////////////////////////
// 内部存储区变量 0~128字节 直接寻址
// 全局变量定义
extern data uchar u8CursorX; // 光标X坐标列
extern data uchar u8CursorY; // 光标Y坐标行
extern data uchar cs; // 显示片选
extern bdata bit reverse; // LCD底色显示控制
//////////////////////////////////////////////////////////////////////////////
// LCD定位,列、行
///////////////////////////////////////////////////////////////////////////////
void GLCD_Locate (uchar u8Column, uchar u8Line)
{
u8CursorX = u8Column;
u8CursorY = u8Line;
}
///////////////////////////////////////////////////////////////////////////////
// LCD延时
///////////////////////////////////////////////////////////////////////////////
void LcdDelay(uchar u32Duration)
{
idata uchar i;
for(i=0;i<u32Duration;i++);
}
///////////////////////////////////////////////////////////////////////////////
// 写指令
///////////////////////////////////////////////////////////////////////////////
void wcmd(uchar cmd)
{
E=0;
RS=0;
RW=0;
E=1;
P0=cmd;
E=0;
}
///////////////////////////////////////////////////////////////////////////////
// 写数据
///////////////////////////////////////////////////////////////////////////////
void wdat(uchar dat)
{
E=0;
RS=1;
RW=0;
E=1;
P0=dat;
E=0;
}
///////////////////////////////////////////////////////////////////////////////
// 输出左屏指令
///////////////////////////////////////////////////////////////////////////////
void OutLI(uchar i)
{
CS1=1; // 左屏片选
CS2=0;
wcmd(i); // 写指令
}
///////////////////////////////////////////////////////////////////////////////
// 输出左屏数据
///////////////////////////////////////////////////////////////////////////////
void OutLD(uchar i)
{
CS1=1; // 左屏片选
CS2=0;
wdat(i); // 写数据
}
///////////////////////////////////////////////////////////////////////////////
// 输出右屏指令
///////////////////////////////////////////////////////////////////////////////
void OutRI(uchar i)
{
CS1=0;
CS2=1; // 右屏片选
wcmd(i); // 写指令
}
///////////////////////////////////////////////////////////////////////////////
// 输出右屏数据
///////////////////////////////////////////////////////////////////////////////
void OutRD(uchar i)
{
CS1=0;
CS2=1; // 右屏片选
wdat(i); // 写数据
}
///////////////////////////////////////////////////////////////////////////////
// 判断LCD控制器是否忙
///////////////////////////////////////////////////////////////////////////////
void LcdWaitBusy (unsigned char u8LcdSide)
{
u8LcdSide=u8LcdSide;
LcdDelay(5);
}
///////////////////////////////////////////////////////////////////////////////
// 向LCD控制器写指令
///////////////////////////////////////////////////////////////////////////////
void LcdInstructionWrite (uchar u8Instruction,uchar u8LcdSide)
{
LcdWaitBusy (u8LcdSide); // 如果忙就等待
if(u8LcdSide==RIGHT)
{
OutRI(u8Instruction); // 写右屏指令
}
else if(u8LcdSide==LEFT)
{
OutLI(u8Instruction); // 写左屏指令
}
}
///////////////////////////////////////////////////////////////////////////////
// 向LCD控制器写数据
///////////////////////////////////////////////////////////////////////////////
void LcdDataWrite (uchar u8Data,uchar u8LcdSide)
{
LcdWaitBusy (u8LcdSide); // 如果忙就等待
if(u8LcdSide == LEFT)
{
OutLD(u8Data); // 写左屏数据
}
else if(u8LcdSide == RIGHT)
{
OutRD(u8Data); // 写左屏数据
}
}
///////////////////////////////////////////////////////////////////////////////
// 清LCD屏幕
//
// LCD分8页
///////////////////////////////////////////////////////////////////////////////
void GLCD_ClearScreen ()
{
idata uchar u8Page=0;
idata uchar u8Column=0;
OutLI(START_LINE);
OutLI(X_ADRESS);
OutLI(Y_ADRESS);
OutLI(DISPLAY_ON);
OutRI(START_LINE);
OutRI(X_ADRESS);
OutRI(Y_ADRESS);
OutRI(DISPLAY_ON);
for(u8Page=0;u8Page<8;u8Page++)
{
LcdInstructionWrite(X_ADRESS|u8Page,LEFT); // 设置页号
LcdInstructionWrite(Y_ADRESS,LEFT); // 设置列号
for(u8Column=0;u8Column<64;u8Column++)
{
LcdDataWrite(0X00,LEFT);
}
LcdInstructionWrite(X_ADRESS|u8Page,RIGHT); // 设置页号
LcdInstructionWrite(Y_ADRESS,RIGHT); // 设置列号
for(u8Column=0;u8Column<64;u8Column++)
{
LcdDataWrite(0X00,RIGHT);
}
}
}
///////////////////////////////////////////////////////////////////////////////
// LCD控制器初始化
///////////////////////////////////////////////////////////////////////////////
void GLCD_LcdInit()
{
OutLI(START_LINE); // 起始行
OutLI(X_ADRESS);
OutLI(Y_ADRESS);
OutLI(DISPLAY_ON);
OutRI(START_LINE);
OutRI(X_ADRESS);
OutRI(Y_ADRESS);
OutRI(DISPLAY_ON);
GLCD_ClearScreen(); // 清屏
}
///////////////////////////////////////////////////////////////////////////////
// 显示定长字符串
///////////////////////////////////////////////////////////////////////////////
void dprintf(char *fmt,uchar uLen)
{
idata char c1,c2; // 汉字占两个ASC字符
idata uchar i=0,j,k; // 计数器
idata uchar pos; // 显示位置
while(i<uLen)
{
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
c1 = fmt[i];
c2 = fmt[i+1];
if(c1 >= 0)
{ // ASCII
LcdInstructionWrite (X_ADRESS + (u8CursorY/ 8),pos);
LcdInstructionWrite (Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=0;k<8;k++)
{
if(reverse)LcdDataWrite(~ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+k],pos);
else
LcdDataWrite(ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+k],pos);
}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8)+1,pos);
LcdInstructionWrite (Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for(k=8;k<16;k++)
{
if(reverse)LcdDataWrite(~ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+k],pos);
else
LcdDataWrite(ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+k],pos);
}
u8CursorX +=8;
}
else
{
// 中文
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)
{
if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
break;
}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8),pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=0;k<8;k++)
{
if(reverse)LcdDataWrite(~GB_16[j].Msk[k],pos);
else
LcdDataWrite(GB_16[j].Msk[k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8),pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=8;k<16;k++)
{
if(reverse)LcdDataWrite(~GB_16[j].Msk[k],pos);
else
LcdDataWrite(GB_16[j].Msk[k],pos);
}
u8CursorX -=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/8)+1,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=16;k<24;k++)
{
if(reverse)LcdDataWrite(~GB_16[j].Msk[k],pos);
else
LcdDataWrite(GB_16[j].Msk[k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8)+1,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=24;k<32;k++)
{
if(reverse)LcdDataWrite(~GB_16[j].Msk[k],pos);
else
LcdDataWrite(GB_16[j].Msk[k],pos);
}
u8CursorX +=8;
i++;
}
i++;
}
}
///////////////////////////////////////////////////////////////////////////////
// 显示大字体
///////////////////////////////////////////////////////////////////////////////
void LcdPutDigit (uchar u8Char)
{
idata uchar c1; // 显示字符
idata uchar k;
idata uchar pos; // 显示位置
c1=u8Char;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8),pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
LcdDataWrite(0x00,pos);
for (k=0;k<7;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8),pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=7;k<14;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
LcdDataWrite(0x00,pos);
u8CursorX -=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/8)+1,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
LcdDataWrite(0x00,pos);
for (k=14;k<21;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8)+1,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=21;k<28;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
LcdDataWrite(0x00,pos);
u8CursorX -=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/8)+2,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
LcdDataWrite(0x00,pos);
for (k=28;k<35;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8)+2,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=35;k<42;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
LcdDataWrite(0x00,pos);
u8CursorX -=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/8)+3,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
LcdDataWrite(0x00,pos);
for (k=42;k<49;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
u8CursorX +=8;
if(u8CursorX <64){pos=LEFT;cs=1;}
else if((u8CursorX >63)&&(u8CursorX <128)){pos=RIGHT;cs=2;}
LcdInstructionWrite(X_ADRESS + (u8CursorY/ 8)+3,pos);
LcdInstructionWrite(Y_ADRESS + u8CursorX - (cs-1)*64,pos);
for (k=49;k<56;k++)
{
LcdDataWrite(clock_digit[(c1-0x30)*56+k],pos);
}
LcdDataWrite(0x00,pos);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -