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

📄 main.c

📁 LCD液晶屏显示程序
💻 C
字号:
#include <reg52.h>
#define uchar unsigned char 
#define uint  unsigned int 
//uchar code shu[]={"0123456789abcdef"};
uchar time[7]={0x08,0x05,0x08,0x23,0x02,0x00,0x02};
uchar second=0;

sbit RS=P1^3;
sbit RW=P1^4;
sbit E =P1^5;
void delay(uint t);
void SendCommandByte(unsigned char ch);
void SendDataByte(unsigned char ch);
void InitLcd();
void DisplayMsg1(uchar *p);

//-----------------------------------------------------
void delay(uint t)                // 延时函数
{
  for(;t!=0;t--) ;
}
//------------------------------------------------------

//------------------------------------------------------
void SendCommandByte(unsigned char ch)     // 向LCD写命令;
{
   RS=0;
   RW=0;
   P0=ch;
   E=1;
   delay(1);
   E=0;
   delay(100);  //delay 40us
}
//-------------------------------------------------------
void SendDataByte(unsigned char ch)		   // 向LCD写数据
{  RS=1;
   RW=0;
   P0=ch;
   E=1;
   delay(1);
   E=0;
   delay(100); //delay 40us
}
//-------------------------------------------------
void InitLcd()							   // 初始化LCD
{SendCommandByte(0x30);
 SendCommandByte(0x30);
 SendCommandByte(0x30);
 SendCommandByte(0x38);	//设置工作方式
 SendCommandByte(0x0c); //显示状态设置
 SendCommandByte(0x01); //清屏
 SendCommandByte(0x06); //输入方式设置
}
//=============================================
void DisplayMsg1(uchar *p)
{ 
 unsigned char count;
 SendCommandByte(0x80);  //设置DDRAM地址
 for(count=0;count<16;count++)
    {
	 SendDataByte(*p++);
   	}
} 

//---------------------------------------------
void DisplayMsg2(uchar *p)
{ 
 unsigned char count;
 SendCommandByte(0xc0);  //设置DDRAM地址
 for(count=0;count<16;count++)
    {
	 SendDataByte(*p++);
   	}
}
//=============================================
void DisplayMsg3(uchar *p)
{ 
 unsigned char count;
 SendCommandByte(0x80);  //设置DDRAM地址
 for(count=0;count<16;count++)
    {
	 SendDataByte(*p++);
   	}
} 

//---------------------------------------------
void DisplayMsg4(uchar *p)
{ 
 unsigned char count;
 SendCommandByte(0xc0);  //设置DDRAM地址
 for(count=0;count<16;count++)
    {
	 SendDataByte(*p++);
   	}
}
//==================================================
main()
{
 char code msg1[16]="3w.huatianst.com";
 char code msg2[16]="  QQ:119120709  ";
 char code msg3[16]="   13724397978  ";
 char code msg4[16]=" 0755-81465285  ";
 InitLcd();
 while(1)
 {
   DisplayMsg1(msg1);
   DisplayMsg2(msg2);
   delay(60000);delay(60000);
   delay(60000);delay(60000);
   DisplayMsg3(msg3);
   DisplayMsg4(msg4);
   delay(60000);delay(60000);

 }

}

⌨️ 快捷键说明

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