本讲任务:
了解液晶1602的相关知识,通过一个例程了解液晶1602的使用。
LCD1602简介:
1602液晶也叫1602字符型液晶,它是一种专门用来显示字母、数字、符号的点阵型液晶模块。它是由若干个5x7或者5x11的点阵字符位组成,每个点阵字符位都可以用显示一个字符,每位之间有一个点距的间隔,每行之间也有间隔,起到了字符间距和行间距的作用,正因为如此,所以它不能很好的显示图片。
例程:
/***********************LCD驱动基本代码 ************************
*单片机型号:STC89C52RC
*开发环境:KEIL
*名称:1602驱动基本代码
********************************************************************/
#include
#include
#define LCD_Data P0
#define Busy 0x80
sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_E=P2^5;
unsigned char code welcome[]={"YOU ARE WELCOME"};
unsigned char code mcu[]={"SL-51A"};
void Delay5Ms(void);
void WriteDataLCD(unsigned char WDLCD);
void WriteCommandLCD(unsigned char WCLCD,BuysC);
unsigned char ReadDataLCD(void);
unsigned char ReadStatusLCD(void);
void LCDInit(void);
void DisplayOneChar(unsigned char X,unsigned char Y,unsigned char DData);
void DisplayListChar(unsigned char X,unsigned char Y,unsigned char code *DData);
void Info_display(void);
void Delay5Ms(void)
{unsigned int TempCyc=3552;while(TempCyc--);}
void WriteDataLCD(unsigned char WDLCD)
{
ReadStatusLCD();
LCD_Data=WDLCD;
LCD_RS=1;
LCD_RW=0;
LCD_E=0;
LCD_E=0;
LCD_E=1;
}
void WriteCommandLCD(unsigned char WCLCD,BuysC)
{
if(BuysC)ReadStatusLCD();
LCD_Data=WCLCD;
LCD_RS=0;
LCD_RW=0;
LCD_E=0;
LCD_E=0;
LCD_E=1;
}
unsigned char ReadDataLCD(void)
{
LCD_RS=1;
LCD_RW=1;
LCD_E=0;
LCD_E=0;
LCD_E=1;
return(LCD_Data);
}
unsigned char ReadStatusLCD(void)
{
LCD_Data=0xFF;
LCD_RS=0;
LCD_RW=1;
LCD_E=1;
while (LCD_Data & Busy);
return(LCD_Data);
}
void LCDInit(void)
{
LCD_Data=0;
Delay5Ms();Delay5Ms();Delay5Ms();
WriteCommandLCD(0x38,0);Delay5Ms();
WriteCommandLCD(0x38,0);Delay5Ms();
WriteCommandLCD(0x38,0);Delay5Ms();
WriteCommandLCD(0x38,1);
WriteCommandLCD(0x08,1);
WriteCommandLCD(0x01,1);
WriteCommandLCD(0x06,1);
WriteCommandLCD(0x0C,1);
}
void DisplayOneChar(unsigned char X,unsigned char Y,unsigned char DData)
{
Y&=0x1;X&=0xF;
if(Y)X|=0x40;
X|=0x80;
WriteCommandLCD(X,0);
WriteDataLCD(DData);
}
void DisplayListChar(unsigned char X,unsigned char Y,unsigned char code *DData)
{
unsigned char ListLength;ListLength=0;
Y&=0x1;X&=0xF;
while(DData[ListLength]>=0x20)
{
if(X<=0xF)
{
DisplayOneChar(X,Y,DData[ListLength]);
ListLength++;
X++;
}
}
}
void main(void)
{
LCDInit();
DisplayListChar(5,0,mcu);
DisplayListChar(0,1,welcome);
while(1){;}
}
最后,求求看到的此文的小伙伴点赞和关注支持一下下哦。毕竟,码字不容易哦,您的支持是我最大的动力呀!!!呜呜呜~~~