数码管静态显示
0赞#include<reg52.h>
typedef unsigned char uchar;
sbit wei=P1^6;
sbit duan=P1^7;
uchar code tab[]={0X3F,0x06,0X5B,0X4F,0X66,0X6D,0X7D, 0X07, 0X7F,0X6F};
uchar i=0;//定义i为全局变量,目的是为了在中断程序里满一秒后回到主程序显示下一个数字
void Timer0Init(void)
{ TMOD=0x01; //定时器t0为方式1
TL0=0x00;//定时时间50ms
TH0=0x4c;
EA=1; //开总中断
ET0=1;
TR0=1; //定时器开始工作
}
void main(void)
{
Timer0Init();
wei=1;
P0=0x00;//8位数码管全选中
wei=0;
while(1)
{ duan=1;
P0=tab[i];
duan=0;
}
}
void Timer0_ISR(void) interrupt 1
{ static uchar j=0;//j为静态局部变量,目的是为了每次中断来都能加1
TL0=0x00; //重新装值
TH0=0x4c;
j++;
if(20==j)//说明1秒时间到了
{ j=0;
i++;
if(10==i)//说明数码管显示的数字溢出了
i=0;
}
}
