用VB编制RS-232与AT89C51的程序Private Sub Command1_Click(Index As Integer) ' 发送文件按键 MSComm1.PortOpen = TrueMSComm1.Output = Text1.Text MSComm1.PortOpen = FalseEnd SubPrivate Sub Command2_Click(Index As Integer) ' 接收文件按键 MSComm1.PortOpen = True Text2.Text = MSComm1.Input MSComm1.PortOpen = False End SubPrivate Sub Command3_Click(Index As Integer) ' 结束按键End End Sub Private Sub Form_Load() ' 读入窗口时的初始化 Option1(0).Value = True Option2(0).Value = True End SubPrivate Sub Option1_Click(Index As Integer) ' 选择COM口 Select Case Index Case 0 MSComm1.CommPort = 1 If MSComm1.PortOpen Then MsgBox "对不起,COM1已被占用,请另外选择。" End IfCase 1 MSComm1.CommPort = 2 If MSComm1.PortOpen Then MsgBox "对不起,COM1已被占用,请另外选择。" End If End SelectEnd SubPrivate Sub Option2_Click(Index As Integer) ' 选择波比率 Select Case Index Case 0 MSComm1.Settings = "9600,n,8,1" Case 1 MSComm1.Settings = "2400,n,8,1" Case 2 MSComm1.Settings = "1200,n,8,1" Case 3 MSComm1.Settings = "600,n,8,1" End Select End Sub
MSComm1.PortOpen = TrueMSComm1.Output = Text1.Text
MSComm1.PortOpen = FalseEnd SubPrivate Sub Command2_Click(Index As Integer) ' 接收文件按键
MSComm1.PortOpen = True
Text2.Text = MSComm1.Input
MSComm1.PortOpen = False
End SubPrivate Sub Command3_Click(Index As Integer) ' 结束按键End
End Sub
Private Sub Form_Load() ' 读入窗口时的初始化
Option1(0).Value = True
Option2(0).Value = True
End SubPrivate Sub Option1_Click(Index As Integer) ' 选择COM口
Select Case Index
Case 0
MSComm1.CommPort = 1
If MSComm1.PortOpen Then
MsgBox "对不起,COM1已被占用,请另外选择。"
End IfCase 1
MSComm1.CommPort = 2
If MSComm1.PortOpen Then
MsgBox "对不起,COM1已被占用,请另外选择。"
End If
End SelectEnd SubPrivate Sub Option2_Click(Index As Integer) ' 选择波比率
Select Case Index
Case 0
MSComm1.Settings = "9600,n,8,1"
Case 1
MSComm1.Settings = "2400,n,8,1"
Case 2
MSComm1.Settings = "1200,n,8,1"
Case 3
MSComm1.Settings = "600,n,8,1"
End Select
End Sub