求助!vb上位机与单片机通信
目的:上位机发送一个数据给单片机,单片机将这个数据+1后返回给上位机现象:发送正常,返回时不论发送是几返回总是49
谁能帮忙看看,那里的问题???
下面是我vb代码:
Private Sub Command1_Click()
Dim outbyte(0) As Byte
Dim number As Integer
number = Val(Text1.Text)
outbyte(0) = CByte(number)
MSComm1.Output = outbyte
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
Unload Me
End Sub
Private Sub Form_Load()
Form1.AutoRedraw = True
= 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0 ' 设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.RThreshold = 1 ' 每个字符到接收缓冲区都触发接收事件
MSComm1.InputMode = comInputModehexadecimal '采用二进制传输
MSComm1.PortOpen = True
Text1 = ""
Text2 = ""
End Sub
Private Sub MSComm1_OnComm()
Dim BytReceived(0) As Byte
Dim strBuff As Variant
Select Case
Case comEvReceive
strBuff = MSComm1.InBufferCount
BytReceived(0) = Asc(strBuff)
Text2 = BytReceived(0)
End Select
End Sub
下面是我c的代码:
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar a,flag;
void main()
{
TMOD=0X20;
TL1=0XFD;
TH1=0XFD;
SCON=0X50;
TR1=1;
EA=1;
ES=1;
while(1)
{
if(flag)
{
ES=0;
flag=0;
SBUF=a+1;
while(!TI);
TI=0;
ES=1;
}
}
}
void xx() interrupt 4
{
RI=0;
a=SBUF;
P0=0XF0|a;
flag=1;
}