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

📄 form1.frm

📁 use USB WITH 8051 做通訊, 包含源碼.
💻 FRM
📖 第 1 页 / 共 2 页
字号:
   Begin VB.CommandButton btIN 
      Caption         =   "IN"
      Height          =   255
      Index           =   2
      Left            =   3240
      TabIndex        =   8
      Top             =   1080
      Width           =   495
   End
   Begin VB.CommandButton btOUT 
      Caption         =   "OUT"
      Height          =   255
      Index           =   1
      Left            =   3780
      TabIndex        =   7
      Top             =   780
      Width           =   495
   End
   Begin VB.CommandButton btIN 
      Caption         =   "IN"
      Height          =   255
      Index           =   1
      Left            =   3240
      TabIndex        =   6
      Top             =   780
      Width           =   495
   End
   Begin VB.CommandButton btOUT 
      Caption         =   "OUT"
      Height          =   255
      Index           =   0
      Left            =   3780
      TabIndex        =   5
      Top             =   480
      Width           =   495
   End
   Begin VB.CommandButton btIN 
      Caption         =   "IN"
      Height          =   255
      Index           =   0
      Left            =   3240
      TabIndex        =   4
      Top             =   480
      Width           =   495
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   4800
      Top             =   1320
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.ComboBox cboCOMM 
      Height          =   315
      Left            =   5880
      TabIndex        =   0
      Text            =   "COM ?"
      Top             =   60
      Width           =   1335
   End
   Begin VB.Label lbData 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "00"
      Height          =   255
      Index           =   3
      Left            =   660
      TabIndex        =   50
      Top             =   1440
      Width           =   435
   End
   Begin VB.Label lbData 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "00"
      Height          =   255
      Index           =   2
      Left            =   660
      TabIndex        =   49
      Top             =   1080
      Width           =   435
   End
   Begin VB.Label lbData 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "00"
      Height          =   255
      Index           =   1
      Left            =   660
      TabIndex        =   48
      Top             =   780
      Width           =   435
   End
   Begin VB.Label lbData 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "00"
      Height          =   255
      Index           =   0
      Left            =   660
      TabIndex        =   47
      Top             =   480
      Width           =   435
   End
   Begin VB.Label Label1 
      BackColor       =   &H8000000E&
      Caption         =   "Port 3"
      Height          =   255
      Index           =   4
      Left            =   120
      TabIndex        =   14
      Top             =   1380
      Width           =   495
   End
   Begin VB.Label Label1 
      BackColor       =   &H8000000E&
      Caption         =   "Port 2"
      Height          =   255
      Index           =   3
      Left            =   120
      TabIndex        =   13
      Top             =   1080
      Width           =   435
   End
   Begin VB.Label Label1 
      BackColor       =   &H8000000E&
      Caption         =   "Port 1"
      Height          =   255
      Index           =   2
      Left            =   120
      TabIndex        =   12
      Top             =   780
      Width           =   495
   End
   Begin VB.Label Label2 
      BackColor       =   &H8000000E&
      Caption         =   "http://www.dainau.com"
      Height          =   315
      Left            =   2280
      TabIndex        =   3
      Top             =   1740
      Width           =   1815
   End
   Begin VB.Image Image1 
      Height          =   1365
      Left            =   4380
      Picture         =   "Form1.frx":0000
      Top             =   420
      Width           =   3000
   End
   Begin VB.Label Label1 
      BackColor       =   &H8000000E&
      Caption         =   "Port 0"
      Height          =   255
      Index           =   1
      Left            =   120
      TabIndex        =   2
      Top             =   480
      Width           =   495
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BackColor       =   &H00C0FFFF&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "USB to 8051"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   1
      Top             =   60
      Width           =   5655
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub io_out(portnum As Integer, outdata As Byte)
Dim c(1) As Byte
On Error Resume Next

c(0) = Asc("E") + portnum
c(1) = outdata
MSComm1.Output = c
If Err Then
   MsgBox Err.Description
End If

End Sub

Private Function io_in(portnum As Integer) As Byte
Dim c As Byte
Dim cin() As Byte
On Error Resume Next

c = Asc("A") + portnum
MSComm1.Output = Chr$(c)

If Err Then
   MsgBox Err.Description
End If

Do
  DoEvents
  If MSComm1.InBufferCount > 0 Then
     Exit Do
  End If
Loop

cin = MSComm1.Input
io_in = cin(0)


End Function

Private Sub btIN_Click(Index As Integer)
Dim c As Byte

c = io_in(Index)

lbData(Index) = Hex(c)

End Sub

Private Sub btOUT_Click(Index As Integer)

io_out Index, "&H" & lbData(Index)

End Sub

Private Sub cboCOMM_Click()
On Error Resume Next


If MSComm1.PortOpen = True Then
   MSComm1.PortOpen = False
End If
MSComm1.CommPort = cboCOMM.ListIndex + 1
MSComm1.PortOpen = True

If Err.Number <> 0 Then
   MsgBox Err.Description
End If

End Sub

Private Sub ckP0bit_Click(Index As Integer)

Dim i As Integer
Dim c As Byte

For i = 0 To 7
    c = c + ckP0bit(i) * 2 ^ i
Next

lbData(0) = Hex$(c)

End Sub

Private Sub ckP1bit_Click(Index As Integer)

Dim i As Integer
Dim c As Byte

For i = 0 To 7
    c = c + ckP1bit(i) * 2 ^ i
Next

lbData(1) = Hex$(c)

End Sub

Private Sub ckP2bit_Click(Index As Integer)
Dim i As Integer
Dim c As Byte

For i = 0 To 7
    c = c + ckP2bit(i) * 2 ^ i
Next

lbData(2) = Hex$(c)

End Sub

Private Sub ckP3bit_Click(Index As Integer)
Dim i As Integer
Dim c As Byte

For i = 0 To 7
    c = c + ckP3bit(i) * 2 ^ i
Next

lbData(3) = Hex$(c)

End Sub

Private Sub Form_Load()
Dim i As Integer

For i = 1 To 10
    cboCOMM.AddItem "COM" & i
Next

MSComm1.Settings = "115200,n,8,1"
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.InputMode = comInputModeBinary


End Sub

Private Sub Form_Unload(Cancel As Integer)
End

End Sub

Private Sub lbData_Change(Index As Integer)
Dim i As Integer
Dim c As Byte

c = "&h" & lbData(Index)
  
Select Case Index
       Case 0
            For i = 7 To 0 Step -1
                'If (c \ 2 ^ i) > 0 Then
                '   ckP0bit(i).Value = 1
                'Else
                '   ckP0bit(i).Value = 0
                'End If
                ckP0bit(i).Value = c \ 2 ^ i
                If ckP0bit(i).Value Then
                    c = c - 2 ^ i
                End If
            Next
       Case 1
            For i = 7 To 0 Step -1
                ckP1bit(i).Value = c \ 2 ^ i
                If ckP1bit(i).Value Then
                    c = c - 2 ^ i
                End If
            Next
       Case 2
            For i = 7 To 0 Step -1
                ckP2bit(i).Value = c \ 2 ^ i
                If ckP2bit(i).Value Then
                    c = c - 2 ^ i
                End If
            Next
       Case 3
            For i = 7 To 0 Step -1
                ckP3bit(i).Value = c \ 2 ^ i
                If ckP3bit(i).Value Then
                    c = c - 2 ^ i
                End If
            Next
  End Select

End Sub

⌨️ 快捷键说明

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