2012年12月12日水曜日

TC9256 PLL source program 

50Mhz Primix用のTC9256を使ったsource programです。
先に公開した物の修正版。

'********************************************************
'50Mhz AM Tranceiver TC9256 PLL program
' Premix version(IF 10.7Mhz)         5khz step
'     Frequency 50.105Mhz to 50.895Mhz Limitted!
'                                       2012/09/06
' BASCOM AVR                               JA2GQP
'********************************************************
'
$regfile = "attiny2313.dat"
$crystal = 800000
Declare Sub Enc_sub                     'define subrutine
Declare Sub Pll_sub
Declare Sub Lcd_sub
Declare Sub Vfo_sub
Declare Sub Tx_sub
Declare Sub Mem_sub
'define memory
Dim Pll_adr As Byte                     'PLL command adress
Dim Pll_dat As Word                     '    freqency data
Dim Pll_cmd As Byte                     '    command
Dim Frq_wrk As Word                     'freqency
Dim Dsp_frq As String * 6               'Display frequency
Dim Frq_man As Word                     'main channel
Dim Flg As Byte                         'flag
Dim Flg_tx As Byte                      'TX flag
Dim Frqa_eep As Eram Word               'power off frequency A
Dim Frqb_eep As Eram Word               'power off frequency B
Dim Flg_eep As Eram Byte
'--------------
'Main roution
'--------------
Main:
   Disable Interrupts
   Config Lcdpin = Pin , Db7 = Portb.0 , Db6 = Portb.1
   Config Lcdpin = Pin , Db5 = Portb.2 , Db4 = Portb.3
   Config Lcdpin = Pin , E = Portb.4 , Rs = Portb.5
   Config Lcd = 16 * 2
   Config Porta.1 = Output              'Period
   'None,D6=TX,D5=VFO,D4=ENC B,D3=ENC A,D2=Main ch,D1=Clock,D0=Data
   Config Portd = &B00000011
   'None,Input=D6,D5,D4,D3,D2,Output=D0,D1
   Portd = &B01111100                   'pull up input pin
   Config Debounce = 1
   'PLL initial data set
   Pll_adr = &B11010000                 'pll CMD address
   Pll_cmd = &B01010110                 'Xtal 4.5Mhz,5khz step,FMl
   Frq_man = 7980                       '(50.60Mhz-10.7Mhz)/5khz
   Flg_tx = 0                           'initial TX flag
   Flg = Flg_eep                        'Restore memory
   If Flg = 0 Then
      Pll_dat = Frqa_eep
      Else
         Pll_dat = Frqb_eep
         End If
   Cursor Off
   Cls
   Call Pll_sub                         'Dummy write
   Call Pll_sub                         'PLL write
   Call Lcd_sub                         'LCD write
   Enable Interrupts
   Do
      If Flg_tx = 0 Then                'TX?
         Debounce Pind.2 , 0 , Mem_sub , Sub       '  no,recive!
         Debounce Pind.3 , 0 , Enc_sub , Sub
         Debounce Pind.5 , 0 , Vfo_sub , Sub
         Debounce Pind.6 , 0 , Tx_sub , Sub
         Else                           '  yes,transmit
            If Pind.6 = 1 Then          'Send SW off?
               Flg_tx = 0               '  yes,recived
               Locate 2 , 7
               Lcd "  "
               End If
         End If
      Loop
End
'-----------------------------
'Memory channel set
'-----------------------------
Sub Mem_sub
   Pll_dat = Frq_man
   Call Pll_sub
   Call Lcd_sub
   If Flg = 0then
      Frqa_eep = Pll_dat
      Else
         Frqb_eep = Pll_dat
         End If
    While Pind.2 = 0
      Wend
End Sub
'-----------------------------
'Encoder count & PLL set
'-----------------------------
Sub Enc_sub
   If Pind.4 = 1 Then                   'Up
      Pll_dat = Pll_dat + 1
      Else                              'down
         Pll_dat = Pll_dat - 1
         End If
   If Pll_dat <= 7880 Then              'pll_data <= (50.10Mhz-10.7Mhz)/5khz ?
      Pll_dat = 7881
      End If
   If Pll_dat >= 8040 Then              'pll_data >= (50.90Mhz-10.7Mhz)/5khz ?
      Pll_dat = 8039
      End If
   Call Pll_sub
   Call Lcd_sub
   If Flg = 0then
      Frqa_eep = Pll_dat
      Else
         Frqb_eep = Pll_dat
         End If
End Sub
'-----------------------------
'TC9256 Data write
'-----------------------------
Sub Pll_sub
   Set Portd.0                          'Data is High
   Set Portd.1                          'Clock is High
   Set Porta.1                          'period is High
   Reset Porta.1                        'period is Low
   Shiftout Portd.0 , Portd.1 , Pll_adr , 2 , 8 , 1       'ADDRESS set
   Set Porta.1
   Shiftout Portd.0 , Portd.1 , Pll_dat , 2 , 16 , 1       'PLL data set
   Shiftout Portd.0 , Portd.1 , Pll_cmd , 2 , 8 , 1
   Reset Porta.1
End Sub
'-----------------------------
'LCD Data write
'-----------------------------
Sub Lcd_sub
   Cls
   Locate 1 , 1
   Frq_wrk = Pll_dat * 5
   Frq_wrk = Frq_wrk + 10700            'pll_dat+10.7Mhz
   Dsp_frq = Str(frq_wrk)
   Dsp_frq = Format(dsp_frq , "00.000")
   Lcd "FREQ:" ; Dsp_frq ; "Mhz"
   Locate 2 , 1
   Lcd "VFO:" ; Flg
   Locate 2 , 7
   Lcd "  "
   Locate 2 , 10
   Lcd "JA2GQP"
End Sub
'-----------------------------
'VFO
'-----------------------------
Sub Vfo_sub
   If Flg = 0then
      Flg = 1
      Pll_dat = Frqb_eep
      Else
         Flg = 0
         Pll_dat = Frqa_eep
         End If
   Flg_eep = Flg
   Call Pll_sub
   Call Lcd_sub
   While Pind.5 = 0
      Wend
End Sub

'-----------------------------
'TX
'-----------------------------
Sub Tx_sub
   If Flg_tx = 0 Then
      Flg_tx = 1
      Locate 2 , 7
      Lcd "TX"
      End If
End Sub

0 件のコメント:

コメントを投稿