参考资料:https://wenku.baidu.com/view/7c9fdc3e1ed9ad51f11df207.html
1.功能描述——控制LED的亮灭
(1)通过设备管理器设置端口(右击属性,端口设置—>高级),然后选择相匹配的端口
(2)运行LED控制系统.exe,点击打开串口,再点击打开按钮(向单片机发送信号1),单片机上的小灯亮起,同时界面上的灯泡变绿,最后,点击关闭按钮(向单片机发送信号2),单片机上的小灯熄灭。
2.VB上位机程序
Dim buff(0) As Byte
Private Sub Command1_Click()
If Command1.Caption = "打开" Then
buff(0) = &H1
If (MSComm1.PortOpen = True) = True Then
MSComm1.Output = buff
Shape1.BackColor = RGB(0, 255, 0)
Command1.Caption = "关闭"
End If
Else
buff(0) = &H2
If (MSComm1.PortOpen = True) = True Then
MSComm1.Output = buff
Shape1.BackColor = RGB(222, 222, 222)
Command1.Caption = "打开"
End If
End If
End Sub
Private Sub Command2_Click()
If Command2.Caption = "打开串口" Then
Command2.Caption = "关闭串口"
Shape2.BackColor = RGB(0, 255, 0)
MSComm1.CommPort = Combo1.ListIndex + 1
MSComm1.PortOpen = True
Else
C