rem Main.bas file generated by New Project wizard
rem
rem Created: 周六 11月 18 2023 taotie
rem Processor: ATmega8
rem Compiler: BASCOM-AVR
rem Software name: 摩爾斯電碼自動發送仿真
rem Write your code here
Dim I As Byte ' 臨時用作循環計數器
Dim M As Byte ' 我們表中當前摩爾斯電碼的索引
Dim L As Byte ' 表示摩爾斯電碼按位生成中最低有效位
Dim P As Byte '用于端口查詢速度和字符集
Dim char_location As Byte '字符位
Dim char_string As String * 26 '字符串
Dim char_string_length As Byte '字符串長度
Dim char_name As String * 1 '單字符名
Dim ASC_byte As Byte At char_name Overlay '覆蓋變量(單詞 char 的字節值)
pouxi_danchi: '剖析單詞
char_string_length = Len(char_string) '單詞長度=Len(返回字符串的長度)。
For char_location = 1 To char_string_length '字符位=1 到 單詞長度
char_name = Mid(char_string , char_location , 1 ) 'char_name = Mid(字符串 , 字符位 , 要獲取/設置的字符數。)
print char_name
Gosub Text_out '調用純文本輸出
Next
if char_string_length=P then waitMS DL_DL '如果字符串已發送到末尾則暫停x秒
Return
Text_out: ' 過濾掉壞字符;查找有用的字符
If ASC_byte > 123 Then ' 重定向壞字符以暫停
ASC_byte = 32
End If
If ASC_byte > 94 Then ' 小寫 -> 大寫
ASC_byte =ASC_byte - 32
End If
ASC_byte = ASC_byte - 32 ' 本ascii表的字符只有以32開頭的部分
M = Lookup(ASC_byte , DIANMA_BIAO) ' 從表中獲取莫爾斯字符
Gosub Morse
Return
'摩爾斯電碼生成:
Morse:
If M = 0 Then ' 特殊情況:空格而不是不可溢出的ASCII字符
Goto char_end
End If
For I = 1 To 8
If M = 1 Then ' 該字節只有值1;繪圖結束!
Goto char_end '字符結束
End If
L = M And &B00000001 ' 讀取最低階位
If L = 1 Then
Sound Speaker , 360, 550 ' 發出嗒聲
Else
Sound Speaker , 120, 550 ' 發出嘀聲
End If
Waitms D_D ' 在摩爾斯電碼中暫停
Shift M , Right , 1 ' 將位向右移動一位
' wait 1
Next I