JI1FGX/DU9 ミンダナオ日記 AVRマイコンのレピーターコントローラー(2010/06/21)
AVRのBASCOMで作っていたレピーターコントローラーがひとまず形になりました
ただしこのコードをBASCOMのお試し版でコンパイルしても4KBを超えているのでエラーになります。
TIMEOUTのモードが1つだけでハングアップのときにTIMEOUTがリセットされるモードのみです
このソースコードはATMEGA88にあわせて作られています。

入出力
 PB2-8 LCD用出力  (20x4)
 PD0 セットアップ用 + 入力
 PD1 セットアップ用 - 入力
 PD2 セットアップ用 次項目入力
 PC1 スケルチ入力
 PC2 セットアップモード 入力
 PC3 運用モード     入力
 PC4 CWトーン 0から+5Vのみ 入力
 PC5 PTT 出力
' Copyright ©2008-2009 JI1FGX Kouichi Ueno
'
$regfile = "m88def.dat" ' specify the used micro
$crystal = 1280000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space


'$sim
'REMOVE the above command for the real program !!
'$sim is used for faster simulation


'note : tested in PIN mode with 4-bit
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7
Config Lcdpin = Pin , E = Portb.3 , Rs = Portb.2
'
'Config Timer1 = Timer , Prescale = 1024 , Clear Timer = 1 , Compare A = Toggle
'Compare1a = 1249
'On Compare1a Tint1


Dim I3 As Byte
Declare Sub Modeselect1()
Declare Sub Lcdvalue()
Declare Sub Lcddisp()
Declare Sub Repeater()
'Declare Sub Cw()

Dim Cwf As Byte

Dim Maxline As Byte

Dim Setupvalue(22) As Byte
$default Eram
Dim Eeprom_value(22) As Eram Byte At $01
$default Sram
Dim Sw(4) As String * 3
Dim Modeselect As Byte
Dim Modechar(5) As String * 20
Dim Page As Byte
Dim Flag As Bit ' Timer 1Hz
Dim Timeout As Byte


Config Lcd = 20 * 4 'configure lcd screen
Config Portd = Input
Config Portd.7 = Output
Config Portd.7 = Output
Config Portc = &B110000
Set Portc.5
Set Portc.6 '&B110000
Maxline = 4

Cursor On

Cwf = 0
Modeselect = 1
Modechar(1) = "Hangup S"
Modechar(2) = "Timeout M"
Modechar(3) = "TO Reset S"
Modechar(4) = "mode(1,2) "
Modechar(5) = "JI1FGX/DU9"
'Modechar(5) = "DTMFON1 "
'Modechar(6) = "DTMFON2 "
'Modechar(7) = "DTMFOFF1 "
'Modechar(8) = "DTMFOFF2 "

'Modechar(5) = "CW1Speed "
'Modechar(6) = "CW1interval M"
'Modechar(7) = "CW2Speed "
'Modechar(8) = "CW2interval M"
'Modechar(09) = "DTMFON1 "
'Modechar(10) = "DTMFON2 "
'Modechar(11) = "DTMFOFF1 "
'Modechar(12) = "DTMFOFF2 "
'Modechar(13) = "JI1FGX DU9"
Page = 1
Modeselect = 1

Cls
'Sound Portc.4 , 5000 , 100
Wait 1

Main:
Do
Debounce Pinc.3 , 1 , Setup , Sub
Debounce Pinc.3 , 0 , Repeater , Sub
Loop
End
Sub Repeater()
Local Timer_1 As Byte
Local Timer_2 As Byte
Local Timer_3 As Byte
Local S1 As String * 2
Local Fstep As Byte
Local Hungup As Byte
'Dim Timeout As Byte

Fstep = 0
Cwf = 0
If Eeprom_value(1) = &HFF Then Eeprom_value(1) = 1
If Eeprom_value(2) = &HFF Then Eeprom_value(2) = 1
If Eeprom_value(3) = &HFF Then Eeprom_value(3) = 1
If Eeprom_value(4) = &HFF Then Eeprom_value(4) = 1
Timer_1 = Eeprom_value(1)
Timer_2 = Eeprom_value(2) * 10
Timer_3 = Eeprom_value(3)
Cls

Do
Select Case Fstep

Case 0
If Pinc.1 = 0 Then
Reset Portc.5
Hungup = 0
Timeout = 0
Fstep = 1
End If

Case 1
If Timeout = Timer_2 Then
Fstep = 4
End If
If Timeout <= Timer_2 Then
Timeout = Timeout + 1
S1 = Str(timeout)
Cls : Locate 1 , 1 : Lcd "PTT ON" : Lcd Format(s1 , " ")
If Cwf = 0 Then Gosub Cw1
Wait 1
End If
If Pinc.1 = 1 Then Fstep = 2

'Hungup count
Case 2
If Pinc.1 = 1 Then
Locate 1 , 1 : Lcd "Hungup "
If Eeprom_value(4) = 2 Then Timeout = Timeout + 1
If Hungup = Timer_1 Then
Fstep = 3
Hungup = 0
End If

If Hungup <= Timer_1 Then
Hungup = Hungup + 1
Wait 1
End If
If Pinc.1 = 0 Then
' Hungup = 0
Fstep = 0
End If
End If

' Hungup
Case 3
Set Portc.5
Cls : Locate 1 , 1 : Lcd "PTT OFF "
Fstep = 0
Cwf = 0
' Timeout
Case 4
Set Portc.5
Cls : Locate 1 , 1 : Lcd "PTT OFF Timeout"
Timeout = 0
Hungup = 0
Fstep = 0
': S1 = 0
Wait Timer_3
Cls : Locate 1 , 1 : Lcd "PTT OFF "
Cwf = 0
End Select



