LCD1602显示 VVcat

#include <reg52.h>

typedef&nbsp;unsigned&nbsp;char&nbsp;uchar;
typedef&nbsp;unsigned&nbsp;int&nbsp;uint;

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

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

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

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

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

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

while(1);
}

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

Write_Dat(0&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(1&nbsp;+&nbsp;&#39;0&#39;);&nbsp;
Write_Dat(2&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(3&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(4&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(5&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(6&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(7&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(8&nbsp;+&nbsp;&#39;0&#39;);
Write_Dat(9&nbsp;+&nbsp;&#39;0&#39;);

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