?? endall.c
字號:
#include <reg51.h>
unsigned char dispcode[]={0xC0,0xCF,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
unsigned char L0=0;
unsigned char L1=0;
unsigned char L2=0;
unsigned char L3=0;
unsigned char T0count=0;
bit flag=0;
/*************************************
程序及中斷初始化
************************************/
void mcu_int(void)
{
TMOD=0x1D; //T1為16位計時器模式,T0為16位計數(shù)器模式
TH1=0x3C;
TL1=0xB0; //初值,產(chǎn)生50ms中斷
TH0=0x00;
TL0=0x00; //計數(shù)初值
EA=1; //開放所有中斷
ET1=1; //允許T1中斷
ET0=1; //允許T0中斷
TR0=1;
TR1=1; //開始定時/計數(shù)
}
void delay(int j)
{
while (j!=0)
{
unsigned char i;
for(i=100;i>0;i--);
j--;
}
}
/***********************************
數(shù)碼管顯示
***********************************/
void show(void)
{
P2=0x01;P0=dispcode[L0]; //L1為個位顯示數(shù)字0x01,0x02,0x04,0x08
delay(1);
P2=0x02;P0=dispcode[L1];
delay(1);
P2=0x04;P0=dispcode[L2];
delay(1);
P2=0x08;P0=dispcode[L3];
delay(1);
}
/*****************************
對計得的數(shù)進(jìn)行處理,返回FX及顯示關(guān)鍵字LX
****************************/
unsigned long int FX;
void process()
{
FX=T0count*65536+TH0*256+TL0;
if(FX>3500&&FX<=8000) //以下兩個 if語句 為修正所測頻率
{
FX=FX-1;
}
if(FX>8000&&FX<=12000)
{
FX=FX-1.3;
}
if(FX>9999)
FX=FX/1000;
L0=(FX%10)/1; //L1為個位顯示的數(shù)字值//
L1=(FX%100)/10; //L2為十位顯示的數(shù)字值//
L2=(FX%1000)/100; //L3為百位顯示的數(shù)字值//
L3=(FX%10000)/1000; //L4為千位顯示的數(shù)字值//
}
main()
{
mcu_int();
while(1)
{
if(flag==1)
{
process();
TH0=0x00;
TL0=0x00;
flag=0;
}
show();
/*
P2=0x01;P0=dispcode[10];
delay(2);
P2=0x02;P0=dispcode[11];
delay(2);
P2=0x04;P0=dispcode[12];
delay(2);
P2=0x08;P0=dispcode[13];
delay(2);
*/
}
}
void Timer0() interrupt 1 using 0
{
TH0=0x00;
TL0=0x00;
T0count++;
}
unsigned char Time_50ms;
void Timer1() interrupt 3 using 1
{
TH1=0x3C;
TL1=0xB0;
Time_50ms++;
if(Time_50ms==20)
{
Time_50ms=0;
flag=1;
// P2=0x01;P0=dispcode[10];
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -