用VB6.0數(shù)字示波單片機實時監(jiān)測數(shù)據(jù)的一種方法
接收數(shù)據(jù)
Do Until MSComm1.InBufferCount = 1
Loop
Buffer = MSComm1.Input
For i = LBound(Buffer) To UBound(Buffer)
d = Buffer(i)
Next i
'判是否第一屏12個數(shù)據(jù),設標志量m
If m 12 Then
m = m + 1
End If
'12個數(shù)據(jù)放a 數(shù)組,a(0)是最新數(shù)據(jù),原a(11)中的數(shù)移出
For i = 11 To 1 Step -1
a(i) = a(i - 1)
Next i
a(0) = d
'清零窗體界面、數(shù)據(jù)
Form1.Cls
'復原窗體界面
Line (0, 0)-(230, 0)
Line (0, 0)-(0, 250)
CurrentX = 200: CurrentY = 13: Print X(s)
CurrentX = 5: CurrentY = 245: Print Y(V)
For i = 0 To 220 Step 20
CurrentX = i: CurrentY = 3: Line -(i, 0)
If i = 200 Then CurrentX = i - 7 Else CurrentX = i - 12
CurrentY = 0: Print i Mod 19
Next i
For i = 0 To 210 Step 20
If i > 0 Then
CurrentX = -14: CurrentY = i: Print i / 10
CurrentX = 230: CurrentY = i: Line -(0, i)
End If
Next i
'連點成波形
For i = 0 To m - 2
Line (20 * i, 230 * a(i) / 20)-(20 * (i + 1), 230 * a(i + 1) / 20), RGB(240, 0, 0)
Next I
Loop
End Sub
參考書:龔沛曾等《Visual Basic程序設計簡明教程》高等教育出版社 2002
單片機相關文章:單片機教程
單片機相關文章:單片機視頻教程
單片機相關文章:單片機工作原理
評論