Browsing this Thread:
1 Anonymous Users
|
dsPIC30f4011 UART 接收的問題
|
|
新會員
Joined
: 2009/8/18 11:40 最後登入時間
: 2010/2/27 22:20
Group:
註冊會員
Level : 1 HP : 0 / 0 MP : 0 / 30 EXP : 2
|
各位大大你們好 因為我是第一次接觸dsPIC及RS232 所以我有些問題想請教大家
我利用XP內建的超級終端機輸出datas至dsPIC 然後dsPIC讀取datas後,作判斷的動作
那我要如何讀取dsPIC接收到的datas呢? (我是設定接收8-bit , no parity,然後我是利用U2RX腳位) command = U2RXREG & 0xFF 是這樣寫嗎?
看書上寫說 RS232傳輸是傳ASCII碼 那我從超級終端機輸出 1 那我接收到的datas會是 ASCII碼十六進制 0x31 嗎?
我從XP內建的超級終端機輸出 1 然後在dsPIC裡作判斷後,使LED燈亮或滅 以下是我寫的code 請各位大大幫我看一下 哪裡有錯?? 謝謝各位大大
#include "p30F4011.h" #include <stdio.h> #include <math.h> #include <timer.h> #include <uart.h> #define FCY 29491200 // Fosc = 7.3728 MHz, XT_PLL16
_FOSC(CSW_FSCM_OFF & XT_PLL16) ; _FWDT(WDT_OFF) ; _FBORPOR(PBOR_OFF & MCLR_EN & PWMxH_ACT_HI & PWMxL_ACT_HI) ; _FGS(CODE_PROT_OFF) ;
void Init_UART2(void); unsigned char command ; #define LED LATDbits.LATD0
void __attribute__((__interrupt__)) _U2RXInterrupt (void) { command = U2RXREG & 0xFF; IFS1bits.U2RXIF = 0 ; }
int main(void) { Init_UART2(); TRISDbits.TRISD0 = 0 ; while(1) { if (command == 0x31) LED = 0; else LED = 1; } }
void Init_UART2(void) { U2BRG = 0x00BF ; U2MODE = 0x8000 ; U2STA = 0x0000 ; return; }
發表於: 2010/2/8 21:49
|
|
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.