
;controller for elcom dfs1295
;dual freq
;12670 (24048 + IF 1292-1290)
;12673.333 (24048 + IF 1298.666-1296.666)
; David Robinson WW2R
; aug 19 2005
; for int rc osc

;	GP5  	GP4   GP3  	GP2  	GP1 	GP0	
;	SCLK	DOUT  freq	CS	n/u	n/u
;	PIN2    PIN3  pin4 	pin 5  	PIN6	PIN7


	LIST P=12F675, R=DEC    ; Use the PIC12F675 and decimal system 

        #include "P12F675.INC"  ; Include header file 

        __FUSES _CP_OFF &_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &_BODEN_OFF &_MCLRE_OFF  

		cblock	0x20

r_temp
count
ncount
kcount
mcount
xcount
run
bits
f1_1
f1_2
f1_3
f1_4
f2_1
f2_2
f2_3
f2_4
		endc

		org 	0


;Initialize ports.

		banksel	GPIO
		clrf	GPIO

		movlw	0x7f
		movwf	CMCON
		
		banksel	TRISIO        	;select pg1

		movlw   B'0001000'	;set gp0-5 as outputs, except 3 input
		movwf	TRISIO

		movlw   B'00000000'     ;select digital operation of input
		movwf   ANSEL            	

		banksel	GPIO        	;select pg0

		movlw	0x08
		movwf	bits

		call	ce_high	
		call	delay1s
		call	delay1s		
		call	delay1s
		call	delay1s
		call	delay1s
		
;values for freq 1 24048 + 1292 IF (12670MHz) ...remember to multiply frequency by 3

		movlw	0x38
		movwf	f1_1

		movlw	0x01
		movwf	f1_2

		movlw	0x00
		movwf	f1_3

		movlw	0x00
		movwf	f1_4


;values for freq 2 24048 + 1298.666 IF (12673.333) ...remember to multiply frequency by 3

		movlw	0x38
		movwf	f2_1

		movlw	0x02
		movwf	f2_2

		movlw	0x00
		movwf	f2_3

		movlw	0x00
		movwf	f2_4



;decide which freq to output

		btfsc	GPIO,3
		goto	freq2


; send values to oscillator (32 bits) for freq1

freq1		bsf	GPIO,0
		bcf	GPIO,1
		call	ce_low
		call 	wait
		movf	f1_4,0
		call 	spi_nbit_word   ;send next 8 bits
		movf	f1_3,0
		call 	spi_nbit_word   ;send next 8 bits ;
		movf	f1_2,0
		call 	spi_nbit_word    ;send next 8 bits
		movf	f1_1,0
		call 	spi_nbit_word    ;send next 8 bits
		call	wait
		call	ce_high
		call	wait
loopf1		btfsc	GPIO,3
		goto	freq2
		goto	loopf1

	
; send values to oscillator (32 bits) for freq2

freq2		bcf	GPIO,0
		bsf	GPIO,1
		call	ce_low
		call 	wait
		movf	f2_4,0
		call 	spi_nbit_word   ;send next 8 bits
		movf	f2_3,0
		call 	spi_nbit_word   ;send next 8 bits ;
		movf	f2_2,0
		call 	spi_nbit_word    ;send next 8 bits
		movf	f2_1,0
		call 	spi_nbit_word    ;send next 8 bits
		call	wait
		call	ce_high
		call	wait
loopf2	btfss	GPIO,3
		goto	freq1
		goto	loopf2
		



;************
spi_nbit_word
;************

		movwf	r_temp		;r_temp = 8 bits of data to send
		movf	bits,w  	;number of bits to w
		movwf	ncount		;number of bits to ncount
btfline1	btfsc	r_temp,0	;test bit 7 of r_temp skip if clear
		goto	spi_hi1
		rrf 	r_temp,f 	;spi_low
		call	wait
		bsf	GPIO,5		;sclk=0
		call	wait
		bcf	GPIO,5		;sclk=1
		call	wait
		decfsz	ncount,1
		goto	btfline1
		goto	lp_end

spi_hi1		rrf	r_temp,f	;spi high
		bsf	GPIO,4 		;Din=1
		call	wait
		bsf	GPIO,5		;sclk=0
		call	wait
		bcf	GPIO,5		;sclk=1
		call	wait
		bcf	GPIO,4		;Din=0
		decfsz	ncount,1
		goto	btfline1

lp_end		return



ce_low	 	bcf	GPIO,2		;cs\=0
		call	wait
		return

ce_high		bsf	GPIO,2		;cs\=1
		call	wait
		return


wait	movlw	0xff			;was 80
		movwf	count		;to kcount
deck	decfsz	count,f			;dec k
		goto	deck
		return	



;********
delay1s
;********

		movlw	0x32		;0x32 to w
		movwf	xcount		;to xcount
loadm2	movlw	0x1a			;0x1a to w    1a and ff give 10ms per loop
		movwf	mcount		;to mcount    at 4MHz
loadk2	movlw	0xff			
		movwf	kcount		
deck2	decfsz	kcount,f		
		goto	deck2	
		decfsz	mcount,f	
		goto	loadk2		
		decfsz	xcount,f;	
		goto	loadm2	;	
		return



	ORG 0X100

        dw      'W'

        dw      'W'

        dw      '2'

        dw      'R'

        dw      ' '

        dw      'E'

        dw      'L'

        dw      'C'

        dw      'O'

        dw      'M'

        dw      ' '

        dw      'C'

        dw      'O'

        dw      'N'

        dw      'T'

        dw      'R'

        dw      'O'

        dw      'L'

        dw      'L'

        dw      'E'

        dw      'R'

        dw      ' '

        dw      'V'

        dw      '1'

        dw      '.'

        dw      '1'

		END

