请各位帮忙看看vb与单片机的通信问题
以下是我的vb程序:
Private Sub send(outstring, n)
Dim instring As String
MSComm1.CommPort = 1
MSComm1.Settings = "1200,n,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
MSComm1.Output = outstring + Chr(&HD)
MSComm1.InputMode = comInputModeText
Do
DoEvents
Loop Until MSComm1.InBufferCount > = 1
Print "inbuffercount="; MSComm1.InBufferCount
instring = MSComm1.Input
Print "OK,get:"; instring
MSComm1.PortOpen = False
End Sub
Private Sub Command1_Click()
Dim outstring As String
Dim message As String, title As String, default As String
title = "输入窗口"
message = "请输入ASCII码字符"
default = "no input"
Cls
outstring = InputBox(message, title, default)
n = Len(outstring)
Print "outstringlength="; n
Call send(outstring, n)
End Sub
相应的单片机调试程序:
main()
{
inicom(); //初始化
while(1)
{
de=0;
while(RI==0);
RI=0;
de=1;
SBUF=0x56;
while(TI==0);
TI=0;
}
}
预计功能是通过vb送一个数据给单片机,单片机送0x56作为应答信号,但是单片机送来的是乱码,是不是通信过程中数据类型的问题啊,很急,在线等,望各位不吝赐教
发表时间:2006年6月5日16:23:58