新手求助关于按键后延时点亮led后,键盘不能扫描的问题
时间:10-02
整理:3721RD
点击:
我现在需要做一个延时程序,就是按下一个键后,延时1秒后,对应的led再亮,但是我做的这个程序第一次按键后正常,但是之后键盘就不再扫描了,这是为什么呢,新手虚心求教~
#include <AT89X51.H>
#define uchar unsigned char
#define uint unsigned int
sbit sh=P3^0;
sbit ds=P3^1;
sbit st=P3^2;
uint m=1331,n=0,i,a,b,c,x,y;
uchar key,sudu,temp;
uchar code h[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code j[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void saomiao()
{
P2=P2^0x50;
switch(P2)
{
case 0xe7:
key=1;
break;
case 0xeb:
key=2;
break;
case 0xed:
key=3;
break;
case 0xee:
key=4;
break;
}
P2=P2^0x30;
switch(P2)
{
case 0xd7:
key=5;
break;
case 0xdb:
key=6;
break;
case 0xdd:
key=7;
break;
case 0xde:
key=8;
break;
}
P2=P2^0x60;
switch(P2)
{
case 0xb7:
key=9;
break;
case 0xbb:
key=10;
break;
case 0xbd:
key=11;
break;
case 0xbe:
key=12;
break;
}
}
void init(void)
{
P0=0xaa;
P2=0xbf;
P1=0;
P3=0;
}
void main()
{
TMOD=0x11;
TL0=(65536-m)%256;
TH0=(65536-m)/256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=0;
PT1=1;
init();
while(1)
{
saomiao();
if(key==1)
{
TR1=1;
temp=key;
while(1)
{
saomiao;
if(temp!=key)
{
break;
}
if(n==20)
{
n=0;
P0_0=0;
P0_1=1;
TR1=0;
break;
}
}
}
if(key==2)
{
TR1=1;
temp=key;
while(1)
{
saomiao;
if(temp!=key)
{
break;
}
if(n==20)
{
n=0;
P0_0=1;
P0_1=0;
TR1=0;
break;
}
}
}
}
}
void timer0() interrupt 1 using 1
{
TL0=(65536-m)%256;
TH0=(65536-m)/256;
P1_7=~P1_7;
}
void timer1() interrupt 3 using 2
{
n++;
TL1=(65536-46083)%256;
TH1=(65536-46083)/256;
}
#include <AT89X51.H>
#define uchar unsigned char
#define uint unsigned int
sbit sh=P3^0;
sbit ds=P3^1;
sbit st=P3^2;
uint m=1331,n=0,i,a,b,c,x,y;
uchar key,sudu,temp;
uchar code h[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code j[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void saomiao()
{
P2=P2^0x50;
switch(P2)
{
case 0xe7:
key=1;
break;
case 0xeb:
key=2;
break;
case 0xed:
key=3;
break;
case 0xee:
key=4;
break;
}
P2=P2^0x30;
switch(P2)
{
case 0xd7:
key=5;
break;
case 0xdb:
key=6;
break;
case 0xdd:
key=7;
break;
case 0xde:
key=8;
break;
}
P2=P2^0x60;
switch(P2)
{
case 0xb7:
key=9;
break;
case 0xbb:
key=10;
break;
case 0xbd:
key=11;
break;
case 0xbe:
key=12;
break;
}
}
void init(void)
{
P0=0xaa;
P2=0xbf;
P1=0;
P3=0;
}
void main()
{
TMOD=0x11;
TL0=(65536-m)%256;
TH0=(65536-m)/256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=0;
PT1=1;
init();
while(1)
{
saomiao();
if(key==1)
{
TR1=1;
temp=key;
while(1)
{
saomiao;
if(temp!=key)
{
break;
}
if(n==20)
{
n=0;
P0_0=0;
P0_1=1;
TR1=0;
break;
}
}
}
if(key==2)
{
TR1=1;
temp=key;
while(1)
{
saomiao;
if(temp!=key)
{
break;
}
if(n==20)
{
n=0;
P0_0=1;
P0_1=0;
TR1=0;
break;
}
}
}
}
}
void timer0() interrupt 1 using 1
{
TL0=(65536-m)%256;
TH0=(65536-m)/256;
P1_7=~P1_7;
}
void timer1() interrupt 3 using 2
{
n++;
TL1=(65536-46083)%256;
TH1=(65536-46083)/256;
}
阵列键盘
顶上去,在线等呀~~ 刚刚想到的,定时器可以随时在程序里启动或关闭吗?