请高手指点下,下面哪里有问提了,数据没办法下至单片机,先多谢了!
'Option Explicit
Public Sub Sendbit(ByVal a As Integer)
If a > 255 Then
a = 255
End If
If a < 0 Then
a = 0
End If
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
Dim mm(0 To 7) As Byte
mm(0) = a
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
If MSComm1.PortOpen = True Then
MSComm1.Output = mm()
Else
MSComm1.PortOpen = True
MSComm1.Output = mm()
End If
End Sub
Public Sub delay(ByVal a As Integer)
For i = 1 To 550000
Next
End Sub
Public Sub bar(ByVal a As Single)
nnn = a * 200
For x = 1 To nnn
Picture1.Line (x, 0)-(x, 1), RGB(0, 0, 200) '进度条
Next
End Sub
Private Sub Combo1_Change()
Dim i As Integer
For i = 1 To 10
Combo1.AddItem Str(i)
Next i
End Sub
Private Sub Combo2_Change()
Dim j As Integer
For j = 1 To 10
Combo2.AddItem Str(j)
Next j
End Sub
Private Sub Combo3_Change()
Dim k As Integer
For k = 1 To 10
Combo3.AddItem Str(k)
Next k
End Sub
Private Sub Combo4_Change()
Dim l As Integer
For l = 0 To 1
Combo4.AddItem Str(l)
Next l
End Sub
Private Sub Command1_Click(Index As Integer)
Picture1.Cls
If Text1.Text = "" Then
Label2.Caption = "文本未编辑!"
Beep
Exit Sub
End If
Label2.Caption = "内码转换中…"
Text2.Text = ""
s = Text1.Text
For i = 1 To Len(s) 'MID从字符串中返回指定数量的字符
If Mid(s, i, 1) <= Chr(&H7F) And Mid(s, i, 1) >= Chr(&H20) Then '返回指定ANSI字符码的字符
ss = ss + "00"
End If
If Mid(s, i, 1) >= Chr(&HA1) And Mid(s, i, 1) >= Chr(&H20) Then
ss = ss + Hex(Asc(Mid(s, i, 1))) '返回字符串首字母的ANSI字符代码
End If
bar (i / Len(s))
Next 'Len(返回字符串中的字符数量,或存储变量所需的字节数
If Len(s) < 6 Then
For ppp = 1 To (6 - Len(s))
ss = ss + "A1A1"
Next
End If
Text2.Text = ss
Label2.Caption = "内码转换结束!"
Picture1.Cls
'Label2.Caption = "下载配置参数…"
On Error GoTo uerror
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
If Val(Combo1.Text) > 10 Or Val(Combo1.Text) < 1 Then
Combo1.Text = 10
End If
If Val(Combo2.Text) > 10 Or Val(Combo2.Text) < 1 Then
Combo2.Text = 5
End If
If Val(Combo3.Text) > 10 Or Val(Combo3.Text) < 1 Then
Combo3.Text = 5
End If
If Combo4.Text <> "阳字" And Combo4.Text <> "阴字" Then
Combo4.Text = "阳字"
End If
refesh = 11 - Val(Combo1.Text)
l_speed = 21 - Val(Combo2.Text) * 2
pause = Val(Combo3.Text)
If Combo4.Text = "阳字" Then
back = 1
ElseIf Combo4.Text = "阴字" Then
back = 0
End If
Picture1.Cls
If Option1.Value = True Then
mode = 1
End If
If Option2.Value = True Then
mode = 2
End If
If Option3.Value = True Then
mode = 3
End If
Sendbit (&HA0)
delay (12)
Sendbit (&HFA)
delay (12)
Sendbit (mode)
Sendbit (refesh)
Sendbit (l_speed)
Sendbit (pause)
Sendbit (back)
hh = (Len(Text2.Text) / 2)
jj = Int(hh / 256)
kk = Int(hh Mod 256)
Sendbit (jj) '校验码1
delay (12)
Sendbit (kk) '校验码2
delay (12)
' Label2.Caption = "下载汉字内码…"
s = Text2.Text
For i = 1 To Len(s) Step 2
ss = "&H" + Mid(s, i, 2)
Sendbit (ss)
delay (12)
bar (i / Len(s)) '进度条显示
Next
Sendbit (&H8F) '下载结束字符
delay (12)
Beep
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Label8.Caption = "下载完成,正在自动重启LED屏!"
Exit Sub
uerror:
Label2.Caption = "COM1被占用或不存在!"
Beep
Exit Sub
Resume Next '程式返回到错误语句的下一句继续
End Sub
Private Sub Command3_Click()
Dim f As String
If Text1.Text = "" Then
Label2.Caption = "文本未编辑!"
Beep
Exit Sub
End If
s = Text1.Text
If Len(s) <= 15 Then
s = Mid(s, 1, 15)
ElseIf Len(s) > 6 Then
s = Mid(s, 1, 15) + "…"
End If
f = s + ".txt"
Open f For Output As #1
Write #1, Form1.Text1.Text
Close #1
Label2.Caption = "当前文本已保存!"
Beep
End Sub
Private Sub Command2_Click(Index As Integer)
Text1.Text = ""
End Sub
Private Sub Command4_Click(Index As Integer)
Dim op As String
Dim rr As String
Text1.Text = ""
CommonDialog1.Filter = "Text _Files (*.txt)|*.txt"
'指定缺省过滤器。
CommonDialog1.FilterIndex = 2
'显示"打开"对话框。
CommonDialog1.ShowOpen
rr = CommonDialog1.FileName
If rr = "" Then
Exit Sub
End If
Text1.Text = ""
Open rr For Input As #1
Do While Not EOF(1)
Input #1, op
Text1.Text = Text1.Text + op
Loop
Close #1
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InputMode = 1
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.Settings = "115200,n,8,1"
MSComm1.PortOpen = True
End Sub
Private Sub Option1_Click()
Option1.Value = True
Option2.Value = Flash
Option3.Value = Flash
End Sub
Private Sub Option2_Click()
Option1.Value = Flash
Option2.Value = True
Option3.Value = Flash
End Sub
Private Sub Option3_Click()
Option1.Value = Flash
Option2.Value = Flash
Option3.Value = True
End Sub
Private Sub Text1_Change()
Label11.Caption = Len(Text1.Text)
End Sub
Private Sub MSComm1_OnComm()
Dim Buffer As Variant
Dim R(0 To 6) As Integer '声明INTEGER数组
Dim t&, j%
Dim R0 As Integer
Dim R1 As Integer
Dim R2 As Integer
Dim R3 As Integer
Dim R4 As Integer
Dim R5 As Integer
R0 = R(0)
R1 = R(1)
R2 = R(2)
R3 = R(3)
R4 = R(4)
R5 = R(5)
Select Case MSComm.CommEvent
Case comEvCD
Case comEvCTS
Case comEvDSR
Case comEvRing
Case comEvReceive
t = GetTickCound()
Do
DoEvents
Loop Until GetTickCount - t > 100
Buffer = MSComm1.Input
j = 0
For il = LBound(Buffer) To UBound(Buffer)
R(j) = Buffer(il)
j = j + 1
Next il
End Select
j = 0
If R0 <> (&HF) Then GoTo re '如果没有收到返回的握手信号,则重新开始
ElseIf R1 <> Not (mode) Then GoTo re '如果第一个设置值不对,则重新开始
ElseIf R2 <> Not (refesh) Then GoTo re '如果第二个设置值不对,则重新开始
ElseIf R3 <> Not (l_speed) Then GoTo re '如果第三个设置值不对,则重新开始
ElseIf R4 <> Not (pause) Then GoTo re '如果第四个设置值不对,则重新开始
ElseIf R5 <> Not (back) Then GoTo re '如果第五个设置值不对,则重新开始
End If
Exit Sub
re:
Sendbit (&HA0)
delay (12)
Sendbit (&HFA)
delay (12)
Sendbit (mode)
Sendbit (refesh)
Sendbit (l_speed)
Sendbit (pause)
Sendbit (back)
hh = (Len(Text2.Text) / 2)
jj = Int(hh / 256) '取整数
kk = Int(hh Mod 256) '取佘数
Sendbit (jj) '总字节数
delay (12)
Sendbit (kk) '总字节数
delay (12)
' Label2.Caption = "下载汉字内码…"
s = Text2.Text
For i = 1 To Len(s) Step 2
ss = "&H" + Mid(s, i, 2)
Sendbit (ss)
delay (12)
bar (i / Len(s)) '进度条显示
Next
Sendbit (&H8F) '下载结束字符
delay (12)
Beep
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
Exit Sub
Resume Next
End Sub |