www.pudn.com > HEX2BIN_VB.zip > binTohex.frm


VERSION 5.00 
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" 
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" 
Begin VB.Form frmbinTohex  
   Caption         =   "HEX2BIN" 
   ClientHeight    =   2520 
   ClientLeft      =   3345 
   ClientTop       =   3735 
   ClientWidth     =   8160 
   FillColor       =   &H00FFFFFF& 
   BeginProperty Font  
      Name            =   "Fixedsys" 
      Size            =   12 
      Charset         =   129 
      Weight          =   400 
      Underline       =   0   'False 
      Italic          =   0   'False 
      Strikethrough   =   0   'False 
   EndProperty 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   168 
   ScaleMode       =   3  'Çȼ¿ 
   ScaleWidth      =   544 
   Begin VB.CommandButton Command3  
      Caption         =   "image HEX => Intel HEX" 
      Height          =   555 
      Left            =   2280 
      TabIndex        =   1 
      Top             =   1200 
      Width           =   3255 
   End 
   Begin MSComctlLib.StatusBar sbrStatus  
      Align           =   2  '¾Æ·¡ ¸ÂÃã 
      Height          =   30 
      Left            =   0 
      TabIndex        =   0 
      Top             =   2490 
      Width           =   8160 
      _ExtentX        =   14393 
      _ExtentY        =   53 
      _Version        =   393216 
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}  
         NumPanels       =   3 
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}  
            Object.Width           =   4586 
            MinWidth        =   4586 
            Key             =   "Status" 
         EndProperty 
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}  
            Style           =   6 
            AutoSize        =   2 
            TextSave        =   "2007-01-10" 
         EndProperty 
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628}  
            Style           =   5 
            AutoSize        =   2 
            TextSave        =   "¿ÀÀü 10:53" 
         EndProperty 
      EndProperty 
   End 
   Begin MSComDlg.CommonDialog cdFile  
      Left            =   600 
      Top             =   7320 
      _ExtentX        =   847 
      _ExtentY        =   847 
      _Version        =   393216 
   End 
   Begin VB.Label Label1  
      Caption         =   "CCS¿¡¼­ »ý¼ºµÈ *.outÆÄÀÏÀ» bootloaderÇü½ÄÀ¸·Î º¯È¯½ÃŲÈÄ »ý¼ºµÈ *.HEXÆÄÀÏÀ» *.BINÀ¸·Î º¯È¯ ½ÃÅ´" 
      ForeColor       =   &H8000000D& 
      Height          =   615 
      Left            =   960 
      TabIndex        =   2 
      Top             =   360 
      Width           =   7095 
   End 
End 
Attribute VB_Name = "frmbinTohex" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
 
 
 
 
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 
 
 
Private Function return_HEX(x As Single, c() As Byte) 
    CopyMemory c(0), ByVal VarPtr(x), 1 
    CopyMemory c(1), ByVal VarPtr(x) + 1, 1 
    CopyMemory c(2), ByVal VarPtr(x) + 2, 1 
    CopyMemory c(3), ByVal VarPtr(x) + 3, 1 
     
End Function 
 
 
Private Function return_HEX_integer(x As Long, c() As Byte) 
    CopyMemory c(0), ByVal VarPtr(x), 1 
    CopyMemory c(1), ByVal VarPtr(x) + 1, 1 
    CopyMemory c(2), ByVal VarPtr(x) + 2, 1 
    CopyMemory c(3), ByVal VarPtr(x) + 3, 1 
     
End Function 
 
' 
'Private Function write_float_to_file(add As Integer, iFileNum0 As Long, x As Single, y As Single) As Byte 
'       Dim c(4) As Byte 
'       Dim i, n As Integer 
'       Dim recode_type As Integer 
'       Dim j, k As Byte 
'       Dim s As Byte 
'       n = 8 '8byte 
'       i = 0 
'       recode_type = 0 
'       'add = add * 4 
' 
'       Do 
'        If add < 65536 Then GoTo exit_End_222 
'        add = add - 65536 
'       Loop 
'exit_End_222: 
' 
' 
' 
' 
'       Print #iFileNum0, ":"; 
'       Print #iFileNum0, Right("00" & Hex$(n), 2); 'n byte 
' 
' 
' 
' 
'       Call return_HEX_integer(add, c) 
'       j = c(1) 
'       k = c(0) 
' 
'       Print #iFileNum0, Right("00" & Hex$(j), 2); 'address high 
'       Print #iFileNum0, Right("00" & Hex$(k), 2); 'address low 
'       Print #iFileNum0, "00";                     'data type 
' 
' 
'       Call return_HEX(x, c) 
'       Print #iFileNum0, Right("00" & Hex$(c(3)), 2); 'data0 
'       Print #iFileNum0, Right("00" & Hex$(c(2)), 2); 'data1 
'       Print #iFileNum0, Right("00" & Hex$(c(1)), 2); 'data2 
'       Print #iFileNum0, Right("00" & Hex$(c(0)), 2); 'data3 
' 
'       i = 8 + j + k + c(0) + c(1) + c(2) + c(3) 
' 
' 
'       Call return_HEX(y, c) 
'       Print #iFileNum0, Right("00" & Hex$(c(3)), 2); 'data0 
'       Print #iFileNum0, Right("00" & Hex$(c(2)), 2); 'data1 
'       Print #iFileNum0, Right("00" & Hex$(c(1)), 2); 'data2 
'       Print #iFileNum0, Right("00" & Hex$(c(0)), 2); 'data3 
' 
'       i = i + c(0) + c(1) + c(2) + c(3) 
' 
' 
'       Do 
'        If i < 256 Then GoTo exit_End_000 
'        i = i - 256 
'       Loop 
' 
'exit_End_000: 
' 
'       If i > 255 Then i = 255 
'       s = i 
'       s = s And 255 
'       s = Not s 
'       If s = 255 Then 
'            s = 0 
'       Else 
'         s = s + 1 
'        End If 
'       write_float_to_file = s 
'       Print #iFileNum0, Right("00" & Hex$(s), 2); vbCrLf; 'check sum 
'End Function 
 
