|
发表于 2020-10-6 13:52:30
|
显示全部楼层
最新版程序
//STC89C52RC 24.00M晶振
#include <STC89C5xRC.H>
#include <stdlib.h>
#include <stdio.h>
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long int u32;
sbit P36_o_74f161_clr_n = P3^6;//外部计数器F161复位
sbit P35_o_74f161_enp = P3^5;//外部计数器F161有效(Enable)
sbit P30_io_74hc393_clr_hold = P3^0;//外部计数器HC393复位/HOLD输入
sbit P37_i_prescaler = P3^7;//64分频的预分频器
u8 dula[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90},
wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f},
fnd[8],mfnd[8],fnd_state,boat;
u16 trimer,int_state;
u32 trailer,task;
bit hold;
void TIMER1() interrupt 1
{
TL1 = 0x60;// 4000 2 M Sec 500 Times
TH1 = 0xF0;// 4000 2 M Sec 500 Times
P0 = 0xff;
P2 = wela[fnd_state];
P0 = fnd[fnd_state++];
fnd_state &= 0x07;
if(int_state == 0)
{
P35_o_74f161_enp = 0;//外部计数器F161计数禁止
P30_io_74hc393_clr_hold = 1;//外部计数器HC393复位
P36_o_74f161_clr_n = 0;//外部计数器F161复位
TL0 = 0x00;//内部计数器复位
TH0 = 0x00;//内部计数器复位
hold = P30_io_74hc393_clr_hold;//HOLD(保持)键状态输入
P36_o_74f161_clr_n = 1;//外部计数器F161有效(Enable)
P30_io_74hc393_clr_hold = 0;//外部计数器HC393有效(Enable)
P35_o_74f161_enp = 1;//外部计数器F161进行计数
}
if(int_state == 316)//10GHz状态(64分频的预分频器)
{
if(!P37_i_prescaler)//门控时间为0.64秒
{
for (trimer = 0; trimer<202; trimer++);//15个机器周期单位
// 测试信号24MHz输入
boat++; // 15360000 用于显示,需调整
boat++; // 延迟1个机器周期(12个时钟周期)
boat++; // 15359988
boat++; // 15360000
// boat++; // 15360012
P35_o_74f161_enp = 0;//外部计数器停止
trailer = TH0;
trailer = (trailer << 20) & 0x0ff00000;
task = TL0;
task = (task << 12) & 0x000ff000;
trailer |= task;
task = P3;
task = (task << 7) & 0x00000f00;
trailer |= task;
task = P1 & 0x000000ff;
trailer |= task;
P35_o_74f161_enp = 1; // ?? ??? ???? ?????
// 电流消耗,
// 外部计数器将重新开始。
}
}
if(int_state == 494)//100 MHz Mode 1 Sec Gate Time
{
if (P37_i_prescaler)//1 Sec Gate Time
{
for (trimer = 0; trimer<248; trimer++);//15个机器周期单位
// 测试24MHz信号源输入
boat++;//24000000 用于显示,需调整
boat++;//
boat++;//
boat++;//
boat++;//延迟1个机器周期(12个时钟周期)
boat++;//23999988
boat++;//24000000
//boat++;//24000012
P35_o_74f161_enp = 0;//外部计数器停止
trailer = TH0;
trailer = (trailer << 20) & 0x0ff00000;
task = TL0;
task = (task << 12) & 0x000ff000;
trailer |= task;
task = P3;
task = (task << 7) & 0x00000f00;
trailer |= task;
task = P1 & 0x000000ff;
trailer |= task;
P35_o_74f161_enp = 1; // ?? ??? ???? ?????
// 电流消耗,以时间表
// 外部计数器重新开始。
}
}
if(int_state == 506)//1Hz数字显示
{
boat = trailer % 10;
mfnd[7] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 507)//10Hz数字显示
{
boat = trailer % 10;
mfnd[6] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 508)//100Hz数字显示
{
boat = trailer % 10;
mfnd[5] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 509)//1KHz数字显示
{
boat = trailer % 10;
mfnd[4] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 510)//10KHz数字显示
{
boat = trailer % 10;
mfnd[3] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 511)//100KHz数字显示
{
boat = trailer % 10;
mfnd[2] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 512)//1MHz数字显示
{
boat = trailer % 10;
mfnd[1] =dula[boat & 0xf];
trailer /= 10;
}
if(int_state == 513)//10MHz数字显示
{
boat = trailer % 10;
mfnd[0] =dula[boat & 0xf];
trailer /= 10;
}
int_state++;
if(int_state >= 514)
{
int_state = 0;
if (hold)
{
fnd[0] = mfnd[0];
fnd[1] = mfnd[1];
fnd[2] = mfnd[2];
fnd[3] = mfnd[3];
fnd[4] = mfnd[4];
fnd[5] = mfnd[5];
fnd[6] = mfnd[6];
fnd[7] = mfnd[7];
if(P37_i_prescaler) fnd[1] &= 0x7F;//MHz点
else fnd[0] &= 0x7F;//GHz点
}
}
}
void main()
{
TMOD=0x15;//0b00010101 Timer0 = Mode1, Counter, use TR0;Timer1 = Mode1, Timer, use TR1
TL0=0X00;
TH0=0X00;
TL1=0X00;
TH1=0X00;
TR0=1;//Timer 0 计数开始
TR1=1;//Timer 1 计数开始
ET1=1;//设置定时器1中断状态
EA=1; //设置全局中断状态
while(1);
} |
评分
-
1
查看全部评分
-
|