drv_prn.bas.bak

来自「VB代码」· BAK 代码 · 共 634 行 · 第 1/2 页

BAK
634
字号
End Function

Function ShiftDataRight(ByVal ucSrcData As Byte) As Byte
        
        ShiftDataRight = ucSrcData \ &H2

End Function

Function LoadByteToProgramDeviceDataPort(ByVal ucLoadByte As Byte) As Boolean
    Dim ucCount As Byte
    Dim bReturnValue As Boolean
        
    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HF0
    ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H4
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
    
    For ucCount = 0 To 7 Step 1     '共计循环8次
        If (ucLoadByte And &H1) Then
            ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H1
        Else
            ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HFE
        End If
        
        bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H2
        bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HFD
        bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        
        ucLoadByte = ShiftDataRight(ucLoadByte)
    Next ucCount
    
    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HF0
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        
End Function

Function PrintPortReadBusyStatus() As Boolean
        Dim bReturnValue  As Boolean
        Dim ucTemp As Byte
        
        ucTemp = ReadData_PrintStatusPort()
        If (ucTemp And &H80) = 0 Then
                PrintPortReadBusyStatus = True
        Else
                PrintPortReadBusyStatus = False
        End If
        
End Function

Function GetByteFromProgramDeviceDataPort() As Byte
    Dim ucCount As Byte
    Dim ucGetData As Byte
    Dim bReturnValue As Boolean
    
    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HF0
    ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &HC
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)

    ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H2
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HFD
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)

    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HF3
    ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H4
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)

    ucGetData = &H0
    If (PrintPortReadBusyStatus()) Then
        ucGetData = ucGetData Or &H80
    End If
    
    For ucCount = 0 To 6 Step 1  '共计循环7次。
 
        ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H2
        bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HFD
        bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
 
        ucGetData = ShiftDataRight(ucGetData)

        If (PrintPortReadBusyStatus()) Then
                ucGetData = ucGetData Or &H80
        End If
        
    Next ucCount
    
    ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HF0
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        
    GetByteFromProgramDeviceDataPort = ucGetData
        
End Function

Sub IncreaseProgramAddress()
    Dim bReturnValue As Boolean

    bReturnValue = ST2051PGM_SetXTAL1High()
    bReturnValue = ST2051PGM_SetXTAL1Low()

End Sub

Sub ResetProgramDevice()
    Dim bReturnValue As Boolean
 
    ucPrintDataPortMemImage = &H4
    bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
        
    ucPrintControlPortMemImage = ucPrintControlPortMemImage And &HF0
    ucPrintControlPortMemImage = ucPrintControlPortMemImage Or &HB
    
    bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)

End Sub

Function CStr_Hex(ucSrcValue As Byte) As String
    Dim ucHighHex As Byte
    Dim ucLowHex As Byte


    ucHighHex = ucSrcValue \ 16
    ucLowHex = ucSrcValue Mod 16
        
    If ucHighHex < 10 Then
        ucHighHex = ucHighHex + &H30
    Else
        ucHighHex = ucHighHex + &H30 + 7
    End If
    
    If ucLowHex < 10 Then
        ucLowHex = ucLowHex + &H30      '转换成ascii码准备显示
    Else
        ucLowHex = ucLowHex + &H30 + 7
    End If

    CStr_Hex = Chr$(ucHighHex) + Chr$(ucLowHex)

End Function

Public Function ReadDeivceSignature(ByRef ucDataBuff As String) As Boolean
        Dim bReturnValue As Boolean
        
        Call ResetProgramDevice
        bReturnValue = ST2051PGM_CloseVpp()
        bReturnValue = ST2051PGM_SetXTAL1Low()
        Call Delay(1)                '55mS
        bReturnValue = ST2051PGM_Load5V()
        Call Delay(1)
        bReturnValue = ST2051PGM_SetP32High()
        
        Call SelectWorkMode(c_Mode_ReadSignature)
        Call Delay(1)                '55mS
        
        ucDataBuff = ""
        ucDataBuff = ucDataBuff & CStr_Hex(GetByteFromProgramDeviceDataPort())
        Call IncreaseProgramAddress
        Call Delay(1)
        
        ucDataBuff = ucDataBuff & " " & CStr_Hex(GetByteFromProgramDeviceDataPort())
        Call IncreaseProgramAddress
        Call Delay(1)
        
        ucDataBuff = ucDataBuff & " " & CStr_Hex(GetByteFromProgramDeviceDataPort())

        bReturnValue = ST2051PGM_SetXTAL1Low()
        bReturnValue = ST2051PGM_Close5V()
        Call ResetProgramDevice

End Function

