全瓷牙肩台预备图解:VB 串行通讯的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/06 02:28:21
如题,用51系列单片机与PC机进行串行通讯,单片机一次只能收一个字节,
不好意思刚才一下子就点击发送了
具体的问题是这样的,我做一个关于串口通讯的问题,就是单片机每发一次申请PC几就送出相应的字节
这是我的源程序,单片机单步运行的时候能够正常收发,但是一旦两边都运行就不能正常收发了。
Select Case .CommEvent
Case comEvReceive
redata = .Input
c = Mid(redata, 1, 1)
If c = "A" Then
MC.Output = "a"
ElseIf c = "F" Then
MC.Output = Mid(outstring, 2, 1)
ElseIf c = "G" Then MC.Output = Mid(outstring, 3, 1)
ElseIf c = "H" Then MC.Output = Mid(outstring, 4, 1)
ElseIf c = "I" Then MC.Output = DIRECT
ElseIf c = "Z" Then
i = 0
Label5.Caption = "发送成功!"
inputtext.Enabled = True
start.Enabled = True
forward.Enabled = True
backward.Enabled = True
Else
End If
End Select
End With
end sub
只是一些片段,整个程序单步运行,一点问题都没有。波特率没有问题,用串口调试工具与单片机也可以正常通讯。

Select Case .CommEvent
Case comEvReceive
redata = .Input
.InBufferSize = 1
.OutBufferSize = 1
c = Mid(redata, 1, 1)
c = UCase(c)
Select Case c
Case "A"
.Output = "a"
Case "F"
.Output = Mid(outstring, 2, 1)
Case "G"
.Output = Mid(outstring, 3, 1)
Case "H"
.Output = Mid(outstring, 4, 1)
Case "I"
.Output = Mid(outstring, 5, 1)
Case "Z"
i = 0
Label5.Caption = "发送成功!"
inputtext.Enabled = True
start.Enabled = True
forward.Enabled = True
backward.Enabled = True
End Select

End Select

End With
End Sub