• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






dsPIC30f4011 UART 接收的問題
#1
新會員
新會員


查看用戶資訊
各位大大你們好
因為我是第一次接觸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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







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.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------