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

📄 module1.bas

📁 CH372调试程序,软件代码及编译好的执行程序
💻 BAS
📖 第 1 页 / 共 2 页
字号:
End Function

Public Function CH375DBG_WriteIRAM(StartAddr As Long, Buffer() As Byte, Count As Byte) As Boolean       '向内部RAM写入数据块
' 输入参数: StartAddr 指定内部RAM的起始地址
'           buffer 指向一个数据缓冲区'存放准备写入的数据块
'           count 指定写入的字节数
' 向内部RAM写入数据块
' 输入参数: StartAddr 指定内部RAM的起始地址
'           buffer 指向一个数据缓冲区,存放准备写入的数据块
'           count 指定写入的字节数
Dim Down As USB_DOWN_PKT
Dim Up  As USB_UP_PKT
Dim Leng As Long
    CH375DBG_WriteIRAM = False
    If (Count > MAX_DATA_SIZE) Then
        CH375DBG_WriteIRAM = False        ' 限制单次处理的数据长度,可以与单片机程序的MAX_DATA_SIZE一起同步修改为更大或更小的值
        Exit Function
    End If
    Down.mCommand = WriteIRamCmdCode
    Down.mCommandNot = Not (Down.mCommand)
    Down.mByte(0) = CByte(StartAddr)
    For i = 1 To 3
      Down.mByte(i) = 0
    Next i
    Down.mLength = Count
    For i = 0 To (Count - 1)
        Down.mBuffer(i) = Buffer(i)
    Next i
    Leng = CONST_CMD_LEN + Down.mLength

    If (CH375Writedata(CH375DBG_Index, Down, Leng)) Then      ' 写出命令块
        Leng = Len(Up)
        If (CH375ReadData(CH375DBG_Index, Up, Leng)) Then
           ' 读取应答块
            If ((Up.mStatus = ERR_SUCCESS) And (Up.mCommandNot = Down.mCommandNot)) Then
              ' 操作成功
                CH375DBG_WriteIRAM = True
            End If
        End If
    End If
End Function

Public Function CH375DBG_ReadXRAM(StartAddr As Long, Buffer() As Byte, Count As Byte) As Boolean         '从外部RAM读取数据块
' 输入参数: StartAddr 指定外部RAM的起始地址
'           buffer 指向一个足够大的数据缓冲区'用于存放读出的数据块
'           count 指定读取的字节数
' 从外部RAM读取数据块
' 输入参数: StartAddr 指定外部RAM的起始地址
'           buffer 指向一个足够大的数据缓冲区,用于存放读出的数据块
'           count 指定读取的字节数
Dim Down As USB_DOWN_PKT
Dim Up  As USB_UP_PKT
Dim Leng As Long
    CH375DBG_ReadXRAM = False
    If (Count > MAX_DATA_SIZE) Then
        CH375DBG_ReadXRAM = False    ' 限制单次处理的数据长度,可以与单片机程序的MAX_DATA_SIZE一起同步修改为更大或更小的值
        Exit Function
    End If
    Down.mCommand = ReadXRamCmdCode
    Down.mCommandNot = Not (Down.mCommand)
    Down.mByte(0) = CByte(StartAddr Mod 256)
    Down.mByte(1) = CByte(StartAddr \ 256)
    Down.mByte(2) = 0
    Down.mByte(3) = 0
    Down.mLength = Count
    Leng = CONST_CMD_LEN
    If (CH375Writedata(CH375DBG_Index, Down, Leng)) Then
       ' 写出命令块
        Leng = Len(Up)
        If (CH375ReadData(CH375DBG_Index, Up, Leng)) Then
            ' 读取应答块
            If ((Up.mStatus = ERR_SUCCESS) And (Up.mCommandNot = Down.mCommandNot) And (Up.mLength >= Count)) Then
              ' 操作成功,并且返回数据
                For i = 0 To (Up.mLength - 1)
                    Buffer(i) = Up.mBuffer(i)  ' 返回数据
                Next i
                CH375DBG_ReadXRAM = True
               
            End If
        End If
    End If
End Function

Public Function CH375DBG_WriteXRAM(StartAddr As Long, Buffer() As Byte, Count As Byte) As Boolean           '向外部RAM写入数据块
' 输入参数: StartAddr 指定外部RAM的起始地址
'           buffer 指向一个数据缓冲区'存放准备写入的数据块
'           count 指定写入的字节数
 ' 向外部RAM写入数据块
' 输入参数: StartAddr 指定外部RAM的起始地址
'           buffer 指向一个数据缓冲区,存放准备写入的数据块
'           count 指定写入的字节数
Dim Down As USB_DOWN_PKT
Dim Up  As USB_UP_PKT
Dim Leng As Long
    CH375DBG_WriteXRAM = False
    If (Count > MAX_DATA_SIZE) Then
        CH375DBG_WriteXRAM = False    ' 限制单次处理的数据长度,可以与单片机程序的MAX_DATA_SIZE一起同步修改为更大或更小的值
        Exit Function
    End If
    Down.mCommand = WriteXRamCmdCode
    Down.mCommandNot = Not (Down.mCommand)
    Down.mByte(0) = CByte(StartAddr Mod 256)
    Down.mByte(1) = CByte(StartAddr \ 256)
    Down.mByte(2) = 0
    Down.mByte(3) = 0
    Down.mLength = Count
    For i = 0 To (Count - 1)
       Down.mBuffer(i) = Buffer(i)
    Next i
    Leng = CONST_CMD_LEN + Down.mLength
    If (CH375Writedata(CH375DBG_Index, Down, Leng)) Then
        ' 写出命令块
        Leng = Len(Up)
        If (CH375ReadData(CH375DBG_Index, Up, Leng)) Then
            ' 读取应答块
            If ((Up.mStatus = ERR_SUCCESS) And (Up.mCommandNot = Down.mCommandNot)) Then
              ' 操作成功
                CH375DBG_WriteXRAM = True
            End If
        End If
    End If
