TITLE (C) MARCH 1999 G3RFL RF SIGNAL GENERATOR ;using MC145190 as a Frequency Synth. ;using AD9850 as Reference Generator. #include "pic16c84.h" ;define constants ;portb p_dat equ 0 ;(6)output port Data p_clk equ 1 ;(7)output port Clock. k_dat equ 2 ;(8)input from Keys. dds_dat equ 3 ;(9)output DDS Data data1 equ 4 ;(10)output Display Data 1-4. data2 equ 5 ;(11)output Display Data 5-8. data3 equ 6 ;(12)output Display Data 9-12. seg_clk equ 7 ;(13)output Display Clock. ;porta syn_en equ 0 ;(17)output Frequency Synth /Enable. syn_clk equ 1 ;(18)output Freq Synth clock. syn_dat equ 2 ;(1)output Frequency Synth Data dds_clk equ 3 ;(2)output serial clock to DDS. dds_ud equ 4 ;(3)ouput DDS Frequency UpDate. ;define ram assignments digit12 equ 0ch ; digit11 equ 0dh ; digit10 equ 0eh ; digit9 equ 0fh ; digit8 equ 10h ; digit7 equ 11h ; digit6 equ 12h ; digit5 equ 13h ; digit4 equ 14h ; digit3 equ 15h ; digit2 equ 16h ; digit1 equ 17h sp1 equ 18h ; q1q8 equ 19h ; q9q16 equ 1ah ; q17q24 equ 1bh ; q25q32 equ 1ch ; q33q36 equ 1dh ; temp1 equ 1eh temp2 equ 1fh ;Tempory registers temp3 equ 20h ; temp4 equ 21h ; temp5 equ 22h ; save1 equ 23h save2 equ 24h ddsbit equ 25h dds1 equ 26h dds2 equ 27h dds3 equ 28h dds4 equ 29h dds5 equ 2ah dds6 equ 2bh dds7 equ 2ch dds8 equ 2dh buf1 equ 2eh buf2 equ 2fh buf3 equ 30h buf4 equ 31h buf5 equ 32h buf6 equ 33h buf7 equ 34h buf8 equ 35h udflg equ 36h modtyp equ 37h ampdev equ 38h atten equ 39h segment byte at:0 'code' ;---- Reset and Interrupt Entry Points ------------------------------- reset nop ;Reset Entry Point clrwdt clrf intcon goto init irq retfie ;IRQ Entry Point (No Interrupts Used) ;---------------------------- TABLES --------------------------------- decval clrf pclath ;Clear page register addwf pcl ;Add W to PC retlw 0f2h retlw 6ah retlw 0cah retlw 5fh ;- retlw 6bh ;1hz retlw 00h ;+ retlw 00h retlw 00h retlw 7bh retlw 2dh retlw 0e8h retlw 0bdh retlw 31h ;10hz retlw 04h retlw 00h retlw 00h retlw 0d1h retlw 0c6h retlw 11h retlw 6bh retlw 0f1h ;100hz retlw 29h retlw 00h retlw 00h retlw 32h retlw 0c4h retlw 0b1h retlw 2eh retlw 6eh ;1khz retlw 0a3h retlw 01h retlw 00h retlw 0fbh retlw 0a9h retlw 0f1h retlw 0d2h retlw 4dh ;10khz retlw 62h retlw 10h retlw 00h retlw 0d7h retlw 0a3h retlw 70h retlw 3dh retlw 0ah ;100khz retlw 0d7h retlw 0a3h retlw 00h retlw 66h retlw 66h retlw 66h retlw 66h retlw 66h ;1mhz retlw 66h retlw 66h retlw 06h retlw 00h retlw 00h retlw 00h retlw 00h retlw 00h ;10mhz retlw 00h retlw 00h retlw 40h ;--------------------------------------- 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 ;--- 7 Segment Display Driver Routines -------------------------------- display ;Clear Displays call seg_start ;Send Start Bit movlw 35 ;Set bit Count movwf temp1 ;Save it disp_l1 call seg_stop decfsz temp1 goto disp_l1 ;Update 7 Segment Displays ;Send Display Data movlw digit1 movwf fsr ;Point to digit 1 movlw 4 movwf temp1 call seg_start ;Send Start Bit disp_l3 call seg_get ;Get Segment Data movwf temp2 ;Save movlw 4 ;Subtract 4 from Digit Pointer address subwf fsr call seg_get ;Get Segment Data movwf temp3 ;Save movlw 4 ;Subtract 4 from Digit Pointer address subwf fsr call seg_get ;Get Segment Data movwf temp4 ;Save movlw 7 ;Add 8 then Subtract 1 from Digit Pointer addwf fsr movlw 8 ;Send 8 Data Bits to both Displays movwf temp5 disp_l2 bcf portb,data1 bcf portb,data2 bcf portb,data3 rrf temp2 btfsc status,c bsf portb,data1 rrf temp3 btfsc status,c bsf portb,data2 rrf temp4 btfsc status,c bsf portb,data3 call seg_clock decfsz temp5 goto disp_l2 decfsz temp1 ;Do Next Digit Pair till Done goto disp_l3 call seg_stop ;Colons Off call seg_stop call seg_stop ;Stop Bit return seg_get movf ind,w ;Get Digit Character call segtab ;Convert to bit pattern return seg_start bsf portb,data1 ;Set Start Data Bit bsf portb,data2 bsf portb,data3 call seg_clock ;Clock it in return seg_stop bcf portb,data1 ;Set Stop Data Bit bcf portb,data2 bcf portb,data3 call seg_clock ;Clock it in return seg_clock ;Send Clock Pulse to Display Drivers bsf portb,seg_clk nop bcf portb,seg_clk return ;------------------------------------------------ init clrf status clrf porta clrf portb movlw 00000000b tris porta movlw 00000100b ;1=input tris portb ;0=output movlw 01100011b ;div16,tmr0, option bcf porta,dds_ud bcf porta,dds_clk clrf digit1 clrf digit2 clrf digit3 clrf digit4 clrf digit5 clrf digit6 clrf digit7 clrf digit8 clrf digit9 movlw 10h movwf digit10 ;turn off movwf digit11 ;turn off movwf digit12 ;turn off call synth1 call synth2 call synth3 call clrsave ;---------------------------------------------------- main call scan call display call sortdat goto main ;-------------------- sort input key data -------------- sortdat movf save1,w andlw 0fh xorlw 0ah ;"down" btfsc status,z call down movf save1,w andlw 0fh xorlw 0bh ; "up" btfsc status,z call upup movf save1,w andlw 0fh xorlw 0ch ; "ent" btfsc status,z call ent movf save1,w andlw 0fh xorlw 0dh ;hz btfsc status,z call hz movf save1,w andlw 0fh xorlw 0eh ;khz btfsc status,z call khz movf save1,w andlw 0fh xorlw 0fh ;mhz btfsc status,z call mhz return ;---------------------- mhz rrf save1 rrf save1 rrf save1 rrf save1 movf save1,w andlw 0fh movwf digit7 movf save2,w andlw 0fh movwf digit8 rrf save2 rrf save2 rrf save2 rrf save2 movf save2,w andlw 0fh movwf digit9 call clrsave call dds movf digit1,w movwf q17q24 call key_port ;send 100's mhz to port switches movlw 01h movwf udflg return ;---------------------- khz rrf save1 rrf save1 rrf save1 rrf save1 movf save1,w andlw 0fh movwf digit4 movf save2,w andlw 0fh movwf digit5 rrf save2 rrf save2 rrf save2 rrf save2 movf save2,w andlw 0fh movwf digit6 call clrsave call dds movlw 02h movwf udflg return ;----------------------- hz rrf save1 rrf save1 rrf save1 rrf save1 movf save1,w andlw 0fh movwf digit1 movf save2,w andlw 0fh movwf digit2 rrf save2 rrf save2 rrf save2 rrf save2 movf save2,w andlw 0fh movwf digit3 call clrsave call dds movlw 03h movwf udflg return ;-------------------- up / down buttons ----------------- down movf udflg,w xorlw 03h btfsc status,c goto dechz xorlw 02h btfsc status,c goto deckhz xorlw 01h btfsc status,c goto decmhz return dechz decf digit10 return deckhz decf digit11 return decmhz decf digit12 return ;-------- upup movf udflg,w xorlw 03h btfsc status,c goto inchz xorlw 02h btfsc status,c goto inckhz xorlw 01h btfsc status,c goto incmhz return inchz incf digit10 return inckhz incf digit11 return incmhz incf digit12 return ;----------- ent return ;------------------ clear save buffer ------------------ clrsave clrf save1 clrf save2 return ;---------------------- scan keys ----------------------- scan clrf q1q8 clrf q9q16 clrf temp5 bsf status,c lpl rlf q1q8 btfsc status,c goto upper incf temp5 call key_port call delay btfsc portb,k_dat goto lpl call save_k call delay lp99 btfss portb,k_dat goto lp99 return upper bsf status,c lph rlf q9q16 btfsc status,c return incf temp5 call key_port call delay call delay call delay btfsc portb,k_dat goto lph call save_k call delay goto lp99 ;------------------------- small delay ------------------ delay clrf temp1 lp256 decfsz temp1 goto lp256 return ;---------------------- save keypad numbers ------------- save_k rlf temp5 rlf temp5 rlf temp5 rlf temp5 rlf temp5 ;bit1 rlf save1 rlf save2 rlf temp5 ;bit2 rlf save1 rlf save2 rlf temp5 ;bit3 rlf save1 rlf save2 rlf temp5 ;bit4 rlf save1 rlf save2 return ;----------------- load keypad/port bits --------------------- key_port call key_start movlw q1q8 movwf fsr movlw 4 movwf temp3 lp4 movf ind,w movwf temp1 movlw 8 movwf temp2 lp8 rrf temp1 bcf portb,p_dat btfsc status,c bsf portb,p_dat call key_clock decfsz temp2 goto lp8 movlw 01h addwf fsr decfsz temp3 goto lp4 call key_clock call key_clock call key_clock call key_clock return key_start bsf portb,p_dat nop key_clock bsf portb,p_clk nop bcf portb,p_clk return ;------------------------- calculate dds value --------- calcdds clrf dds8 clrf dds7 clrf dds6 clrf dds5 clrf dds4 clrf dds3 clrf dds2 clrf dds1 ;clear dds buffer movlw 08h movwf temp1 movlw digit9 movwf fsr ;point at highest digit6+1 lpdig movlw 01h addwf fsr ;inc pointer movf ind,w ;get digit data ;100k,10k,1k,100,10,1. movwf temp2 ;save movf temp2 btfsc status,z goto lpj ;if zero exit lpdigg movf temp1,w ;dec decade counter movwf temp3 ;save call bufload ;load buffer with decade data call adder ;add it to total decfsz temp2 ;dec digit value goto lpdigg ;if not zero yet lpj decfsz temp1 ;dec to next decade value goto lpdig ;if not zero yet return ;---------------------------------------------- bufload rlf temp3 rlf temp3 rlf temp3 ;x 8 decf temp3 ;x8-1 movf temp3,w call decval movwf buf8 decf temp3 movf temp3,w call decval movwf buf7 decf temp3 movf temp3,w call decval movwf buf6 decf temp3 movf temp3,w call decval movwf buf5 decf temp3 movf temp3,w call decval movwf buf4 decf temp3 movf temp3,w call decval movwf buf3 decf temp3 movf temp3,w call decval movwf buf2 decf temp3 movf temp3,w call decval movwf buf1 return ;------------------------------ adder movf buf1,w addwf dds1 btfsc status,c call carry1 movf buf2,w addwf dds2 btfsc status,c call carry2 movf buf3,w addwf dds3 btfsc status,c call carry3 movf buf4,w addwf dds4 btfsc status,c call carry4 movf buf5,w addwf dds5 btfsc status,c call carry5 movf buf6,w addwf dds6 btfsc status,c call carry6 movf buf7,w addwf dds7 btfsc status,c call carry7 movf buf8,w addwf dds8 return carry1 incfsz dds2 return carry2 incfsz dds3 return carry3 incfsz dds4 return carry4 incfsz dds5 return carry5 incfsz dds6 return carry6 incfsz dds7 return carry7 incfsz dds8 return ;--------------------- DDS synth update ----------------- dds call calcdds movlw 4 movwf temp1 movlw dds5 movwf fsr ;Point to DDS data1 lpbyte movf ind,w movwf temp2 incf fsr ;increment pointer movlw 8h movwf temp3 lpdds bcf portb,dds_dat rrf temp2 ;LSB first btfsc status,c bsf portb,dds_dat call clock_dds decfsz temp3 goto lpdds decfsz temp1 goto lpbyte bcf portb,dds_dat ;00h=control byte call clock_dds call clock_dds call clock_dds call clock_dds call clock_dds call clock_dds call clock_dds call clock_dds bsf porta,dds_ud ;stobe full block nop bcf porta,dds_ud return clock_dds bsf porta,dds_clk nop bcf porta,dds_clk return ;----------------------------------------------------- segment byte at:280 'synths' ;------------------- control ------------------------- synth1 bcf porta,syn_clk call en_on ;set enable low movlw 6cH movwf temp3 movlw 8 ;8 data bits to send movwf temp2 s1l8 bcf porta,syn_dat rlf temp3 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp2 goto s1l8 call en_off ;finished return ;---------------------- REFERENCE DIVIDER ---------------- ;reference counter "R" set to div by 100 synth2 bcf porta,syn_clk call en_on ;set enable low movlw 20h movwf temp2 movlw 8 ;8 data bits to send movwf temp1 s2l8 bcf porta,syn_dat rlf temp2 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp1 goto s2l8 movlw 64h movwf temp2 movlw 8 ;8 data bits to send movwf temp1 s2l9 bcf porta,syn_dat rlf temp2 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp1 goto s2l9 call en_off ;finished return ;-------------------- FREQUENCY CONTROL ------------ synth3 bcf porta,syn_clk call en_on ;set enable low movlw 0f0h movwf temp2 movlw 8 ;8 data bits to send movwf temp1 s3l8 bcf porta,syn_dat rlf temp2 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp1 goto s3l8 movlw 9ch movwf temp2 movlw 8 ;8 data bits to send movwf temp1 s3l9 bcf porta,syn_dat rlf temp2 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp1 goto s3l9 movlw 10h movwf temp2 movlw 8 ;8 data bits to send movwf temp1 s3l7 bcf porta,syn_dat rlf temp2 btfsc status,c bsf porta,syn_dat call syn_clock decfsz temp1 goto s3l7 call en_off return en_on bcf porta,syn_en return en_off bsf porta,syn_en return syn_clock ;Send Clock Pulse to Display Drivers bsf porta,syn_clk nop bcf porta,syn_clk return ;------------- Configuration Data Area ----------------- segment byte at:2000-2007 '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 3ff2h ;Configuation Fuses, ;(CP_OFF, PWRUPT_OFF, WDT_OFF, OSC_HS) ;-------------------------------------------------- END