// 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

  • UC3846控制芯片工作原理控制图 逆变焊机原理与用途
  • 数字万用表电阻档测试二极管正反向没有阻值(使用万用表测量二极管的正向电阻,为什么各档)
  • 学单片机需要学数电模电吗(学单片机要先学数电模电吗)
  • 电工怎么选择适合自己用的万用表(电工初学者买什么样的万用表好)
  • 单片机需要同时运行多个任务怎么办(单片机怎么同时执行多个任务)
  • 电机保护的方案取决于负载的机械特性
  • 绝缘电阻表正负搭接不复零位是怎么回事
  • 短路怎么用万用表查