Fw: [2010] 8051與VB通訊的資料去回不同

看板Visual_Basic作者 (貝纳頌)時間14年前 (2012/03/07 16:07), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 Electronics 看板 #1FLnNG6Z ] 作者: Deltaguita (貝纳頌) 看板: Electronics 標題: [問題] 8051與VB通訊的資料去回不同 時間: Wed Mar 7 16:01:17 2012 請教一下各位前輩 小弟正在弄一個透過VB2010(PC)-RS232-8051 資料去回的實習 以便將來我監控資料 目前可以用VB把資料傳過去,也可以把資料傳回來 可是傳過去的資料沒有辦法正確的傳回來 例如我傳送1 回來是g(113) 傳送2 回來是r(114) b 194 c 195 可以請問 問題是出在哪個環節嗎? 300P幣答謝! VB CODE: ********************變數定義**************************** Dim i As Integer Dim aa As Integer = 0 Dim send_data As String Dim input As Integer = 0 Dim receive_data As String Dim Ctr As Control Dim BRx(256) As char ********************************************************* receive ********************************************************* Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick For Me.i = 0 To 255 'BRX CLEAR BRx(i) = 0 Next receive_data = SerialPort1.BytesToRead If receive_data = 0 Then Exit Sub If receive_data > 256 Then receive_data = 256 End If For Me.j = 1 To receive_data BRx(input) = SerialPort1.ReadByte aa = BRx(input) txt_receive.Text = txt_receive.Text & Chr(BRx(input)) input = input + 1 Next input = 0 Timer1.Enabled = False For Me.i = 0 To 255 BRx(i) = 0 Next Timer1.Interval = 500 Timer1.Enabled = True *********************************************************************** *******************************SEND************************************ Private Sub send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles send.Click send_data = 0 For Me.i = 0 To Len(txtSend.Text) - 1 send_data = Mid(txtSend.Text, 1 + i, 1) Me.SerialPort1.Write(send_data) Call delay(90000) Next i End Sub 8051 CODE /*------------------------------------------------ 串口中斷程式 ------------------------------------------------*/ void UART_SER (void) interrupt 4 //串列中斷服務程式 { unsigned char Temp; //定義臨時變數 if(RI) //判斷是接收中斷產生 { RI=0; //標誌位元清零 Temp=SBUF; //讀入緩衝區的值 P1=Temp; //把值輸出到P1口,用於觀察 SBUF=Temp; //把接收到的值再發回電腦端 } if(TI) //如果是發送標誌位元,清零 TI=0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.251.222.115 ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: Deltaguita (60.251.222.115), 時間: 03/07/2012 16:07:20 ※ 編輯: Deltaguita 來自: 60.251.222.115 (03/07 16:08) ※ 編輯: Deltaguita 來自: 60.251.222.115 (03/07 16:12) ※ 編輯: Deltaguita 來自: 60.251.222.115 (03/07 16:16)
文章代碼(AID): #1FLnSvij (Visual_Basic)