⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converthexfile.bas

📁 VB代码
💻 BAS
字号:
Attribute VB_Name = "ConVertHexFile"
Option Explicit
Const c_HexFileLineID = ":"


Public Function ConvertHexFileContentToDataBuff(ByVal sFileName As String) As Boolean
    Dim iProgramFileNumberID As Integer
    Dim sLineInputBuf As String
    
    Dim ucRecordCount As Byte       '记录数计数器
    'Dim iCurrentAddress As Integer   '起始地址
    Dim lCurrentAddress As Long
    Dim ucDataType As Byte          '数据类型
    
    Dim ucCurrentData As Byte
    Dim ucCount As Byte

    iProgramFileNumberID = FreeFile()
    Open sFileName For Input As iProgramFileNumberID
    
      '初始化缓冲区
    Dim lCount As Long
    For lCount = 0 To lMaxCodeLength - 1 Step 1
        ucDataBuff(lCount) = &HFF
    Next lCount
  
    
    Do Until (EOF(iProgramFileNumberID))
        
        Line Input #iProgramFileNumberID, sLineInputBuf
        If (Left$(sLineInputBuf, 1) = c_HexFileLineID) Then
            'MsgBox ("Intel Hex 文件格式有误")
            
            'Start CRC Check
            '
            'Start Convert Data
            ucRecordCount = Val("&H" & Mid$(sLineInputBuf, 2, 2))
           ' lCurrentAddress = Val("&h" & Mid$(sLineInputBuf, 4, 4))
           ' If (lCurrentAddress < 0) Then
           '     lCurrentAddress = -lCurrentAddress + 32768
            
           ' End If
            
            lCurrentAddress = (Val("&H" & Mid$(sLineInputBuf, 4, 2))) * (&H100) + Val("&H" & Mid$(sLineInputBuf, 6, 2))
            ucDataType = Val("&H" & Mid$(sLineInputBuf, 8, 2))
            
            If (ucRecordCount = 0) Then
                Close #iProgramFileNumberID
                FrmMain.LblOperationInfoDisp.Caption = "完成转换HEX文件的操作"
                GoTo ExitLabel
            End If
            
            
            If (lCurrentAddress > lMaxCodeLength) Then
                MsgBox ("数据地址大于器件的最大地址范围,请检查HEX文件")
                GoTo ExitLabel
            End If
          
            
            '用HEX文件内容填充缓冲区
            For ucCount = 0 To (ucRecordCount - 1) Step 1
                ucCurrentData = Val("&H" & Mid$(sLineInputBuf, (10 + (ucCount * 2)), 2))
                ucDataBuff(lCurrentAddress) = ucCurrentData
                
                lCurrentAddress = lCurrentAddress + 1
                
                If (lCurrentAddress > lMaxCodeLength) Then
                    MsgBox ("数据地址大于器件的最大地址范围,请检查HEX文件")
                    GoTo ExitLabel
                End If
                
            Next ucCount
    
        End If
    Loop
    
ExitLabel:
    ConvertHexFileContentToDataBuff = True
      
End Function




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -