|
发表于 2013-6-12 01:10:25
|
显示全部楼层
本帖最后由 yxw_bob 于 2013-6-12 01:17 编辑
韩国的爱好者 开源的基于C51的频率计
http://www.sample.co.kr/sefcntr/index.htm
http://bbs.yleee.com.cn/thread-1079-1-1.html
C51+COUNTER原理图:
200MHz ANALOG PREAMP 原理图:
2GHz ANALOG PREAMP 原理图:
程序:
//
// 100MHz / 2.4GHz Universal Counter
//
// SAMPLE Electronics co. 25. Nov. 2003
//
// Crossware Embedded Development Studio V 3.3.1.2
//
//
//
// 74F161 의 4 Bit, 74HC393의 8 Bit 그리고 8051 내부 카운터 T0 16 Bit 로
// 28 비트의 카운터를 구성한다.
// 펄스 계수시간을 1 Sec 가 되도록 하여 8 디지트표시100 MHz 카운터를 만든다.
// 64 분주 프리스케일러를 사용하기 위하여 펄스 계수 시간을 0.64 S 가
// 되도록 한다.
//
//
// 8051 Initial C Source File
//
#include <sfr.h>
#include <os.h>
#include <stdlib.h>
#include <stdio.h>
_sfrbit P36_o_74f161_clr_n = _p3^6; // 외부 카운터 F161 리세트
_sfrbit P35_o_74f161_enp = _p3^5; // 외부 카운터 F161 인에이블
_sfrbit P30_io_74hc393_clr_hold = _p3^0; // 외부 카운터 HC393 리세트 / HOLD입력
_sfrbit P37_i_prescaler = _p3^7; // 64 분주 Pre Scaler
//
// 7 Segment LED 패턴 데이터
// hgfedcba
#define DIG0 0xC0 // 11000000b ; 0 P2.0
#define DIG1 0xF9 // 11111001b ; 1 +-----a-----+
#define DIG2 0xA4 // 10100100b ; 2 | |
#define DIG3 0xB0 // 10110000b ; 3 P2.5 f b P2.1
#define DIG4 0x99 // 10011001b ; 4 | |
#define DIG5 0x92 // 10010010b ; 5 | P2.6 |
#define DIG6 0x82 // 10000010b ; 6 +-----g-----+
#define DIG7 0xD8 // 11011000b ; 7 | |
#define DIG8 0x80 // 10000000b ; 8 P2.4 e c P2.2
#define DIG9 0x98 // 10011000b ; 9 | |
// ; | P2.3 |
#define DIGM 0xBF // 10111111b ; - +-----d-----+ * h P2.7
#define DIGP 0x7F // 01111111b ; .
#define DIGB 0xFF // 11111111b ; "Blank"
//
const char segment_pattern[] = { DIG0, DIG1, DIG2,\
DIG3, DIG4, DIG5, DIG6, DIG7, DIG8, DIG9 };
//
const char segment_select[] = { 0xFE, 0xFD, 0xFB, \
0xF7, 0xEF, 0xDF, 0xBF, 0x7F };
//
unsigned long trailer;
unsigned long task;
unsigned int trimer;
unsigned char fnd[8];
unsigned char mfnd[8];
unsigned int int_state;
unsigned char fnd_state;
unsigned char boat;
bit hold;
//
//
void _interrupt IVN_TIMER1 time_base() {
//////////////////////////////////////////////
_tl1 = 0x60; _th1 = 0xF0; // 4000 2 M Sec 500 Times
//////////////////////////////////////////////
_p0 = 0xff;
_p2 = segment_select[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 Key 상태 입력
P36_o_74f161_clr_n = 1; // 외부 카운터 F161 카운터 인에이블
P30_io_74hc393_clr_hold = 0; // 외부 카운터 HC393 카운터 인에니블
//
P35_o_74f161_enp = 1; // 외부 카운터 F161 카운터 동작 개시
}
//////////////////////////////////////////////
if(int_state == 316) { // 10 GHz Mode(64 Divide Prescaler)
if (!P37_i_prescaler) { // 0.64 Sec Gate Time
for (trimer = 0; trimer<202; trimer++) ; // 15 Machine Cycle 단위
// 테스트 신호원을 24 MHz 로 입력하고
boat++; // 15360000 이 표시되도록 조정한다.
boat++; // 1 Machine Cycle (12 Clock) Delay
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 Machine Cycle 단위
// 테스트 신호원을 24 MHz 로 입력하고
boat++; // 24000000 이 표시되도록 조정한다.
boat++; //
boat++; //
boat++; //
boat++; // 1 Machine Cycle (12 Clock) Delay
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] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 507) {
boat = trailer % 10;
mfnd[6] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 508) {
boat = trailer % 10;
mfnd[5] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 509) {
boat = trailer % 10;
mfnd[4] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 510) {
boat = trailer % 10;
mfnd[3] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 511) {
boat = trailer % 10;
mfnd[2] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 512) {
boat = trailer % 10;
mfnd[1] = segment_pattern[boat & 0xf];
trailer /= 10;
}
//////////////////////////////////////////////
if(int_state == 513) {
boat = trailer % 10;
mfnd[0] = segment_pattern[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 Point
} else {
fnd[0] &= 0x7F; // GHz Point
}
}
}
//////////////////////////////////////////////
}
main()
{
_tmod = 0x15; // 0b00010101 Timer0 = Mode1, Counter, use TR0
// Timer1 = Mode1, Timer, use TR1
_tl0 = 0X0; _th0 = 0X0;
_tl1 = 0X0; _th1 = 0X0;
_tr0 = 1; // Timer 0 START
_tr1 = 1; // Timer 1 START
_et1 = 1; // TIMER1 INT ,타이머 1 인터럽트 가능상태 설정
_ea = 1; // ENABLE INT,글로벌 인터럽트 가능상태 설정
while(1) ;
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|