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

📄 lcd.c.txt

📁 at89s51实验例程代码
💻 TXT
字号:
/*实验名称:字符型LCD接口实验
  功能:在LCD上显示
	 AT89S51 DEMO
	www.mcuyjf.com
  作者:http://www.mcuyjf.com
        05-02-01
*/
#include <reg51.h>
sbit E=P3^5;
sbit RW=P3^6;
sbit RS=P3^7;	
typedef unsigned char uchar;
//-------------------------------------
void Delay(unsigned int t)   // delay 40us
{
 for(;t!=0;t--) ;
}
//=============================================
void SendCommandByte(unsigned char ch)
{
   RS=0;
   RW=0;
   P0=ch;
   E=1;
    Delay(1);
   E=0;
   Delay(100);  //delay 40us
}
//-------------------------------------------------------
void SendDataByte(unsigned char ch)
{  RS=1;
   RW=0;
   P0=ch;
   E=1;
       Delay(1);
   E=0;
   Delay(100); //delay 40us
}
//-------------------------------------------------
void InitLcd()
{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++);
   	}
}
//=============================================
main()
{char msg1[16]="  AT89S51 DEMO  ";
 char msg2[16]="www.mcuyjf.com ";
 InitLcd();
 DisplayMsg1(msg1);
 DisplayMsg2(msg2);
 while(1);
}

⌨️ 快捷键说明

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