End Function

Public Function CH375DBG_ReadROM(StartAddr As Long, Buffer() As Byte, Count As Byte) As Boolean      '从程序ROM读取数据块
' 输入参数: StartAddr 指定程序ROM的起始地址
'           buffer 指向一个足够大的数据缓冲区'用于存放读出的数据块
'           count 指定读取的字节数
 ' 从程序ROM读取数据块
' 输入参数: StartAddr 指定程序ROM的起始地址
'           buffer 指向一个足够大的数据缓冲区,用于存放读出的数据块
'           count 指定读取的字节数
Dim Down As USB_DOWN_PKT
Dim Up  As USB_UP_PKT
Dim Leng As Long
    CH375DBG_ReadROM = False
    If (Count > MAX_DATA_SIZE) Then     ' 限制单次处理的数据长度,可以与单片机程序的MAX_DATA_SIZE一起同步修改为更大或更小的值
      CH375DBG_ReadROM = False
      Exit Function
    End If
    Down.mCommand = ReadRomCmdCode
    Down.mCommandNot = Not Down.mCommand
    Down.mByte(0) = CByte(StartAddr Mod 256)
    Down.mByte(1) = CByte(StartAddr \ 256)
    Down.mByte(2) = 0
    Down.mByte(3) = 0
    Down.mLength = Count
    Leng = CONST_CMD_LEN
    If (CH375Writedata(CH375DBG_Index, Down, Leng)) Then
       ' 写出命令块
        Leng = Len(Up)
        If (CH375ReadData(CH375DBG_Index, Up, Leng)) Then
           ' 读取应答块
            If ((Up.mStatus = ERR_SUCCESS) And (Up.mCommandNot = Down.mCommandNot) And (Up.mLength >= Count)) Then
              ' 操作成功,并且返回数据
                For i = 0 To (Count - 1)
                   Buffer(i) = Up.mBuffer(i)  ' 返回数据
                Next i
                CH375DBG_ReadROM = True
            End If
        End If
    End If
End Function

Function hextobcd(str As String) As Byte                 '将文本框中输入的十六进制值转换成BCD码
Dim Length As Integer
Dim x As String
Length = Len(str)
For i = 0 To Length - 1
x = Mid(str, Length - i, 1)
Select Case x
       Case "a", "A"
         hextobcd = hextobcd + 10 * (16 ^ i)
       Case "b", "B"
         hextobcd = hextobcd + 11 * (16 ^ i)
       Case "c", "C"
         hextobcd = hextobcd + 12 * (16 ^ i)
       Case "d", "D"
         hextobcd = hextobcd + 13 * (16 ^ i)
       Case "e", "E"
         hextobcd = hextobcd + 14 * (16 ^ i)
       Case "f", "F"
         hextobcd = hextobcd + 15 * (16 ^ i)
       Case "0" To "9"
         hextobcd = hextobcd + val(x) * 16 ^ i
       Case Else
       'MsgBox "非十六进制数", vbCritical, "信息提示"
       hextobcd = 0
End Select
Next i
End Function

Function hex2bit(var As Byte) As String
If var < 16 Then
   hex2bit = "0" & Hex(var)
 Else
   hex2bit = Hex(var)
End If
End Function

Public Function HexKeyAscii(KeyAscii As Integer) '屏蔽非十六进制位键值
  If KeyAscii > 96 And KeyAscii < 123 Then
     KeyAscii = KeyAscii - 32  '字母小写转成大写
  End If
  If KeyAscii > 70 And KeyAscii < 91 Or (KeyAscii >= 0 And KeyAscii <= 7) Or (KeyAscii >= 11 And KeyAscii <= 12) _
      Or (KeyAscii >= 14 And KeyAscii <= 47) Or (KeyAscii >= 58 And KeyAscii <= 64) Or (KeyAscii >= 91 And KeyAscii <= 96) _
     Or (KeyAscii >= 123 And KeyAscii <= 127) Then   '非有效进制值为0
     KeyAscii = 48
  End If
  HexKeyAscii = KeyAscii
End Function

Public Function SFR_ADDR(x As String) As Byte                   'SFR地址函数:根据TEXT3的内容返回其值
Select Case x
Case "P0"
SFR_ADDR = &H80
Case "SP"
SFR_ADDR = &H81
Case "DPL"
SFR_ADDR = &H82
Case "DPH"
SFR_ADDR = &H83
Case "PCON"
SFR_ADDR = &H87
Case "TCON"
SFR_ADDR = &H88
Case "TMOD"
SFR_ADDR = &H89
Case "TL0"
SFR_ADDR = &H8A
Case "TL1"
SFR_ADDR = &H8B
Case "TH0"
SFR_ADDR = &H8C
Case "TH1"
SFR_ADDR = &H8D
Case "P1"
SFR_ADDR = &H90
Case "SCON"
SFR_ADDR = &H98
Case "SBUF"
SFR_ADDR = &H99
Case "P2"
SFR_ADDR = &HA0
Case "IE"
SFR_ADDR = &HA8
Case "P3"
SFR_ADDR = &HB0
Case "IP"
SFR_ADDR = &HB8
Case "T2CON"
SFR_ADDR = &HC8
Case "PSW"
SFR_ADDR = &HD0
Case "ACC"
SFR_ADDR = &HE0
Case "B"
SFR_ADDR = &HF0
Case "TL2"
SFR_ADDR = &HCC
Case "TH2"
SFR_ADDR = &HCD
Case Else
SFR_ADDR = 0
End Select
End Function


⌨️ 快捷键说明

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