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

📄 form1.frm

📁 单片机与PC机的通信,下位机用汇编写的,上位机用VB实现.
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8250
   ClientLeft      =   3645
   ClientTop       =   1770
   ClientWidth     =   9135
   FillColor       =   &H8000000B&
   ForeColor       =   &H00FFFFFF&
   LinkTopic       =   "Form1"
   ScaleHeight     =   550
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   609
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   7320
      Top             =   6600
   End
   Begin VB.Frame Frame3 
      Caption         =   "当前时间:"
      Height          =   855
      Left            =   5280
      TabIndex        =   5
      Top             =   6360
      Width           =   2535
      Begin VB.Label Label1 
         Caption         =   " "
         Height          =   375
         Left            =   480
         TabIndex        =   6
         Top             =   360
         Width           =   1935
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "水位状态  "
      Height          =   6135
      Left            =   1080
      TabIndex        =   2
      Top             =   1080
      Width           =   3975
      Begin VB.PictureBox Picture1 
         Height          =   5295
         Left            =   360
         Picture         =   "Form1.frx":0000
         ScaleHeight     =   349
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   213
         TabIndex        =   3
         Top             =   600
         Width           =   3255
      End
   End
   Begin VB.CommandButton Command2 
      Caption         =   "清   除"
      Height          =   495
      Left            =   5880
      TabIndex        =   1
      Top             =   3000
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "手   动"
      Height          =   495
      Left            =   5880
      TabIndex        =   0
      Top             =   2400
      Width           =   1455
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   7200
      Top             =   1200
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      NullDiscard     =   -1  'True
      RThreshold      =   1
      RTSEnable       =   -1  'True
      BaudRate        =   2400
      InputMode       =   1
   End
   Begin VB.Frame Frame2 
      Caption         =   "控制  "
      Height          =   3255
      Left            =   5280
      TabIndex        =   4
      Top             =   1080
      Width           =   2535
      Begin VB.CommandButton Command4 
         Caption         =   "关  闭"
         Height          =   495
         Left            =   600
         TabIndex        =   12
         Top             =   2520
         Width           =   1455
      End
      Begin VB.CommandButton Command3 
         Caption         =   "打开串口"
         Height          =   495
         Left            =   600
         TabIndex        =   11
         Top             =   720
         Width           =   1455
      End
      Begin VB.ComboBox Combo1 
         Height          =   300
         Left            =   600
         Style           =   2  'Dropdown List
         TabIndex        =   9
         Top             =   240
         Width           =   1455
      End
   End
   Begin VB.Label Label6 
      Caption         =   "智能水塔控制系统"
      BeginProperty Font 
         Name            =   "黑体"
         Size            =   21.75
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000080&
      Height          =   495
      Left            =   2760
      TabIndex        =   14
      Top             =   360
      Width           =   4215
   End
   Begin VB.Label Label5 
      Caption         =   "黎明职业大学电子工程系单片机测试程序"
      BeginProperty Font 
         Name            =   "幼圆"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000080&
      Height          =   375
      Left            =   1440
      TabIndex        =   13
      Top             =   7440
      Width           =   6255
   End
   Begin VB.Label Label4 
      Caption         =   " "
      Height          =   255
      Left            =   5640
      TabIndex        =   10
      Top             =   4680
      Width           =   2055
   End
   Begin VB.Label Label3 
      Caption         =   "故   障"
      Height          =   375
      Left            =   6840
      TabIndex        =   8
      Top             =   5760
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "运   行"
      Height          =   375
      Left            =   5520
      TabIndex        =   7
      Top             =   5760
      Width           =   855
   End
   Begin VB.Shape Shape2 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   495
      Left            =   6720
      Shape           =   3  'Circle
      Top             =   5160
      Width           =   735
   End
   Begin VB.Shape Shape1 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   495
      Left            =   5400
      Shape           =   3  'Circle
      Top             =   5160
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim temp As Byte
Dim outbyte(1 To 1) As Byte
Dim inbyte() As Byte
Dim buf As Byte
Dim b As Double
Dim loadpath As String
Dim pp As Integer
Dim cc As Integer
 
 
Private Sub Combo1_Click()
    cc = Combo1.ListIndex
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
End Sub

