#include
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long int ulint;
void Display();
void Get_Value(uchar *pCount);
void Init_Timer();
void Add_Dec();
sbit Duan_Code = P2^2;
sbit Wei_Code = P2^3;
sbit Key_Add = P1^0;
sbit Key_Dec = P1^1;
uchar code dofly_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar TempData[8];
static ulint Led_Value = 0;
static uchar sign = 1;/*中断2标志位*/
void main(void)
{
Init_Timer();
while(1)
{
Add_Dec();
}
}
/**加减操作**/
void Add_Dec()
{
if(!Key_Add)
{
Display();
if(!Key_Add)
{
while(!Key_Add)
{
Display();
}
if(Led_Value <= 99)
{
Led_Value++;
}
}
}
if(!Key_Dec)
{
Display();
if(!Key_Dec)
{
while(!Key_Add)
{
Display();
}
if(Led_Value > 0)
{
Led_Value--;
}
}
}
}
/*数码管显示函数*/
void Display()
{
uchar Count;
uchar i;
uchar j;
Get_Value(&Count);
for(i = 0, j = 7; i <= Count;i++,j--)
{
P0 = 0;
Duan_Code = 1;
Duan_Code = 0;
P0 = dofly_WeiMa[j];
Wei_Code = 1;
Wei_Code = 0;
P0 = TempData;
Duan_Code = 1;
Duan_Code = 0;
while(sign);
sign = 1;
}
}
/**此函数功能是把一个数按10进制划分,并返回他的一个记录数**/
void Get_Value(uchar *pCount)
{
uchar i;
ulint Temp_Value = Led_Value;
for(i = 0; i < 8; i++)
{
TempData = dofly_DuanMa[Temp_Value%10];
Temp_Value = Temp_Value / 10;
if(Temp_Value == 0)
{
break;
}
}
*pCount = i;
}
/**初始化中断**/
void Init_Timer()
{
Key_Add = 1;
Key_Dec = 1;
TMOD = 0x11;
TH1 = (65535 - 10000) / 256;
TL1 = (65535 - 10000) % 256;
EA = 1;
ET1 = 1;
TR1 = 1;
}
/**中断函数**/
void Timer1() interrupt 3
{
TH1 = (65535 - 50000) / 256;
TL1 = (65535 - 50000) % 256;
sign = 0;