📄 timer1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "TIMER1溢出中断测试 苏州大学freescale MCU&DSP研发中心 2005年3月版"
ClientHeight = 4335
ClientLeft = 3420
ClientTop = 2970
ClientWidth = 8535
Icon = "Timer1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4335
ScaleWidth = 8535
Begin VB.CommandButton ComStop
Caption = "暂停"
BeginProperty Font
Name = "隶书"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 6090
TabIndex = 6
Top = 1200
Width = 1125
End
Begin MSCommLib.MSComm MSComm1
Left = 5220
Top = 3090
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.TextBox TxtRECV
BackColor = &H00C0E0FF&
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 585
Left = 2220
Locked = -1 'True
TabIndex = 3
Text = "Text1"
Top = 2940
Width = 1965
End
Begin VB.CommandButton CmdEXIT
BeginProperty Font
Name = "隶书"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 645
Left = 6060
MaskColor = &H00E0E0E0&
Picture = "Timer1.frx":0A02
Style = 1 'Graphical
TabIndex = 2
Top = 2820
Width = 705
End
Begin VB.CommandButton CmdSEND
Caption = "发送"
BeginProperty Font
Name = "隶书"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 4500
TabIndex = 1
Top = 1200
Width = 1125
End
Begin VB.TextBox TxtSEND
BackColor = &H00C0E0FF&
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 585
Left = 2190
Locked = -1 'True
TabIndex = 0
Text = "Text1"
Top = 1230
Width = 1935
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 5160
Top = 2370
End
Begin VB.Frame Frame1
Caption = "当前系统时间"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 1545
Left = 1050
TabIndex = 4
Top = 510
Width = 6705
End
Begin VB.Frame Frame2
Caption = "MCU传来的时间"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 1395
Left = 1050
TabIndex = 5
Top = 2370
Width = 3405
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'程序描述:
' (1)把当前系统时间从COM1发送出去
' (2)把接收到的数据显示在接收窗口中
'-------------------------------------------------------
Option Explicit '检查未经声明的变量
Dim TimData() As Byte '原始时间数组
Dim SendData(2) As Byte '发送数据数组
Dim RecvData() As Byte '接收数据数组
Private Sub Form_Load()
'串行口初始化
Call SCIinit(MSComm1, 1, "9600,N,8,1")
'清空有关文本框
TxtSEND.Text = ""
TxtRECV.Text = ""
'开放串行中断
MSComm1.RThreshold = 1
'计时器开始计时
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
TxtSEND.Text = Format$(Time(), "HH:MM:SS")
End Sub
Private Sub CmdSEND_Click() '单击"发送"按钮
SendData(0) = Val(Mid$(TxtSEND.Text, 1, 2))
SendData(1) = Val(Mid$(TxtSEND.Text, 4, 2))
SendData(2) = Val(Mid$(TxtSEND.Text, 7, 2))
MSComm1.Output = SendData
End Sub
Private Sub ComStop_Click() '单击"暂停/继续"按钮
If ComStop.Caption = "暂停" Then
ComStop.Caption = "继续"
Timer1.Enabled = False
Else
ComStop.Caption = "暂停"
Timer1.Enabled = True
End If
End Sub
Public Sub MSComm1_OnComm() '串行接收中断
Dim i As Integer
Dim S1 As String
MSComm1.RThreshold = 0 '关闭串行中断
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 3
RecvData = MSComm1.Input
For i = LBound(RecvData) To UBound(RecvData)
S1 = S1 & Format$(RecvData(i), "00") & ":"
Next i
S1 = Mid$(S1, 1, 8)
TxtRECV.Text = S1
MSComm1.RThreshold = 1 '开放串行中断
End Sub
Private Sub CmdEXIT_Click() '单击"退出"按钮
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
Timer1.Enabled = False
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -