📄 lcd_zb成功3.c
字号:
/*==============================================================*/
/*※※※※※※※※※※※※※系统主文※※※※※※※※※※※※※※*/
/*==============================================================*/
#include <at89x51.h>
/////////////////////////////////
#define LCM_RS P2_2
#define LCM_RW P2_1 //定义LCD引脚
#define LCM_E P2_0
#define LCM_Data P0
#define Busy 0x80 //用检测LCM状态
#define uchar unsigned char
#define uint unsigned int
//////////////////////////////////////////////////
void delayms(uint i)
{ uint j;
for(;i--;i>0)
for(j=0;j<125;j++)
{;}
}
//////////////////////////////////////////////////
void Delay5Ms(void) //5ms延时
{
unsigned int TempCyc = 3552;
while(TempCyc--);
}
////////////////////////////////////////////////////////////////////////
void Delay400Ms(void) //400ms延时
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=5269;
while(TempCycB--);
};
}
//////////////////////////////////////////////////
unsigned char ReadStatusLCM(void) //读状态
{
LCM_Data = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
while (LCM_Data & Busy); //检测忙信号
return(LCM_Data);
}
//////////////////////////////////////////////////
void WriteDataLCM(unsigned char WDLCM) //写数据
{
ReadStatusLCM();
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}
//////////////////////////////////////////////////
void WriteCommandLCM(unsigned char WCLCM,BuysC) //写指令
{
if (BuysC) ReadStatusLCM();
LCM_Data = WCLCM;
LCM_RS =0;
LCM_RW =0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}
//////////////////////////////////////////////////]
/*unsigned char ReadDataLCM(void) //读数据
{
LCM_RS = 1;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
return(LCM_Data);
}*/
//////////////////////////////////////////////////
void LCMInit(void) //LCM初始化
{
LCM_Data = 0;
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
//////////////////////////////////////////////////
/*void Locatexy(char x,char y) //确定光标位置
{ char temp;
temp=x&0xf;
y&=0x1;
if(y)
temp|=0x40;
temp|=0x80;
WriteCommandLCM(temp,0);
}*/
//////////////////////////////////////////////////
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF;
if (Y) X |= 0x40;
X |= 0x80;
WriteCommandLCM(X, 0);
WriteDataLCM(DData);
}
//////////////////////////////////////////////////
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData) //按指定位置显示一串字符
{
unsigned char ListLength;
ListLength = 0;
Y &= 0x1;
X &= 0xF; //X不能大于15,Y不能大于1
while (DData[ListLength]>0x20) //若到达字串尾则退出
{
if (X <= 0xF) //X小于0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //显示单个字符
ListLength++;
X++;
}
}
}
//////////////////////////////////////////////////
void main(void) //主函数显示
{
Delay400Ms();
LCMInit();
Delay5Ms();
DisplayListChar(0,0, "cross--1" );
delayms(2000);
DisplayListChar(0,0, "cross--2" );
delayms(2000);
DisplayListChar(0,0, "cross--3" );
delayms(2000);
DisplayListChar(0,0, "cross--4" );
delayms(2000);
DisplayListChar(0,0, "cross--5" );
delayms(2000);
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -