// IT1 = 0;
TR0 = 1;
}
void delayms(uint x)//延时函数
{
uint i,j;
for(i = x;i》0;i--)
for(j=110;j》0;j--);
}
void display(uchar gw,uchar sw)//显示函数
{
dula = 1;
P0 = table[sw];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
delayms(5);
P0 = 0x0;//消影
dula = 1;
P0 = table[gw];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
delayms(5);
}
void main()
{
init();
while(1)
{
display(gw,sw);
}
}
void timer0()interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
aa ++;
if(aa ==20)
{
aa =0;
num++;
if(num == 99)
num =0;
gw = num%10;
sw = num/10;
if(num == 6)
{
ET0 = 0;//关闭定时器
PCON = 0x01;//单片机进入空闲模式
}
}
}
void ex_int0()interrupt 0
{
// PCON = 0;//可要可不要
ET0 =1;
}
void ex_int1()interrupt 2
{
// PCON = 0;//可要可不要
ET0 = 1;
}
正确代码:
#include
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;
uchar num ,gw,sw,aa;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init()//初始化函数
{
TMOD = 0x01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
ET0 = 1;
EX0 = 1;//打开外部中断0
// IT0 = 0;//电平触发方式
EX1 = 1;//打开外部中断1
// IT1 = 0;
TR0 = 1;
}
void delayms(uint x)//延时函数
{
uint i,j;
for(i = x;i》0;i--)
for(j=110;j》0;j--);
}
void display(uchar gw,uchar sw)//显示函数
{
dula = 1;
P0 = table[sw];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
delayms(5);
P0 = 0x0;//消影
dula = 1;
P0 = table[gw];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
delayms(5);
}
void main()
{
init();
while(1)
{
if(aa ==20)
{
aa =0;
num++;
if(num == 99)
num =0;
gw = num%10;
sw = num/10;
if(num == 6)
{
ET0 = 0;//关闭定时器
PCON = 0x01;//单片机进入空闲模式
}
}
display(gw,sw);
}
}
void timer0()interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
aa ++;
}
void ex_int0()interrupt 0