TITLE (C) 28th Dec 1999 G3RFL 2.4GHz SYNTH tx.

;Using Farnell Stealth Units and TMS 6755 Displays

#include "pic16c84.h

;define constant
rotor_div equ 8 ;Rotor Divisor

;define ports
ioport equ portb ;output ports
psh1 equ 0 ;(6)
psh2 equ 1 ;(7)
psh3 equ 2 ;1Mhz up (8)
psh4 equ 3 ;1Mhz down (9)
rot1 equ 4 ;rot125khz up (10)
rot2 equ 5 ;rot125khz down (11)
scl equ 6 ;synth clock (12)
sda equ 7 ;synth data (13)

segport equ porta ;7 Segment display port
seg_clk equ 0 ;common clock bit (17)
seg_d0 equ 1 ;1-4 digit data bit(18)
seg_d1 equ 2 ;5-8 digit data bit(1)
spare1 equ 3 ; (2)
spare2 equ 4 ; (3)

;define ram assignments
keeps equ 0ch ;On Interrupt Status Register
keepw equ 0dh ;On Interrupt W Register
keeppch equ 0eh ;On Interrupt PCLATH Register
msdiv equ 0fh
dpoint equ 10h
digit8 equ 11h ;tens GHZ
digit7 equ 12h ;units GHZ
digit6 equ 13h ;hundreds MHZ
digit5 equ 14h ;tens MHZ
digit4 equ 15h ;units MHZ
digit3 equ 16h ;hundreds KHZ
digit2 equ 17h ;tens KHZ
digit1 equ 18h ;units KHZ
count1 equ 19h
count2 equ 1ah
valid equ 1bh ;button pressed flag
store equ 1ch
msval equ 1dh

last equ 1fh ;last direction
temp1 equ 20h ;Tempory registers
temp2 equ 21h ;
temp3 equ 22h ;
temp4 equ 23h ;
byte1 equ 24h
byte2 equ 25h
byte3 equ 26h
byte4 equ 27h
tempc1 equ 2ah
tempc2 equ 2bh
;-----------------------------------------------
segment byte at:0 'code'

;--- Reset and Interrupt Entry Points ----------
reset
nop ;Reset Entry Point
clrwdt
clrf intcon
goto init
;-------------------------------------------------
irq
movwf keepw ;Save Acc W
swapf keepw
swapf status,w ;Save Status
movwf keeps
movf pclath,w ;Save PCLATH
movwf keeppch
incf valid ;inform main routine
swapf ioport,w
andlw 03h ;mask off higher bits
call quad
movwf store
subwf last
btfsc status,z
goto exit
btfsc status,c
goto clockwise

anticlockwise
decfsz msdiv
goto exit

movlw rotor_div
movwf msdiv
movf msval
decf msval
goto exit

clockwise
movlw rotor_div
xorwf msdiv,w
btfss status,z
goto clock_div
movlw 1
movwf msdiv
incf msval,w
incf msval
goto exit

