• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






uart的問題
#1
新會員
新會員


查看用戶資訊
各位兄台:
我現在有關於rs232接收的問題,我針對Datasheet上的uart模組做設定,但是卻不會動作!!
因此想問問各位先進,是否小弟我哪裡做錯呢?

這個程式是利用rs232從pc端傳送ascii給dspic,然後dspic看是收到哪個按鍵,在選擇亮甚麼led:

謝謝各位兄台的幫忙!!!!

void InitGPIO(void);
void InitUART1(void);
unsigned int InChar(void) ;
//---------------------------------------------------------------------------
unsigned int RxValue;


//***************************************************************************
//*Program Start
//***************************************************************************
void main(void)
{
InitUART1(); // Initialize UART1
InitGPIO();

while(1) // repeat forever
{
RxValue=InChar();
if (RxValue == '1'){ PORTD = 0x000E; }
else if (RxValue == '2'){ PORTD = 0x000C; }
else if (RxValue == '3'){ PORTD = 0x0008; }
else if (RxValue == '4'){ PORTD = 0x0000; }
else if (RxValue == '5'){ PORTD = 0x000A; }
else if (RxValue == '6'){ PORTD = 0x0005; }
else if (RxValue == 0x0000){ PORTD = 0x0004; }
} // end of while forever*/

} // end of main program
//***************************************************************************
//*Initialize
//***************************************************************************
void InitGPIO(void)
{
TRISA = 0xFFFF; // make RA all inputs for SW1-SW4
TRISD = 0x0000; // make RD all output
PORTD = 0x0000;
}
void InitUART1(void)
{
unsigned int baudvalue;
unsigned int U1MODEvalue;
unsigned int U1STAvalue;

CloseUART1();
ConfigIntUART1(
UART_RX_INT_EN & UART_RX_INT_PR6 &
UART_TX_INT_DIS & UART_TX_INT_PR2
);

U1MODEvalue = UART_EN & UART_IDLE_CON &
UART_DIS_WAKE & UART_EN_LOOPBACK &
UART_EN_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT;
U1STAvalue = UART_INT_TX_BUF_EMPTY &
UART_TX_PIN_NORMAL &
UART_TX_ENABLE & UART_INT_RX_CHAR &
UART_ADR_DETECT_DIS &
UART_RX_OVERRUN_CLEAR;


// The BAUDRATE = 9600, FCY is already defined so use
// it as "FCY". Plug into the formula provided in the slides

baudvalue = 48; //FCY/(16*BAUDRATE) - 1 initialize the variable baudvalue
OpenUART1(U1MODEvalue, U1STAvalue, baudvalue);
}

//************************************************************************
//*Uart polling Function
//************************************************************************
unsigned int InChar(void)
{
/**********************************************
* Function: POLLING LOOP * *
**********************************************/
do{

}while(!IFS0bits.U1RXIF);
IFS0bits.U1RXIF=0;
return(U1RXREG);
}

發表於: 2004/12/13 15:29
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... ]

教育訓練中心

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