PC机(上位机)VB程序如下:
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 8
End SubPrivate Sub MSComm1_OnComm() '接收
Dim indata
Dim arr() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
    Case comEvReceive
        indata = MSComm1.Input
        arr() = indata
        Label1(0).Caption = arr(0) & arr(1) '用户号
        Select Case arr(2)
            Case 0 '正常
                Label1(1).Caption = "正常"
            Case 1 '异常
                Label1(1).Caption = "异常"
        End Select
        Label1(2).Caption = arr(3) * 10 + arr(4) + arr(5) / 10 '温度
        Select Case arr(6)
            Case 0 '心率正常
                Label1(3).Caption = "心率正常"
            Case 1 '心动过快
                Label1(3).Caption = "心动过快"
            Case 2 '心动过缓
                Label1(3).Caption = "心动过缓"
            Case 4 '心律不齐
                Label1(3).Caption = "心律不齐"
        End Select
        Label1(4).Caption = arr(7) '心搏频率值
End Select
For i = 0 To UBound(arr)
    Text1 = Text1 & " " & Hex(arr(i))
Next
End Sub0、1两个字节来表示用户号。在销售时给每个用户设置一个专门的用户号,并将用户的信息存入相应数据库中。发送数据时连同用户号一起发送,接收方可凭此区分不同用户,并查看该用户的个人信息。(16进制)
     字节2表示温度的状态,0000 0000表示温度值为正常,0000 0001表示异常。(二进制)
     字节3,4,5分别表示温度值的十位、个位和小数位。(ascii码).
     字节6表示脉搏的状态,0000 0000表示心率正常,0000 0001表示心动过快,0000 0010表示心动过缓,0000 0100表示心律不齐。(二进制)
     字节7表示心搏频率值。(十六进制) 为什么调试的时候 label显示的不是汉字 心率正常之类的 却是数字 温度状态 脉搏状态没有显示出来

解决方案 »

  1.   

    只是把单片机发送到 PC,pc不需要返回什么命令。
    建立了五个label 分别显示 用户号 温度状态 温度值 脉搏状态 脉搏值
    还有一个text 里面显示十六进制的数据 所有的8个字节的数据您说的通信协议不就是这个么?
    9600,n,8,1。
      

  2.   

    LZ:按你昨晚叙述的数据帧约定,代码修改如下:
    Option Explicit
    Private Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
        MSComm1.InputMode = comInputModeBinary '二进制接收
        MSComm1.PortOpen = True
        MSComm1.InBufferCount = 0
        MSComm1.RThreshold = 8
        MSComm1.InputLen = 0
    End SubPrivate Sub MSComm1_OnComm() '接收
        Dim indata
        Dim arr() As Byte
        Dim i As Integer
        Select Case MSComm1.CommEvent
            Case comEvReceive
                indata = MSComm1.Input
                arr() = indata
                Label1(0).Caption = Chr(arr(0)) & Chr(arr(1)) '用户号
                Select Case arr(2)
                    Case 0 '正常
                        Label1(1).Caption = "正常"
                    Case 1 '异常
                        Label1(1).Caption = "异常"
                End Select
                Label1(2).Caption = Val(Chr(arr(3))) * 10 + Val(Chr(arr(4))) + Val(Chr(arr(5))) / 10 '温度
                Select Case arr(6)
                    Case 0 '心率正常
                        Label1(3).Caption = "心率正常"
                    Case 1 '心动过快
                        Label1(3).Caption = "心动过快"
                    Case 2 '心动过缓
                        Label1(3).Caption = "心动过缓"
                    Case 4 '心律不齐
                        Label1(3).Caption = "心律不齐"
                End Select
                Label1(4).Caption = arr(7) '心搏频率值
        End Select
        'For i = 0 To UBound(arr)
        '    Text1 = Text1 & " " & Hex(arr(i))
        'Next
    End Sub
      

  3.   

    Option Explicit
    Private Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
        MSComm1.InputMode = comInputModeBinary '二进制接收
        MSComm1.PortOpen = True
        MSComm1.InBufferCount = 0
        MSComm1.RThreshold = 8
        MSComm1.InputLen = 0
    End SubPrivate Sub MSComm1_OnComm() '接收
        Dim indata
        Dim arr() As Byte
        Dim i As Integer
        Select Case MSComm1.CommEvent
            Case comEvReceive
                MSComm1.RThreshold = 0
                indata = MSComm1.Input
                arr() = indata
                Label1(0).Caption = Chr(arr(0)) & Chr(arr(1)) '用户号
                Select Case arr(2)
                    Case 0 '正常
                        Label1(1).Caption = "正常"
                    Case 1 '异常
                        Label1(1).Caption = "异常"
                End Select
                Label1(2).Caption = Val(Chr(arr(3))) * 10 + Val(Chr(arr(4))) + Val(Chr(arr(5))) / 10 '温度
                Select Case arr(6)
                    Case 0 '心率正常
                        Label1(3).Caption = "心率正常"
                    Case 1 '心动过快
                        Label1(3).Caption = "心动过快"
                    Case 2 '心动过缓
                        Label1(3).Caption = "心动过缓"
                    Case 4 '心律不齐
                        Label1(3).Caption = "心律不齐"
                End Select
                Label1(4).Caption = arr(7) '心搏频率值
                  MSComm1.RThreshold = 8
        End Select
        'For i = 0 To UBound(arr)
        '    Text1 = Text1 & " " & Hex(arr(i))
        'Next
    End Sub