'Private Function write_byte_to_hex_file(add As Integer, iFileNum0 As Long, x1 As Integer) As Byte 
' 
'       Dim i, n As Integer 
'       Dim recode_type As Integer 
'       Dim j, k As Byte 
'       Dim s As Byte 
'       Dim c(4) As Byte 
'       n = 1 '8byte 
'       i = 0 
'       recode_type = 0 
'       'add = add * 4 
' 
'       Do 
'        If add < 65536 Then GoTo exit_End_222 
'        add = add - 65536 
'       Loop 
'exit_End_222: 
' 
' 
' 
' 
'       Print #iFileNum0, ":"; 
'       Print #iFileNum0, Right("00" & Hex$(n), 2); 'n byte 
' 
' 
'       Call return_HEX_integer(add, c) 
'       j = c(1) 
'       k = c(0) 
' 
'       Print #iFileNum0, Right("00" & Hex$(j), 2); 'address high 
'       Print #iFileNum0, Right("00" & Hex$(k), 2); 'address low 
'       Print #iFileNum0, "00";                     'data type 
'       If add = 511 Then 
'        add = add 
'    End If 
'       If x1 = 128 Then x1 = 127 
'       If x1 < 0 Then 
'            x1 = 256 + x1 
'        End If 
' 
'       Print #iFileNum0, Right("00" & Hex$(x1), 2); 'data0 
' 
'       i = 1 + j + k + x1 
' 
' 
'       Do 
'        If i < 256 Then GoTo exit_End_000 
'        i = i - 256 
'       Loop 
' 
'exit_End_000: 
' 
'       If i > 255 Then i = 255 
'       s = i 
'       s = s And 255 
'       s = Not s 
'       If s = 255 Then 
'            s = 0 
'       Else 
'         s = s + 1 
'        End If 
'       write_byte_to_hex_file = s 
'       Print #iFileNum0, Right("00" & Hex$(s), 2); vbCrLf; 'check sum 
'End Function 
 
 
 
Private Sub Command3_Click() 
    Dim i As Integer 
    Dim iFilenumW As Long 
    Dim iFileNumR As Long 
    Dim x1 As Integer 
    Dim ifileNameW As String 
    Dim ifileNameR As String 
    Dim s As String 
    Dim inData(3) As Byte 
    Dim addr As Long 
    Dim datah As Byte 
    Dim datal As Byte 
    iFileNumR = FreeFile 
 
    cdFile.Filter = "HEX file(*.HEX)|*.hex| All files(*.*) |*.*" 
    cdFile.ShowOpen 
    ifileNameR = cdFile.FileName 
    Open ifileNameR For Binary As iFileNumR 
     
     
     
     
    iFilenumW = FreeFile 
 
    i = InStr(1, ifileNameR, ".", 1) 
    ifileNameW = Mid(FileName, 1, i) 
     
    ifileNameW = ifileNameR & "bin" 
 
 
    'cdFile.Filter = "HEX file(*.HEX)|*.hex| All files(*.*) |*.*" 
    'cdFile.ShowOpen 
    'ifileNameW = cdFile.fileName 
    Open ifileNameW For Binary As iFilenumW 
     
     
     
     
    Do While Not EOF(iFileNumR) 
        Get iFileNumR, , inData(0) 
        If (inData(0) > &H29) Then 
            datah = inData(0) - &H30 
            If (inData(0) > &H40) Then 
                datah = datah - 7 
            End If 
             
            Get iFileNumR, , inData(0) 
            datal = inData(0) - &H30 
            If (inData(0) > &H40) Then 
                datal = datal - 7 
            End If 
            datah = datah * 16 + datal 
                      
             
            Put iFilenumW, , datah 
        End If 
    Loop 
 
    Close iFilenumW 
    Close iFileNumR 
 End Sub 
 
Private Sub Form_Load() 
Command3_Click 
End Sub