?? 復件 lcd.c
字號:
/*實驗名稱:字符型LCD接口實驗
功能:在LCD上顯示
AT89S51 DEMO
www.mcuprog.com
作者:http://www.mcuprog.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.mcuprog.com ";
InitLcd();
DisplayMsg1(msg1);
DisplayMsg2(msg2);
while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -