|
用数码管显示555产生的脉冲宽度显示并保留一位小数,在用数码管显示时发现总是闪烁,而且小数部分还时常不怎么显示数字,,
附程序:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
long ss=0;
uchar n,bai,shi,ge,xiao;
sbit Sl=P3^3;
uchar code duanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code weiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delayMs(uint x);
void display();
void main()
{
TMOD=0x90;
TH1=0;
TL1=0;
EA=1;
TR1=0;
while(Sl);
while(Sl==0);
TR1=1;
while(Sl);
TR1=0;
ss=65536*n+256*TH1+TL1;
bai=ss/100000;
shi=ss%100000/10000;
ge=ss%100000%10000/1000;
xiao=ss%100000%10000%1000;
display();
}
void delayMs(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
P2=0xff;
P2=weiMa[0];
P0=duanMa[bai];
delayMs(3);
P2=0xff;
P2=weiMa[1];
P0=duanMa[shi];
delayMs(3);
P2=0xff;
P2=weiMa[2];
P0=duanMa[ge]|0x80;
delayMs(3);
P2=0xff;
P2=weiMa[3];
P0=duanMa[xiao];
delayMs(3);
}
void T1_time()interrupt 1
{
n++;
}
|
|