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

📄 form1.frm

📁 基于PROTEUS的仿真 含带源代码 C语言编程
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "串行通讯示例(16进制转10进制)"
   ClientHeight    =   3960
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5565
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3960
   ScaleWidth      =   5565
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text8 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   1800
      TabIndex        =   15
      Top             =   2520
      Width           =   1215
   End
   Begin VB.TextBox Text7 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   1800
      TabIndex        =   14
      Top             =   1800
      Width           =   615
   End
   Begin VB.TextBox Text6 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   3120
      TabIndex        =   13
      Top             =   1800
      Width           =   615
   End
   Begin VB.TextBox Text5 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   4440
      TabIndex        =   12
      Top             =   1800
      Width           =   615
   End
   Begin VB.TextBox Text4 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   4440
      TabIndex        =   6
      Top             =   240
      Width           =   615
   End
   Begin VB.TextBox Text3 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   3120
      TabIndex        =   5
      Top             =   240
      Width           =   615
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   1800
      TabIndex        =   4
      Top             =   240
      Width           =   615
   End
   Begin VB.CommandButton Command2 
      Caption         =   "退出"
      Height          =   375
      Left            =   3720
      TabIndex        =   3
      Top             =   3360
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "接收"
      Height          =   375
      Left            =   360
      TabIndex        =   2
      Top             =   3360
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Alignment       =   2  'Center
      Height          =   375
      Left            =   1800
      TabIndex        =   0
      Top             =   1080
      Width           =   1215
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   4680
      Top             =   2400
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label7 
      Caption         =   "(最高位)"
      Height          =   255
      Left            =   1800
      TabIndex        =   18
      Top             =   720
      Width           =   735
   End
   Begin VB.Label Label12 
      Caption         =   "接收的分离数据:"
      Height          =   255
      Left            =   240
      TabIndex        =   17
      Top             =   1920
      Width           =   1455
   End
   Begin VB.Label Label11 
      Caption         =   "接收的组合数据:"
      Height          =   255
      Left            =   240
      TabIndex        =   16
      Top             =   2640
      Width           =   1455
   End
   Begin VB.Line Line1 
      X1              =   0
      X2              =   5520
      Y1              =   1560
      Y2              =   1560
   End
   Begin VB.Label Label6 
      Alignment       =   2  'Center
      Caption         =   "H"
      Height          =   255
      Left            =   3000
      TabIndex        =   11
      Top             =   1200
      Width           =   255
   End
   Begin VB.Label Label5 
      Alignment       =   2  'Center
      Caption         =   "H"
      Height          =   255
      Left            =   5040
      TabIndex        =   10
      Top             =   360
      Width           =   255
   End
   Begin VB.Label Label4 
      Alignment       =   2  'Center
      Caption         =   "H"
      Height          =   255
      Left            =   3720
      TabIndex        =   9
      Top             =   360
      Width           =   255
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      Caption         =   "H"
      Height          =   255
      Left            =   2400
      TabIndex        =   8
      Top             =   360
      Width           =   255
   End
   Begin VB.Label Label1 
      Caption         =   "接收的组合数据:"
      Height          =   255
      Left            =   240
      TabIndex        =   7
      Top             =   1200
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "接收的分离数据:"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   360
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click() '发送联络信号
Dim num As Integer
Dim outbte(0) As Byte
num = 1
outbte(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = outbte() '动态数组

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 4
MSComm1.Settings = "1200,n,8,1"
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 3 '每次接受3个字符
End Sub

Private Sub MSComm1_OnComm()
Dim indata As Variant
Dim bte(2) As Byte '定义接受数组(3个)
Select Case MSComm1.CommEvent
Case comEvReceive
indata = MSComm1.Input
bte(0) = indata(0)
bte(1) = indata(1)
bte(2) = indata(2)
Text2.Text = Hex(bte(0)) & Hex(bte(1)) & Hex(bte(2)) '组合后的16进制数
Text1.Text = Hex(bte(0))
Text3.Text = Hex(bte(1))
Text4.Text = Hex(bte(2))

Text8.Text = Val("&H" & (Hex(bte(0)) & Hex(bte(1)) & Hex(bte(2)))) '组合后的10进制数
Text7.Text = Val("&H" & Hex(bte(0))) 'Val()接受到以"&H"开头的16进制数会直接转成10进制数
Text6.Text = Val("&H" & Hex(bte(1)))
Text5.Text = Val("&H" & Hex(bte(2)))
MSComm1.InBufferCount = 0
End Select
End Sub

⌨️ 快捷键说明

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