📄 chn.c
字号:
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define x1 0x80
#define x2 0x88
#define y 0x80
#define comm 0
#define dat 1
sbit rs = P0^0; //H=data; L=command;
sbit rw = P0^1; //H=read; L=write;
sbit e = P0^2; //input enable;
sbit psb= P0^3; //H=并口; L=串口;
sbit rst= P0^4; //Reset Signal 低电平有效
sbit busy=P2^7; //lcd busy bit
void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint us);
uchar code tab2[]={
"祝: "
" 涂涂 "
"愚人节快乐 "
" 柒柒 "
};
/*------------------初始化-----------------*/
void init_lcd (void)
{
rst=1;
psb=1;
wr_lcd (comm,0x30); /*30---基本指令动作*/
wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/
wr_lcd (comm,0x06); /*光标的移动方向*/
wr_lcd (comm,0x0f); /*开显示,关游标*/
}
/*---------------显示汉字或字符----------------*/
void chn_disp (uchar code *chn)
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
for (j=0;j<4;j++)
{
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
}
/*--------------清DDRAM------------------*/
void clrram (void)
{
wr_lcd (comm,0x30);
wr_lcd (comm,0x01);
}
/*---------------------------------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
chk_busy ();
if(dat_comm)
{
rs=1; //data
rw=0; //write
}
else
{
rs=0; //command
rw=0; //write
}
P2=content; //output data or comm
e=1;
e=0;
}
void chk_busy (void)
{
P2=0xff;
rs=0;
rw=1;
e =1;
while(busy==1);
e =0;
}
void delay (uint us) //delay time
{
while(us--);
}
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<15;j++)
delay(1);
}
/*------------------主程序--------------------*/
void main ()
{
SP=0x5f;
clrram();
init_lcd ();
while(1)
{
chn_disp (tab2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -