$regfile = "m168def.dat" $crystal = 10000000 Dim Send As Word , Low_word As Word , High_word As Word , Freq As Long Dim Tmp As Single , Tmp_l As Single , Tmp_h As Single , Tmp1 As Single
'Starting frequency Freq = 3690000
' 2^28 / MCLK ( for 16MHz it is about 16.7772) Const Vak = 16.7772
'Ports´ directions and pull up Ddrb = &B00000111 Portb = &B00000111 Ddrd = &B10011111 Portd = &B11111111 'LCD ports Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.1 , Db6 = Portb.0 , Db7 = Portd.7 , E = Portd.0 , Rs = Portd.1
'Subroutines Declare Sub Ser_out Declare Sub Up Declare Sub Dn Declare Sub Laske
'DDS ports Fsync Alias Portd.2 Sdata Alias Portd.4 Sclk Alias Portd.3
'DDS ports up Set Fsync Set Sclk Set Sdata
'Debounce time for frequency keys Config Debounce = 50
Main: 'Starting frequency and init values Cls Lcd "3.690000 Hz" Send = &H2100 Gosub Ser_out Send = &H639C Gosub Ser_out Send = &H4EC2 Gosub Ser_out Send = &HC000 Gosub Ser_out Send = &H2000 Gosub Ser_out 'Loop for check keys Do Debounce Pind.6 , 0 , Up , Sub Debounce Pind.5 , 0 , Dn , Sub Loop
End
' 'Send data ' Ser_out: Reset Fsync Shiftout Sdata , Sclk , Send , 0 Set Fsync Return ' 'Frequence up ' Up: Freq = Freq + 100 If Freq > 6000000 Then Freq = 6000000 End If Gosub Laske Return ' 'Frequence down ' Dn: Freq = Freq - 100 If Freq < 3500000 Then Freq = 3500000 End If Gosub Laske Return ' 'Count data for a dds ' Laske: Tmp1 = Freq * Vak Tmp_h = Tmp1 / 16384 High_word = Int(tmp_h) Tmp = High_word * 16384 Tmp_l = Tmp1 - Tmp Low_word = Int(tmp_l) Low_word.15 = 0 Low_word.14 = 1 Send = Low_word Gosub Ser_out High_word.15 = 0 High_word.14 = 1 Send = High_word Gosub Ser_out
'Show a frequency on a LCD Cls Waitms 10 Lcd Freq , ; " Hz" Waitms 10 Return
|