clock_div
incf msdiv
exit
movf store,w
movwf last
movf keeppch,w ;Restore PCLATH
movwf pclath
swapf keeps,w ;Restore Status
movwf status
swapf keepw,w ;Restore Acc W
bcf intcon,rbif
retfie
;-------------------------------------------------
quad
bcf pclath,0 ;set to 000h
bcf pclath,1 ;
addwf pcl
retlw 00h
retlw 01h
retlw 03h
retlw 02h
;-------------------------------------------------
init
clrf status
clrf last
clrf msdiv
clrf porta
clrf portb
movlw 00000000b ;0=output
tris porta ;1= input
movlw 00111111b
tris portb
bcf portb,sda ;synth data
nop
bcf portb,scl ;synth clock
movlw 01h
movwf digit1 ;lsb
movlw 02h
movwf digit2
movlw 03h
movwf digit3
movlw 04h
movwf digit4
movlw 05h
movwf digit5
movlw 06h
movwf digit6
movlw 07h
movwf digit7
movlw 08h
movwf digit8
movlw 01001000b
movwf dpoint ;set up dec points
call display
movlw 00h
option ;int on neg falling edge
bsf intcon,gie ;global int enable.
bsf intcon,rbie ;port changed int.
call restore
movlw count2
movwf byte1
movlw count1
movwf byte2
movlw 0ceh
movwf byte3
movlw 00h
movwf byte4
goto ppp
;------------main routines--------------------------
main
btfsc ioport,psh1
goto but2
call incdec
goto ppp
but2
btfsc ioport,psh2
goto but3
call decinc
goto ppp
but3
btfsc ioport,psh3
goto but4
call upmhz
goto ppp
but4
btfsc ioport,psh4
goto main
call dwnmhz
ppp
movf count1,w
movwf byte2
movf count2,w
movwf byte1
call dspadd
call display
call synth
call save
goto main
;------------ save to -----------
save
clrf eeadr
movf count1,w
movwf eedata
call write_ee
incf eeadr
movf count2,w
movwf eedata
call write_ee
return
;------------- recover ----------
restore
clrf eeadr
call read_ee
movwf count1
incf eeadr
call read_ee
movwf count2
return
;--- 7 Segment Display Driver Routines TMS7655-------------
display ;Update 7 Segment Displays
;Clear Displays
movlw 36 ;Set bit Count
movwf temp1 ;Save it
disp_l1
call seg_clock
decfsz temp1
goto disp_l1 ;send 36 bits to display

movlw digit1 ;Send Display Data
movwf fsr
movlw 4
movwf temp1
call seg_start ;Send Start Bit
disp_l3
call seg_get ;Get Segment Data
movwf temp3 ;Save
swapf dpoint
movlw 4
subwf fsr
call seg_get ;Get Segment Data
movwf temp4
swapf dpoint
movlw 3 ;add 4 then subtract 1 from digit pointer.
addwf fsr
movlw 8 ;Send 8 Data Bits to Displays
movwf temp2
disp_l2
bcf segport,seg_d0
nop
bcf segport,seg_d1
rrf temp3
btfsc status,c
bsf segport,seg_d0
rrf temp4
btfsc status,c
bsf segport,seg_d1
call seg_clock
decfsz temp2
goto disp_l2

decfsz temp1 ;Do Next Digit
goto disp_l3
call seg_stop ;Colons Off
call seg_stop
call seg_stop ;Stop Bit
return
segtab ;Segment look up table
clrf pclath ;Clear page register
addwf pcl ;Add W to PC
retlw 0f6h ;0 led segment table
retlw 014h ;1 for tsm6755 display
retlw 0bah ;2 send bit0 first
retlw 03eh ;3 7 6 5 4 3 2 1 0
retlw 05ch ;4 E F A B G C D DP
retlw 06eh ;5
retlw 0eeh ;6
retlw 074h ;7
retlw 0feh ;8
retlw 07eh ;9
retlw 0fch ;A
retlw 0ceh ;B
retlw 0e2h ;C
retlw 09eh ;D
retlw 0eah ;E
retlw 0e8h ;F
retlw 000h ;SP
seg_get
movf dpoint,w
movwf temp2
movf temp1,w
clrf pclath
addwf pcl
nop
rrf temp2
rrf temp2
rrf temp2
movf ind,w
call segtab ;Convert to bit pattern
btfsc temp2,0
addlw 1
return
seg_start
bsf segport,seg_d0 ;Set Start Data Bit
nop
bsf segport,seg_d1
call seg_clock ;Clock it in
return
seg_stop
bcf segport,seg_d0 ;Set Stop Data Bit
nop
bcf segport,seg_d1
call seg_clock ;Clock it in
return
seg_clock ;Send Clock Pulse to Display Drivers
bsf segport,seg_clk
nop
bcf segport,seg_clk
return
;------------- mhz inc/dec -----------------
upmhz
movlw 08h
movwf temp1
loop8
call incdec
decfsz temp1
goto loop8
return
dwnmhz
movlw 08h
movwf temp1
loop_8
call decinc
decfsz temp1
goto loop_8
return
;---------------inc/dec display----------------
incdec
incfsz count1
return
incf count2
return
decinc
movlw 01h
subwf count1
btfss status,c
decf count2
return
;----------------- convert values --------------
convert
btfss msval,0
goto eed ;exit if no change
btfss msval,7
goto dee
call decinc
goto next
dee
call incdec
next
movf count1,w
movwf byte2
movf count2,w
andlw 7fh
movwf byte1
clrf msval ;clear done flag
call dspadd
eed
return
;---------------------------------
dspadd
movf count1,w
movwf tempc1
movf count2,w
movwf tempc2
comf tempc1
comf tempc2
clrf digit1
clrf digit2
clrf digit3
clrf digit4
clrf digit5
clrf digit6
clrf digit7
clrf digit8
incfsz tempc1
goto lpagn
incf tempc2 ;dec count by 1 to correct invertion
lpagn
call incdig
incfsz tempc1
goto lpagn
incfsz tempc2
goto lpagn
return
;-------------------------------
incdig
movf digit1,w
addlw 05h ;add 125 KHz
andlw 0fh
movwf digit1
xorlw 0ah
btfss status,z
goto skip5
clrf digit1
incf digit2
skip5
movf digit2,w
addlw 02h
movwf digit2
xorlw 0ah
btfss status,z
goto skip2
clrf digit2
incf digit3
skip2
movf digit3,w
addlw 01h
movwf digit3
xorlw 0ah
btfss status,z
return

