;-----------------------------------------------------------------------------; ; Micro control for RIG RX2 vhf weather receiver ; ; As supplied for synthesiser type TSA6060, remove semicolons in ; ; synth_routine for TSA6057. ; ;-----------------------------------------------------------------------------; ;Version Date 24 Feb 98 ; ;-----------------------------------------------------------------------------; ;This source code is written for Microchip's Windows based assemmbler V01.40 ;and later. (Including MPLAB) ; ;For data on this device and development software see Microchip's site at ;http://www.microchip.com or contact a Microchip supplier. ; ;-----------------------------------------------------------------------------; ; ; ; OPERATION ; ; ; ;-----------------------------------------------------------------------------; ; On reset (turn on) the micro starts scanning the five channels, after ; ;4 seconds the scan pin is checked to see if a signal is present. If so the ; ;micro will stop scanning and will produce a beep on the beep pin. The ; ;software will wait for 15 clear seconds before resuming scan. The scan mode ; ;can be cancelled by pressing the push switch, each succesive press will ; ;increment the channel by one,rolling over from 5 to 1. After each channel ; ;change the micro waits for 3 seconds before testing for a signal,if a signal ; ;is present then a beep is output. If the key is held for over 0.5 seconds ; ;scanning will resume from channel 1. Holding the key whilst reseting (i.e. ; ;powering up) will set the synthesiser to test mode, the frequency is set to ; ;137.97 Mhz which is 5 Khz from the Mercury pager transmitters so producing a ; ;strong test signal! During test mode the letter "t" is displayed, this mode ; ;can only be exited by reseting the micro. Scan mode is indicated by the ; ;decimal point being lit. Key press confirmation is given by a short beep ; ;output from the beep pin. ; ; More channels can be assigned (up to 9), their frequencies are ; ;entered in to the frequency_table (see the begining of "frequency_table" for ; ;details. The equate max_channels is changed to the highest number used. ; ;-----------------------------------------------------------------------------; ;Pin uses of PIC16C84, PIC16F83 or PIC16C554 ; ; PIN NO PIN USE ; ; 1 RA2 channel switch, active low. ; 2 RA3 scan input, low to stop scan ; 3 RA4 beep ; 4 RESET Tie to vdd. internal reset used.(Backed up by watchdog.) ; 5 vss negative or ground ; 6 RB0 segment A ; 7 RB1 segment B ; 8 RB2 segment C ; 9 RB3 segment D ; 10 RB4 segment E ; 11 RB5 segment F ; 12 RB6 segment G ; 13 RB7 decimal point (scan led) ; 14 vdd positive 5v supply ; 15 clk/out crystal ; 16 clk/in crystal ; 17 RA0 SCL to synth ; 18 RA1 SDA to synth, pull high with 10K ; ;############################################################################## ;############################################################################## list p=16C84 __config b'11111111111101' ; ;Configuration Byte for:Watchdog on, Startup timer on, normal Xt crystal ;oscilator (30pf crystals) no code protection. ;-----------------------------------------------------------------------------; ; Data locations ; ;-----------------------------------------------------------------------------; TMR0 equ 01 PCL equ 02 STATUS equ 03 FSR equ 04 porta equ 05 portb equ 06 PCLATH equ 0a intcon equ 0b option_reg equ 81 trisa equ 85 trisb equ 86 lsb equ 20 msb equ 21 loop_count equ 22 i2c_data equ 23 tsa_byte_2 equ 24 key_duration equ 25 synth_freq equ 26 pass_count equ 27 flags equ 28 scan_duration equ 29 timer_5ms equ 2a timer_200ms equ 2b channel_no equ 2c beep_dur_lo equ 2d beep_dur_hi equ 2e ;-----------------------------------------------------------------------------; ; Bit equates ; ;-----------------------------------------------------------------------------; C equ 0 ;clear bit in STATUS Z equ 2 ;Zero bit in STATUS t0if equ 2 ;t0 interupt flag in intcon RP0 equ 5 ;register select bit in STATUS scan_flag equ 0 ;in flags,set during band scan alarm_enable equ 1 ;in flags,set to enable alarm ;-----------------------------------------------------------------------------; ; Label values ; ;-----------------------------------------------------------------------------; s_out_sda_out equ b'00001100' s_out_sda_in equ b'00001110' s_in_sda_in equ b'00001111' tsa_mod_add equ b'11000100' rc_data equ b'01100100' digit_t equ b'10000111' ;data for "t" on seven segment display max_channels equ .7 ;change to max no. used ;-----------------------------------------------------------------------------; ; Port A pin assignments ; ;-----------------------------------------------------------------------------; key_port equ porta scl equ 0 sda equ 1 chan_switch equ 2 ;bit 2 scan_control equ 3 ;bit 3 beep_pin equ 4 ;bit 4 ;-----------------------------------------------------------------------------; ; Port B pin assignments ; ;-----------------------------------------------------------------------------; display_port equ portb scan_led equ 7 ;bit 7 ;-----------------------------------------------------------------------------; org 0 ;start of program rom area ;-----------------------------------------------------------------------------; ; Initialisation routine ; ;-----------------------------------------------------------------------------; initialise bsf STATUS,RP0 ;set to bank 1 clrf trisb ;tristate portb movlw b'11101111' movwf trisa ;tristate porta movlw b'11000001' ;set up TMR0 with prescaler movwf option_reg ;div by 2,internal clock bcf STATUS,RP0 ;reset to bank 0 clrf key_duration clrf pass_count clrf scan_duration clrf flags ;clear all flags movlw .200 ;set 200ms loop counter for an initial movwf timer_200ms ; delay of 1 second movlw .246 ;set beep for a duration movwf beep_dur_hi ;of about 2 seconds. in_1 call time_delay btfss key_port,chan_switch ;test for key pressed goto in_2 ;yes so test mode requested movlw .1 ;set to starting ch no movwf channel_no movlw .20 ;set scan delay to 4 secs movwf scan_duration bsf flags,scan_flag ;default to scan mode bsf flags,alarm_enable ;enable alarm call synth_routine call display_routine goto main_loop in_2 ;test mode clrf channel_no ;set to channel 0 i.e test call synth_routine ;frequency movlw digit_t ;display "t" (test mode) call display_out stop clrwdt ;clear watchdog timer goto stop ;halts program, micro has to be reset ;to get out of test mode ;-----------------------------------------------------------------------------; ; Convert, converts bcd (or binary) in w to seven segment data for ; ; common anode display, result left in w ; ;-----------------------------------------------------------------------------; convert addwf PCL,f retlw b'11000000' ;0 retlw b'11111001' ;1 retlw b'10100100' ;2 retlw b'10110000' ;3 retlw b'10011001' ;4 retlw b'10010010' ;5 retlw b'10000010' ;6 retlw b'11111000' ;7 retlw b'10000000' ;8 retlw b'10010000' ;9 ;-----------------------------------------------------------------------------; ; Frequency table, converts channel no. to a frequency held in the ; ; Hi Byte and Lo Byte. Result returned in W. ; ;-----------------------------------------------------------------------------; ; This table has entries for commonly used satelites and three ; ; other frequencies for down convertors. If other frequencies are ; ; required then they can be calculated and entries given as follows: ; ; ; ; 1. Subtract 10.7 Mhz from the reception frequency, result = osc freq ; ; 2. Divide osc freq (in Mhz) by 10,000, result = freq steps ; ; 3. Divide freq steps by 256 use the result on the left of the decimal ; ; point as the Hi Byte and enter into table. ; ; 4.Multiply the fraction on the right hand side of decimal point by 256; ; use this result for the Lo Byte and enter into table. ; ; 5. Set the constant max_channels to the highest no of channels used ; ; in this code as supplied it is 7 (141.1 Mhz is disabled). ; ; 6. It is possible to remove unwanted entries in the table by placing ; ; a semicolon before the relevant retlw instructions, remember ; ; however to set the constant max_channels to the correct no. ; ; 7. Although the TSA6057/TSA6060 can tune 30 - 150+ Mhz modifications ; ; would have to be made to the RX2 circuit to allow much more ; ; than a 6 Mhz osc. bandwith (centred around 136 Mhz) ; frequency_table addwf PCL,f ;Test Frequency for UK pager network on 137.975MHz retlw .49 ;0 Hi Byte retlw .183 ;0 Lo Byte ;Test frequency for Orbcomm satellite on 137.800MHz ;retlw .49 ;0 Hi Byte ;retlw .166 ;0 Lo Byte ;METEOR 137.30MHZ retlw .49 ;1 Hi Byte retlw .116 ;1 Lo Byte ;METEOR 137.40MHZ retlw .49 ;2 Hi Byte retlw .126 ;2 Lo Byte ;NOAA 137.50MHZ retlw .49 ;3 Hi Byte retlw .136 ;3 Lo Byte ;NOAA 137.62MHZ retlw .49 ;4 Hi Byte retlw .148 ;4 Lo Byte ;METEOR 137.85MHZ retlw .49 ;5 Hi Byte retlw .171 ;5 Lo Byte ;134.0 Mhz retlw .48 ;6 Hi Byte retlw .42 ;6 Lo Byte ;137.0 Mhz retlw .49 ;7 Hi Byte retlw .86 ;7 Lo Byte ;141.1 Mhz ;retlw .50 ;8 Hi Byte ;retlw .240 ;8 Lo Byte ;-----------------------------------------------------------------------------; main_loop call time_delay call beep_serv decfsz timer_5ms,f goto main_loop clrwdt ;clear watchdog timer movlw .17 movwf timer_5ms ;reload 5ms loop count ; routines in this section are serviced ; every 5 ms call key_serv decfsz timer_200ms,f goto main_loop movlw .40 ;reload 200ms loop count movwf timer_200ms ; routines in this section are serviced ; every 200ms call scan_serv ;check for scanning ; call channel_test ;check if signal present goto main_loop ;-----------------------------------------------------------------------------; ; Synth routine, aligns bytes and then transmits to synth via. ; ; i2c bus ; ;-----------------------------------------------------------------------------; synth_routine clrc rlf channel_no,w movwf synth_freq call frequency_table movwf msb incf synth_freq,w call frequency_table movwf lsb movlw rc_data movwf tsa_byte_2 ;load byte 2 clrc rlf lsb,f ;ready for transmission rlf msb,f ;to synth ic bsf lsb,0 ;set pd to hi current call i2c_start movlw tsa_mod_add ;ic address call i2c_tx ;For TSA6057 remove semicolons before the instructions on next two lines ; movlw 00 ;sub address ### not used on TSA6060 ; call i2c_tx ; ### not used on TSA6060 movfw lsb ;synth low byte & cp bit call i2c_tx movfw msb ;synth hi byte call i2c_tx movfw tsa_byte_2 call i2c_tx movlw 00 call i2c_tx call i2c_stop return ;-----------------------------------------------------------------------------; ; i2c comunication routines (no error handling performed) ; ;-----------------------------------------------------------------------------; i2c_start movlw s_out_sda_out ;set scl and sda bsf STATUS,RP0 movwf trisa ;as output bcf STATUS,RP0 bsf porta,sda nop bsf porta,scl nop bcf porta,sda ;set start condition nop bcf porta,scl nop return i2c_tx movwf i2c_data movlw s_out_sda_out ;set scl and sda bsf STATUS,RP0 movwf trisa ;as output bcf STATUS,RP0 movlw .8 ;loop 8 times (8 bits) movwf loop_count shift_loop rlf i2c_data,f ;rotate into carry bsf porta,sda btfss STATUS,C bcf porta,sda nop bsf porta,scl ;clock data bit nop bcf porta,scl ;out nop decfsZ loop_count,1 goto shift_loop movlw s_out_sda_in ;set sda as bsf STATUS,RP0 movwf trisa ;input to allow for bcf STATUS,RP0 bsf porta,scl ;aknowledge nop bcf porta,scl nop return i2c_stop movlw s_out_sda_out ;set scl and bsf STATUS,RP0 movwf trisa ;sda as output bcf STATUS,RP0 bcf porta,sda nop bsf porta,scl nop bsf porta,sda nop movlw s_in_sda_in ;send scl and sda bsf STATUS,RP0 movwf trisa ;to high imp. bcf STATUS,RP0 return ;-----------------------------------------------------------------------------; ; Beep, starts a beep of about 0.25 seconds duration ; ;-----------------------------------------------------------------------------; beep movlw .254 ;set beep for a duration movwf beep_dur_hi ;of about 0.25 sec. clrf beep_dur_lo return ;-----------------------------------------------------------------------------; ; Time delay, generates a time delay of 1/(1750*2) i.e. 1 half cycle of ; ; a 1750hz toneburst waveform. (software has it's origins in the ; ; Piccolo VHF transciever. ; ;-----------------------------------------------------------------------------; time_delay btfss intcon,t0if ;loop until TMR0=0 goto time_delay movlw .185 ;load TMR0 movwf TMR0 bcf intcon,t0if ;clear t0 interupt flag return ;-----------------------------------------------------------------------------; ; Scan serv, called about every 50ms. ; ;-----------------------------------------------------------------------------; scan_serv movf scan_duration,f ;test for zero btfsc STATUS,Z goto scan_1 ;timed out so next channel btfsc key_port,scan_control goto scan_3 ;no signal so decrement movlw .75 ;signal so wait 15 secs movwf scan_duration btfss flags,alarm_enable goto scan_end ;alarm disabled movlw .210 ;set beep for a duration movwf beep_dur_hi ;of about 4 seconds. bcf flags,alarm_enable ;disable alarm scan_end return scan_1 btfss flags,scan_flag ;in scan mode? goto scan_2 ;not in scan mode call up_key ;in scan mode so call synth_routine ;advance channel, set call display_routine ; synthesiser and display scan_2 bsf flags,alarm_enable ;enable signal alarm movlw .20 ;set delay to movwf scan_duration ; 4 secs (20*200ms) goto scan_end scan_3 decf scan_duration,f ;decrement scan duration goto scan_end ;-----------------------------------------------------------------------------; ; Key serv, called every 5ms approx. Checks for key pressed. ; ;-----------------------------------------------------------------------------; key_serv movf pass_count,f btfss STATUS,Z ;check if first entry goto key_pressed? ;no btfsc key_port,chan_switch ;yes, test for key pressed goto key_serv_end ;no key pressed so end call beep clrf key_duration ;key pressed for first time movlw .10 movwf pass_count ;pass count = 50ms (10*5ms) btfsc flags,scan_flag ;test flag goto scan_cancel ;set so cancel scan call up_key ;increment channel no. call synth_routine ;set synthesiser and call display_routine ;display key_serv_end return key_pressed? btfsc key_port,chan_switch ;test for key pressed goto decr_count ;key not pressed movlw .10 ;key has been pressed movwf pass_count ;pass count = 50ms (10*5ms) incf key_duration,f ;increment key duration movlw .100 subwf key_duration,w ;test for duration of 0.5 secs btfss STATUS,Z goto key_serv_end ;not 0.5 seconds bsf flags,scan_flag ;pressed for 0.5 secs so bsf flags,alarm_enable ;enable signal alarm movlw .20 ;set delay to movwf scan_duration ; 4 secs (20*200ms) bcf display_port,scan_led call beep goto key_serv_end decr_count decf pass_count,f goto key_serv_end scan_cancel movlw .15 ;set to wait 3 secs to stop movwf scan_duration ; annoying beep on channel bcf flags,alarm_enable ; change if signal present bcf flags,scan_flag bsf display_port,scan_led goto key_serv_end ;------------------------------------------------------------------------------; ; Beep serv, called every beep half cycle. Complements beep pin if ; ; beep hasn't timed out. ; ;------------------------------------------------------------------------------; beep_serv movf beep_dur_hi,f skpnz goto beep_end ;finished movlw .1 addwf beep_dur_lo,f addcf beep_dur_hi,f movlw b'00010000' ;complement beep pin xorwf porta,f beep_end return ;-----------------------------------------------------------------------------; ; Up key, increments channel no. ; ;-----------------------------------------------------------------------------; up_key movlw max_channels subwf channel_no,w ;is channel no > max_channels? skpnc clrf channel_no ;yes incf channel_no,f uk_end return ;-----------------------------------------------------------------------------; ; Display routine, displays channel no. and scan led ; ;-----------------------------------------------------------------------------; display_routine movfw channel_no call convert call display_out ;display seven segments btfsc flags,scan_flag bcf display_port,scan_led return ;-----------------------------------------------------------------------------; ; Display out, copies data to display port (seperate routine so ; ; data may be "mapped" into individual port pins if neccesary) ; ;-----------------------------------------------------------------------------; display_out movwf display_port return ;-----------------------------------------------------------------------------; end