📄 jhd162.c
字号:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dc=0xc4; /*P4.4 LCD的RS*/
sbit rw=0xc5; /*P4.5 LCD的R/W*/
sbit cs=0xc6; /*P4.6 LCD的E*/
#define lcdbus P0 /*P0LCD 数据D0=P0.0*/
void soft_nop(){}
uchar lcd_checkbusy() /*检查LCD忙*/
{
register lcdstate;
dc=0;
rw=1;
cs=1;
soft_nop();
lcdstate=lcdbus;
cs=0;
return((lcdstate&0x80));
}
void lcd_wrcmd(uchar lcdcmd) /*写LCD命令*/
{
while(lcd_checkbusy());
lcdbus=lcdcmd;
dc=0;
rw=0;
cs=1;
soft_nop();
cs=0;
lcdbus=0xff;
}
void lcd_moveto(uchar position) /*移动光标到:0-79*/
{
register cmd=0x80;
//lcdcounter=position;
if(position>59)
position+=0x18;
else
{
if(position>39)
position-=0x14;
else
{
if(position>19)
position+=0x2c;
}
}
cmd=cmd|position;
lcd_wrcmd(cmd);
}
void lcd_wrdata(uchar lcddata)/*在当前显示位置显示数据*/
{
while(lcd_checkbusy());
/*if(lcdcounter==20)
{
lcd_moveto(20);
while(lcd_checkbusy());
}
if(lcdcounter==40)
{
lcd_moveto(40);
while(lcd_checkbusy());
}
if(lcdcounter==60)
{
lcd_moveto(60);
while(lcd_checkbusy());
}
if(lcdcounter==80)
{
lcd_moveto(0);
while(lcd_checkbusy());
lcdcounter=0;
}*/
//lcdcounter++;
lcdbus=lcddata;
dc=1;
rw=0;
cs=1;
soft_nop();
cs=0;
lcdbus=0xff;
}
// position 显示地址
// count 显示字符个数(包括空格)
// *strpoint 字符串
void lcd_string(uchar position,uchar count,uchar *strpoint) /*在指定位置显示LCD字符串*/
{
uchar i;
lcd_moveto(position);
for(i=0;i<count;i++)
{
lcd_wrdata(strpoint[i]);
}
}
void lcd_init() /*初始化*/
{
lcd_wrcmd(0x38); /*设置8位格式,2行,5*7 */
lcd_wrcmd(0x0c); /*整体显示,关光标,不闪烁*/
lcd_wrcmd(0x06); /*设定输入方式,增量不移位*/
lcd_wrcmd(0x01); /*清除显示*/
//lcdcounter=0;
}
void lcd_cls() /*清除显示*/
{
lcd_wrcmd(0x01);
// lcdcounter=0;
}
/**********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -