8051 藍芽傳輸問題 |
尚未結案
|
good321
一般會員 ![]() ![]() 發表:6 回覆:6 積分:2 註冊:2006-11-10 發送簡訊給我 |
小弟在做以vb控制 藍芽傳輸 8051動作的專題
電腦vb程式=>藍芽發出(虛擬comport)~~~~(UART)~~~~>藍芽接收=>8051=>動作 然後按8051按鈕回給電腦,但是電腦無法判讀,不知道哪一個環節出錯了 有請高手可以幫忙解決 --------------------------------- 8051程式 LED8 equ P2 Btn0 equ P1.0 Btn1 equ P1.1 Btn2 equ P1.2 Btn3 equ P1.3 org 00h jmp start org 23h jmp comINT start: setb EA ;啟動中斷 setb ES ;啟動接收 mov SCON,#01110000b ;SM0=0&SM1=1=>mode1 SM2=1,REN=1=>啟動接收 mov TMOD,#00100000b ;timer1工作於模式2 mov TL1,#0fdh ;鮑率=9600 mov TH1,#0fdh ;自動載入值 mov a,#7fh setb TR1 ;啟動計時器1 main: mov LED8,a call delay rr a call CheckBtn jmp main CheckBtn: jnb Btn0,sendA jnb Btn1,sendB jnb Btn2,sendC jnb Btn3,sendD jmp endCheck SendA: jnb Btn0,$ mov a,#041h mov SBUF,a jnb TI,$ jmp endCheck SendB: jnb Btn1,$ mov a,#042h mov SBUF,a jnb TI,$ jmp endCheck SendC: jnb Btn2,$ mov a,#043h mov SBUF,a jnb TI,$ jmp endCheck SendD: jnb Btn3,$ mov a,#044h mov SBUF,a jnb TI,$ jmp endCheck endCheck: clr TI ret comINT: mov a,SBUF xrl a,#41h jz isA ;------------------- mov a,SBUF xrl a,#42h jz isB ;------------------- mov a,SBUF xrl a,#43h jz isC ;------------------- mov a,SBUF xrl a,#44h jz isD ;------------------- isA: mov a,#01111111b jmp EOI isB: mov a,#00111111b jmp EOI isC: mov a,#00011111b jmp EOI isD: mov a,#00001111b jmp EOI EOI: clr RI reti delay: mov R5,#10 End ---------------------------- ---------------------------- VB程式 Imports System.IO.Ports Public Class Form1 Dim baud, baud1, baud2, baud3 As Integer Dim com, com1, com2 As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load com1 = "COM4" com2 = "COM10" baud1 = "4800" baud2 = "9600" baud3 = "19200" Call InitSerialPort() lebelSendMsg.Visible = False lebelReceMsg.Visible = False Timer1.Enabled = True ButtonRece.Enabled = False ButtonSend.Enabled = False End Sub Private Sub InitSerialPort() SerialPort1.PortName = com1 SerialPort1.BaudRate = baud1 SerialPort1.DataBits = 8 SerialPort1.Parity = 0 SerialPort1.StopBits = 1 SerialPort1.Open() End Sub Private Sub mnuCOM1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCOM1.Click, mnuCOM2.Click On Error GoTo err Dim pt As String Timer1.Enabled = False pt = sender.ToString Select Case pt Case "COM4" mnuCOM1.Checked = True mnuCOM2.Checked = False com = com1 lblcomport.Text = "com4" Case "COM10" mnuCOM1.Checked = False mnuCOM2.Checked = True com = com2 lblcomport.Text = "com10" End Select If SerialPort1.IsOpen Then SerialPort1.Close() End If SerialPort1.PortName = com SerialPort1.Open() Timer1.Enabled = True Exit Sub err: MsgBox("無法打開通訊埠,可能沒有這個埠或已開啟!", MsgBoxStyle.Critical, "開啟錯誤") If SerialPort1.IsOpen Then SerialPort1.Close() End If SerialPort1.PortName = "COM4" SerialPort1.Open() mnuCOM1.Checked = True mnuCOM2.Checked = False Timer1.Enabled = True End Sub Private Sub B4800_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4800.Click, B9600.Click, B19200.Click Dim item As String item = sender.ToString Select Case item Case baud1 B4800.Checked = True B9600.Checked = False B19200.Checked = False Case baud2 B4800.Checked = False B9600.Checked = True B19200.Checked = False Case baud3 B4800.Checked = False B9600.Checked = False B19200.Checked = True Case Else item = baud2 End Select SerialPort1.BaudRate = item End Sub Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click SerialPort1.Write(UCase(TBSend.Text)) TBSend.Text = Nothing End Sub Private Sub ButtonRece_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRece.Click On Error GoTo RECerr TBRece.Text &= SerialPort1.ReadExisting lblRD.BackColor = Color.GreenYellow lblSD.BackColor = Color.OldLace Exit Sub RECerr: MsgBox("無法接收資料,請檢查連線。", MsgBoxStyle.Critical, "接收錯誤") End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If SerialPort1.CDHolding Then lblDCD.BackColor = Color.GreenYellow Else lblDCD.BackColor = Color.OldLace End If If SerialPort1.CtsHolding Then lblCTS.BackColor = Color.GreenYellow Else lblCTS.BackColor = Color.OldLace End If If SerialPort1.DsrHolding Then lblDSR.BackColor = Color.GreenYellow Else lblDSR.BackColor = Color.OldLace End If If SerialPort1.RtsEnable Then lblRTS.BackColor = Color.GreenYellow Else lblRTS.BackColor = Color.OldLace End If If SerialPort1.DtrEnable Then lblDTR.BackColor = Color.GreenYellow Else lblDTR.BackColor = Color.OldLace End If If Len(TBSend.Text) <> 0 Then lebelSendMsg.Text = "緩衝區有資料尚未傳送。" lebelSendMsg.Visible = Not lebelSendMsg.Visible ButtonSend.Enabled = True Else lebelSendMsg.Visible = False ButtonSend.Enabled = False End If If SerialPort1.BytesToRead <> 0 Then lebelReceMsg.Text = "有資料輸入,要求讀取。" lebelReceMsg.Visible = True ButtonRece.Enabled = True Else lebelReceMsg.Text = Nothing lebelReceMsg.Visible = False ButtonRece.Enabled = False End If End Sub Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click TBRece.Text = Nothing End Sub Private Sub lblSD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSD.Click End Sub End Class |
aki
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:30 回覆:696 積分:755 註冊:2004-01-15 發送簡訊給我 |
問題: (1)你所附的文字檔好像是亂碼耶! (2)你所畫的流程式單向(1-way)的. ===================引 用 good321 文 章=================== 小弟在做以vb控制 藍芽傳輸 8051動作的專題 電腦vb程式=>藍芽發出(虛擬comport)~~~~(UART)~~~~>藍芽接收=>8051=>動作 然後按8051按鈕回給電腦,但是電腦無法判讀,不知道哪一個環節出錯了 有請高手可以幫忙解決 --------------------------------- 8051程式 LED8 equ P2 Btn0 equ P1.0 Btn1 equ P1.1 Btn2 equ P1.2 Btn3 equ P1.3 org 00h jmp start org 23h jmp comINT start: setb EA ;啟動中斷 setb ES ;啟動接收 mov SCON,#01110000b ;SM0=0&SM1=1=>mode1 SM2=1,REN=1=>啟動接收 mov TMOD,#00100000b ;timer1工作於模式2 mov TL1,#0fdh ;鮑率=9600 mov TH1,#0fdh ;自動載入值 mov a,#7fh setb TR1 ;啟動計時器1 main: mov LED8,a call delay rr a call CheckBtn jmp main CheckBtn: jnb Btn0,sendA jnb Btn1,sendB jnb Btn2,sendC jnb Btn3,sendD jmp endCheck SendA: jnb Btn0,$ mov a,#041h mov SBUF,a jnb TI,$ jmp endCheck SendB: jnb Btn1,$ mov a,#042h mov SBUF,a jnb TI,$ jmp endCheck SendC: jnb Btn2,$ mov a,#043h mov SBUF,a jnb TI,$ jmp endCheck SendD: jnb Btn3,$ mov a,#044h mov SBUF,a jnb TI,$ jmp endCheck endCheck: clr TI ret comINT: mov a,SBUF xrl a,#41h jz isA ;------------------- mov a,SBUF xrl a,#42h jz isB ;------------------- mov a,SBUF xrl a,#43h jz isC ;------------------- mov a,SBUF xrl a,#44h jz isD ;------------------- isA: mov a,#01111111b jmp EOI isB: mov a,#00111111b jmp EOI isC: mov a,#00011111b jmp EOI isD: mov a,#00001111b jmp EOI EOI: clr RI reti delay: mov R5,#10 End ---------------------------- ---------------------------- VB程式 Imports System.IO.Ports Public Class Form1 Dim baud, baud1, baud2, baud3 As Integer Dim com, com1, com2 As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load com1 = "COM4" com2 = "COM10" baud1 = "4800" baud2 = "9600" baud3 = "19200" Call InitSerialPort() lebelSendMsg.Visible = False lebelReceMsg.Visible = False Timer1.Enabled = True ButtonRece.Enabled = False ButtonSend.Enabled = False End Sub Private Sub InitSerialPort() SerialPort1.PortName = com1 SerialPort1.BaudRate = baud1 SerialPort1.DataBits = 8 SerialPort1.Parity = 0 SerialPort1.StopBits = 1 SerialPort1.Open() End Sub Private Sub mnuCOM1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCOM1.Click, mnuCOM2.Click On Error GoTo err Dim pt As String Timer1.Enabled = False pt = sender.ToString Select Case pt Case "COM4" mnuCOM1.Checked = True mnuCOM2.Checked = False com = com1 lblcomport.Text = "com4" Case "COM10" mnuCOM1.Checked = False mnuCOM2.Checked = True com = com2 lblcomport.Text = "com10" End Select If SerialPort1.IsOpen Then SerialPort1.Close() End If SerialPort1.PortName = com SerialPort1.Open() Timer1.Enabled = True Exit Sub err: MsgBox("無法打開通訊埠,可能沒有這個埠或已開啟!", MsgBoxStyle.Critical, "開啟錯誤") If SerialPort1.IsOpen Then SerialPort1.Close() End If SerialPort1.PortName = "COM4" SerialPort1.Open() mnuCOM1.Checked = True mnuCOM2.Checked = False Timer1.Enabled = True End Sub Private Sub B4800_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4800.Click, B9600.Click, B19200.Click Dim item As String item = sender.ToString Select Case item Case baud1 B4800.Checked = True B9600.Checked = False B19200.Checked = False Case baud2 B4800.Checked = False B9600.Checked = True B19200.Checked = False Case baud3 B4800.Checked = False B9600.Checked = False B19200.Checked = True Case Else item = baud2 End Select SerialPort1.BaudRate = item End Sub Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click SerialPort1.Write(UCase(TBSend.Text)) TBSend.Text = Nothing End Sub Private Sub ButtonRece_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRece.Click On Error GoTo RECerr TBRece.Text &= SerialPort1.ReadExisting lblRD.BackColor = Color.GreenYellow lblSD.BackColor = Color.OldLace Exit Sub RECerr: MsgBox("無法接收資料,請檢查連線。", MsgBoxStyle.Critical, "接收錯誤") End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If SerialPort1.CDHolding Then lblDCD.BackColor = Color.GreenYellow Else lblDCD.BackColor = Color.OldLace End If If SerialPort1.CtsHolding Then lblCTS.BackColor = Color.GreenYellow Else lblCTS.BackColor = Color.OldLace End If If SerialPort1.DsrHolding Then lblDSR.BackColor = Color.GreenYellow Else lblDSR.BackColor = Color.OldLace End If If SerialPort1.RtsEnable Then lblRTS.BackColor = Color.GreenYellow Else lblRTS.BackColor = Color.OldLace End If If SerialPort1.DtrEnable Then lblDTR.BackColor = Color.GreenYellow Else lblDTR.BackColor = Color.OldLace End If If Len(TBSend.Text) <> 0 Then lebelSendMsg.Text = "緩衝區有資料尚未傳送。" lebelSendMsg.Visible = Not lebelSendMsg.Visible ButtonSend.Enabled = True Else lebelSendMsg.Visible = False ButtonSend.Enabled = False End If If SerialPort1.BytesToRead <> 0 Then lebelReceMsg.Text = "有資料輸入,要求讀取。" lebelReceMsg.Visible = True ButtonRece.Enabled = True Else lebelReceMsg.Text = Nothing lebelReceMsg.Visible = False ButtonRece.Enabled = False End If End Sub Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click TBRece.Text = Nothing End Sub Private Sub lblSD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSD.Click End Sub End Class |
good321
一般會員 ![]() ![]() 發表:6 回覆:6 積分:2 註冊:2006-11-10 發送簡訊給我 |
|
johnpage
初階會員 ![]() ![]() 發表:0 回覆:79 積分:40 註冊:2004-08-07 發送簡訊給我 |
|
good321
一般會員 ![]() ![]() 發表:6 回覆:6 積分:2 註冊:2006-11-10 發送簡訊給我 |
|
johnpage
初階會員 ![]() ![]() 發表:0 回覆:79 積分:40 註冊:2004-08-07 發送簡訊給我 |
|
good321
一般會員 ![]() ![]() 發表:6 回覆:6 積分:2 註冊:2006-11-10 發送簡訊給我 |
|
johnpage
初階會員 ![]() ![]() 發表:0 回覆:79 積分:40 註冊:2004-08-07 發送簡訊給我 |
|
good321
一般會員 ![]() ![]() 發表:6 回覆:6 積分:2 註冊:2006-11-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |