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

📄 form1.frm

📁 51单片机工程应用实例
💻 FRM
📖 第 1 页 / 共 2 页
字号:
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"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   BackColor       =   &H00C0C0C0&
   Caption         =   "USB编程器TC51 V3.0"
   ClientHeight    =   6390
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7830
   FillColor       =   &H00E0E0E0&
   LinkTopic       =   "Form1"
   ScaleHeight     =   6390
   ScaleWidth      =   7830
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command13 
      Caption         =   "LK3"
      Height          =   315
      Left            =   960
      Picture         =   "Form1.frx":0000
      TabIndex        =   19
      Top             =   3120
      Width           =   600
   End
   Begin VB.CommandButton Command12 
      Caption         =   "LK2"
      Height          =   315
      Left            =   960
      Picture         =   "Form1.frx":0442
      TabIndex        =   18
      Top             =   2400
      Width           =   600
   End
   Begin VB.CommandButton Command3 
      Caption         =   "搜索"
      Height          =   800
      Left            =   2400
      TabIndex        =   17
      Top             =   4680
      Width           =   680
   End
   Begin VB.ComboBox Combo2 
      Height          =   300
      ItemData        =   "Form1.frx":0884
      Left            =   1080
      List            =   "Form1.frx":0891
      TabIndex        =   16
      Text            =   "89C51"
      Top             =   840
      Width           =   855
   End
   Begin MSComctlLib.ProgressBar ProgressBar1 
      Height          =   255
      Left            =   120
      TabIndex        =   14
      Top             =   5760
      Width           =   7575
      _ExtentX        =   13361
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
   End
   Begin VB.CommandButton Command11 
      Caption         =   "LK1"
      Height          =   315
      Left            =   960
      Picture         =   "Form1.frx":08AC
      TabIndex        =   13
      Top             =   1680
      Width           =   600
   End
   Begin VB.CommandButton Command10 
      Caption         =   "退出"
      Height          =   555
      Left            =   480
      Picture         =   "Form1.frx":0CEE
      TabIndex        =   12
      Top             =   3960
      Width           =   1485
   End
   Begin VB.CommandButton Command9 
      Caption         =   "清除窗口"
      Height          =   375
      Left            =   6240
      Picture         =   "Form1.frx":1130
      TabIndex        =   11
      Top             =   0
      Width           =   1035
   End
   Begin VB.CommandButton Command8 
      Caption         =   "校验"
      Height          =   800
      Left            =   6840
      Picture         =   "Form1.frx":1572
      TabIndex        =   10
      Top             =   4680
      Width           =   680
   End
   Begin VB.CommandButton Command7 
      Caption         =   "编程"
      Height          =   800
      Left            =   6120
      Picture         =   "Form1.frx":19B4
      TabIndex        =   9
      Top             =   4680
      Width           =   680
   End
   Begin VB.CommandButton Command6 
      Caption         =   "空检查"
      Height          =   800
      Left            =   5040
      Picture         =   "Form1.frx":1DF6
      TabIndex        =   8
      Top             =   4680
      Width           =   680
   End
   Begin VB.CommandButton Command5 
      Caption         =   "擦除"
      Height          =   800
      Left            =   4320
      Picture         =   "Form1.frx":2238
      TabIndex        =   7
      Top             =   4680
      Width           =   680
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   3480
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command4 
      Caption         =   "读出"
      Height          =   800
      Left            =   3120
      Picture         =   "Form1.frx":267A
      TabIndex        =   6
      Top             =   4680
      Width           =   680
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      ItemData        =   "Form1.frx":2ABC
      Left            =   1080
      List            =   "Form1.frx":2ACC
      TabIndex        =   4
      Text            =   "1"
      Top             =   360
      Width           =   855
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   3960
      Top             =   -120
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
   End
   Begin VB.TextBox Text2 
      Height          =   3375
      Left            =   2160
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   360
      Width           =   5415
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   2160
      TabIndex        =   2
      Top             =   4185
      Width           =   5415
   End
   Begin VB.CommandButton Command2 
      Caption         =   "存盘"
      Height          =   800
      Left            =   1200
      Picture         =   "Form1.frx":2ADC
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   4680
      Width           =   680
   End
   Begin VB.CommandButton Command1 
      Caption         =   "打开"
      Height          =   800
      Left            =   480
      Picture         =   "Form1.frx":2F1E
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   4680
      Width           =   680
   End
   Begin VB.Frame Frame1 
      Caption         =   "加密"
      Height          =   2415
      Left            =   480
      TabIndex        =   15
      Top             =   1320
      Width           =   1455
   End
   Begin VB.Label Label4 
      Caption         =   "状态栏"
      Height          =   255
      Left            =   2160
      TabIndex        =   22
      Top             =   3960
      Width           =   855
   End
   Begin VB.Label Label3 
      Caption         =   "数据窗口"
      Height          =   255
      Left            =   2160
      TabIndex        =   21
      Top             =   120
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "单片机"
      Height          =   255
      Left            =   480
      TabIndex        =   20
      Top             =   840
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "串口号"
      Height          =   255
      Left            =   480
      TabIndex        =   5
      Top             =   360
      Width           =   600
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H00C0C0C0&
      BorderColor     =   &H00000000&
      FillColor       =   &H00C0C0C0&
      FillStyle       =   0  'Solid
      Height          =   165
      Left            =   3120
      Shape           =   3  'Circle
      Top             =   3960
      Width           =   165
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'2008/3/21修改,编程器硬件改动,全部正常。
    Dim rcmd As String '应答
    
    Dim chip As String '芯片号
    Dim chipname As String '芯片名称
    Dim chiplen As Integer '芯片闪存长度
    
    Dim sfile As String '打开的文件内容,无间隔字符串
    Dim flash As String '闪存中的数据
    Dim sbuf As String '收到的数据

    Dim lastads As Integer 'file last address
    Dim strAddH As String
    Dim strAddL As String

    Dim I As Integer
    Dim J As Integer
    Dim m As Integer   '数据个数
    Dim w As Integer   '接收数据个数计数器

