|
#include<reg51.h>
unsigned char f_h;
unsigned int yichu_count;
bit count_over;
sbit s1=P0^5;
sbit s2=P0^6;
sbit rl=P2^0;
char zixing[10]={ 0x88,0xEB,0x4C,0x49,0x2B,0x19,0x18,0xCB,0x08,0x09};
unsigned long f;
void main(void)
{
void Delay(char i);
char shift_164(char a);
void test_f(void);
shift_164(0x88);
Delay(200);
shift_164(0xEB);
Delay(200);
shift_164(0x4C);
Delay(200);
shift_164(0x49);
Delay(200);
shift_164(0x2B);
Delay(200);
// while(1);
if(P0^2==0)
{
s1=0;
s2=1;
test_f();
}
if(P0^3==0)
{
s1=0;
s2=0;
test_f();
}
if(P0^4==0)
{
s1=1;
s2=0;
test_f();
}
}
void test_f(void)
{
unsigned long get_f();
char x1,x2,x3,x4,x5,x6;
void Delay(char i);
loop:
f=get_f();
if(f==0)
{
rl=0;
T0=1;
f=get_f();
}
// x6=f/100000;
x5=(f-x6*100000)/10000;
x4=(f-x6*100000-x5*10000)/1000;
x3=(f-x6*100000-x5*10000-x4*1000)/100;
x2=(f-x6*100000-x5*10000-x4*1000-x3*100)/10;
x1=f-x6*100000-x5*10000-x4*1000-x3*100-x2*10;
shift_164(zixing[x1]);
Delay(200);
shift_164(zixing[x2]);
Delay(200);
shift_164(zixing[x3]);
Delay(200);
shift_164(zixing[x4]);
Delay(200);
shift_164(zixing[x5]);
Delay(200);
shift_164(zixing[x6]);
Delay(200);
goto loop;
}
//******************************測頻率子程序*******************
void intt0_f()interrupt 1//T0作為頻率值最高八位,頻率值共24位
{
f_h=f_h+1;
}
void intt1_time()interrupt 3//T1作為門控時間產(chǎn)生器200US中斷一次
{
if (yichu_count>=5000)
{
TR0=0;//頻率停止計數(shù)
TR1=0;//時間停止計數(shù)
EA=0;//關(guān)中斷
count_over=1;
yichu_count=0;
return;
}
yichu_count=yichu_count+1;
}
unsigned long get_f()
{
unsigned long f;
count_over=0;
TMOD=0X25;
TH1=TL1=0X9C;//設(shè)置T1計數(shù)初值,可以100US中斷一次
f_h=TH0=TL0=0;//頻率值清零
count_over=0;//清零計數(shù)完成標志
EA=1;//開所有中斷
ET0=1;
ET1=1;
TR0=1;//頻率計數(shù)器開始計數(shù)
TR1=1;//時間計數(shù)器開始計時
wait_count_over:
if(count_over!=1)
goto wait_count_over;
f=(TL0+TH0*256+f_h*65536);
return (f);
}
void Delay(char i)
{ int j;
for(;i>0;i--)
for(j=0;j<125;j++)
{;}
}
char shift_164(char a)
{
SCON=0x00;
TI=0x00;
SBUF=a;
if(TI==0)
{};
return(a);
Powered by 單片機教程網(wǎng)