'Voltage Controled DDS(AD9850) for ICB-700mod. v1.04 '2014.08.09 by JA1VZV 'Freq.range 28.1745-28.4300 MHz 'Call ch=28.305MHz 'RX DDS output = F-455kHz '0.5kHz step mode (Usage:Lump ON + power on) '================Pin Assignment========================= 'DDS FqUD out:B3 / D7 out:B4 / Wclk out:B5 'Tune in:C0 / CH1 in:B0 / PTT in:C2 / Step select in: B2 'Auto-shift:C1 '======================================================= 'Use external ceramic resonator 560kHz $regfile = "m88def.dat" $crystal = 560000 'Spec. Sclock freq. '--- config port --- Config Portb = &B00111000 'B0-2,6-7:In ,B3-5:Out Config Portc = &B0000010 'C0,2-6input ,C1:Output Config Portd = &H00 'All input(Not used) '--- port pullup --- Portb = &B00000101 'B0:L=CH1,B2:L=0.5kHz Portc = &B1000100 'C0:Tune,C1:Shift,C2:L=TX,C6:L:Reset Portd = &H00 'All low '--- debounce set --- Config Debounce = 1 'ADC mode setting & start Config Adc = Single , Prescaler = Auto Start Adc '---Define Variables--- Dim R As Word 'Tune VR value Dim R1 As Integer 'Tune VR past value Dim R2 As Long 'Tune calc Dim Rd As Integer 'Tune calc Dim I As Long 'IF freqency Dim F0 As Long 'Lower Freq. data Dim F As Long 'Freq. data Dim Ff As Single 'For F calc(DDS) Dim Fa As Long 'For F calc(DDS) Dim Fb As Long 'For F calc(DDS) Dim Lk As Bit 'Freq.Lock flag Dim Md As Bit 'Dial mode flag Dim Dc As Byte 'DDS command Dim Dd As Byte ' Dim Tr As Bit 'Tx flag TX=1 '---Variables initialize--- I = 455000 'IF freq.[Hz] Lk = 0 'Lock bit to unlock F0 = 28174500 'Lower limit Freq. R1 = 1026 'Initial ADC memory value Md = Pinb.2 'Dial mode read & memory If Md = 1 then Dd=2 Else Dd=1 End If Dc = &B00000000 'DDS command value Tr = 0 'Tx flag reset (=Rx) '---Set DDS to serial mode--- Reset Portb.4 Reset Portb.5 Waitus 10 Set Portb.5 Waitus 10 Reset Portb.5 Waitus 10 Set Portb.3 Waitus 10 Reset Portb.3 Waitus 10 '*** Main loop *** Do If Pinb.0 = 1 Then 'If Vfo mode then R = Getadc(0) ' Read ADC0 (TUNE in) Else 'else R = 522 ' Set fixed value(=28.305MHz) End If Rd = R - R1 'Calc.VR data cange Rd = Abs(rd) If Lk = 0 Then 'Not F-lock then If Rd > 1 Then 'If VR value canged R1 = R If Md = 0 Then '0.5kHz mode Shift R , Right , 1 ' /2 R2 = R * 500 Else '10kHz mode R = R \ 40 R2 = R * 10000 R2 = R2 + 500 'Add offset freq. End If F = F0 + R2 'Calc. Operation freq If F >= 28275000 And F <= 28295000 Then 'MPU clock auto-shift Reset Portc.1 Else Set Portc.1 End If Gosub Dds 'Set freq.to DDS End If End If If Lk = 1 And Rd >= 12 Then Lk = 0 'F-lock off(F changed >3kHz) ' Check PTT If Tr = 1 Then 'In TX Debounce Pinc.2 , 1 , Rx , Sub ' Check PTT Off Else 'In RX Debounce Pinc.2 , 0 , Tx , Sub ' Check PTT On End If Waitms 50 Loop '= End main loop = '*** DDS data calc & set*** Dds: '---Freq.calc--- If Tr = 1 Then 'IF in TX then Fa = F 'Set TX Freq. Else 'In RX Fa = F - I 'Set RXLo Freq. End If Ff = Fa * 34.36010179 'Conv. F to DDS data Fb = Ff 'Conv. to integer '---Set DDS data--- Shiftout Portb.4 , Portb.5 , Fb , 3 , 32 , 0 Shiftout Portb.4 , Portb.5 , Dc , 3 , 8 , 0 Waitus 10 Set Portb.3 Waitus 10 Reset Portb.3 Return '*** TX sub *** Tx: Tr = 1 'TX flag on Lk = 1 'F-Lock flag on Gosub Dds Return '*** RX sub *** Rx: Tr = 0 'TX flag off Gosub Dds Return