#include
#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();
}
}