这个程序是单片机空闲与掉电模式应用,实验现象是数码管从00递增到05,接着变成5,我想请问为什么会这样?
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uchar unsigned int
#define uint unsigned int
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar num;
void delay(uint);
void display(uchar shi,uchar ge)
{
LSA=0,LSB=0,LSC=0;
P0=table[shi];
delay(5);
LSA=0,LSB=0,LSC=1;
P0=table[ge];
delay(5);
}
void delay(uint ms)
{
uint i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
uchar a,b,num1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
EX0=1;
EX1=1;
TR0=1;
while(1) //从这里开始看不懂,程序是如何实现的
{
if(num>=20)
{
num=0;
num1++;
if(num1==6)
{
ET0=0;
PCON=0x02;
}
a=num1/10;
b=num1%10;
}
display(a,b);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void ex_int0() interrupt 0
{
PCON=0;
ET0=1;
}
void ex_int1() interrupt 2
{
PCON=0;
ET0=1;
}
#define uchar unsigned int
#define uint unsigned int
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar num;
void delay(uint);
void display(uchar shi,uchar ge)
{
LSA=0,LSB=0,LSC=0;
P0=table[shi];
delay(5);
LSA=0,LSB=0,LSC=1;
P0=table[ge];
delay(5);
}
void delay(uint ms)
{
uint i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
uchar a,b,num1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
EX0=1;
EX1=1;
TR0=1;
while(1) //从这里开始看不懂,程序是如何实现的
{
if(num>=20)
{
num=0;
num1++;
if(num1==6)
{
ET0=0;
PCON=0x02;
}
a=num1/10;
b=num1%10;
}
display(a,b);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void ex_int0() interrupt 0
{
PCON=0;
ET0=1;
}
void ex_int1() interrupt 2
{
PCON=0;
ET0=1;
}