⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1602111.c

📁 此程序是关于液晶显示屏1602的完整显示程序
💻 C
字号:
#include <at89x52.h>
#include<intrins.h>

sbit LCM_RS=P2^0;
sbit LCM_RW=P2^1;  
sbit LCM_E=P2^2;
#define LCM_Data P0
#define Busy 0x80   


void WriteDataLCM(unsigned char WDLCM);      
void WriteCommandLCM(unsigned char WCLCM,BuysC);   
unsigned char ReadStatusLCM(void);       
void LCMInit(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 Delay5Ms(void);
void Delay400Ms(void);


unsigned char code Y1[]={"rong yi dian zi "};         //取消
unsigned char code Y2[]={"meg is a pig    "};         //取消

void main(void)
{
Delay400Ms();         
LCMInit();          
Delay5Ms();         
DisplayListChar(0, 0, Y1);              //取消
DisplayListChar(0, 1, Y2);              //取消
//DisplayOneChar(5,0,'a');
        
while(1);
}


void WriteDataLCM(unsigned char WDLCM) 
{
ReadStatusLCM();//检测忙
LCM_RS = 1;//产生写操作时序


LCM_RW = 0;
  _nop_();
LCM_Data = WDLCM;
   _nop_();
 LCM_E = 1;          //若晶振速度太高可以在这后加小的延时
    _nop_();_nop_();
 LCM_E = 0;          //延时

}


void WriteCommandLCM(unsigned char WCLCM,BuysC){
 if (BuysC) ReadStatusLCM();      //根据需要检测忙
 LCM_RS = 0;          //产生写指令时序
    LCM_RW = 0;                                      //RW=0,时序写
    _nop_();
 LCM_Data = WCLCM;
    _nop_();
 LCM_E = 1;                                       //下降沿
 _nop_();_nop_();
 LCM_E = 0;                                       //E置位
}

unsigned char ReadStatusLCM(void) {
 LCM_Data = 0xFF;
 LCM_RS = 0;                                    //rs=0
 LCM_RW = 1;                                    //rw=1
    _nop_();
     LCM_E = 1;                                              //LCM_E=1
  _nop_();                                      // DB7=0  LCD控制器空闲 ,  DB7=1  LCD控制器忙
    _nop_();
 while (LCM_Data & Busy);       //检测忙信号
 return(LCM_Data);
}

 


void LCMInit(void) {        
 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 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;            
 //while (DData[ListLength]>0x20) {    
 while (ListLength<0x0f) {
  if (X <= 0xF) {         
   DisplayOneChar(X, Y, DData[ListLength]);  
   ListLength++;
   X++;
  }
 }
}

//5ms延时
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}

//400ms延时
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -