[求助]关于编程序发送字符到单片机显示的程序
我编一个发送字符(包括数字、英文大小写字母、汉字)到单片机显示的上位机程序,但调试不出,请大虾们帮助!源程序在下:Private Sub Form_load()
MSComm1.CommPort = 1 '使用串行口1
MSComm1.Settings = "9600,n,8,1"
'波特率9600,奇偶校验无,8位数据,1位停止位
MSComm1.InputLen = 0
'读取接收缓冲区的所有字符
MSComm1.OutBufferSize = 4096
MSComm1.InBufferSize = 4096
'设置接收缓冲区为512字节
MSComm1.InputMode = 1
'设置输入模式为二进制
MSComm1.RThreshold = 1
'每一个字符到接收缓冲区都会触发接收事件
If Not MSComm1.PortOpen = True Then
MSComm1.PortOpen = True
End If '//打开串口
End Sub
Private Sub Command1_Click()
Dim outstring() As Byte
Dim outstring1() As Byte
Dim all(100) As Byte
Dim i As Integer
Dim p() As Byte
Dim str1 As String
Dim srr2 As String
Dim HzFile As String
Dim C1, C2
Dim rec As Integer
Dim Location As Long '汉字在字库中的位置
Dim Hz(0 To 31) As Byte '转换完的32字节的字模数据
Dim Buf1(0 To 31) As Byte '暂存转换过程中的32字节字模数据
Dim TempDestFile As String
TempDestFile$ = App.Path + "\" + "TempDest.txt"
Flag = 0
TotalNum = 0
L = Len(send.Text)
For i = 1 To L
'tmpStr = StrConv(Mid$(send.Text, i, 1), vbWide)
If Asc(Mid$(send.Text, i, 1)) < 0 Then
str1 = Mid$(send.Text, i)
p = str1
C1 = CStr(p(0)) - &HA1 '区内码
C2 = CStr(p(1)) - &HA1 '位内码
rec = C1 * 94 + C2
Location = CLng(rec) * 32 + 1 '该汉字在16*16点阵字库中字模第一个字节的位置
HzFile = App.Path + "\" + "hzk16"
'TempFile = App.Path + "\" + "TempSrc.txt"
Open HzFile For Binary Access Read As #1 '读取该汉字在16点阵字库中的原始字模
Get #1, Location, Hz
Close #1
'以下是将UCDOS字库的存储格式调整为HD61202的规范格式
'For j = 0 To 3
'If j = 0 Then k4 = 14
'If j = 1 Then k4 = 15
'If j = 2 Then k4 = 30
'If j = 3 Then k4 = 31
'For k = 0 To 7
'Bit = &H80
'Bit = byteRight((Bit), (k))
'For i = 0 To 7
'k2 = byteleft(Buf1(j * 8 + k), 1) '整个流程是由低位向高位移动,最后凑成一个字节
'k3 = byteRight((hz(k4 - i * 2) And Bit), 7 - k) '将字节中的某位移到最低位
'k3 = k3 And &H1 '屏蔽掉其余7位
'Buf1(j * 8 + k) = k2 Or k3
'Next i
'Next k
'Next j
'For i1 = 0 To 31 '将调整后的汉字字模再装入原数组
'hz(i1) = Buf1(i1)
'HzAll(LoopAll * 32 + i1) = Buf1(i1)
'Next
'Next LoopAll
'Open TempDestFile For Binary Access Write As #1 '转换结果保存到TempDestFile中
'Put #1, 1, HzAll
'Close #1
'MsgBox "OK!"
'str1 = send.Text
'outstring = str1
Open TempDestFile For Binary Access Write As #2 '转换结果保存到TempDestFile中
Put #2, i, Hz
Close #2
Else
str2 = Mid$(send.Text, i)
outstring1 = str2
Open TempDestFile For Binary Access Write As #2 '转换结果保存到TempDestFile中
Put #2, i, outstring1
Close #2
End If
Next i
Open TempDestFile For Binary Access Write As #2
Get #2, 1, all
Close #2
MSComm1.OutBufferCount = 0
MSComm1.Output = all '发送数据
End Sub
这个程序始终调试不出,请帮助改错!