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

📄 mainform.frm

📁 F320单片机实现于上位机USB接口通信的源代码
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   Caption         =   "ML-320DK USB演示"
   ClientHeight    =   3990
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4920
   Icon            =   "MainForm.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3990
   ScaleWidth      =   4920
   StartUpPosition =   2  '屏幕中心
   Visible         =   0   'False
   Begin VB.CheckBox chkP1B4 
      Caption         =   "5"
      Height          =   255
      Left            =   4080
      Style           =   1  'Graphical
      TabIndex        =   16
      Top             =   600
      Width           =   375
   End
   Begin VB.CheckBox chkP0B0 
      Caption         =   "1"
      Enabled         =   0   'False
      Height          =   255
      Left            =   480
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   600
      Width           =   375
   End
   Begin VB.CheckBox chkP0B1 
      Caption         =   "2"
      Enabled         =   0   'False
      Height          =   255
      Left            =   840
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   600
      Width           =   375
   End
   Begin VB.CheckBox chkP0B2 
      Caption         =   "3"
      Enabled         =   0   'False
      Height          =   255
      Left            =   1200
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   600
      Width           =   375
   End
   Begin VB.CheckBox chkP0B3 
      Caption         =   "4"
      Enabled         =   0   'False
      Height          =   255
      Left            =   1560
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   600
      Width           =   375
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   2160
      Top             =   2040
   End
   Begin VB.Frame Frame6 
      Caption         =   "芯片温度"
      Height          =   975
      Left            =   240
      TabIndex        =   4
      Top             =   2400
      Width           =   4455
      Begin MSComctlLib.ProgressBar pbAnalog2 
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   240
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   450
         _Version        =   393216
         Appearance      =   1
         Max             =   80
         Scrolling       =   1
      End
      Begin VB.Label Label3 
         Caption         =   "80℃"
         Height          =   255
         Left            =   3960
         TabIndex        =   19
         Top             =   480
         Width           =   375
      End
      Begin VB.Label Label2 
         Caption         =   "0℃"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   480
         Width           =   375
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "控制目标板LED"
      Height          =   855
      Left            =   2400
      TabIndex        =   2
      Top             =   240
      Width           =   2295
      Begin VB.CheckBox chkP1B3 
         Caption         =   "4"
         Height          =   255
         Left            =   1320
         Style           =   1  'Graphical
         TabIndex        =   9
         Top             =   360
         Width           =   375
      End
      Begin VB.CheckBox chkP1B2 
         Caption         =   "3"
         Height          =   255
         Left            =   960
         Style           =   1  'Graphical
         TabIndex        =   8
         Top             =   360
         Width           =   375
      End
      Begin VB.CheckBox chkP1B1 
         Caption         =   "2"
         Height          =   255
         Left            =   600
         Style           =   1  'Graphical
         TabIndex        =   7
         Top             =   360
         Width           =   375
      End
      Begin VB.CheckBox chkP1B0 
         Caption         =   "1"
         Height          =   255
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   6
         Top             =   360
         Width           =   375
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "按键状态显示"
      Height          =   855
      Left            =   240
      TabIndex        =   1
      Top             =   240
      Width           =   1935
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "退出"
      Height          =   375
      Left            =   3840
      TabIndex        =   0
      Top             =   3480
      Width           =   855
   End
   Begin VB.Frame Frame5 
      Caption         =   "ADC0采样电压"
      Height          =   855
      Left            =   240
      TabIndex        =   3
      Top             =   1200
      Width           =   4455
      Begin MSComctlLib.ProgressBar pbAnalog1 
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   240
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   450
         _Version        =   393216
         Appearance      =   1
         Max             =   50
         Scrolling       =   1
      End
      Begin VB.Label Label1 
         Caption         =   "5V"
         Height          =   255
         Left            =   3960
         TabIndex        =   17
         Top             =   480
         Width           =   375
      End
      Begin VB.Label Label0 
         Caption         =   "0V"
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   480
         Width           =   375
      End
   End
   Begin VB.Label Label4 
      Caption         =   "铭朗科技-WWW.MLARM.COM"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF8080&
      Height          =   375
      Left            =   240
      TabIndex        =   20
      Top             =   3480
      Width           =   3495
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdExit_Click()
    
    'close use device and exit program
    SI_Close (hUSBDevice)
    End
    
End Sub

Private Sub Form_Unload(Cancel As Integer)

    'close usb device and exit program
    SI_Close (hUSBDevice)
    End
    
End Sub

Private Sub Timer1_Timer()

    Dim B0, B1, B2, B3, B4
    Dim P1
    
    B0 = chkP1B0.Value
    B1 = chkP1B1.Value * 2   'shift left 1
    B2 = chkP1B2.Value * 4   'shift left 2
    B3 = chkP1B3.Value * 8   'shift left 3
    B4 = chkP1B4.Value * 16   'shift left 3
    P1 = (B0 + B1 + B2 + B3 + B4) 'or all of the bits together to get the byte value
    P1 = P1 And &H1F          'and then with &h0F to get the low 4 bits
    IOBuf(0) = P1            'set the third element to this value to send out

    Dim BytesSucceed As Long
    Dim BytesWriteRequest As Long
    Dim BytesReadRequest As Long

    BytesSucceed = 0
    BytesWriteRequest = IOBufSize - 4
    BytesReadRequest = IOBufSize - 4
    
    'send data to the board
    Status = SI_Write(hUSBDevice, IOBuf(0), BytesWriteRequest, BytesSucceed)
    
    If (BytesSucceed <> BytesWriteRequest) Or (Status <> SI_SUCCESS) Then
        MsgBox "Error writing to USB. Wrote " + Str(BytesSucceed) + " of " + Str(BytesWriteRequest) + " bytes. Application is aborting. Reset hardware and try again."
        End
    End If

    'clear out the iobuf and bytessucceed for the next read
    BytesSucceed = 0
    Call MemSet(IOBuf, 0, IOBufSize)

    'read data from the board
    Status = SI_Read(hUSBDevice, IOBuf(0), BytesReadRequest, BytesSucceed)
    
    If (BytesSucceed <> BytesReadRequest) Or (Status <> SI_SUCCESS) Then
        MsgBox "Error writing to USB. Read " + Str(BytesSucceed) + " of " + Str(BytesReadRequest) + " bytes. Application is aborting. Reset hardware and try again."
        End
    End If
        
    
    Dim P0, N
    P0 = IOBuf(2) And &HF
    chkP0B0.Value = (Not P0) And &H1
    chkP0B1.Value = Not (P0 \ 2) And &H1
    chkP0B2.Value = Not (P0 \ 4) And &H1
    chkP0B3.Value = Not (P0 \ 8) And &H1
    
    If IOBuf(0) > 50 Then IOBuf(0) = 50
    If IOBuf(1) > 80 Then IOBuf(1) = 80
    
    Frame5.Caption = "ADC0采样电压:" & IOBuf(0) / 10 & "V" 'set each analog label to the corresponding value
    Frame6.Caption = "芯片温度:" & IOBuf(1) & "℃"
    
    pbAnalog1.Value = IOBuf(0)    'set each analog graphic as well
    pbAnalog2.Value = IOBuf(1)
    
End Sub

⌨️ 快捷键说明

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