clrf digit3
incf digit4 ;1mhz
movf digit4,w
andlw 0fh
movwf digit4
xorlw 0ah
btfss status,z
return

clrf digit4
incf digit5 ;10mhz
movf digit5,w
andlw 0fh
movwf digit5
xorlw 0ah
btfss status,z
return

clrf digit5
incf digit6 ;100mhz
movf digit6,w
andlw 0fh
movwf digit6
xorlw 0ah
btfss status,z
return

clrf digit6
incf digit7 ;1ghz
movf digit7,w
andlw 0fh
movwf digit7
return

;-----------------------------------------------------
segment byte at:200 'synths'
synth
call start
call write1
movf byte1,w
movwf temp2
call send_byte
movf byte2,w
movwf temp2
call send_byte
movf byte3,w
movwf temp2
call send_byte
movf byte4,w
movwf temp2
call send_byte
call stop
return
;-----------------------------------------------------
send_byte
movlw 08h
movwf temp3 ;8 data bits to send
data8
bcf portb,sda
rlf temp2
btfsc status,c
bsf portb,sda
call synth_clk
decfsz temp3
goto data8
bcf portb,sda
call synth_clk
return
;------------------
write1
movlw 0c2h
movwf temp2
call send_byte
return
;-----------------
synth_clk
nop
bsf portb,scl
nop
nop
bcf portb,scl ;synth clock pulse
return
;---------------------
start
bsf portb,sda
nop
nop
bsf portb,scl
nop
nop
bcf portb,sda
nop
nop
bcf portb,scl ;start condition
return
;----------------------
stop
bsf portb,scl
nop
nop
bsf portb,sda
nop
nop
bcf portb,scl
nop
nop
bcf portb,sda ;stop condition
return

;-------------- EEPROM read and write -------------------
write_ee
bsf status,rp0
bcf eecon1,ee_eeif
bsf eecon1,ee_wren
movlw 055h
movwf eecon2
movlw 0aah
movwf eecon2
bsf eecon1,ee_wr
wr_wait
clrwdt
btfss eecon1,ee_eeif
goto wr_wait
bcf eecon1,ee_wren
bcf status,rp0
return

read_config
movwf eeadr
read_ee
bsf status,rp0
bsf eecon1,ee_rd
bcf status,rp0
movf eedata,w
return

;------ Configuration Data Area ----------------

segment byte at:2000-2004 'id'

code 3fffh ;ID Location 1
code 3fffh ;ID Location 2
code 3fffh ;ID Location 3
code 3fffh ;ID Location 4
;---------------------------------------------------
segment byte at:2007-2008 'fuses'

code 3ff1h ;Configuation Fuses,
;(CP_OFF, PWRUPT_OFF, WDT_OFF, OSC_XT)

;--- EEPROM Data Area, Holding Programable Offsets ---------

segment byte at:2100-2140 'eedata'
data 0d0h ;MSB tx frequecy default 2330MHz
data 48h ;LSB

;----------------------------------------------------------
END