;******************************************************************** ; Frequency Dependant Switch - TMR0 Count ; TMR0_count.asm ; ; Displays TMR0 count on LEDs connected to PortB in binary ; ;******************************************************************** errorlevel -302, -305 ; Skip nuisance messages LIST P=PIC16F628A INCLUDE P16F628A.inc __config _CP_OFF&_LVP_OFF&_BODEN_OFF&_MCLRE_OFF&_PWRTE_ON&_WDT_OFF&_INTOSC_OSC_NOCLKOUT #define PTT PORTA,1 #define RF PORTA,4 #define LED1 PORTA,6 ; Frequency measured ; decimal #'s following equal time in mS (approx) #define tD d'20' ; debounce time CBLOCK 0x20 ; Start Data Block delay1 ; misc counters for use in time delays delay2 delay3 freq ; cache for freq count repeat ; number of extra times freq is counted temp ; general purpose transient variable endc ;-------------------------------------------------------------------------------- org 0 goto main org 4 goto main main clrf PORTA ; initialise clrf PORTB ; initialise movlw 0x07 ; movwf CMCON ; Turn off comparators bsf STATUS,RP0 ; to Bank 1 movlw b'10100111' ; prescale /256 to RA4, no pull-ups movwf OPTION_REG movlw b'00010010' ; RA1 & RA4=input movwf TRISA clrf TRISB ; PortB all outputs bcf STATUS,RP0 ; back to Bank 0 initialise clrf PORTA ; wait_Tx btfsc PTT ; is PTT activated? goto wait_Tx ; if not, go back and wait movlw tD ; Input debounce call w_mS btfsc PTT goto wait_Tx btfsc RF goto $-1 clrf PORTB ; ; Measure freq. Potential errors are:- ; Tx stops/starts while measuring ; out of band measure ; no count, not enough power ; successive counts not same movlw d'4' movwf repeat ; # times to repeat call freqcount ; measure once movwf freq ; and retain btfsc STATUS,Z ; test for zero goto initialise ; zero or > 10m error ; light Frequency measured LED freq_again call freqcount ; measure again subwf freq,w ; compare btfss STATUS,Z ; same? goto initialise ; not same freq error decfsz repeat ; all done? goto freq_again ; no, so loop movf freq,w ; yes, all OK, continue movwf PORTB btfss PTT ; wait for PTT to be released goto $-1 goto initialise ; FREQUENCY COUNT freqcount clrf TMR0 ; reset & start count call delay_150uS movf TMR0,w ; end & latch result movwf temp ; preserve w ; sublw d'17' ; max legal count <--For 30MHz Max sublw d'32' ; max legal count <--For 54MHz Max btfss STATUS,C ; test for >max? clrf temp ; count was >max movf temp,w ; recover w return ; with count in w (0 if error) delay_150uS ;PIC Time Delay = 0.00014900 s with Osc = 4,000,000 Hz ; movlw D'48' ; Adjust up or down if BIAS LED movlw D'50' ; doesn't light on some channels movwf delay1 ; or band switching is intermittent on some bands loop decfsz delay1,f goto loop return ; ; DELAY LOOP 1 millisecond one_mS movlw d'4' movwf delay1 loop1 movlw d'81' movwf delay2 loop2 decfsz delay2 goto loop2 decfsz delay1 goto loop1 return ; DELAY LOOP w milliseconds (roughly) w_mS movwf delay3 w_mS_loop call one_mS decfsz delay3 goto w_mS_loop return END ;--------------------------------------------------------------------------------