下面是我用keil写的代码,我想通过按键来唤醒处于休眠模式中的
单片机,但不知道哪一步有问题,按键没有反应。希望各位大神能帮我指点一下。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
uchar num;
void display(uchar,uchar);
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
}
void main()
{
uchar a,b,num1;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(a,b);
if(num==20)
{
num=0;
num1++;
a=num1/10;
b=num1%10;
if(num1==6)
{
PCON=0x02;
TR0=0;
if(key1==0)
{
delay(10);
if(key1==0)
{
PCON=0;
TR0=1;
}
}
}
}
}
}
void
time0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num++;
}
一周热门 更多>