#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
float num=51;
float temp;
uchar val;
uchar aa[4];
unsigned char code disp_code[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0xff};//数码管显现
/**********************************************************
延时子函数
**********************************************************/
void delayms(uint ms)
{
uchar t;
while(ms–)
{
for(t = 0; t < 120; t++);
}
}
/******************************************************************
函数功用:显现计数次数的子程序
进口参数:x
********************************************************************/
void Display(void)
{ uchar i;
P2=0xfe ;
for(i=0;i<4;i++)
{ P1=disp_code[aa[i]];
if(P2==0xfb)
P1=disp_code[aa[i]]&0x7f;
delayms(5);
P2=_crol_(P2,1);
}
}
/*******************************************
函数功用:主函数
******************************************/
void main(void)
{
EA=1; //敞开总中止
EX0=EX1=1; //答应运用外中止
IT0=IT1=1; //挑选负跳变来触发外中止
temp=num/8.5;
val=(uchar)temp;
if(val<15)
{aa[0]=16;val=15-val;}
else {aa[0]=17;val=val-15;}
aa[1]=val/10;
if (aa[1]==0)
aa[1]=17;
aa[2]=val%10;
aa[3]=0;
P0=(uchar)num;
while(1)
Display();
}
void int0(void) interrupt 0 //外中止0的中止编号为0
{
if(num==0)
num=num+8.5;
num=num-8.5;
temp=num/8.5;
val=(uchar)temp;
if(val<15)
{aa[0]=16;val=15-val;}
else {aa[0]=17;val=val-15;}
aa[1]=val/10;
if (aa[1]==0)
aa[1]=17;
aa[2]=val%10;
aa[3]=0;
}
void int1(void) interrupt 2 //外中止1的中止编号为0
{
if(num==255)
num=num-8.5;
num=num+8.5;
temp=num/8.5;
val=(uchar)temp;
if(val<15)
{aa[0]=16;val=15-val;}
else {aa[0]=17;val=val-15;}
aa[1]=val/10;
if (aa[1]==0)
aa[1]=17;
aa[2]=val%10;
aa[3]=0;
P0=(uchar)num;
}