用VB6.0數(shù)字示波單片機實時監(jiān)測數(shù)據(jù)的一種方法
三.軟件設(shè)計思想(一個具體的例)
要求:單片機每1秒串行發(fā)送給PC一幀十位數(shù)據(jù),VB6.0波形動態(tài)顯示數(shù)據(jù)。
設(shè)計:通過窗體Load事件程序完成如圖3所示界面設(shè)計,使得程序一運行即出現(xiàn)該界面,單擊接收數(shù)據(jù)按鈕,通過MsComm控件接收串行通信數(shù)據(jù)并波形動態(tài)顯示。顯示時一屏12個數(shù)據(jù),每次接收了新數(shù)據(jù)后,數(shù)組中的數(shù)據(jù)依次后移,既a(0)(假設(shè)為數(shù)組a(11))放最新接收的數(shù)據(jù),原a(11)中的數(shù)據(jù)被移出而移入原a(10)中的數(shù)。每次有新數(shù)據(jù)移入并且有原數(shù)據(jù)移出時,先清屏再復(fù)原背景顯示數(shù)據(jù),造成數(shù)據(jù)平移視覺效果。
設(shè)計時波形一定要從界面最左端入,從最右端出,這樣動態(tài)平移視覺效果才好。窗體的AutoRedraw屬性要設(shè)為True.
四.軟件設(shè)計源程序(波形參見圖4、圖5)
'定義所用變量
Dim a(11) As Single
Dim d As Integer
Dim n As Integer
Dim m As Integer
Dim Buffer As Variant
Private Sub Form_Load()
'一屏顯示的12個數(shù)賦初值0
For i = 0 To 11
a(i) = 0
Next i
'定義坐標原點
Form1.Scale (-10, 250)-(220, -15)
'畫X、Y軸
Line (0, 0)-(220, 0)
Line (0, 0)-(0, 250)
'加坐標刻度和數(shù)值
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
'mscomm控件初始化
MSComm1.CommPort = 1
MSComm1.Settings = 9600,n,8,1
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 0
MSComm1.RThreshold = 0
End Sub
'接收并顯示數(shù)據(jù)
Private Sub Command1_Click()
'無條件循環(huán)接收數(shù)據(jù)
Do
單片機相關(guān)文章:單片機教程
單片機相關(guān)文章:單片機視頻教程
單片機相關(guān)文章:單片機工作原理
評論