#include <reg51.h>
#include <intrins.h>
unsigned char code LED7Code[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,//0-9字模
0x88,0x83,0xc6,0xa1,0x86,0x8e};//共阳极7段数码管A-F字模,原来的是错误的.
unsigned char num,temp;
unsigned int a, b,c;
void system_init()
{
EA=1; //开中断总开关
ET0=1;//加一行,开定时器T0中断
TMOD=0x01; //定时器0方式1
TH0=(65535-50000)/256; //定时50ms
TL0=(65535-50000)%256;
num=0;
temp=0;
TR0=1; //开定时器0
P0=LED7Code[num]; //不能是num++
}
void delay(int m){
while(m--);
}
void main()
{
system_init(); //参数初始化
while(1)
{
if(temp==20) //定时1s,刷新数码管数字显示
{
temp=0; //标志位置零,计数程序修改后是这样的
num++; //原来的写法有问题
//显示字符,不能是num++
}
a = num % 10;
b = num/10%10;
c = num/100;
P2 = 0xdf;
delay(500);
P0=LED7Code[a];
P2 = 0x7f;
delay(500);
P0= LED7Code[b];
P2=0xbf;
delay(500);
P0= LED7Code[c];
}
}
void Time() interrupt 1 using 1 //中断函数
{
TH0=(65535-50000)/256; //定时50ms
TL0=(65535-50000)%256;
temp++;
}
#include <intrins.h>
unsigned char code LED7Code[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,//0-9字模
0x88,0x83,0xc6,0xa1,0x86,0x8e};//共阳极7段数码管A-F字模,原来的是错误的.
unsigned char num,temp;
unsigned int a, b,c;
void system_init()
{
EA=1; //开中断总开关
ET0=1;//加一行,开定时器T0中断
TMOD=0x01; //定时器0方式1
TH0=(65535-50000)/256; //定时50ms
TL0=(65535-50000)%256;
num=0;
temp=0;
TR0=1; //开定时器0
P0=LED7Code[num]; //不能是num++
}
void delay(int m){
while(m--);
}
void main()
{
system_init(); //参数初始化
while(1)
{
if(temp==20) //定时1s,刷新数码管数字显示
{
temp=0; //标志位置零,计数程序修改后是这样的
num++; //原来的写法有问题
//显示字符,不能是num++
}
a = num % 10;
b = num/10%10;
c = num/100;
P2 = 0xdf;
delay(500);
P0=LED7Code[a];
P2 = 0x7f;
delay(500);
P0= LED7Code[b];
P2=0xbf;
delay(500);
P0= LED7Code[c];
}
}
void Time() interrupt 1 using 1 //中断函数
{
TH0=(65535-50000)/256; //定时50ms
TL0=(65535-50000)%256;
temp++;
}