線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:930
推到 Plurk!
推到 Facebook!

接收問題...

缺席
inboy
一般會員


發表:1
回覆:0
積分:0
註冊:2005-08-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-06 12:23:33 IP:140.122.xxx.xxx 未訂閱
我用bcb寫一個rs232的發送端,每次丟出以"#"開頭的字串,可是reChar本應收到35值,但卻都收到00的值,實在想不出來錯在哪,請各位高手不吝指教..    #include "nios.h" #include  #include #include "excalibur.h" #define SUCCESS 1 #define FAILURE 0 int ind = 0; int i=0; char command[4]; int stage = 0; int total_comm = 0; typedef struct{ np_uart *uart; char rxChar; }UARTISRContext; UARTISRContext gC = {0, -1}; void emptyArray() { int i; for(i=0; i<4; i ) command[i] = 0; } //*************************************************** int rGetChar(void) { int result; if(gC.rxChar >= 0) { result = gC.rxChar; gC.rxChar = -1; } else result = nr_uart_rxchar(0); return result; } void InterruptServiceRoutine(int context) { UARTISRContext *c = (UARTISRContext *)context; int status; int rxChar; status = c->uart->np_uartstatus; rxChar = c->uart->np_uartrxdata; c->uart->np_uartstatus = 0; // clear the interrupt condition if(status & np_uartstatus_rrdy_mask ) { if(stage == 0) { nr_pio_showhex(rxChar); nr_delay(800); if(rxChar == 35) { nr_pio_showhex(169); nr_delay(800); stage = 1; command[ind] = (char)rxChar; ind =1; } } else if(stage ==1) { command[ind] = (char)rxChar; ind =1; nr_pio_showhex(164); nr_delay(800); if(rxChar == 64) { nr_pio_showhex(169); nr_delay(800); total_comm = ind; ind = 0; if((command[0] == 35) && (command[total_comm-1] == 64)) { nr_delay(800); nr_pio_showhex(160); } stage = 0; } } } c->rxChar = rxChar; } void EnableUartInterrupt(void) { gC.uart = (np_uart *)na_uart_0; nr_installuserisr(na_uart_0_irq,InterruptServiceRoutine,(long)&gC); { np_uart *uart = na_uart_0; uart->np_uartcontrol = np_uartcontrol_irrdy_mask; } } int main(void) { int s; EnableUartInterrupt(); emptyArray(); while((s = rGetChar()) != 27) { } return 0; }

版主


發表:261
回覆:2302
積分:1667
註冊:2005-01-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-06 18:10:51 IP:61.70.xxx.xxx 未訂閱
PO程式碼請縮排.不知如何做請參考版規. 請修改配合, 謝謝!
------
-------------------------------------------------------------------------
走是為了到另一境界,停是為了欣賞人生;未走過千山萬水,怎知生命的虛實與輕重!?
derrenbol1
中階會員


發表:5
回覆:113
積分:93
註冊:2004-12-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-07 17:35:49 IP:210.202.xxx.xxx 未訂閱
To inboy : 由你的程式看來, 不像是給PC用的程式, 所以我覺得你收到0是 應該的. 你確定你的"中斷"有執行?
系統時間:2024-07-03 13:17:26
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!