📄 comprotocol.bas
字号:
Attribute VB_Name = "ComProtocol"
Option Explicit
Public Const c_LockType_unLock = 0
Public Const c_LockType_LockLevel1 = 1
Public Const c_LockType_LockLevel2 = 2
Public Const c_LockType_LockLevel3 = 3
Public ucCurrentLockLevel As Byte '加密等级
Const c_PackDataLength = 16
'Const c_PackDataLength = 64
Const c_OKPack_HeadByte1 = &H4F
Const c_OKPack_HeadByte2 = &H4B
Const c_ERRPack_HeadByte1 = &H45
Const c_ERRPack_HeadByte2 = &H52
Public Const c_MaxProgramDeviceNumber = 1 '最大编程器件的数量
Public ucDataBuff(0 To &H100000) As Byte '编程内容的缓冲区
Public lMaxCodeLength As Long
Public Type PgmDeviceCharacteristic
DeviceCompleteIDNumber As Long '器件所在顺序号 主索引
DeviceGroup As Byte '按器件类型分成大类
DeviceManufacturerID As Byte '按厂商分类
DeviceManufacturerName As String '厂商名称
DeviceSeriesNumber As Integer '在同一制造厂内某类器件分类后的顺序号
DeviceMaxCodeLength As Long
DeviceNameString As String '器件名称
DeviceSignature As String
DeviceConvertBoardFlag As Boolean '是否需转接适配器的标志。
End Type
Public Type PGMSysInformation
PGMSysInfo_FileName As String '编程文件名
PGMSysInfo_DispFileName As String '编程文件名的显示版本
PGMSysInfo_DeviceGroupName As String
PGMSysInfo_ManufacturerName As String
PGMSysInfo_DeviceNameString As String
PGMSysInfo_DeviceSignature As String
PGMSysInfo_CommPortNumber As Byte '通讯端口号
PGMSysInfo_ConvertBoardFlag As Boolean '是否需转接适配器的标志位
End Type
Public Type PGMAutoExecOption
bReadDeviceSignature As Boolean
bEraseChip As Boolean
bCheckBank As Boolean
bProgramCode As Boolean
bVerify As Boolean
bLockBits As Boolean
End Type
Public UserDefineAutoExecOption As PGMAutoExecOption
Public Current_PGMSysInformation As PGMSysInformation '当前编程环境信息结构体
Public PGMDeviceLib(c_MaxProgramDeviceNumber - 1) As PgmDeviceCharacteristic
Public iCurrentDeviceID As Integer
Public ucCurrentDeviceGroup As Byte '当前设备所在的类别 eprom cpu pld..
Public ucCurrentDeviceManufacturer As Byte '当前设备的制造厂商 如ST Atmel.Winbond
Public ucCurrentDeviceSeriesNumber As Integer '当前设备的顺序流水号
Public ucCurrentDeviceIDEnCode As Byte '通讯过程中对当前设备进行身份识别压缩编码
'以下定义接收与发送数据的串行缓冲区
Public ucReceiveDataBuff(c_PackDataLength + 20) As Byte
Public sComReceiveDataBuff As String '接收数据缓冲区
Public ucReceiveDataLength As Byte
Public ucComSendDataBuff(c_PackDataLength + 20)
Public sComSendDataBuff As String '发送数据缓冲区
Public ucComSendDataLength As Byte
'用于标识宿主机是否下发读取设备特征字命令
'当选取了新的编程器件时,此标志复位
'执行完读设备特征字命令后置位,
'保护编程芯片免遭选错器件而误伤。
Public bReadDeviceSignatureFlag As Boolean
Public bSendCmd_SelectProgramDeviceIDNuberFlag As Boolean
'设备大类
Public Const c_DeviceGroup_MCU = 0
Public Const c_DeviceGroup_MEM = 1
Public Const c_DeviceGroup_PLD = 2
'设备制造商分类
Public Const c_DeviceManufacturerID_Atmel = 0
Public Const c_DeviceManufacturerID_Winbond = 1
Public Const c_DeviceManufacturerID_ST = 2
Public Const c_DeviceManufacturerID_AMD = 3
Public Const c_DeviceManufacturerID_NS = 4
Public Const c_DeviceManufacturerID_Philips = 5
'设备序列号
Const c_DeviceSeriesNumber_AT89C2051 = 0
Const c_DeviceSeriesNumber_AT89S51 = 1
Const c_DeviceSeriesNumber_AT89C52 = 2
Const c_DeviceSeriesNumber_AT89C55WD = 3
Const c_DeviceSeriesNumber_AT89C51 = 4
Const c_DeviceSeriesNumber_AT89S52 = 5
Const c_DeviceSeriesNumber_AT89C4051 = 6
Const c_DeviceSeriesNumber_W78E52B = 0
Const c_DeviceSeriesNumber_AT29C256 = 0
Const c_DeviceSeriesNumber_AT28C256 = 1
Const c_DeviceSeriesNumber_AT28C64 = 1
Const c_DeviceSeriesNumber_AT24C02 = 128
Const c_DeviceSeriesNumber_AT93C46 = &HC0
Const c_DeviceSeriesNumber_ST27C256 = 0
Const c_DeviceSeriesNumber_ST27C512 = 1
Const c_DeviceSeriesNumber_ST27C128B = 2
Const c_DeviceSeriesNumber_ST27C4001 = 3
Const c_DeviceSeriesNumber_AM29F040B = 0
Const c_DeviceSeriesNumber_AM28F256 = 1
Const c_DeviceSeriesNumber_AM28F020 = 2
Const c_DeviceSeriesNumber_NMC27C64Q = 0
Const c_DeviceSeriesNumber_W27E512 = 0
Const c_DeviceSeriesNumber_W29C020 = 1
Const c_DeviceSeriesNumber_W29C040 = 2
Const c_DeviceSeriesNumber_P89C61X2 = 0
'设备顺序流水号,主索引,不允许重复。Host 使用
Public Const c_DeviceCompleteIDNumber_AT89C2051 = 0
Public Const c_DeviceCompleteIDNumber_AT29C256 = 1
Public Const c_DeviceCompleteIDNumber_AT28C256 = 2
Public Const c_DeviceCompleteIDNumber_AT28C64 = 3
Public Const c_DeviceCompleteIDNumber_ST27C256 = 4
Public Const c_DeviceCompleteIDNumber_ST27C512 = 5
Public Const c_DeviceCompleteIDNumber_ST27C128 = 6
Public Const c_DeviceCompleteIDNumber_ST27C040 = 7
Public Const c_DeviceCompleteIDNumber_AM29F040B = 8
Public Const c_DeviceCompleteIDNumber_AT89C52 = 9
Public Const c_DeviceCompleteIDNumber_W29C020 = 10
Public Const c_DeviceCompleteIDNumber_AT24C02 = 11
Public Const c_DeviceCompleteIDNumber_AT93C46 = 12
Public Const c_DeviceCompleteIDNumber_AT89S51 = 13
Public Const c_DeviceCompleteIDNumber_AT89C55WD = 14
Public Const c_DeviceCompleteIDNumber_W78E52B = 15
Public Const c_DeviceCompleteIDNumber_AT89C51 = 16
Public Const c_DeviceCompleteIDNumber_AT89S52 = 17
Public Const c_DeviceCompleteIDNumber_AT89C4051 = 18
Public Const c_DeviceCompleteIDNumber_NMC27C64Q = 19
Public Const c_DeviceCompleteIDNumber_AM28F256 = 20
Public Const c_DeviceCompleteIDNumber_AM28F020 = 21
Public Const c_DeviceCompleteIDNumber_W27E512 = 22
Public Const c_DeviceCompleteIDNumber_W29C040 = 23
Public Const c_DeviceCompleteIDNumber_P89C61X2 = 24
'设备特征字
Const c_DeviceSignature_AT89C2051 = "1E 21 FF"
Const c_DeviceSignature_AT89S51 = "1E 51 06"
Const c_DeviceSignature_AT89C52 = "1E 52 FF"
Const c_DeviceSignature_AT89C55WD = "1E 55 06"
Const c_DeviceSignature_AT89C51 = "1E 51 FF"
Const c_DeviceSignature_AT89S52 = "1E 52 06"
Const c_DeviceSignature_AT89C4051 = "1E 41 FF"
Const c_DeviceSignature_W78E52B = "78 0E 58"
Const c_DeviceSignature_AT29C256 = "1F DC 88"
Const c_DeviceSignature_AT28C256 = "28 C2 56"
Const c_DeviceSignature_AT28C64 = "28 C2 56"
Const c_DeviceSignature_AT24C02 = "24 C0 02"
Const c_DeviceSignature_AT93C46 = "93 C0 46"
Const c_DeviceSignature_ST27C256 = "20 8D 99"
Const c_DeviceSignature_ST27C512 = "20 8D 9A"
Const c_DeviceSignature_ST27C128B = "20 0A 9B"
Const c_DeviceSignature_ST27C4001 = "20 41 9C"
Const c_DeviceSignature_AM29F040B = "01 A4 00"
Const c_DeviceSignature_AM28F256 = "0A A1 00"
Const c_DeviceSignature_AT28F020 = "01 2A 00"
Const c_DeviceSignature_NMC27C64Q = "8F C2 9B"
Const c_DeviceSignature_W27E512 = "DA 08 A0"
Const c_DeviceSignature_W29C020 = "DA 45 00"
Const c_DeviceSignature_W29C040 = "DA 46 00"
'Const c_DeviceSignature_P89C61X2 = "15 C2 F0"
Const c_DeviceSignature_P89C61X2 = "15 C2 82"
'初始化编程器件库
Sub InitProgramDeviceLib()
'Dim lCount As Long
'For lCount = 0 To c_MaxProgramDeviceNumber - 1 Step 1
'Next lCount
'P89c61x2
PGMDeviceLib(0).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_P89C61X2
PGMDeviceLib(0).DeviceGroup = c_DeviceGroup_MCU
PGMDeviceLib(0).DeviceManufacturerID = c_DeviceManufacturerID_Philips
PGMDeviceLib(0).DeviceManufacturerName = "Philips"
PGMDeviceLib(0).DeviceMaxCodeLength = 65536
PGMDeviceLib(0).DeviceNameString = "P89C61X2"
'PGMDeviceLib(0).DeviceSeriesNumber = 0
'PGMDeviceLib(0).DeviceSignature = "1E 21 FF"
PGMDeviceLib(0).DeviceSeriesNumber = c_DeviceSeriesNumber_P89C61X2
PGMDeviceLib(0).DeviceSignature = c_DeviceSignature_P89C61X2
'AT89c2051
' PGMDeviceLib(0).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_AT89C2051
' PGMDeviceLib(0).DeviceGroup = c_DeviceGroup_MCU
' PGMDeviceLib(0).DeviceManufacturerID = c_DeviceManufacturerID_Atmel
' PGMDeviceLib(0).DeviceManufacturerName = "Atmel"
' PGMDeviceLib(0).DeviceMaxCodeLength = &H800
' PGMDeviceLib(0).DeviceNameString = "AT89C2051"
'PGMDeviceLib(0).DeviceSeriesNumber = 0
'PGMDeviceLib(0).DeviceSignature = "1E 21 FF"
' PGMDeviceLib(0).DeviceSeriesNumber = c_DeviceSeriesNumber_AT89C2051
' PGMDeviceLib(0).DeviceSignature = c_DeviceSignature_AT89C2051
'AT29C256
' PGMDeviceLib(1).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_AT29C256
' PGMDeviceLib(1).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(1).DeviceManufacturerID = c_DeviceManufacturerID_Atmel
' PGMDeviceLib(1).DeviceManufacturerName = "Atmel"
' PGMDeviceLib(1).DeviceMaxCodeLength = 32768 'use &h8000 Err why ???
' PGMDeviceLib(1).DeviceNameString = "AT29C256"
' PGMDeviceLib(1).DeviceSeriesNumber = 0
' PGMDeviceLib(1).DeviceSignature = "1F DC 88"
' PGMDeviceLib(1).DeviceSeriesNumber = c_DeviceSeriesNumber_AT29C256
' PGMDeviceLib(1).DeviceSignature = c_DeviceSignature_AT29C256
'AT28C256
' PGMDeviceLib(2).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_AT28C256
' PGMDeviceLib(2).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(2).DeviceManufacturerID = c_DeviceManufacturerID_Atmel
' PGMDeviceLib(2).DeviceManufacturerName = "Atmel"
' PGMDeviceLib(2).DeviceMaxCodeLength = 32768
' PGMDeviceLib(2).DeviceNameString = "AT28C256"
'PGMDeviceLib(2).DeviceSeriesNumber = 1
'PGMDeviceLib(2).DeviceSignature = "28 C2 56"
' PGMDeviceLib(2).DeviceSeriesNumber = c_DeviceSeriesNumber_AT28C256
' PGMDeviceLib(2).DeviceSignature = c_DeviceSignature_AT28C256
'AT28C64
' PGMDeviceLib(3).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_AT28C64
' PGMDeviceLib(3).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(3).DeviceManufacturerID = c_DeviceManufacturerID_Atmel
' PGMDeviceLib(3).DeviceManufacturerName = "Atmel"
' PGMDeviceLib(3).DeviceMaxCodeLength = 8192
' PGMDeviceLib(3).DeviceNameString = "AT28C64"
' PGMDeviceLib(3).DeviceSeriesNumber = 1
' PGMDeviceLib(3).DeviceSignature = "28 C2 56"
' PGMDeviceLib(3).DeviceSeriesNumber = c_DeviceSeriesNumber_AT28C64
' PGMDeviceLib(3).DeviceSignature = c_DeviceSignature_AT28C64
'ST27C256
' PGMDeviceLib(4).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_ST27C256
' PGMDeviceLib(4).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(4).DeviceManufacturerID = c_DeviceManufacturerID_ST
' PGMDeviceLib(4).DeviceManufacturerName = "ST"
' PGMDeviceLib(4).DeviceMaxCodeLength = 32768
' PGMDeviceLib(4).DeviceNameString = "ST27C256"
' PGMDeviceLib(4).DeviceSeriesNumber = 0
' PGMDeviceLib(4).DeviceSignature = "20 8D 99"
' PGMDeviceLib(4).DeviceSeriesNumber = c_DeviceSeriesNumber_ST27C256
' PGMDeviceLib(4).DeviceSignature = c_DeviceSignature_ST27C256
'ST27C512
' PGMDeviceLib(5).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_ST27C512
' PGMDeviceLib(5).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(5).DeviceManufacturerID = c_DeviceManufacturerID_ST
' PGMDeviceLib(5).DeviceManufacturerName = "ST"
' PGMDeviceLib(5).DeviceMaxCodeLength = 65536
' PGMDeviceLib(5).DeviceNameString = "ST27C512"
'PGMDeviceLib(5).DeviceSeriesNumber = 1
'PGMDeviceLib(5).DeviceSignature = "20 8D 9A"
' PGMDeviceLib(5).DeviceSeriesNumber = c_DeviceSeriesNumber_ST27C512
' PGMDeviceLib(5).DeviceSignature = c_DeviceSignature_ST27C512
'ST27C128
' PGMDeviceLib(6).DeviceCompleteIDNumber = c_DeviceCompleteIDNumber_ST27C128
' PGMDeviceLib(6).DeviceGroup = c_DeviceGroup_MEM
' PGMDeviceLib(6).DeviceManufacturerID = c_DeviceManufacturerID_ST
' PGMDeviceLib(6).DeviceManufacturerName = "ST"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -