#include<reg52.h> #define uint unsigned int #define uchar unsigned char
sbit P10=P1^0; sbit P11=P1^1; //位码口 sbit P12=P1^2; sbit P13=P1^3;
sbit P32=P3^2;
unsigned char code Duan[]={0x3F, 0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //对应0---9 unsigned char Data_Buffer[4]={0,0,0,0}; //存放统计的数据。 单位为(100uS)
uint time=0;
void fenge() //分割数据,以便于统计较大间隔时间。 { Data_Buffer[0]=time/1000; Data_Buffer[1]=time/100%10; Data_Buffer[2]=time/10%10; Data_Buffer[3]=time%10; }
void display() //用于四个数码管显示数据 { uchar Bit=0; while(1) { Bit++; if(Bit>=4) Bit=0; P0=Duan[Data_Buffer[Bit]]; //数据的输出 switch(Bit)//开位码 { case 0: P10=0;break; case 1: P11=0;break; case 2: P12=0;break; case 3: P13=0;break; } } }
void mian() { EX0=0; EA=1; IT0=0;//低电平有效
TMOD=0x02; //设置为自动重载方式 TH0=0x92; //设置为100uS的计数 TL0=0x92; TR0=0;
while(1) { fenge(); display(); time=0; //当前显示完毕后,清当前time的值 EX0=1; //开启外部中断 }
}
void zhongduan() interrupt 0 { TR0=1; if(TH0==1) //100uS定时器溢出 { time++; //统计两个脉冲的时间 TH0=0; } if(P32==1) //如果外部中断变为高电平,关闭中断。保证统计的是两个脉冲的间隔时间。为主函数显示数据争取时间。 EX0=0;
}
有点问题,谁能帮我改改吗! |