|
/**
LCD1602基本顯示 12345
**/
#include <reg52.h>
/**/
typedef unsigned char uchar;
typedef unsigned int uint;
sbit EN = P3^4;//使能信號
sbit RS = P3^5;//數(shù)據(jù)/命令選擇端
sbit RW = P3^6;//讀/寫選擇端
//判斷液晶忙,如果忙則等待
void Read_Busy()
{
uchar busy;
P0 = 0xff;//復(fù)位P0
RS = 0;
RW = 1;
do
{
EN = 1;// RS = 0; RW = 1;EN = 1;讀狀態(tài),輸出P0=D0~D7狀態(tài)字
busy = P0;//P0是啥?busy=0x80才跳出來
EN = 0;
}while(busy & 0x80);
}
//寫LCD1602命令一個(gè)字節(jié)
void Write_Cmd(uchar cmd)
{
Read_Busy();//判斷忙
RS = 0;
RW = 0;
P0 = cmd;//cmd是變量
EN = 1;//這是高脈沖?**寫指令無輸出
EN = 0;
}
//寫一個(gè)字節(jié)數(shù)據(jù)
void Write_Dat(uchar dat)
{
Read_Busy();
RS = 1;
RW = 0;
P0 = dat;
EN = 1; //寫數(shù)據(jù),高脈沖。。。D0~D7=P0
EN = 0;
}
void main()
{
Write_Cmd(0x38);//設(shè)置16*2顯示
Write_Cmd(0x0f);//開顯示 顯示光標(biāo),光標(biāo)閃爍
Write_Cmd(0x01);//清屏
Write_Cmd(0x06);//地址指針移位命令
Write_Cmd(0x80 | 0x06);//顯示地址
//80H按位與地址碼,這里是從第六位之后顯示
Write_Dat(1 + '0');
Write_Dat(2 + '0');
Write_Dat(3 + '0');
Write_Dat(4 + '0');
Write_Dat(5 + '0');
while(1);
}
|
|