Re: OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
高級會員
|
請問有先進可以替我解答一下第六篇的疑惑嗎?
感激不盡!!
發表於: 2008/8/28 9:15
|
|||
|
Re: OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
高級會員
|
#include <p18f452.h>
#include <sw_uart.h> #include <usart.h> #include <timers.h> #define count_val 9 //宣告函式原型 void F_Initial_TMR0 (void); //中斷 void timer0_isr (void); //宣告並安排中斷執行程式記憶體位置 #pragma code low_vector=0x18 void low_interrupt (void) { _asm GOTO timer0_isr _endasm } #pragma code #pragma interruptlow timer0_isr void timer0_isr (void) { INTCONbits.TMR0IF = 0; // 清除中斷旗標 WriteTimer0(count_val); // 當將計數器觸 發次數歸零寫入預設值 } void main (void) { OpenUSART( USART_TX_INT_OFF & //Set TXSTA Reg. =0b 0010 0100 USART_RX_INT_ON & //Set RCSTA Reg. =0b 1001 0000 USART_ASYNCH_MODE & //開啟資料接收中斷功能 USART_EIGHT_BIT & USART_SYNC_SLAVE & USART_BRGH_HIGH,207 //BAUD = 4800 ); PIR1bits.RCIF = 0; IPR1bits.RCIP = 0; F_Initial_TMR0(); //初始化設定TIMER0函式 } void F_Initial_TMR0 () { OpenTimer0( TIMER_INT_ON & //使用C18編譯器TIMER函式庫 T0_8BIT & //初始化設定TIMER0 T0_SOURCE_INT & //開啟TIMER0中斷功能 T0_EDGE_RISE & T0_PS_1_1 ); //T0CON=11101000 WriteTimer0(count_val); //相當於TMR0L=count_val } 請問這程式還要改哪邊呢 ? 我是要用 IO + TIMER0 完成 software Uart 的,雖然之前有用時間delay的方式完成,但 是要提高baud的話卻一直卡在1200,所以後來改寫用 IO + 中斷的方式來完成,我是要利用start bit 來啟動INT0中斷後 將Timer打開 9 次將UART訊號送進來再送出去的 ! 可是程式 都沒有跑到中斷哪裡去耶 ?
發表於: 2008/8/27 15:01
|
|||
|
Re: OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
版主
|
第二問題應該可以自 Data Sheet 所提供的公式算出,或參考一下內附的表格驗算一下就知道了。
以前也有討論過: http://www.microchip.com.tw/modules/n ... t_id=21317#forumpost21317 用 baud rate 去搜尋一下。
發表於: 2008/8/27 13:56
|
|||
|
Re: OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
高級會員
|
oh ! 原來我忘記加表頭檔了 ...
Q1解決了 ~ 感謝版主 那 Q2 的問題是 ? 放高速低速的值亦或是baud值呢 ?
發表於: 2008/8/27 13:41
|
|||
|
Re: OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
版主
|
要使用 UART 的函數庫就需要將 UART.H 檔加進來,參考一下範例:
C:/MCC18/doc/periph-lib/USART.htm 裡的說明
2.6 OpenUSART
發表於: 2008/8/27 13:25
|
|||
|
OPENUART 裡面的函數該如何定義
|
||||
---|---|---|---|---|
高級會員
|
void main (void)
{ OpenUSART(USART_TX_INT_OFF & //Set TXSTA Reg. =0b 0010 0100 USART_RX_INT_ON & //Set RCSTA Reg. =0b 1001 0000 USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_SYNC_SLAVE & USART_BRGH_HIGH,16 //BAUD = 4800 ); } 錯誤如下: 'USART_RX_INT_ON' has not been defined 'USART_ASYNCH_MODE' has not been defined 'USART_EIGHT_BIT' has not been defined 'USART_SYNC_SLAVE' has not been defined 'USART_BRGH_HIGH' has not been defined Q1:請問這OPENUART函數該如何下定義 ? Q2:最後的USART_BRGH_HIGH,16 它是要放高速16低速64的數值 還是放我算出來的baud 207 4800
發表於: 2008/8/27 12:39
|
|||
|