Private Sub Command1_Click()
   If MSComm1.PortOpen = False Then
      MsgBox ("串口未打开,请先设置串口")
      Exit Sub
   End If
   
    If b = 0 Then
       temp = 0
       Command1.Caption = "停   止"
       b = 1
       Shape1.FillColor = RGB(0, 255, 0)
       pp = 1
    Else
       temp = 1
       pp = 0
       b = 0
       Shape1.FillColor = RGB(255, 255, 255)
       Command1.Caption = "手   动"
    End If
    outbyte(1) = temp
    MSComm1.Output = outbyte '需采用数组
End Sub

Private Sub Command2_Click()
     If MSComm1.PortOpen = False Then
      MsgBox ("串口未打开,请先设置串口")
      Exit Sub
   End If
    Shape2.FillColor = RGB(255, 255, 255)
     Command1.Enabled = True
    temp = 2
    outbyte(1) = temp
    MSComm1.Output = outbyte '送停止符号
End Sub

Private Sub Command3_Click()
 
   If Command3.Caption = "打开串口" Then
        MSComm1.CommPort = cc
        If MSComm1.PortOpen = False Then
            MSComm1.PortOpen = True
            outbyte(1) = 2
            MSComm1.Output = outbyte
        End If
        Command3.Caption = "关闭串口"
        
   Else
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
        Command3.Caption = "打开串口"
   End If
   
  
End Sub

Private Sub Command4_Click()
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
        Unload Me
End Sub

Private Sub Form_Load()
   Picture1.Picture = LoadPicture(App.Path & "\00.bmp")
    b = 0
    Shape1.FillColor = RGB(255, 255, 255)
    Shape2.FillColor = RGB(255, 255, 255)
    Combo1.AddItem "串口设置"
    Combo1.AddItem "com1 9600,n,8,1"
    Combo1.AddItem "com2 2400,n,8,1"
    Combo1.AddItem "com3 2400,n,8,1"
    Combo1.AddItem "com4 9600,n,8,1"
    Combo1.Text = "串口设置"
     Command1.Enabled = False
     Command2.Enabled = False
     Command3.Enabled = False
End Sub







Private Sub MSComm1_OnComm()
    Dim p As Integer
    Select Case MSComm1.CommEvent
        Case comEvReceive
            inbyte = MSComm1.Input
                        For p = LBound(inbyte) To UBound(inbyte)
        buf = inbyte(p)
    Select Case buf
        
        Case 1
          loadpath = "\01.bmp"
          Command2.Enabled = True
          Shape1.FillColor = RGB(0, 255, 0)
           Label4.Caption = " "
          pp = 1
        Case 2
          loadpath = "\02.bmp"
           Label4.Caption = " "
           Command2.Enabled = True
           pp = 1
            Shape1.FillColor = RGB(0, 255, 0)
          
        Case 3
          loadpath = "\03.bmp"
           Label4.Caption = " "
           Command2.Enabled = True
           If pp = 1 Then
            Shape1.FillColor = RGB(0, 255, 0)
          End If
        Case 4
          loadpath = "\04.bmp"
           Label4.Caption = " "
           Command2.Enabled = True
           If pp = 1 Then
            Shape1.FillColor = RGB(0, 255, 0)
          End If
        Case 5
          loadpath = "\05.bmp"
           Label4.Caption = " "
           Command2.Enabled = True
           If pp = 1 Then
            Shape1.FillColor = RGB(0, 255, 0)
          End If
          Command1.Enabled = True
        Case 6
         loadpath = "\06.bmp"
          Shape1.FillColor = RGB(255, 255, 255)
           Label4.Caption = "已到上限,停止加水!"
           pp = 0
           If b = 1 Then
                b = 0
                temp = 1
                Shape1.FillColor = RGB(255, 255, 255)
                Command1.Caption = "手   动"
            End If
           Command1.Enabled = False
           Command2.Enabled = False
           
        Case 40
         b = 0
           Command1.Caption = "手   动"
           Shape1.FillColor = RGB(255, 255, 255)
           
          
        Case 80
         b = 1
           Command1.Caption = "停   止"
           Shape1.FillColor = RGB(0, 255, 0)
        
        Case Else
          Shape2.FillColor = RGB(255, 0, 0)
         'Label4.Caption = "液位传感器故障!"
          Command1.Enabled = False
          loadpath = "\00.bmp"
    End Select
        
        Picture1.Picture = LoadPicture(App.Path & loadpath)
  Next p

    End Select
End Sub


Private Sub Timer1_Timer()
    Label1.Caption = Now
End Sub

⌨️ 快捷键说明

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