/*-----------------------------------------------
名称:LCD1602
学校:中州大学
网站:www.zhzhu.edu.cn
编写:我就是我lxw
内容:通过标准程序静态显示2行字符
------------------------------------------------*/
#include<reg52.h>
#include<stdio.h>
#include<intrins.h>
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
#define Data P0
char data TimeNum[]=" ";
char data Test1[]=" ";
void DelayUs(unsigned char us)
{
unsigned char uscnt;
uscnt=us>>1;
while(--uscnt);
}
void DelayMs(unsigned char ms)
{
while(--ms)
{
DelayUs(250);
DelayUs(250);
DelayUs(250);
DelayUs(250);
}
}
void WriteCommand(unsigned char c)
{
DelayMs(5);
E=0;
RS=0;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
}
void WriteData(unsigned char c)
{
DelayMs(5);
E=0;
RS=1;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
RS=0;
}
void ShowChar(unsigned char pos,unsigned char c)
{
unsigned char p;
if (pos>=0x10)
p=pos+0xb0;
else
p=pos+0x80;
WriteCommand (p);
WriteData (c);
}
void ShowString (unsigned char line,char *ptr)
{
unsigned char l,i;
l=line<<4;
for (i=0;i<16;i++)
ShowChar (l++,*(ptr+i));
}
void InitLcd()
{
DelayMs(15);
WriteCommand(0x38);
WriteCommand(0x38);
WriteCommand(0x38);
WriteCommand(0x06);
WriteCommand(0x0c);
WriteCommand(0x01);
}
void main(void)
{
InitLcd();
DelayMs(15);
sprintf(Test1,"MCU--DIY");
ShowString(0,Test1);
sprintf(TimeNum,"www.eepw.com.cn");
ShowString(1,TimeNum);
while(1);
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |