HD4478U显示LCD与51单片机驱动程序
#include
#include
sbit LCDRSPIN = P3^7;
sbit LCDRWPIN = P3^6;
sbit LCDEPIN = P2^6;
#define UCHAR unsigned char
void delay(unsigned int i)
{
UCHAR j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}
//控制LCD
unsigned char XPOS,YPOS;
//测忙
void LcdWaitIdle(void)
{ P0=0xff;
LCDRSPIN=0;
LCDRWPIN=1;
LCDEPIN=1;
while((P0&0x80)==0x80);
LCDEPIN=0;
}
//写指令代码
void LcdWCN(unsigned char c)
{ LCDRSPIN=0;
LCDRWPIN=0;
P0=c;
LCDEPIN=1;
_nop_();
LCDEPIN=0;
}
//写指令代码(测忙)
void LcdWC(unsigned char c)
{ LcdWaitIdle();
LcdWCN(c);
}
//写数据
void LcdWD(unsigned char d)
{ LcdWaitIdle();
LCDRSPIN=1;
LCDRWPIN=0;
P0=d;
LCDEPIN=1;
_nop_();
LCDEPIN=0;
}
//内部数据地址指针定位
void LcdPos(void)
{ XPOS&=0x0f;
YPOS&=0x03;
if(YPOS==0x00)
LcdWC(XPOS|0x80);
else if(YPOS==0x01)
LcdWC((XPOS+0x40)|0x80);
else if(YPOS==0x02)
LcdWC((XPOS+0x10)|0x80);
}
//初始化
void InitLcd()
{
LCDEPIN=0;
delay(150); LcdWCN(0x38); /*设置8位格式,2行,2*16*/
LcdWC(0x08); /*清除显示*/
LcdWC(0x06); /*设定输入方式,增量不移位*/
LcdWC(0x0c); /*整体显示,关光标,不闪烁*/
}
void LcdWDA(unsigned char x,unsigned char y,unsigned char *s)
{
YPOS=y;
for(XPOS=x;XPOS<16 && *s != 0;XPOS++)
{ LcdPos();
LcdWD(*s);
s++;
}
}
char LcdStr[13]={L,A,N,D, ,C,5,1,-,P,R,O,0x0};
char * str1=LcdStr;
char * str2="WWW.LDMCU.COM";
char CharPos=-11;
char CharLen = 12; //滚动的字符的个数
bit LcdPause = 0; //是否停止滚动
以下为字符显示位置与主程序,可相应修改。
//设置str1从左边进入
void LcdLeftIn()
{
delay(1500);
LCDEPIN=0;
LcdWDA(2,1,str2);
if(CharPos > 16)
{
CharPos = (CharLen - 1)* -1;
}
if(CharPos > 0)
{
LcdWDA(CharPos-1,0," "); //前进一格清除前面的字符
LcdWDA(CharPos,0,str1);
}
else
{
LcdWDA(0,0,str1-CharPos);
}
CharPos++;
// P3=P3B;
}
main()
{
InitLcd();
while(1)
{
LcdLeftIn();
}
}
HD4478ULCD51单片机驱动程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)