#include<reg52.h>
#define DataPort P0
#include <intrins.h>
sbit LATCH1=P2^2;
sbit LATCH2=P2^3;// 位锁存
sbit LED=P2^0;
unsigned int b;
unsigned char num=12;
unsigned char code dofly_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 显示段码值0~9
unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
unsigned char TempData[8]; //存储显示值的全局变量
//unsigned char kjh[3]={0,1,1};
void Delay(unsigned int t); //函数声明
void Display(unsigned char FirstBit,unsigned char Num);
void TIM2Inital(void)
{
RCAP2H = (65536-60000)/256;//
RCAP2L = (65536-60000)%256;
ET2=1; //打开定时器中断
EA=1; //打开总中断
TR2=1; //打开定时器开关
}
main()
{
unsigned int j,jj=1;
//if( TempData[1]==0x5b)
TIM2Inital();
P1=0XFE;
while(1)
{
j++; if(j==100)
{
j=0;
if(num>0) num--;
else {num=10;
P1=_crol_(P1,1);
while(P1==0xf7)
{P1=0XFE; }
}
}
TempData[0]=dofly_DuanMa[num/10];//
TempData[1]=dofly_DuanMa[num%10];
Display(1,2);
}
}
void Delay(unsigned int t)
{
while(--t);
}
void Display(unsigned char FirstBit,unsigned char Num)
{
unsigned char i;
for(i=0;i<Num;i++)
{
DataPort=0; //清空数据,防止有交替重影
LATCH1=1; //段锁存
LATCH1=0;
DataPort=dofly_WeiMa[i+FirstBit]; //取位码
LATCH2=1; //位锁存
LATCH2=0;
DataPort=TempData[i]; //取显示数据,段码
LATCH1=1; //段锁存
LATCH1=0;
Delay(10); //
}
}
void TIM2(void) interrupt 5 using 1
{
RCAP2H = (65536-100)/256;//
RCAP2L = (65536-100)%256;
b++;
if(b>=60000)
{b=0x00;
TF2=0;
} if(num<=3)LED=~ LED;
//指示灯反相
}