在项目开发过程中,有时候软件编译生成的HEX文件会比较大,这样的话就得考虑存储空间比较大的控制器,那样会增加成本,BIN文件相比HEX文件来说会小很多,所以有这样一个转化软件还是很不错的,呵呵。
给大家发一个HEX文件转BIN文件的软件,希望对大家有用
同时附上源码,有兴趣的朋友可以自己写来试试。
在此感谢软件的原创者yy945提供源码,由于是在论坛找到的,也没法知道作者真名,所以得更加感谢,呵呵。
源码如下:
Private Sub CmdChange_Click()
Dim temp As String
Dim Path As String
Dim DatAddress As Integer
Dim DatNum As Integer
Dim i As Integer
Dim Buf As String
Dim HexBuf As Byte
Path = Text1.Text
If Path = "" Then
MsgBox "请选择源文件路径!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If
Path = Text2.Text
If Path = "" Then
MsgBox "请选择目标文件存储路径!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If
If Dir(Path) <> "" Then
Kill "down.bin"
End If
Open Text1.Text For Input As #1
Open Path For Binary As #2
Do
Line Input #1, temp
DatNum = CLng("&h" & Mid(temp, 2, 2))
DatAddress = CLng("&h" & Mid(temp, 4, 4)) + 1
For i = 10 To Len(temp) - 2 Step 2
Buf = Mid(temp, i, 2)
HexBuf = CLng("&h" & Buf)
Put #2, DatAddress, HexBuf
DatAddress = DatAddress + 1
Next
Loop Until EOF(1)
Close #1
Close #2
MsgBox "转换完成!", vbInformation + vbOKOnly, "提示"
End Sub
用户1128144 2012-12-25 13:10