📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3120
ClientLeft = 60
ClientTop = 420
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3120
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'VB通过串口控制单片机读写24C02源代码下载
Const READIIC As Byte = &H1
Const WRITEIIC As Byte = &H2
Const RESETIIC As Byte = &H0
Option Explicit
Dim Mcom.Portopen As Boolean
Dim buff(0 To 32) As Byte '缓冲区
Dim filebuff(0 To 255) As Byte '发送文件缓冲区
Dim recebuff(0 To 255) As Byte '接收文件缓冲区
Dim mycount As Integer '计数器
Private Sub Form_Load()
If Mcom.Portopen = False Then Mcom.Portopen = True
End Sub
Private Sub Command1_Click()
Me.Enabled = False
mycount = 0
'发送写命令和数据
buff(0) = WRITEIIC
Dim i As Integer
For i = 1 To 32
buff(i) = filebuff(i - 1)
Next i
Mcom.Output = buff
End Sub
Private Sub Command2_Click()
Me.Enabled = False
'发送读命令和数据
mycount = 0
buff(0) = READIIC
Mcom.Output = buff
End Sub
Private Sub Command3_Click()
Dim buff() As Byte
Dim i As Integer
Dim str As String
'打开对话框
CD1.InitDir = "c:\"
CD1.ShowOpen
Text3.Text = CD1.FileName
If Len(Text3.Text) = 0 Then Exit Sub
Command1.Enabled = True
'打开文件
Open Text3.Text For Binary As #1
If LOF(1) = 0 Then End
'--------------------------------
If (LOF(1) > 0) And (LOF(1) < 256) Then
ReDim buff(0 To LOF(1)) As Byte
Get 1, , buff()
For i = 0 To LOF(1) - 1
filebuff(i) = buff(i)
Next i
For i = LOF(1) To 255
filebuff(i) = 0
Next i
Else
Get 1, , filebuff()
End If
For i = 0 To 255
If filebuff(i) > 15 Then
str = str & Hex(filebuff(i)) & "H "
Else
str = str & "0" & Hex(filebuff(i)) & "H "
End If
Next i
Text1.Text = str
Close #1
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Mcom.Portopen = True Then Mcom.Portopen = False
End Sub
Private Sub Mcom_OnComm()
Dim str As String
Dim aa As Variant
Dim i As Integer
'接收数据
If Mcom.CommEvent = 2 Then
aa = Mcom.Input
For i = 1 To 32
recebuff(mycount * 32 + i - 1) = aa(i)
Next i
mycount = mycount + 1
If mycount = 8 Then
mycount = 0
For i = 0 To 255
If recebuff(i) > 15 Then
str = str & Hex(recebuff(i)) & "H "
Else
str = str & "0" & Hex(recebuff(i)) & "H "
End If
Next i
Text2.Text = str
Me.Enabled = True
Else
For i = 1 To 32
buff(i) = filebuff(mycount * 32 + i - 1)
Next i
Mcom.Output = buff
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -