/*
功能:LCD1602 测试C程序
单片机:STC12C2052AD
晶振 :12M
接线:P1^0到P1^7 接 D0到D7
E=P3^4;
RW=P3^3;
RS=P3^2;
时间:2015年10月4日
*/
#include <STC12C2052AD.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(0x06); //输入方式设置
SendCommandByte(0x02); //回零
SendCommandByte(0x01); //清屏
}
//=============================================
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() {
InitLcd();
while(1) {
unsigned char msg1[16]="http://990487026";
unsigned char msg2[16]=".blog.51cto.com/";
DisplayMsg1(msg1);
DisplayMsg2(msg2);
}
}
//显示结果:
//http://990487026
//.blog.51cto.com/
转载于:https://blog.51cto.com/990487026/1700046