Debounce Pinc.3 , 1 , Endofloop

Loop


Endofloop:
'Disable Oc0a
'Disable Interrupts
End Sub

Cw1:
Cwf = 1
Dim In_char As String * 1
Dim M_data As String * 5
Dim M As String * 1
Dim Cwlen As Byte
Dim Cwcodelen As Byte
Cls
For Cwlen = 1 To Len(modechar(5))
Locate 2 , Cwlen
Lcd Mid(modechar(5) , Cwlen , 1)
In_char = Mid(modechar(5) , Cwlen , 1)

If In_char = " " Then M_data = " "
If In_char = "A" Then M_data = "0-"
If In_char = "B" Then M_data = "-000"
If In_char = "C" Then M_data = "-0-0"
If In_char = "D" Then M_data = "-00"
If In_char = "E" Then M_data = "0"
If In_char = "F" Then M_data = "00-0"
If In_char = "G" Then M_data = "--0"
If In_char = "H" Then M_data = "0000"
If In_char = "I" Then M_data = "00"
If In_char = "J" Then M_data = "0---"
If In_char = "K" Then M_data = "-0-"
If In_char = "L" Then M_data = "0-00"
If In_char = "M" Then M_data = "--"
If In_char = "N" Then M_data = "-0"
If In_char = "O" Then M_data = "---"
If In_char = "P" Then M_data = "0--0"
If In_char = "Q" Then M_data = "--0-"
If In_char = "R" Then M_data = "0-0"
If In_char = "S" Then M_data = "000"
If In_char = "T" Then M_data = "-"
If In_char = "U" Then M_data = "00-"
If In_char = "V" Then M_data = "000-"
If In_char = "W" Then M_data = "0--"
If In_char = "X" Then M_data = "-00-"
If In_char = "Y" Then M_data = "-0--"
If In_char = "Z" Then M_data = "--00"
If In_char = "0" Then M_data = "-----"
If In_char = "1" Then M_data = "0----"
If In_char = "2" Then M_data = "00---"
If In_char = "3" Then M_data = "000--"
If In_char = "4" Then M_data = "0000-"
If In_char = "5" Then M_data = "00000"
If In_char = "6" Then M_data = "-0000"
If In_char = "7" Then M_data = "--000"
If In_char = "8" Then M_data = "---00"
If In_char = "9" Then M_data = "----0"
If In_char = "/" Then M_data = "-00-0"

For Cwcodelen = 1 To Len(m_data)
If Mid(m_data , Cwcodelen , 1) = "0" Then Sound Portc.4 , 100 , 100
If Mid(m_data , Cwcodelen , 1) = "-" Then Sound Portc.4 , 300 , 100
If Mid(m_data , Cwcodelen , 1) = " " Then Waitms 80
Waitms 30
Next
Waitms 200
Next

Return
Setup:


Set Portc.5
Gosub Lcddisp
Do

Debounce Pind.0 , 0 , Sw0on , Sub
Debounce Pind.1 , 0 , Sw1on , Sub
Debounce Pind.2 , 0 , Modeselect1 , Sub
Debounce Pinc.3 , 0 , Endofsetup
Loop
Endofsetup:
Return
End


Sw0on:
Incr Setupvalue(modeselect)
Eeprom_value(modeselect) = Setupvalue(modeselect)
Gosub Lcdvalue

Bitwait Pind.0 , Set
Return

Sw1on:

If Setupvalue(modeselect) > 1 Then
Decr Setupvalue(modeselect)
End If
Eeprom_value(modeselect) = Setupvalue(modeselect)

Gosub Lcdvalue
Bitwait Pind.1 , Set
Return


Sub Modeselect1()
Local Amari As Byte
Local I2 As Byte
'Local I As Byte
Local I1 As Byte

Modeselect = Modeselect + 1
I2 = Page - 1
I2 = Maxline * I2
I1 = Modeselect - I2
I2 = I1 - 1
If I1 > 1 Then
Locate I2 , 13
Lcd " "
End If
Locate I1 , 13
Lcd ">"


Amari = Modeselect Mod 4
If Amari = 1 Then
Page = Page + 1


' Cls
Gosub Lcddisp
End If
If Modeselect > 4 Then
' If Modeselect > 10 Then
Modeselect = 1
Page = 1
' Cls
Gosub Lcddisp
End If

'Return
End Sub

Sub Lcdvalue()
Local I2 As Byte
Local I1 As Byte
I2 = Page - 1
I2 = Maxline * I2
I1 = Modeselect - I2


Sw(i1) = Str(setupvalue(modeselect))
Sw(i1) = Format(sw(i1) , " 0")

Locate I1 , 17
Lcd Sw(i1)
'Return
End Sub

Tint1:
Toggle Portd.7
Flag = 1
Return

Sub Lcddisp()
Local I As Byte
Local I2 As Byte
Local I1 As Byte
Cls

For I = 1 To Maxline
I2 = Page - 1
I2 = Maxline * I2
I1 = I + I2
Setupvalue(i1) = Eeprom_value(i1)
If Setupvalue(i1) = 255 Then
Setupvalue(i1) = 1
End If

Sw(i) = Str(setupvalue(i1))
Sw(i) = Format(sw(i) , " 0")

Locate I , 1 : Lcd Modechar(i1)

Locate I , 17 : Lcd Sw(i)
Next
Locate 1 , 13
Lcd ">"
'Return
End Sub



End
2010年06月07日  2010年07月03日
フレーム表示に戻す