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


Browsing this Thread:   1 Anonymous Users






Re: OPENUART 裡面的函數該如何定義
#7
高級會員
高級會員


查看用戶資訊
請問有先進可以替我解答一下第六篇的疑惑嗎?
感激不盡!!

發表於: 2008/8/28 9:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: OPENUART 裡面的函數該如何定義
#6
高級會員
高級會員


查看用戶資訊
請問一下當OPENUART被執行以後是不是就定義了
1. RX TX 的腳位 ?
2. 模擬硬體 UART的功能 ?
3. 文件中提到的 TXSTA 與 RCSTA 設定是屬於模擬的
亦或是拿硬體的UART暫存器來用 ?
4. 我要 IO + TIMER0 模擬UART的話,那麼我是不是就不要
使用OPENUART函數了 ? 因為它裡面有三個 Delay 的 TX
Half , RX 函數值要去給, 那我還用TIMER0計算幹麻 ?
我是不是就自己定義PORT的輸出入腳位然後掛中斷就好
了 ?

發表於: 2008/8/27 17:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: OPENUART 裡面的函數該如何定義
#5
高級會員
高級會員


查看用戶資訊
#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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: OPENUART 裡面的函數該如何定義
#4
版主
版主


查看用戶資訊
第二問題應該可以自 Data Sheet 所提供的公式算出,或參考一下內附的表格驗算一下就知道了。
以前也有討論過:
http://www.microchip.com.tw/modules/n ... t_id=21317#forumpost21317

用 baud rate 去搜尋一下。

發表於: 2008/8/27 13:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: OPENUART 裡面的函數該如何定義
#3
高級會員
高級會員


查看用戶資訊
oh ! 原來我忘記加表頭檔了 ...
Q1解決了 ~ 感謝版主
那 Q2 的問題是 ? 放高速低速的值亦或是baud值呢 ?

發表於: 2008/8/27 13:41
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: OPENUART 裡面的函數該如何定義
#2
版主
版主


查看用戶資訊
要使用 UART 的函數庫就需要將 UART.H 檔加進來,參考一下範例:
C:/MCC18/doc/periph-lib/USART.htm 裡的說明

2.6         OpenUSART
Open1USART
Open2USART

Function:
    

Configure the specified USART module.

[
color=ff0000]Include:
    

usart.h
:
:
[/
color]

發表於: 2008/8/27 13:25
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


OPENUART 裡面的函數該如何定義
#1
高級會員
高級會員


查看用戶資訊
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
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... ]

教育訓練中心

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