大家好,最近在搞一个设计,是单片机通过上位机在VB上面显示温度曲线,但是我程序程序不是很会写,各位大神能帮帮吗

解决方案 »

  1.   

    google vb mschart
      

  2.   

    google我说的关键字,自己就能找到答案。
      

  3.   

    Dim x As Variant
    Dim s As VariantPrivate Sub Command1_Click()
    Timer1.Enabled = True
    MSComm1.RThreshold = 1
    End SubPrivate Sub Command2_Click()
    Timer1.Enabled = False
    MSComm1.RThreshold = 0
    End SubPrivate Sub Command3_Click()
    Dim b(1) As Byte
    b(0) = &H2
    MSComm1.Output = bEnd SubPrivate Sub Command4_Click()
    Dim b(1) As Byte
    b(0) = &H0
    MSComm1.Output = bEnd SubPrivate Sub Command5_Click()
    End
    End SubPrivate Sub 全开_Click()
    Dim b(1) As Byte
    b(0) = &H3
    MSComm1.Output = bEnd SubPrivate Sub Command7_Click()
    Dim b(1) As Byte
    b(0) = &H1
    MSComm1.Output = bEnd SubPrivate Sub Command8_Click()
    Picture1.Cls
    End SubPrivate Sub Form_Load()
    With MSComm1
    .CommPort = 1 '使用COM1
    .Settings = "9600,N,8,1" '设置通信口参数
    .InBufferSize = 1 '设置接收缓冲区为1字节
    .OutBufferSize = 1 '设置发送缓冲区为1字节
    .InputMode = comInputModeBinary '设置接收数据模式为二进制形式
    .InputLen = 1  '设置Input 一次从接收缓冲读取字节数为1
    .SThreshold = 1 '设置Output 一次从发送缓冲读取字节数为1
    .RThreshold = 1 '设置接收一个字节产生OnComm事件
    .InBufferCount = 0 '清除接收缓冲区.OutBufferCount = 0 '清除发送缓冲区
    .PortOpen = True '打开通信口
    End WithEnd SubPrivate Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent '判断MSComm控件的当前状态
    Dim temp As Variant, buffer() As Byte
        Case comEventOverrun
            Text2.Text = ""
            Text2.SetFocus
            Exit Sub
        Case comEventRxOver
            Text2.Text = ""
            Text2.SetFocus3
            Exit Sub
        Case comEventTxFull
            Text2.Text = ""
            Text2.SetFocus
            Exit Sub
        Case comEvReceive '收到Rthreshold个字节产生的接收事件
            'temp = MSComm1.Input
            'buffer = temp
            'For i = 0 To UBound(buffer)
            's = s & (buffer(i))
            'Next i
            s = AscB(MSComm1.Input)
            Text1.Text = s
            MSComm1.InBufferCount = 0
            RThreshold = 0 '关闭OnComm事件接收
             End Select
    End Sub
    Private Sub Picture1_Click()
    Picture1.Scale (0, 50)-(50, 0)
    Picture1.Line (5, 5)-(5, 50)
    Picture1.Line (5, 5)-(50, 5)
    Picture1.CurrentX = 3:
    Picture1.CurrentY = 50:
    Picture1.Print "Y (。C)"
    Picture1.CurrentX = 43:
    Picture1.CurrentY = 4:
    Picture1.Print "X(ms)"
    End Sub
    Private Sub Timer1_Timer()
    x = x + 0.1
    Picture1.PSet (x, s), RGB(24, 32, 5)
    Picture1.Line (x - 0.5, s)-(x, s)
    If x = 20 Then x = 0
    End Sub
    Private Sub Timer2_Timer()
    T.Text = Format(Now, "yyyy年mm月dd日 ") & WeekdayName(Weekday(Now)) & Format(Now, " hh:mm:ss")
    End Sub