/*实验名称:字符型LCD接口实验
功能:在LCD上显示
AT89S51 DEMO
www.mcuprog.com
作者:http://www.mcuprog.com
05-02-01
*/
#include <stc12c5a60s2.h>
sbit E=P3^4;
sbit RW=P3^3;
sbit RS=P3^2;
typedef unsigned char uchar;
//-------------------------------------
void Delay(unsigned int t) // delay 40us
{
for(;t!=0;t--) ;
}
void SendCommandByte(unsigned char ch)
{
RS=0;
RW=0;
P1=ch;
E=1;
Delay(1);
E=0;
Delay(100); //delay 40us
}
void SendDataByte(unsigned char ch)
{ RS=1;
RW=0;
P1=ch;
E=1;
Delay(1);
E=0;
Delay(100); //delay 40us
}
void InitLcd()
{
SendCommandByte(0x38); //设置工作方式
SendCommandByte(0x0c); //显示状态设置
SendCommandByte(0x01); //清屏
SendCommandByte(0x06); //输入方式设置
}
//=============================================
void DisplayMsg1(uchar *p)
{
unsigned char count;
SendCommandByte(0x); //设置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]="0123456789ABCDEF";
char msg2[16]="WWW.LiChunli.COM";
InitLcd();
DisplayMsg1(msg1);
DisplayMsg2(msg2);
while(1);
}
显示结果:
456789ABCDEF
WWW.LiChunli.COM
本文出自 “生命不息,折腾不止。” 博客,谢绝转载!
原文:http://990487026.blog.51cto.com/10133282/1700046