打印

课程设计求助~~~~~~~单片机高手进

[复制链接]
1502|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ljm191571524|  楼主 | 2012-7-3 17:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个是题目要求:串行通信:(1)单片机不断读取p0口所接8个独立按键状态,并通过串行口送至
上位计算机,计算机上运行自编的软件将p0口8个状态用只是灯方式显示,
(2)上位机软件界面设有8个开关点击不同按键,按键开关状态用串行口发至单片机
单片机根据收到信息将8个开关状态通过p2口所接8个LED显示出来
这个是VB程序。
Private Sub Command1_Click()
Dim num As Integer
Dim b(0) As Byte
num = 0
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command2_Click()
Dim num As Integer
Dim b(0) As Byte
num = 1
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command3_Click()
Dim num As Integer
Dim b(0) As Byte
num = 2
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command4_Click()
Dim num As Integer
Dim b(0) As Byte
num = 3
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command5_Click()
Dim num As Integer
Dim b(0) As Byte
num = 4
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command6_Click()
Dim num As Integer
Dim b(0) As Byte
num = 5
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command7_Click()
Dim num As Integer
Dim b(0) As Byte
num = 6
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Command8_Click()
Dim num As Integer
Dim b(0) As Byte
num = 7
b(0) = CByte(num)
MSComm1.OutBufferCount = 0
MSComm1.Output = b
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
End Sub

Private Sub Timer1_Timer()
Dim i As Integer
Dim j As Integer
Dim Buffer As String
Dim Rsend() As Byte
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
Buffer = MSComm1.Input
Rsend() = Buffer
For j = 0 To UBound(Rsend)
If Len(Hex(Rsend(j))) = 1 Then
Data = Data & "0" & Hex(Rsend(j))
Else
Data = Data & Hex(Rsend(j))
End If
Next
Dim s As String
Dim a As Integer
s = Data
a = Val("&H" & s)
i = CInt(a)
Data = ""
MSComm1.InBufferCount = 0
If i = 0 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 1 Then
Shape1.FillColor = vbYellow
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 2 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbYellow
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 3 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbYellow
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 4 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbYellow
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 5 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbYellow
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 6 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbYellow
Shape7.FillColor = vbBlack
Shape8.FillColor = vbBlack
ElseIf i = 7 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbYellow
Shape8.FillColor = vbBlack
ElseIf i = 8 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape4.FillColor = vbBlack
Shape5.FillColor = vbBlack
Shape6.FillColor = vbBlack
Shape7.FillColor = vbBlack
Shape8.FillColor = vbYellow
End If
End Select
End Sub
下面是串行通信的程序:
ORG 23H   
LJMP COMPRO        
ORG  40H               
MAIN:   MOV TMOD,#20H   
MOV TL1,#0FDH
MOV TH1,#0FDH
MOV PCON,#00H
MOV SCON,#0D0H
        CLR RI
        CLR TI        
SETB TR1  
SETB EA
SETB ES        
M1:     MOV A,P0
        MOV R0,#00H
JNB ACC.0 , M2
MOV R0,#01H
SJMP M9
M2:     JNB ACC.1  ,M3
MOV R0,#02H
SJMP M9
M3:     JNB ACC.2,M4
MOV  R0,#03H
SJMP M9
M4:     JNB  ACC.3,M5
MOV R0,#04H
SJMP  M9
M5:     JNB  ACC.4,M6
MOV R0,#05H
SJMP M9
M6:     JNB ACC.5,M7
MOV R0,#05H
SJMP  M9
M7:     JNB ACC.6,M8
MOV R0,#07H
SJMP M9
M8:     JNB ACC.7,M9
MOV R0,#08H
M9:     MOV A,R0
MOV SBUF,A
SJMP M1
COMPRO: JNB TI,RECV     
CLR TI            
       SJMP RETURN
RECV:   CLR RI        
MOV A,SBUF
        MOV DPTR ,#TAB
MOVC A,@A+DPTR
MOV P2,A
SJMP RETURN
TAB:    DB 01H ,02H,04H,08H,10H,20H,40H,80H
RETURN: NOP
        RETI   
END
一共有两个问题:
1.为什么P2.0初始会亮
2.为什么说通信的时候有溢出

相关帖子

沙发
NE5532| | 2012-7-3 22:36 | 只看该作者
问题从单片机程序开始找,而不是来找后台,否则你将劳而无获。

使用特权

评论回复
板凳
dlyt_test001| | 2012-7-5 10:36 | 只看该作者
1、要看单片机的程序。

使用特权

评论回复
地板
一路向南| | 2012-7-13 00:54 | 只看该作者

使用特权

评论回复
5
wukunshan| | 2012-7-13 12:13 | 只看该作者
单片机程序用的是汇编?哎。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

0

粉丝