我用一个四输入与门扩展外部中断,实现16*64点阵屏功能切换,key1是移动的汉字,key2是静态的汉字,刚给单片机上电,按1可以显示移动的汉字,再按2可以显示静态的汉字,但是再按1就回不去了,求帮忙看看程序怎么实现,感激不尽,移动中用了串口发送数据
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit r=P3^0;
sbit stb=P2^4;
sbit clk=P3^1;
sbit key1=P1^4;
sbit key2=P1^5;
uchar flag1,flag2;
uchar BUFF[14];
uchar code write_table[]={
};
uchar code table[]={
};
/*移动汉字子程序模块*/
void in_data(uchar h,uchar zimo)
{
uchar num;
for(num=0;num<=6;num++)
{
BUFF[2*num]=table[32*num+2*h+zimo];
BUFF[2*num+1]=table[32*num+1+2*h+zimo];
}
}
void rxd_data(uchar yid)
{
uchar inc,s,tempyid,temp;
if(yid<8)
inc=0;
else
inc=1;
for(s=0+inc;s<8+inc;s++)
{
if(yid<8)
tempyid=yid;
else
tempyid=yid-8;
temp=(BUFF[s]<<tempyid)|(BUFF[s+1]>>(8-tempyid));
SBUF=temp;
while(!TI);
TI=0;
}
}
void sbuf_out(uchar yid,uint zimo)
{
uchar h;
for(h=0;h<16;h++)
{
in_data(h,zimo);
rxd_data(yid);
P2=15;
stb=0;
stb=1;
P2=h;
}
}
/*延时*/
void delay(uchar z)
{
uchar x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
/*静态一个字节写入*/
void write_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat=dat>>1;
r=CY;
clk=0;
clk=1;
}
}
void main()
{
EA=1;
EX0=1;
IT0=1;
while(1)
{
if(flag1==1)
{
uint zimo;
uchar d,yid;
for(yid=0;yid<16;yid++)
{
for(d=0;d<5;d++)
{
sbuf_out(yid,zimo);
}
}
yid=0;
zimo=zimo+32;
if(zimo>=320)
zimo=0;
}
if(flag2==1)
{
uchar num;
for(num=0;num<16;num++)
{
write_byte(write_table[2*num]);
write_byte(write_table[2*num+1]);
write_byte(write_table[2*num+32]);
write_byte(write_table[2*num+1+32]);
write_byte(write_table[2*num+64]);
write_byte(write_table[2*num+1+64]);
write_byte(write_table[2*num+96]);
write_byte(write_table[2*num+1+96]);
P2=num;
stb=1;
stb=0;
delay(1);
}
num=0;
}
}
}
void zhongduan() interrupt 0
{
EX0=0;
if(key1==0)
{
flag1=1;
flag2=0;
}
if(key2==0)
{
flag1=0;
flag2=1;
}
EX0=1;
}
|