于是VB与51的通信把我难住了……
问题:VB与单片机串口通信 控制几个LED灯亮前面几个数据都能正常显示LED 灯 但是最后一个数据 单片机收到了就是不按数据点亮LED 求大家帮我看看
51的程序:
#include<reg52.h>
unsigned char flag,a;
unsigned char temp1;
unsigned char temp2;
unsigned char temp3;
unsigned char temp4;
unsigned char temp5,temp6,temp7;
unsigned char num;
void delay(unsigned int t)
{
unsigned int z;
for(z=t;t>0;t--)
{unsigned int j;
for(j=0;j<125;j++)
{}
}
}
void main()
{
TMOD=0x20;//设置定时器1为工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
while(1)
{
if(num==7)
{
ES=0;
P1=temp1;
delay(1000);
P1=temp2;
delay(1000);
P1=temp3;
delay(1000);
P1=temp4;
delay(1000);
P1=temp5;
delay(1000);
P1=temp6;
delay(1000);
P1=temp7;
delay(1000);
}
}
}
void ser() interrupt 4
{
RI=0;
switch (num)
{
case 0:temp1=SBUF;num++;break;
case 1:temp2=SBUF;num++;break;
case 2:temp3=SBUF;num++;break;
case 3:temp4=SBUF;num++;break;
case 4:temp5=SBUF;num++;break;
case 5:temp6=SBUF;num++;break;
case 6:temp7=SBUF;num++;break;
default:break;
}
RI=0;
}
vVB的程序:
Private Sub Command1_Click()
Dim a(0 To 6) As Byte
a(0) = &H7F '1
a(1) = &HBF '2
a(2) = &HDF '3
a(3) = &HEF '4
a(4) = &HF7 '5
a(5) = &HFB '6
a(6) = &H0 '7
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
MSComm1.Output = a
MSComm1.PortOpen = False
End If
End Sub
Private Sub Command2_Click()
MSComm1.OutBufferCount = 0
End Sub
Private Sub Command3_Click()
Dim b(0) As Byte
b(0) = &HFF
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
MSComm1.Output = b
MSComm1.PortOpen = False
End If
End Sub
Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
= 6
MSComm1.OutBufferSize = 512 ' 设置发送缓冲区512Byte
MSComm1.OutBufferCount = 0
End Sub
求高手教教我啊,急