第一个程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar count,a;
uchar leddata[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint t)
{
uint x,y;
for(x=0;x<t;x++)
for(y=0;y<114;y++);
}
void timer_init()
{
TMOD=0x01;
TH0=0X4B;
TL0=0XFD;
IE=0x82;
TR0=1;
}
void timer_zd() interrupt 1
{
TH0=0X4B;
TL0=0XFD;
count++;
}
void main()
{
timer_init();
while(1)
{
if(count==20)
{
count=0;
a++;
}
P0=leddata[a/10];
P2=0x03;
delay(1);
P0=leddata[a%10];
P2=0x04;
delay(1);
}
}
第二个程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar count,a;
uchar leddata[]={0x3f,//0
0x06,//1
0x5b,//2
0x4f,//3
0x66,//4
0x6d,//5
0x7d,//6
0x07,//7
0x7f,//8
0x6f//9
};
void delay(uint t)
{
uint x,y;
for(x=0;x<t;x++)
for(y=0;y<114;y++);
}
void timer_init()
{
TMOD=0x01;
TH1=0X4B;
TL1=0XFD;
IE=0x88;
TR1=1;
}
void timer_zd() interrupt 3
{
TH1=0X4B;
TL1=0XFD;
count++;
}
void main()
{
timer_init();
while(1)
{
if(count==20)
{
count=0;
a++;
}
P0=leddata[a/10];
P2=0x03;
delay(1);
P0=leddata[a%10];
P2=0x04;
delay(1);
}
}
两个程序的区别就是用T0和T1,其它的都一样,但是数码管显示的不一样 啊,第一个程序用T0,图片右边的数字是一秒一秒的加,第二个程序用T1,图片右边的数字是100mS的加,怎么回事啊???
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar count,a;
uchar leddata[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint t)
{
uint x,y;
for(x=0;x<t;x++)
for(y=0;y<114;y++);
}
void timer_init()
{
TMOD=0x01;
TH0=0X4B;
TL0=0XFD;
IE=0x82;
TR0=1;
}
void timer_zd() interrupt 1
{
TH0=0X4B;
TL0=0XFD;
count++;
}
void main()
{
timer_init();
while(1)
{
if(count==20)
{
count=0;
a++;
}
P0=leddata[a/10];
P2=0x03;
delay(1);
P0=leddata[a%10];
P2=0x04;
delay(1);
}
}
第二个程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar count,a;
uchar leddata[]={0x3f,//0
0x06,//1
0x5b,//2
0x4f,//3
0x66,//4
0x6d,//5
0x7d,//6
0x07,//7
0x7f,//8
0x6f//9
};
void delay(uint t)
{
uint x,y;
for(x=0;x<t;x++)
for(y=0;y<114;y++);
}
void timer_init()
{
TMOD=0x01;
TH1=0X4B;
TL1=0XFD;
IE=0x88;
TR1=1;
}
void timer_zd() interrupt 3
{
TH1=0X4B;
TL1=0XFD;
count++;
}
void main()
{
timer_init();
while(1)
{
if(count==20)
{
count=0;
a++;
}
P0=leddata[a/10];
P2=0x03;
delay(1);
P0=leddata[a%10];
P2=0x04;
delay(1);
}
}
两个程序的区别就是用T0和T1,其它的都一样,但是数码管显示的不一样 啊,第一个程序用T0,图片右边的数字是一秒一秒的加,第二个程序用T1,图片右边的数字是100mS的加,怎么回事啊???
