[問題] 判斷SBUF接收內容

看板C_and_CPP作者 (RJ)時間10年前 (2014/04/24 11:05), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) keil_c 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 如何正確判斷SBUF裡的內容 然後做相對應的程式碼 餵入的資料(Input): 預期的正確結果(Expected Output): 搭配超級終端機 按下電腦鍵盤W 做程式一 若不是W鍵 則進入程式二 錯誤結果(Wrong Output): 無論按下哪顆按鍵 都只會執行同個程式 判斷式 if(SBUF = 'W')功能一 else 功能二 .. => 永遠執行程式一 程式碼(Code):(請善用置底文網頁, 記得排版) #include <at89x51.h> #include <stdio.h> void delay_ms(unsigned int ms); define uchar unsigned char void UART_init (unsigned int bps) ; void delay (int); void delay(int msec) { int i = 1000; while(msec--){ while(i--); } } void UART_init (unsigned int bps) { SCON = 0x50; TMOD |= 0x20; REN = 1; TH1 = TL1 = 255 - (28800 / bps); // Fosc = 11.0592MHz IE |= 0x90; //EA = 1 TR1 = 1; } void UART_get_char(void) interrupt 4 using 1 { if(RI==1){ RI = 0; if(SBUF == "W"){ 功能一; }else{ 功能二 } }} void main() { UART_init(9600); while(1) delay(1); } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.18.60.134 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1398308756.A.D81.html

04/24 21:49, , 1F
'w'
04/24 21:49, 1F

04/24 21:53, , 2F
我搞錯了別理會...
04/24 21:53, 2F

05/30 11:57, , 3F
當你接受到w時你要吧 SBUF清掉不然都會一直執行 程式
05/30 11:57, 3F
文章代碼(AID): #1JM7-Ks1 (C_and_CPP)