Private Sub Combo1_Click() '串口号改变
    With MSComm1
        If .PortOpen = True Then       '判断通信口是否打开
       .PortOpen = False
        End If
       .CommPort = Combo1.Text
       .PortOpen = True
       .DTREnable = True
       .RTSEnable = True
    End With
    Send (chip)
    rcmd = ""
    rcmd = Reci(1)

    If rcmd = chip Then
    Text1.Text = "编程器就绪"
    Else
    Text1.Text = "串口号错误"
    End If
 
End Sub

Private Sub Combo2_Click() '改变器件 OK
    chipname = Combo2.Text '芯片名称
    chipinf (chipname)     '芯片信息
    Text1.Text = chipname
    Send (chip)
    rcmd = ""
    rcmd = Reci(1)

    If rcmd = chip Then
    Text1.Text = "芯片改为" + chipname
    Else
    Text1.Text = "编程器故障"
    End If
End Sub

Private Sub Form_Load() 'OK!
    Form1.Height = 6800
    Form1.Width = 8000
    Shape1.FillColor = vbWhite      '串口打开/关闭显示
    Command2.Enabled = False
    Command7.Enabled = False
    Command8.Enabled = False

    rcmd = ""
    ProgressBar1.Visible = False
    sbuf = ""
    With MSComm1
        .CommPort = 3
        .Settings = "19200,N,8,1"
        .InputMode = comInputModeBinary
        .InBufferSize = 4096
         Combo1.Text = .CommPort
     
     On Error Resume Next       '改变错误处理的方式。
     Err.Clear
     If .PortOpen = False Then       '判断通信口是否打开
        .PortOpen = True         '打开通信口
        .DTREnable = True
        .RTSEnable = True
        
        
        '.DSRHolding = True
         chipname = Combo2.Text '芯片名称
         Call chipinf(chipname)      '芯片信息
         Shape1.FillColor = vbGreen
         ProgressBar1.Align = vbAlignBottom
         ProgressBar1.Visible = False
         ProgressBar1.Min = 0

        If Err Then              '错误处理
         MsgBox "串口通信无效"
         Exit Sub
        End If
      Else:
        Shape1.FillColor = vbWhite
       .PortOpen = False
     End If
    End With
    Send (chip)
    rcmd = ""
    rcmd = Reci(1)

    If rcmd = chip Then
    Text1.Text = "编程器就绪"
    Else
    Text1.Text = "编程器未连接"
    End If
 
End Sub

Private Sub Form_Unload(Cancel As Integer)     '退出窗体 OK!
    With MSComm1
     If .PortOpen = True Then       '判断通信口是否打开
        .PortOpen = False
     End If
    End With
    '程序退出关闭设备
End Sub

Private Function Send(cmd As String) '发单字节OK!
    Dim az(0) As Byte
    az(0) = "&H" & cmd
    MSComm1.Output = az
End Function

Private Function Reci(m As Integer) As String '接收多字节OK!
    Dim Rcv() As Byte   'serial port receive
    Dim str As String
    Dim Buf As String
    Dim I As Integer
    str = ""
    ReDim Rcv(m - 1)
    Do Until MSComm1.InBufferCount >= m
    DoEvents
    Loop
    MSComm1.InputLen = m
    Rcv = MSComm1.Input
    For I = 0 To m - 1
        Buf = Hex(Rcv(I))
        Buf = IIf(Len(Buf) = 1, "0" & Buf, Buf)
        str = str & Buf
    Next I
    Reci = str
End Function

Private Sub Command1_Click() '打开文件 OK!
    Dim strArray(8192) As String
    Dim name As String
    Dim strByte As String
    Dim strLine As String
    Dim strLen As String
    Dim strAdd As String
    Dim strType As String
    Dim strData As String
    Dim line As String
    Dim s_add As String
    
    FileAddMax = 0
    With CommonDialog1
        .DialogTitle = "打开"
        .CancelError = False

⌨️ 快捷键说明

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