program DDSTotaal 'Versie v0.1 30 december 2007 A.Koopman PA0AKV 'DDS aangestuurd door POORTA bit 0,1,2 'Keypad aangestuurd door POORTC bit 0,1,2,3 'Rotary encoder aangestuurd door POORTB bit1,2 $06 'Lcd gebruikt POORTB en POORTD bit 4,5,6,7 all 'Menu opties************ '*****CORREKTIE X TAL '********** Ingave keypad afsluiten # '*****STAP FREQUENTIE afsluiten # '**********Rotary encoder '**********click 1=10Hz '**********click 2=100Hz '**********click 3 =1Khz '**********click 4=10Khz '**********click 5=100Khz '**********click 6=1Mhz '*****Frequentie invoeren '**********Ingave keypad afsluiten # '**********Rotary encoder afsluiten # 'symbols symbol FQ_UD = PORTA,0 symbol DAT = PORTA,2 symbol CLK = PORTA,1 'declarations Dim RotorO as Byte Dim RotorN as Byte Dim Click as Byte Dim Klok as Byte Dim ToetsWaarde as Byte Dim Teller as Byte Dim Menu as Byte Dim n as Byte Dim FwaardeH as Integer Dim FwaardeL as Integer Dim Fwaarde as LongInt Dim Offset as LongInt Dim Osc as Longint Dim Frequentie as LongInt Dim Stap as LongInt Dim FreQ as String[8] Dim MenuTekst as String[16] Dim LeftString as String[4] Dim RightString as String[4] Dim Display as String[11] Dim OscString as String[11] Dim Controllword as Byte Dim g as float Dim Result as longint 'constanten const Keypad as Byte[12] = (49,50,51, 52,53,54, 55,56,57, 48,42,35) 'Map 4*3 to ASCII 'subroutines 'subroutine voor het afvragen van de Menu toets sub procedure interrupt INTCON.INTF = 0 FreQ = "########" Offset = 0 Teller = 0 If Menu = 1 then Menu = 2 else Menu =1 end if end sub 'subroutine voor het afpellen van een byte naar 8 bits sub procedure SHIFTOUT_LSB(dim databyte as byte) dim bits as byte CLEARBIT(CLK) 'Start Clock low For bits = 0 to 7 databyte = byte(databyte >> 1) 'Least Significant Bit First If STATUS.0 = 0 Then 'Shifted bit is in Carry Bit of Status Register CLEARBIT(DAT) 'Put bit data on output Delay_us(1) Else SETBIT(DAT) Delay_us(1) End If SETBIT(CLK) 'Clock High Delay_us(1) CLEARBIT(CLK) 'Clock Low Delay_us(1) Next bits 'Get next bit end sub 'subroutine voor het afpellen van het Frequentie word naar 32 bits sub procedure SHIFTOUT_LSB32(dim waarde as longint) dim bits as byte CLEARBIT(CLK) 'Start Clock low For bits = 0 to 31 waarde = longint(waarde >> 1) 'Least Significant Bit First If STATUS.0 = 0 Then 'Shifted bit is in Carry Bit of Status Register CLEARBIT(DAT) 'Put bit data on output Delay_us(1) Else SETBIT(DAT) Delay_us(1) End If SETBIT(CLK) 'Clock High Delay_us(1) CLEARBIT(CLK) 'Clock Low Delay_us(1) Next bits 'Get next bit end sub 'subroutine voor bepaling DDS controll word sub procedure DDS_value 'bepalen waarde g = (Frequentie/osc)* $7FFFFFFF Result = longint(g)*2 'inklokken SHIFTOUT_LSB32(Result) SHIFTOUT_LSB(Controllword) Delay_us(1) SetBit(FQ_UD) Delay_us(1) ClearBit(FQ_UD) end sub sub procedure Rotor RotorN = PORTB and $06 'get rotary encoder inputs If RotorN <> RotorO then If (RotorN = 0) and RotorO = 6 then Inc(Click) 'clockwise move end if If (RotorN = 2) and RotorO = 6 then Dec(Click) 'anti clockwise move end if RotorO = RotorN end if end sub sub procedure UpDown RotorN = PORTB and $06 'get rotary encoder inputs If RotorN <> RotorO then If (RotorN = 0) and RotorO = 6 then Frequentie = Frequentie + Stap end if If (RotorN = 2) and RotorO = 6 then Frequentie = Frequentie - Stap end if RotorO = RotorN end if end sub sub procedure NumToets Lcd8_Out(1,1,"Invoeren svp") Lcd8_Out(2,1,FreQ) Lcd8_Out(2,9," Hz") if PORTC = 0 then Klok = 255 end if If Klok and PORTC > 0 then Delay_ms(5) ToetsWaarde = Keypad[PORTC-1] Klok = 0 Select case ToetsWaarde case "*" If Teller > 0 then Dec(Teller) else Teller = 0 end if FreQ[Teller] = "*" Lcd8_Out(2,1,FreQ) case 48,49,50,51,52,53,54,55,56,57 FreQ[Teller] = ToetsWaarde Inc(Teller) Lcd8_Out(2,1,FreQ) end select end if end sub sub procedure SetFreQ For n = 0 to 3 LeftString[n] = FreQ[n] Next n For n = 4 to 7 RightString[n-4] = FreQ[n] Next n FwaardeL = StrToInt(RightString) FwaardeH =StrToInt(LeftString) Fwaarde = FwaardeH * 10000 Fwaarde = Fwaarde + FwaardeL end sub main: 'mainprogram 'Initalisatie '************ TRISB = 7 'make RB0,1,2 inputs OPTION_REG = 128 'Pull ups inactive,INTEDG HI INTCON = 128 + 16 'GIE active,INTE active,INTF = 0 TRISC = $0F 'maak PORTD RD0,1,2,3 inputs Click = 0 'start with clean click RotorO = 6 Teller = 0 Osc = 180000000 Stap = 100 Frequentie = 10000000 Fwaarde = 0 FreQ = "########" MenuTekst = " " LeftString = "####" RightString = "####" 'Initalisation LCD '***************** Lcd8_Init(PORTB,PORTD) Lcd8_Cmd(Lcd_Clear) Menu = 1 Lcd8_Out(1,1,"DDS AD9851") Lcd8_Out(2,1,"PA0AKV v0.1 2007") Delay_ms(1500) Lcd8_Cmd(Lcd_Clear) 'Initalisatie DDS chip AD9851 '**************************** Controllword = $09 TRISA = %11000000 ADCON0 = 0 ADCON1 = ADCON1 or $07 ClearBit(DAT) ClearBit(CLK) ClearBit(FQ_UD) 'zet serieel inlezen in goede stand '********************************** SetBit(CLK) Delay_us(1) ClearBit(CLK) Delay_us(1) SetBit(FQ_UD) Delay_us(1) ClearBit(FQ_UD) Delay_us(1) '32 lege plaatsen inklokken '************************** SHIFTOUT_LSB32($00000000) 'en nog eens 8 '************* SHIFTOUT_LSB($00) Delay_us(1) SetBit(FQ_UD) Delay_us(1) ClearBit(FQ_UD) Delay_ms(100) 'en nu dan echt beginnen ! '************************ loop: Select case Menu case 1 Lcd8_Out(1,1,"Druk op MENU") case 2 Lcd8_Out(1,1,"Draai voor keuze") Lcd8_Out(2,1,"# = EINDE keuze") Delay_ms(1500) Lcd8_Cmd(Lcd_Clear) While PORTC <> 12 Lcd8_Out(2,1," Draai..") Rotor If Click > 3 then Click = 1 end if Select case Click case 1 Menu = 3 Lcd8_Out(1,1,"Calibratie!") case 2 Menu = 4 Lcd8_Out(1,1,"Afstem Stap") case 3 Menu = 5 Lcd8_Out(1,1,"Afstem freq") end select Wend Delay_ms(100) case 3 Lcd8_Out(1,1,"Ingave in Hz") Delay_ms(500) FreQ = "########" Teller = 0 Osc = 180000000 While PORTC <> 12 NumToets Wend Lcd8_Cmd(Lcd_Clear) Lcd8_Out(1,1, "Osc Offset Hz !") Delay_ms(1000) Lcd8_Cmd(Lcd_Clear) SetFreQ OscString = " " Osc = Osc - Fwaarde LongIntToStr(Osc,OscString) Lcd8_Out(1,1,OscString) Lcd8_Out(1,12," Hz") Lcd8_Out(2,1,"Cal. OK!") Delay_ms(1000) Lcd8_Cmd(Lcd_Clear) Menu = 2 case 4 Lcd8_Out(1,1, "Afstem stap") Lcd8_Out(2,1, "Nu 100 Hz") Delay_ms(1500) Lcd8_Cmd(Lcd_Clear) Display = "###########" While PORTC <> 12 Rotor If Click > 7 then Click = 7 end if Select case Click case 1 Stap = 10 case 2 Stap = 100 case 3 Stap = 1000 case 4 Stap = 10000 case 5 Stap = 100000 case 6 Stap = 1000000 case 7 Stap = 10000000 end select LongIntToStr(Stap,Display) Lcd8_Out(2,1," Hz") Lcd8_Out(2,1,Display) Wend Lcd8_Out(1,1,"Stap ingevoerd") Delay_ms(1000) Lcd8_Cmd(Lcd_Clear) Menu = 2 case 5 Lcd8_Out(1,1, "Afstemmen") Lcd8_Out(2,1,"Geef Freq in") Delay_ms(1000) Lcd8_Cmd(Lcd_Clear) FreQ = "########" Teller = 0 While PORTC <> 12 NumToets Wend Lcd8_Out(1,1, " Step") SetFreQ Frequentie = Fwaarde LongIntToStr(Frequentie,Display) Lcd8_Out(2,1,Display) LongIntToStr(Stap,Display) Lcd8_Out(1,1,Display) DDS_value Delay_ms(500) While PORTC <> 12 UpDown LongIntToStr(Frequentie,Display) Lcd8_Out(2,1,Display) DDS_value Wend Lcd8_Out(1,1,"Stop VFO ") Delay_ms(1000) Lcd8_Cmd(Lcd_Clear) Menu = 2 end select goto loop end.