Public Function EraseChip() As Boolean
        Dim bReturnValue As Boolean
        
        Call ResetProgramDevice
        bReturnValue = ST2051PGM_CloseVpp()
        bReturnValue = ST2051PGM_Close5V()
        bReturnValue = ST2051PGM_SetXTAL1Low()
        Call Delay(1)                '55mS
        bReturnValue = ST2051PGM_Load5V()
        Call Delay(1)
        bReturnValue = ST2051PGM_SetP32High()
        
        Call SelectWorkMode(c_Mode_EraseChip)
        Call Delay(1)                '55mS
    
        bReturnValue = ST2051PGM_LoadVpp()
        bReturnValue = ST2051PGM_SetP32Low()
        Call Delay(10)
                bReturnValue = ST2051PGM_SetP32High()
                
        bReturnValue = ST2051PGM_SetXTAL1Low()
        bReturnValue = ST2051PGM_CloseVpp()
        bReturnValue = ST2051PGM_Close5V()
        Call ResetProgramDevice

End Function

Function ReadProgramCodeFromDevice() As Boolean
        Dim bReturnValue As Boolean
    Dim iCount As Integer
    
    Call ResetProgramDevice
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_SetXTAL1Low()
    Call Delay(1)                '55mS
    bReturnValue = ST2051PGM_Load5V()
    Call Delay(1)
    bReturnValue = ST2051PGM_SetP32High()
    
    Call SelectWorkMode(c_Mode_ReadPGMCode)
    Call Delay(1)                '55mS
        
    For iCount = 0 To c_MaxCodeLength Step 1
        ucDataBuff(iCount) = GetByteFromProgramDeviceDataPort()
        Call IncreaseProgramAddress
    Next iCount

    bReturnValue = ST2051PGM_SetXTAL1Low()
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_Close5V()
    Call ResetProgramDevice

End Function

Function WriteProgramCodeToDevice() As Boolean
        Dim bReturnValue As Boolean
    Dim iCount As Integer
    
    Call ResetProgramDevice
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_SetXTAL1Low()
    Call Delay(1)                '55mS
    bReturnValue = ST2051PGM_Load5V()
    Call Delay(1)
    bReturnValue = ST2051PGM_SetP32High()

    Call SelectWorkMode(c_Mode_WritePGMCode)
    Call Delay(1)                '55mS
        
    For iCount = 0 To c_MaxCodeLength Step 1
        LoadByteToProgramDeviceDataPort (ucDataBuff(iCount))
        bReturnValue = ST2051PGM_LoadVpp()
        bReturnValue = ST2051PGM_SetP32Low()
        bReturnValue = ST2051PGM_SetP32High()
    
        Call Delay(1)   '55mS
        Call IncreaseProgramAddress
    Next iCount
    
    bReturnValue = ST2051PGM_SetXTAL1Low()
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_Close5V()
    Call ResetProgramDevice

End Function

Function LockDeviceBit1() As Boolean

    Dim bReturnValue As Boolean
    
    Call ResetProgramDevice
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_SetXTAL1Low()
    Call Delay(1)                '55mS
    bReturnValue = ST2051PGM_Load5V()
    Call Delay(1)
    bReturnValue = ST2051PGM_SetP32High()

    Call SelectWorkMode(c_Mode_LockBit1)
    Call Delay(1)                '55mS
        bReturnValue = ST2051PGM_LoadVpp()
        Call Delay(1)

        bReturnValue = ST2051PGM_SetP32Low()
        bReturnValue = ST2051PGM_SetP32High()
        Call Delay(1)   '55mS
        
        bReturnValue = ST2051PGM_SetXTAL1Low()
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_Close5V()
    Call ResetProgramDevice
  
    LockDeviceBit1 = True
End Function

Function LockDeviceBit2() As Boolean

    Dim bReturnValue As Boolean
    
    Call ResetProgramDevice
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_SetXTAL1Low()
    Call Delay(1)                '55mS
    bReturnValue = ST2051PGM_Load5V()
    Call Delay(1)
    bReturnValue = ST2051PGM_SetP32High()

    Call SelectWorkMode(c_Mode_LockBit2)
    Call Delay(1)                '55mS
    
    bReturnValue = ST2051PGM_LoadVpp()
    Call Delay(1)

    bReturnValue = ST2051PGM_SetP32Low()
    bReturnValue = ST2051PGM_SetP32High()
    Call Delay(1)   '55mS
        
    bReturnValue = ST2051PGM_SetXTAL1Low()
    bReturnValue = ST2051PGM_CloseVpp()
    bReturnValue = ST2051PGM_Close5V()
    Call ResetProgramDevice
  
    LockDeviceBit2 = True
End Function

⌨️ 快捷键说明

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