📄 1602.c
字号:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P3^4;
sbit lcdrs=P3^5;
#define DataPort P0
uchar num;
void delay(uint z) //延时子函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}
void write_com(uchar com) //写指令
{
lcdrs=0;
DataPort=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date) //写数据
{
lcdrs=1;
DataPort=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init() //初始化液晶
{
lcden=0;
write_com(0x38); //xianshi shezi
write_com(0x0f); //0x0f光标闪烁,0x0e不闪烁 0x0c不显示光标
write_com(0x06); //光标自动加一,整屏不移动
write_com(0x01); //清屏
write_com(0x80); //数据指针初始化
}
void lcd_mov(uchar x)//整屏移动
{
uchar num;
for(num=0;num<x;num++)
{
write_com(0x1c);//资料上0x18是左移,但这里用0x1c才能左移
delay(200);
}
}
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
write_com(0x80|x);
if(y==1)
write_com(0x80|(x-0x40));
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
write_data(*str);
str++;
}
}
void main()
{
init();
GotoXY(10,0);
Print("I LOVE YOU");
lcd_mov(10);
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -