📄 lcd_char.h
字号:
#ifndef LCD_2003_7_21
#define LCD_2003_7_21
#include "User.H"
/*sbit Light=P2^3;
sbit LcdRs=P2^4;
sbit LcdRw=P2^5;
sbit LcdEn=P2^6;
sbit ACC_7=ACC^7;
sbit ch=P3^5;
*/
sbit LcdRs=P3^6;
sbit LcdRw=P3^4;
sbit LcdEn=P3^5;
sbit ACC_7=ACC^7;
#define LcdCmdPort P0
#define LcdDataPort P0
code char table[]="0123456789ABCDEF";
void Delay1ms(word count); // 时间延迟
char Wait(); // 等待函数
void Write(byte style, byte input); // 向LCD写入命令或数据
#define COMMAND 0 // style
#define DATA 1 // style
#define CLEAR_SCREEN 0x01 // 清屏
#define HOMING 0x02 // 光标返回原点
#define PutChar(x) Write(DATA,x)
#define ClearScreen(); Write(COMMAND,CLEAR); Delay1ms(100);
void GotoXY(byte x, byte y); // 跳到LCD的某个坐标点
void SetDisplay(byte DisplayMode); // 设置显示模式
/************* DisplayMode ***************/
#define SHOW 0x04
#define HIDE 0x00 // default
#define CURSOR 0x02
#define NO_CURSOR 0x00 // default
#define FLASH 0x01 // 光标闪动
#define NO_FLASH 0x00 // default
/*********** End DisplayMode *************/
void SetInput(byte InputMode); // 设置输入模式
/************** InputMode ****************/
#define AC_UP 0x02
#define AC_DOWN 0x00 // default
#define MOVE 0x01 // 画面可平移
#define NO_MOVE 0x00 //default
/************ End InputMode **************/
void Move(byte object, byte direction); // 移动光标或屏幕
#define CURSOR 0x02
#define SCREEN 0x08
#define LEFT 0x00
#define RIGHT 0x04
void Print(byte *str); // 显示字符串str
void LCD_Initial(); // 液晶初始化函数
void LoadChar(byte user[8], byte place); //加载自定义点阵信息
char Wait()
{
LcdRs=0;
LcdRw=1; _nop_();
LcdEn=1; _nop_();
do{ ACC=P0;
}while(ACC_7==1);
LcdEn=0;
Delay1ms(1);
return ACC;
}
void Write(byte style, byte input)
{
LcdRs=style;
LcdRw=0; _nop_();
LcdEn=1; _nop_();
P0=input; _nop_();
LcdEn=0; _nop_();
Wait();
}
void GotoXY(byte x, byte y)
{
if(y==0)
Write(COMMAND,0x80|x);
if(y==1)
Write(COMMAND,0x80|(x-0x40));
}
void SetDisplay(byte DisplayMode)
{
Write(COMMAND, 0x08|DisplayMode);
}
void SetInput(byte InputMode)
{
Write(COMMAND, 0x04|InputMode);
}
void Move(byte object, byte direction)
{
if(object==CURSOR)
Write(COMMAND,0x10|direction);
if(object==SCREEN)
Write(COMMAND,0x18|direction);
}
void Print(byte *str)
{
while(*str!='\0')
{
Write(DATA,*str);
str++;
}
}
void LcdData(char); /* LCD数据输入函数 */
void LcdData(char c)
{
LcdDataPort = c;
LcdRs = 1;
LcdRw = 0;
LcdEn = 0;
LcdEn = 1;
}
void LcdHex2(char); /* 字符的十六进制显示函数 */
void LcdHex2(char c)
{
LcdData(table[(((c&0xf0)>>4)&0x0f)]);
LcdData(table[(c&0x0f)]);
}
void LCD_Initial()
{
LcdEn=0;
Delay1ms(100);
Write(COMMAND,0x38); //8位数据端口,2行显示,5*7点阵
Delay1ms(20);
Write(COMMAND,0x38);
Delay1ms(20);
SetDisplay(SHOW|NO_CURSOR); //开启显示, 无光标
Write(COMMAND,CLEAR_SCREEN); //清屏
SetInput(AC_UP|NO_MOVE); //AC递增, 画面不动
}
void LoadChar(byte user[8], byte place)
{
byte i;
Write(COMMAND,0x40|(place*8));
for(i=0; i<8; i++)
Write(DATA,user[i]);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -