十年專注單片機方案開發(fā)的方案公司英銳恩,分享一款用F84做的測頻儀。英銳恩現(xiàn)提供服務產(chǎn)品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。
;*******************************************************************
;
; Frequency display
; Crystal freq. 4.000MHz +/- a bit
;
;*******************************************************************
;
; FM000.TXT Originally from FM3/4 9:39pm 14 May 2002
; As implemented in experimental 3.5MHz receiver
;
;*******************************************************************
;
; FM003 Fixed? major silliness in LO-IF code
; Re-wrote USB/LSB suffix code
; Added #defines for crook displays
; Added #defines for two line displays
; Wrapped #ifdef ... endif around debugging code
;
;*******************************************************************
;#define testing 1 ; Comment out when testing finished
;#define Bad_Display 1 ; Un-comment for "stop at 8" displays
;#define Two_Line 1 ; Un-comment for two line displays
;*******************************************************************
;
; CPU configuration
; It's a 16F84, HS oscillator,
; watchdog timer off, power-up timer on
;
processor 16f84
include
__config _HS_OSC & _PWRTE_ON & _WDT_OFF
#define S_out PORTA,0x00 ; 9600 baud serial out
#define PUFF PORTA,0x00 ; Future stabiliser
#define HUFF PORTA,0x01 ; Ditto.
#define ENA PORTA,0x02 ; Display "E"
#define RS PORTA,0x03 ; Display "RS"
#define PORTA4 PORTA,0x04 ; From LS393 divider chip
#define RESET PORTB,0x01 ; Pin 7, Counter RESET
#define UP_CNT PORTB,0x02 ; Pin 8, Counter FLUSH
#define GATE PORTB,0x03 ; Pin 9, Counter GATE
#define Store PORTB,0x04 ; Pin 10, 0 = Measure BFO
#define Add_LO PORTB,0x05 ; Pin 11, 0 = RF := LO + IF
; 1 = RF := | LO + (-IF) |
#define BFO_Lo PORTB,0x06 ; Pin 12, 0 = BFO on lower freq.
#define BFO_Hi PORTB,0x07 ; Pin 13, 0 = BFO on higher freq.
#define LOK_FLG FLAGS,0x06
#define Prg_FLG FLAGS,0x05
#define Ovr_Rng FLAGS,0x04
#define AMflag FLAGS,0x03 ; 0 = Don't print USB/LSB suffix
#define BANKSEL STATUS,RP0
#define beq bz ; Motorola syntax branches
#define BEQ bz
#define BNE bnz
#define bne bnz
#define BCC bnc
#define bcc bnc
#define BCS bc
#define bcs bc
#define BRA goto
#define bra goto
;*******************************************************************
;
; file register declarations: use only registers in bank0
; bank 0 file registers begin at 0x0c in the 16F84
;
;*******************************************************************
cblock 0x0c
COUNT ; Bin to BCD convert (bit count)
TEMP
cnt ; (BCD BYTES)
COUNT1 ; Used by delay routines
; and "prescaler flush"
COUNT2 ; Timing (100ms)
COUNT3 ; Timing (100ms)
COUNT4 ; Timing (400ms)
CHR
AccA:3 ; Binary, MSB first
AccB:3 ; Intermediate frequency
bcd:4 ; BCD, MSD first
FLAGS
SBflag ; 0 = Lower BFO frequency
; 1 = Higher
W_TEMP ; W saved here by ISR
STATUS_TEMP ; Status Register saved here by ISR
dbg0:3 ; Debugging stuff
dbg1:3
dbg2:3
dbg3:3
dbg4:3
dbg5:3
S_Wtemp ; "debug" Variables
S_count
D_Wtemp
D_Stemp
D_FSR
D_hex
endc
;**********************************************************
;
; Begin Executable Stuff(tm)
;
org 0
GO clrwdt ; 0 << Reset
call InitIO ; 1 INITIALISE PORTS
CLRF PORTA ; 2
goto START ; 3
INTRUPT goto ISR ; 4 << Interrupt
;**********************************************************
;
; Text Strings (stored in RETLWs)
;
mhz dt " MHz ",0
Spaces dt " ",0
USB dt "USB",0
LSB dt "LSB",0
Prog dt "PRG",0
adv1 dt "DFM 3.0 ",0
adv2 dt "- VK3BHR",0
ovr1 dt " Over ",0
ovr2 dt "Range ",0
#ifdef Two_Line
adv3 dt "1234567890ABCDEF",0
endif
;**********************************************************
;
; Main Program
;
START CLRF PORTB
#ifdef testing
bsf PUFF
endif
CALL LCDINIT ; INITIALIZE LCD MODULE
MOVLW adv1 ; Sign on
call pmsg
#ifdef Bad_Display
CALL LINE2
endif
movlw adv2
call pmsg
MOVLW 0x28 ; Delay for 4 sec.
CALL DECI
CALL CLEAR
tx_1 decfsz S_count,f ; Done all bits?
goto put_clp
movlw 0xE7 ; Delay for last data
txd_1 addlw 0x01
bne txd_1
bsf S_out ; Transmit two stop bit
movlw 0xCD
txd_9 addlw 0x01
bne txd_9
return
endif
;********************************************************************
; Tail End Charlie
;********************************************************************
END