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

📄 form1.frm

📁 MCS-51单片机双机通信实现程序原代码
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5445
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   7710
   LinkTopic       =   "Form1"
   Picture         =   "Form1.frx":0000
   ScaleHeight     =   5445
   ScaleWidth      =   7710
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Interval        =   500
      Left            =   6840
      Top             =   4320
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   5280
      Top             =   4320
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      Filter          =   "All Files(*.*)|*.*|Text Files(*.TXT)|*.txt"
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   6000
      Top             =   4200
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   375
      Left            =   4080
      TabIndex        =   10
      Top             =   3960
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "确定"
      Height          =   375
      Left            =   2040
      TabIndex        =   9
      Top             =   3960
      Width           =   1095
   End
   Begin VB.Frame Frame1 
      Caption         =   "接收设置"
      Height          =   1935
      Left            =   600
      TabIndex        =   3
      Top             =   480
      Width           =   2775
      Begin VB.ComboBox Combo2 
         Height          =   300
         Left            =   1320
         TabIndex        =   4
         Top             =   840
         Width           =   1215
      End
      Begin VB.Label Label3 
         Caption         =   "选择气室:"
         Height          =   255
         Left            =   240
         TabIndex        =   11
         Top             =   840
         Width           =   975
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "接收显示"
      Height          =   1935
      Left            =   3720
      TabIndex        =   2
      Top             =   480
      Width           =   3135
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   1200
         TabIndex        =   12
         Top             =   600
         Width           =   1095
      End
      Begin VB.CommandButton Command4 
         Caption         =   "清除显示"
         Height          =   375
         Left            =   1440
         TabIndex        =   8
         Top             =   1200
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "串口接收"
         Height          =   375
         Left            =   240
         TabIndex        =   7
         Top             =   1200
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "%"
         Height          =   255
         Left            =   2400
         TabIndex        =   6
         Top             =   600
         Width           =   255
      End
      Begin VB.Label Label1 
         Caption         =   "当前浓度"
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   600
         Width           =   735
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "参数设置"
      Height          =   855
      Left            =   600
      TabIndex        =   0
      Top             =   2760
      Width           =   6255
      Begin VB.CommandButton Command6 
         Caption         =   "用户设置与参考"
         Height          =   495
         Left            =   600
         TabIndex        =   1
         Top             =   240
         Width           =   4575
      End
   End
   Begin VB.Menu file 
      Caption         =   "文件(&F)"
      Begin VB.Menu save 
         Caption         =   "保存(&S)"
      End
      Begin VB.Menu close 
         Caption         =   "关闭(&C)"
      End
      Begin VB.Menu open 
         Caption         =   "打开(&O)"
      End
      Begin VB.Menu fenge 
         Caption         =   "-"
      End
      Begin VB.Menu exit 
         Caption         =   "退出(&E)"
      End
   End
   Begin VB.Menu set 
      Caption         =   "设置(&S)"
      Begin VB.Menu setport 
         Caption         =   "设置串口"
      End
      Begin VB.Menu setalarm 
         Caption         =   "设置报警"
      End
   End
   Begin VB.Menu help 
      Caption         =   "帮助(&H)"
      Begin VB.Menu about 
         Caption         =   "关于(&A)"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 Dim aa As Single
 
Private Sub Combo2_Change()
    Dim Channel As String
    Dim cmdChannel As String
    Channel = Combo2.Text
     
      Form1.MSComm1.PortOpen = True
  Dim xiaoshu1 As Integer
  Dim xiaoshu2 As Single
  Dim ftos As String
  xiaoshu1 = 2
  xiaoshu2 = 3.1223
  ftos = Trim(Str(xiaoshu2)) & "$"
    cmdChannel = Channel + "$"
    
       ' Form1.Text1.Text = ftos
        
    Form1.MSComm1.Output = cmdChannel
     Form1.MSComm1.PortOpen = False
    
       
        
End Sub

Private Sub Command1_Click()
    If Command1.Caption = "串口接收" Then
        Command1.Caption = "停止接收"
        Form1.MSComm1.InputMode = comInputModeText
        Form1.MSComm1.InputLen = 1
        Form1.MSComm1.RThreshold = 10
        Form1.MSComm1.SThreshold = 10
        Form1.MSComm1.PortOpen = True
                                                '打开串口
        Else: Command1.Caption = "停止接收"
         Command1.Caption = "串口接收"
         Form1.MSComm1.PortOpen = False
                                        '关闭串口
        End If
        
        
End Sub

Private Sub Command5_Click()

     
End Sub

Private Sub Command3_Click()
Unload Me

End Sub

Private Sub Command4_Click()
   Text1.Text = 0
    
End Sub

Private Sub Command6_Click()
Form2.Show

End Sub

Private Sub Frame3_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Form_Load()
    
    '串口设置
   ' MSComm1.InputLen = 40
   ' MSComm1.RThreshold = 10
   ' MSComm1.SThreshold = 10
    
    '气室选择
    Combo2.AddItem 1
    Combo2.AddItem 2
    Combo2.AddItem 3
    Combo2.AddItem 4
    
   
     
    
End Sub


Private Sub MSComm1_OnComm()

    Select Case MSComm1.CommEvent
    Case comEvReceive
       
        'aa = Mid(aa, 1, 1)
        'bb = CSng(aa)
       aa = Form1.MSComm1.Input
        
       
       Form1.Text1.Text = aa
                                        
       'If Text1.Text > alarm_value Then MsgBox "警告,瓦斯浓度超过安全水平!"
       
        
    Case comEvSend
      
    End Select
    
End Sub

Private Sub open_Click()
    CommonDialog1.ShowOpen
    
End Sub

Private Sub save_Click()
    Dim strFileName As Integer
    CommonDialog1.ShowSave
   strFileName = CommonDialog1.FileName
   If strFileName <> "" Then
    Open strFileName For Output As #1
    End If
    
End Sub

Private Sub setalarm_Click()
    Form5.Show
    
End Sub

Private Sub setport_Click()
    Form3.Show
    
End Sub

Private Sub StartTiming()
    StartTime = Now
    Form1.Timer1.Enabled = True
End Sub
Private Sub StopTiming()
    Form1.Timer1.Enabled = False
    
    
End Sub

⌨️ 快捷键说明

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