#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//12òõ¼«êyÂë±í
sbit wei0 = P2^0;
sbit wei1 = P2^1;
sbit wei2 = P2^2;
sbit wei3 = P2^3;
sbit wei4 = P2^4;
sbit wei5 = P2^5;
sbit CLK = P3^2;
uint HZ;
//***********************Ñóê±oˉêy*************************
void delay(uint x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<120;j++);
}
//**********************êyÂë1üÏÔê¾oˉêy***************************
void display(uint z)
{
uint g,s,b,q,w,sw;
sw=z/100000;//»ñ衼ÆêyÖμμÄê®íòλ
w=z%100000/10000;//»ñ衼ÆêyÖμμÄíòλ
q=z%100000%10000/1000;//»ñ衼ÆêyÖμμÄǧλ
b=z%100000%10000%1000/100;//»ñ衼ÆêyÖμμÄ°ùλ
s=z%100000%10000%1000%100/10;//»ñ衼ÆêyÖμμÄê®Î»
g=z%100000%10000%1000%100%10;//»ñ衼ÆêyÖμμĸöλ
wei5 = 0;//¿aÆôλѡ
P0 = table[g];
delay(1);
wei5 = 1; //1رÕλѡ
wei4 = 0;//¿aÆôλѡ
P0 = table[s];
delay(1);
wei4 = 1; //1رÕλѡ
wei3 = 0;
P0 = table[b];
delay(1);
wei3 = 1;
wei2 = 0;
P0 = table[q];
delay(1);
wei2 = 1;
wei1 = 0;
P0 = table[w];
delay(1);
wei1 = 1;
wei0 = 0;
P0 = table[sw];
delay(1);
wei0 = 1;
}
//*************************Ö÷oˉêy***********************************
main()
{
uint T;
TMOD=0x09; //¶¨ê±Æ÷01¤×÷Ôú·½ê½1£¬GATE=1
TH0 = 0;
TL0 = 0;
while(1)
{
TH0 = 0;
TL0 = 0;
while(CLK);//μèÂö3å±äμí
TR0 = 1; //èí¼t¿aÆe
while(!CLK); //μèÂö3å±ä¸ß
while(CLK); //¶¨ê±Æ÷¿aê¼¼Æê±
TR0 = 0;
T = TH0*256+TL0;
HZ = 1*1000000/T;
display(HZ);
}
}
|