?? bear.frm
字號:
Disconnect = 0
Busy = False
Exit Sub
End If
ElseIf Opration = "Signature" Then '識別芯片型號
SignatureCode(SigAddr) = AscB(Command)
SigAddr = SigAddr + 1
If SigAddr = 2 Then
SetType
Timer1.Enabled = False
Com1.InputMode = comInputModeText
Else:
Com1.Output = Trim("S")
End If
Exit Sub
ElseIf Opration = "SetMcuType" Then '手動設定芯片型號
If Command = "T" Then
TypeProcedue = TypeProcedue + 1
If TypeProcedue = 1 Then
Sendbuffer(1) = SignatureCode(1)
Com1.Output = Sendbuffer
ElseIf TypeProcedue = 2 Then
Status.Caption = "芯片已設定!"
Timer1.Enabled = False
TypeProcedue = 0
SetType
End If
Else
Status.Caption = "芯片設定失敗!"
Timer1.Enabled = False
Code_Max = 0
End If
End If
Else '無回應則換端口
Status.Caption = "正在連接,請稍候!"
If Com1.CommPort = 1 Then
Com1.PortOpen = False
Com1.CommPort = 1
Com1.PortOpen = True
ElseIf Com1.CommPort = 2 Then
Com1.PortOpen = False
Com1.CommPort = 1
Com1.PortOpen = True
End If
Com1.Output = Trim("C")
Disconnect = Disconnect + 1
Progress.Max = 50
Progress.Value = Disconnect
Status.Caption = "正在連接,請稍候!"
If Disconnect = 50 Then
Status.Caption = "設備連接失敗!"
Busy = False
Disconnect = 0
Progress.Value = 0
Timer1.Enabled = False
End If
End If
End Sub
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'寫入代碼,已經確定
Private Sub Write_Click() '寫入代碼
If Busy = True Then Exit Sub
If Code_Max = 0 Then
Status.Caption = "請先設定芯片型號!"
Exit Sub
End If
If Code_all = 0 Then
Status.Caption = "請先載入有效文件!"
Exit Sub
End If
Busy = True
Opration = "Write"
Status.Caption = "正在寫入,請稍候!"
If Com1.PortOpen = False Then
Com1.PortOpen = True
End If
Com1.Output = Trim("W")
WriteTimer.Enabled = True
End Sub
Private Sub WriteTimer_Timer()
If Com1.InBufferCount > 0 Then '收到應答
Disconnect = 0
Codes = Com1.Input
If Codes = "W" Then '應答為就緒“Ready”
WriteProcedue = WriteProcedue + 1
If WriteProcedue = 1 Then
Sendbuffer(1) = (Code_all + 1) \ 256 '最后一位代碼的高位地址
Com1.Output = Sendbuffer
ElseIf WriteProcedue = 2 Then
Sendbuffer(1) = (Code_all + 1) Mod 256 '最后一位代碼的低位地址
Com1.Output = Sendbuffer
Addr = 0
Progress.Max = Code_all + 1
Progress.Value = 0
Else
If Addr <= Code_all Then '判斷是否是最后一位代碼
Sendbuffer(1) = Code(Addr)
Com1.Output = Sendbuffer
Progress.Value = Progress.Value + 1
Addr = Addr + 1
Exit Sub
End If
Status.Caption = "寫入完成!"
WriteProcedue = 0
WriteTimer.Enabled = False
Progress.Value = 0
Busy = False '寫入完成
Exit Sub
End If
End If
Else '無應答
Disconnect = Disconnect + 1
If Disconnect < 1000 Then Exit Sub
Status.Caption = "連接超時,寫入失敗!" '連接超時
Opration = "Failed"
Disconnect = 0
WriteTimer.Enabled = False
Busy = False
End If
End Sub
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'擦除代碼,已經確定
Private Sub Eraze_Click() '擦除
If Busy = True Then Exit Sub
If Code_Max = 0 Then
Status.Caption = "請先設定芯片型號!"
Exit Sub
End If
Busy = True
Opration = "Eraze"
Status.Caption = "正在擦除,請稍候!"
If Com1.PortOpen = False Then
Com1.PortOpen = True
End If
Com1.Output = Trim("E") '發送擦除命令
ErazeTimer.Enabled = True
End Sub
Private Sub WriteLockBits_Click()
If Busy = True Then Exit Sub
If Code_Max = 0 Then
Status.Caption = "請先設定芯片型號!"
Exit Sub
End If
Com1.Output = Trim("L")
Busy = True
Opration = "WriteLockBits"
ErazeTimer.Enabled = True
End Sub
Private Sub ErazeTimer_Timer()
If Com1.InBufferCount > 0 Then '收到應答
Disconnect = 0
Codes = Com1.Input
If Opration = "Eraze" Then
If Codes = "E" Then
Status.Caption = "擦除完成!"
ElseIf Codes = "F" Then
Status.Caption = "擦除失敗!"
Opration = "Failed"
End If
ElseIf Opration = "WriteLockBits" Then
If Codes = "L" Then
Status.Caption = "加密完成!"
Else
Status.Caption = "加密失敗!"
Opration = "Failed"
End If
End If
ErazeTimer.Enabled = False
Progress.Value = 0
Busy = False '擦除完成
Exit Sub
Else '無應答
Disconnect = Disconnect + 1
Progress.Max = 100
Progress.Value = Disconnect
If Disconnect < 100 Then Exit Sub
Status.Caption = "連接超時!"
Disconnect = 0
Progress.Value = 0
ErazeTimer.Enabled = False
Busy = False
End If
End Sub
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'讀出代碼和校驗,已經確定
Private Sub Read_Click(Index As Integer)
If Busy = True Then Exit Sub
If Code_Max = 0 Then
Status.Caption = "請先設定芯片型號!"
Exit Sub
End If
Com1.InputMode = comInputModeBinary
If Index = 0 Then
Opration = "Read" '讀代碼
Status.Caption = "正在讀出,請稍候!"
Progress.Max = Code_Max
ElseIf Index = 1 Then
If Code_all = 0 Then
Status.Caption = "請先載入有效文件!"
Exit Sub
End If
Opration = "Verify" '校驗
Status.Caption = "正在校驗,請稍候!"
Progress.Max = Code_all
Else
Busy = False
Exit Sub
End If
Addr = 0
If Com1.PortOpen = False Then
Com1.PortOpen = True
End If
Busy = True
Com1.Output = Trim("R")
Progress.Value = 0
ReadTimer.Enabled = True
End Sub
Private Sub ReadTimer_Timer()
If Com1.InBufferCount > 0 Then '收到應答
Disconnect = 0
Codes = Com1.Input
If Opration = "Verify" Then '當前操作為校驗
If AscB(Codes) = Code(Addr) Then
If Addr < Code_all Then
Com1.Output = Trim("R")
Addr = Addr + 1
Progress.Value = Progress.Value + 1
Exit Sub
End If
Com1.Output = Trim("O")
Status.Caption = "校驗正確!"
Else
Com1.Output = Trim("O") '校驗錯誤,中途退出讀出狀態
Status.Caption = "校驗錯誤!"
Opration = "Failed"
End If
ElseIf Opration = "Read" Then '當前操作為讀出
Code(Addr) = AscB(Codes)
If Addr < Code_Max - 1 Then
Com1.Output = Trim("R")
Addr = Addr + 1
Progress.Value = Progress.Value + 1
Exit Sub
End If
Com1.Output = Trim("C")
Status.Caption = "讀出完成!"
Code_all = Addr
SaveCode
End If
Else '無應答
Disconnect = Disconnect + 1
If Disconnect < 100 Then Exit Sub
Status.Caption = "連接超時,操作失敗!" '連接超時
Disconnect = 0
End If
Com1.InputMode = comInputModeText
ReadTimer.Enabled = False
Progress.Value = 0
Busy = False '讀出或者校驗完成
End Sub
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'打開和保存 Intel Hex 文件,已經確定
Private Sub LoadFile_Click() '載入文件
If Busy = True Then Exit Sub
On Error GoTo Failed
Busy = True
Cmd1.Filter = "Intel Hex Files|*.hex"
Cmd1.ShowOpen
If Cmd1.FileName = "" Then
Busy = False
Exit Sub
End If
Open Cmd1.FileName For Input As #1
Status.Caption = "正在載入文件"
i = 0
Progress.Value = 0
Progress.Max = 100
Code_all = 0
Do Until EOF(1)
i = i + 1
If Progress.Value < 100 Then Progress.Value = i
Codes = 0
Do Until Codes = ":"
Codes = Input(1, #1) '讀入行起始位
Loop
Verify_Code = 0
Code_Num = Val("&H" + Input(2, #1))
Verify_Code = Verify_Code + Code_Num
If Code_Num = 0 Then Exit Do '本行代碼數
AddrH = Val("&H" + Input(2, #1))
AddrL = Val("&H" + Input(2, #1))
Address(i) = AddrH * 256 + AddrL '起始地址
Verify_Code = Verify_Code + AddrH + AddrL
Codes = Input(2, #1) '去掉“00”
For a = Address(i) To Address(i) + Code_Num - 1
Code(a) = Val("&H" + Input(2, #1))
Verify_Code = Verify_Code + Code(a) '有效代碼
Next a
If Code_all < a - 1 Then Code_all = a - 1
Codes = Val("&H" + Input(2, #1))
Verify_Code = Verify_Code + Codes
If Verify_Code Mod 256 > 0 Then GoTo Failed '校驗位錯誤
Loop
i = 0
Close #1
Status.Caption = CStr(Code_all + 1) + " Bytes" '"文件載入成功!" +
Progress.Value = 0
Busy = False
Exit Sub
Failed:
Close #1
Status.Caption = "格式非法或超出容量!"
Progress.Value = 0
Busy = False
End Sub
Private Sub SaveCode() '保存代碼為 HEX 文件
Busy = True
Cmd1.Filter = "Intel Hex Files|*.hex"
Cmd1.ShowSave
If Cmd1.FileName = "" Then
Busy = False
Exit Sub
End If
Open Cmd1.FileName For Output As #1
For i = 0 To Code_all \ 16
For j = 0 To 15
Codes = CInt(Code(16 * i + j))
If Codes < 255 Then Exit For
If j = 15 Then GoTo NextLine '檢查是否為空行(一行全部為 FF)
Next j
Print #1, ":10"; '行開始以及本行代碼數
Codes = CInt((i * 16) \ 256)
If Codes < 16 Then
Print #1, "0";
End If
Print #1, Hex((i * 16) \ 256); '高位地址
Codes = CInt((i * 16) Mod 256)
If Codes < 16 Then
Print #1, "0";
End If
Print #1, Hex((i * 16) Mod 256); '低位地址
Print #1, "00"; '有效代碼
Verify_Code = 16 + (i * 16) Mod 256 + (i * 16) \ 256 '校驗位初始化
For j = 0 To 15
Codes = CInt(Code(16 * i + j))
If Codes < 16 Then
Print #1, "0";
End If
Print #1, Hex(Code(16 * i + j)); '代碼
Verify_Code = Verify_Code + Code(16 * i + j)
Next j
Verify_Code = 256 - Verify_Code Mod 256
If Verify_Code = 256 Then Verify_Code = 0
If Verify_Code < 16 Then
Print #1, "0";
End If
Print #1, Hex(Verify_Code) '校驗位計算
NextLine:
Next i
Print #1, ":00000001FF" '文件結束
Print #1, ";Created By Bear Programmer V1.0"
Close #1
Busy = False
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -