📄 isulcd1602.c
字号:
#include<EXAM.H>
#include<intrins.h>
typedef unsigned char uchar;
uchar data temp1[0x10],temp2[0x10],temp,lineflag=0;
void delay(uchar i)//延时函数
{
uchar data j=255;
while(i--)
while(j--);
}
void test_1602busy()//测忙函数
{
do{
DBPort=0xff;
LCDEN=0;
LCDRS=0;
LCDWR=1;
_nop_();
_nop_();
LCDEN=1;
}while(DBPort&0x80);
LCDEN=0;
}
void write_1602co(uchar co,busy)//写命令函数
{
if(busy)
test_1602busy();
LCDRS=0;
LCDWR=0;
LCDEN=0;
_nop_();
_nop_();
DBPort=co;
_nop_();
_nop_();
_nop_();
_nop_();
LCDEN=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDEN=0;
}
void write_1602da(uchar da,busy)//写数据函数
{
if(busy)
test_1602busy();
LCDRS=1;
LCDWR=0;
LCDEN=0;
_nop_();
_nop_();
DBPort=da;
_nop_();
_nop_();
LCDEN=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDEN=0;
}
void init_1602(void)//初始化函数
{
/* */
write_1602co(0x38,0);
delay(5);
write_1602co(0x38,0);
delay(5);
write_1602co(0x38,0);
delay(5);
write_1602co(0x38,1);
delay(5);
write_1602co(0x08,1);
delay(5);
write_1602co(0x01,1);
delay(5);
write_1602co(0x06,1);
delay(5);
write_1602co(0x0c,1);
delay(5);
}
/*void display_1602(uchar *p,x,y)//正向显示函数
{
x&=0x0f;
y&=0x01;
y<<=6;
x|=y;
x|=0x80;
write_1602co(x,0);//定起始字符位置
delay(5);
while(*p)
{
write_1602da(*p,1);//写字符
p++;
delay(70);//每输出一个字符,延时,实现拉幕效果
}
} */
void display1602(uchar *p,x,y)//正向显示函数
{
uchar i;
x&=0x0f;
y&=0x01;
y<<=6;
x|=y;
x|=0x80;
write_1602co(x,0);//定起始字符位置
delay(5);
for(i=0;i<0x10;i++)
{
write_1602da(*(p+i),1);//写字符
// p++;
// delay(70);//每输出一个字符,延时,实现拉幕效果
}
}
void indisplay_1602(uchar *p,y)//反向显示函数
{
uchar x,i,j;
x=0x0f;
x&=0x0f;
y&=0x01;
y<<=6;
x|=y;
x|=0x80;
for(i=0x00;i<0x10;i++)
{
write_1602co(x-i,0);//定起始字符位置
delay(5);
for(j=0;j<i+1;j++)
{
write_1602da(*(p+j),1);//写字符
delay(5);//每输出一个字符,延时,实现拉幕效果
}
}
}
void timemovie()
{
char i;
//uchar *s;
temp=temp1[0x0f];
for(i=0x0e;i>=0;i--)
{
temp1[i+1]=temp1[i];
}
temp1[0]=temp2[0];
for(i=0;i<0x0f;i++)
{
temp2[i]=temp2[i+1];
}
temp2[0x0f]=temp;
// s="movie end";
// display1602(s,0,0);
}
void time()
{
timemovie();
write_1602co(0x01,1);//清屏
display1602(temp1,0,0);
display1602(temp2,0,1);
delay(50);
}
void timerun()
{uchar i;
for(i=0;i<0x20;i++)
{
time();
delay(70);
}
}
void untimemovie()
{
char i;
//uchar *s;
temp=temp2[0x0f];
for(i=0x0e;i>=0;i--)
{
temp2[i+1]=temp2[i];
}
temp2[0]=temp1[0];
for(i=0;i<0x0f;i++)
{
temp1[i]=temp1[i+1];
}
temp1[0x0f]=temp;
// s="movie end";
// display1602(s,0,0);
}
void untime()
{
untimemovie();
display1602(temp1,0,0);
display1602(temp2,0,1);
delay(50);
}
void untimerun()
{uchar i;
for(i=0;i<0x20;i++)
{
untime();
delay(70);
}
}
void linemovie(uchar path)
{uchar i;
if(path) //left
{
temp=temp1[0];
for(i=0;i<0x0f;i++)
{
temp1[i]=temp1[i+1];
}
temp1[i]=temp;
temp=temp2[0];
for(i=0;i<0x0f;i++)
{
temp2[i]=temp2[i+1];
}
temp2[i]=temp;
}
else
{
temp=temp1[0x0f];
for(i=0x0f;i>0;i--)
{
temp1[i]=temp1[i-1];
}
temp1[i]=temp;
temp=temp2[0x0f];
for(i=0x0f;i>0;i--)
{
temp2[i]=temp2[i-1];
}
temp2[i]=temp;
}
}
void line()
{uchar i;
for(i=0;i<0x06;i++)
{
linemovie(lineflag);
display1602(temp1,0,0);
display1602(temp2,0,1);
delay(50);
}
for(i=0;i<0x06;i++)
{
linemovie(~lineflag);
display1602(temp1,0,0);
display1602(temp2,0,1);
delay(50);
}
lineflag=~lineflag;
}
void exchange()
{uchar i;
for(i=0;i<0x10;i++)
{
temp=temp1[i];
temp1[i]=temp2[i];
temp2[i]=temp;
}
display1602(temp1,0,0);
display1602(temp2,0,1);
delay(50);
}
void Inter0 (void) interrupt 0 //INIT0
{
unsigned char i,k,j,flag,*s ;
//EA=1;
EA=0;
flag=0;
P2=0xff;
write_1602co(0x01,1);//清屏
s="Get Input.......";
display1602(s,0,0);//第一行显示
for(i=0;i<255;i++)
{
if (i==250)
{
k=k+1;
if (k>250)
{
s="Time Out!! ";
display1602(s,0,1);//第二行显示
break ;
}
}
j= P2&0x0f ;
// if (j>0)
// {
// inttostr(j,3,0);
// break;
// }
switch (j)
{
case 0x07: timerun();flag=1;break;
case 0x0b: untimerun();flag =1;break;
case 0x0d: line();flag=1;break;
case 0x0e: exchange();flag=1;break;
default: time();
}
if (flag)
{
EA=1;
break;
}
}
}
void main()
{
uchar *s;
//uchar i;
EA = 1;
EX0 = 1;//INT0 OPEN
ES = 1;//RS232 OPEN
IT0 = 0;
EA=0;
init_1602();//1602初始化
delay(15);
/* s=" Welcome to ISU ";
display_1602(s,0,0);//第一行显示"Welcome to"
s=" Luozc 9701110E ";
display_1602(s,0,1);//第二行显示
delay(200);
for(i=5;i;i--)//5次闪烁。。。
{
write_1602co(0x08,1);//关显示
delay(200);
write_1602co(0x0c,1);//开显示,实现闪烁效果
delay(200);
}
delay(200);
delay(200);
delay(200);
write_1602co(0x01,1);//清屏
delay(200); */
s="**XX-86-01-24***";
indisplay_1602(s,0);
delay(200);
delay(200);
delay(200);
delay(200);
delay(190);
write_1602co(0x01,1);//清屏
s=" GOOD ";
display1602(s,0,0);
s=" LUCK ";
display1602(s,0,1);
temp1[0x00]=0x80;
temp1[0x01]=0x80;
temp1[0x02]=0x80;
temp1[0x03]=0x80;
temp1[0x04]=0x80;
temp1[0x05]=0x80;
temp1[0x06]=0x47;
temp1[0x07]=0x4f;
temp1[0x08]=0x4f;
temp1[0x09]=0x44;
temp1[0x0a]=0x80;
temp1[0x0b]=0x80;
temp1[0x0c]=0x80;
temp1[0x0d]=0x80;
temp1[0x0e]=0x80;
temp1[0x0f]=0x80;
temp2[0x00]=0x80;
temp2[0x01]=0x80;
temp2[0x02]=0x80;
temp2[0x03]=0x80;
temp2[0x04]=0x80;
temp2[0x05]=0x80;
temp2[0x06]=0x4c;
temp2[0x07]=0x55;
temp2[0x08]=0x43;
temp2[0x09]=0x4b;
temp2[0x0a]=0x80;
temp2[0x0b]=0x80;
temp2[0x0c]=0x80;
temp2[0x0d]=0x80;
temp2[0x0e]=0x80;
temp2[0x0f]=0x80;
//EA = 1;
EX0 = 1;//INT0 OPEN
//ES = 1;//RS232 OPEN
IT0 = 0;
EA=1;
/*
while(1)
{
for(i=0;i<0x20;i++)
{
time();
delay(70);
}
for(i=0;i<0x20;i++)
{
untime();
delay(70);
}
}
*/
// s=" !LUCK! ";
// display_1602(s,0,1);
for(;;)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -