#include <reg51.h>
unsigned char code table[]={0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90};
unsigned int cnt,t1count;
unsigned long fre;
sbit s0=P3^0;
sbit s1=P3^1;
sbit s2=P3^2;
# define M 6
void delay ( int m)
{
unsigned char i,j;
for (i=0;i<m;i++)
for (j=0;j<23;j++);
}
void T1_ISP(void) interrupt 3
{
t1count ++;
TL1=0;
TH1=0;
}
void T0_ISP(void) interrupt 1
{
cnt++;
if (cnt==4000)
{
cnt="0";
EA="0";
fre="t1count"*65536+TH1*256+ TL1;
}
}
void led(long n) //数码管显示及数据处理程序
{
P2=0x01;
P0 = table[n / 10000000]; //千万位
delay(M);
P0=0xff;
P2=0x02;
P0 = table[n % 10000000 /1000000]; //百万位
delay(M);
P0=0xff;
P2=0x04;
P0 = table[n %1000000/100000]; //十万位
delay(M);
P0=0xff;
P2=0x08;
P0 = table[n % 100000/10000]; //万位
delay(M);
P0=0xff;
P2=0x10;
P0 = table[n %10000/ 1000]; //千位
delay(M);
P0=0xff;
P2=0x20;
P0 = table[n % 1000/100]; //百位
delay(M);
P0=0xff;
P2=0x40;
P0 = table[n %100/10]; //十位
delay(M);
P0=0xff;
P2=0x80;
P0 = table[n %10]; //个位
delay(M);
P0=0xff;
}
main()
{
TMOD="0x52";
TH0=0x06;
TL0=0x06;
EA="1";
ET0=1;
ET1=1;
while (1)
{
if (s0==0)
{
delay (2);
if (s0==0)
TR0=1;
TR1=1;
led (fre);
}
if (s1==0)
{
delay (2);
if (s1==0)
TR0=1;
TR1=1;
led (1000000000/fre);
}
if (s2==0)
{
delay (2);
if (s2==0)
TR0=1;
TR1=1;
led (500000000/fre);
}
}
}
文章评论(0条评论)
登录后参与讨论