STC89C52单片机 LCD1602液晶显示屏

LCD1602显示 VVcat
#include <reg52.h>

typedef unsigned char uchar;
typedef unsigned int uint;

sbit RS = P3^5;
sbit RW = P3^6;
sbit EN = P3^4;

//判断液晶忙,如果忙则等待
void Read_Busy(){
	uchar busy;
	P0 = 0xff;
	RS = 0;
	RW = 1;
	do{
		EN = 1;
		busy = P0;
		EN = 0;
	}while(busy & 0x80);
}

//写LCD1602命令一个字节
void Write_Cmd(uchar cmd){
	Read_Busy();//判断忙
	RS = 0;
	RW = 0;
	P0 = cmd;
	EN = 1;
	EN = 0;
}

//写一个字节数据
void Write_Dat(uchar dat){
	Read_Busy();
	RS = 1;
	RW = 0;
	P0 = dat;
	EN = 1;
	EN = 0;
}

void main(){
	Write_Cmd(0x38);//设置16*2显示
	Write_Cmd(0x0c);//设置为0x0c为开显示 设置为0x0e为显示光标,设置为0x0f光标闪烁
	Write_Cmd(0x01);//清屏
	Write_Cmd(0x06);//地址指针移位命令
	Write_Cmd(0x80);//显示地址

// 调动显示函数(每个方格只能显示一位)
	Write_Dat(0x56);  // 0x56转换为十进制 86 在ASCII码表中对应的字母为 V
	Write_Dat(0x56);  // 0x56转换为十进制 86 在ASCII码表中对应的字母为 V
	Write_Dat(0x43);  // 0x43转换为十进制 67 在ASCII码表中对应的字母为 C
	Write_Dat(0x61);  // 0x61转换为十进制 97 在ASCII码表中对应的字母为 a
	Write_Dat(0x74);  // 0x74转换为十进制 116 在ASCII码表中对应的字母为 t

	while(1);
}

通过以下方式也可以在LCD1602液晶显示屏中显示数值

	Write_Dat(0 + '0');
	Write_Dat(1 + '0'); 
	Write_Dat(2 + '0');
	Write_Dat(3 + '0');
	Write_Dat(4 + '0');
	Write_Dat(5 + '0');
	Write_Dat(6 + '0');
	Write_Dat(7 + '0');
	Write_Dat(8 + '0');
	Write_Dat(9 + '0');

注:0 要用单引号’ '括起来而不是双引号括起来" "否则显示屏不能正常显示数值。

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值