功能:-9.99-99.99,每50ms增加0.01,终止状态为99.99
#include<reg52.h>
char duan[12]={0x3f,0x06,0x5b,0x4f, 0x66, 0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
char wei[8] = {0xff, 0xfb, 0xf7, 0xf3, 0xef, 0xeb, 0xe7, 0xe3 };
char shownum[8] = {10,10,10,10,11,9,9,9}; //显示8位数值
char showpos = 4; //显示位
int t0_time = 0; //T0中断次数 0-50
char incflag = 0; //是否增1
void T0int( ) interrupt 1 // T0定时1ms中断响应子函数
{
TH0 = 0xFC;
TL0 = 0x18;
showpos++;
if(showpos==8)
showpos=4;
if(incflag==0)
{
t0_time ++;
if(t0_time==50) //2用来调整数值,
{
t0_time = 0;
shownum[7]--;
if(shownum[7]<0)
{
shownum[7]=9;
shownum[6]--;
if(shownum[6]<0)
{
shownum[6]=9;
shownum[5]--;
}
}
}
}
if(shownum[4]==11&&shownum[5]==0&&shownum[6]==0&&shownum[7]==0)
{
incflag=1;
shownum[4]=0;
}
if(incflag==1)
{
t0_time++;
if(t0_time==50)
{
t0_time=0;
shownum[7]++;
if(shownum[7]==10)
{
shownum[7]=0;
shownum[6]++;
if(shownum[6]==10)
{
shownum[6]=0;
shownum[5]++;
if(shownum[5]==10)
{
shownum[5]=0;
shownum[4]++;
}
}
}
}
}
if(shownum[4]==9&&shownum[5]==9&&shownum[6]==9&&shownum[7]==9)
incflag=-1;
}
void Show1(void) //显示
{
P0 = duan[ shownum[showpos] ] +(showpos==5)*0x80; //加小数点
P2 = wei[showpos];
}
void init() //初始化
{
TMOD = 0x01; //参数设置
TH0 = 0xFC; //定时1ms
TL0 = 0x18;
ET0 = 1;
EA = 1;
TR0 = 1;
}
main()
{
init();
while(1)
Show1();
}