Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
版主
|
參照:
另外什麼是DelayRXHalfBitUART和DelayRXBitUART的意思 ㄧ個是 Delay 接收速度的一半時間,另一個是 Delay 一個位元的接收時間。 接收是 delay 0.5 bit time 後開始取樣接收,每次取樣都延遲 1 bit 時間。 到底程式延遲了多少時間請自行用 MPLAB SIM 底下的 STOPWATCH 去量一下真正的時間。用算的可能會錯。
發表於: 2008/10/27 9:26
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
已抓取成功,程式寫法最下面所示:
使用:4MHz,Baud:2400。 只是對於下列公式有疑問 因為如果使用4MHz,Baud:2400,DelayTXBitUART 計算出需要delay 405.16 Cycle才是2400 Baud。 可是程式的i卻得設定為24 (看程式應該是i=1是一個cycle吧???) 還請高手解惑 謝謝 (另外什麼是DelayRXHalfBitUART和DelayRXBitUART的意思) --------------------------------------------------------- DelayTXBitUART Delay for: ((((2*Fosc) / (4*baud)) + 1) / 2) - 12 cycles DelayRXHalfBitUART Delay for: ((((2*Fosc) / (8*baud)) + 1) / 2) - 9 cycles DelayRXBitUART Delay for: ((((2*Fosc) / (4*baud)) + 1) / 2) - 14 cycles -------------------------------------------------------------- 程式 #define Nop() {_asm nop _endasm} int i; void DelayRXHalfBitUART(void) { for(i=0;i<15;i++) Nop(); } void DelayRXBitUART(void) { for(i=0;i<4;i++) Nop(); } void DelayTXBitUART(void) { for(i=0;i<24;i++) Nop(); } void main ( void ) { char data; //configure software UART OpenUART(); while( 1 ) { WriteUART (0x55); //bounce it back } }
發表於: 2008/10/24 17:20
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
目前compile成功了,參考之前文章,少設了一些設定期
只是我用4MHZ,鮑率設2400 可是這樣寫,卻抓不到值。都只是抓0x00 我算出來是405.16cycle.... ----------------------------------------------------------------- #define Nop() {_asm nop _endasm} int i; void DelayRXHalfBitUART(void) { for(i=0;i<405;i++) Nop(); } void DelayRXBitUART(void) { for(i=0;i<405;i++) Nop(); } void DelayTXBitUART(void) { for(i=0;i<0x195;i++) Nop(); } void main ( void ) { char data; // configure software UART OpenUART(); while( 1 ) { //data = ReadUART(); //read a byte WriteUART (0x66); //bounce it back } ---------------------------------------------------
發表於: 2008/10/23 17:35
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
參照:
Ryang版主,您好。 看了第六章的6-1範例,那個是用硬體函數做控制嗎? 因為我看了,"hlpC18Lib"的範例,如下所示: ---------------------------------------------------------------- #include <p18C452.h> #include <sw_uart.h> void main( void ) { char data; // configure software UART OpenUART(); while( 1 ) { data = ReadUART(); //read a byte WriteUART( data ); //bounce it back } } --------------------------------------------------------------------- 但我在Compile時會發生,錯誤訊息如下所示: Error - could not find definition of symbol 'DelayRXHalfBitUART' in file 'openuart.O'. -------------------------------------------------------------------- 找不到能使用軟體函數的方法, 因為打算一組用硬體函數,另一組用軟體函數。 做雙uart控制 =.=..
發表於: 2008/10/23 14:30
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
謝謝 Ryang 版主
當我把usart和timer0的問題解決後,我會努力研究第六章的範例。 非常謝謝您
發表於: 2008/10/18 16:03
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
版主
|
參照:
第六章的練習 6-1 就有 UART 的程式。I2C 為主,而 UART 為輔功能為自 RS-232 收近資料。
發表於: 2008/10/18 8:58
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
謝謝 leowang 指教。
不過組語我看不懂 =.=.. 而且現在也不太會用C18內崁組語。
發表於: 2008/10/18 0:27
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
新會員
|
軟體UART...我想應該是以GPIO是收送UART的訊號
簡單的說就是一根IO設為INPUT當RX 另一根IO設為output當TX 若以baud-rate 9600,8,n,1來說 一個start bit+8bits+一個stop bit=10 bits 所以每送一筆資料就需1040ms(每個bit 為104us) 這部分最好是以ASM來寫以確保時間的準確 以下是TX的範例 ;號後的數字是該行的指令週期(cycle) ;////////////////////////////// ;//Funciton:F_SEND_CODE ;//12PC508 ;//OSC= 4Mhz 內部振盪 ;//9600,8,n,1 ;//Tx_data....要送出去的DATA(GPIO2) ;/////////////////////////////// F_SEND_CODE MOVWF Tx_data ; BCF GPIO,2 ;1 SEND "START BIT" MOVLW D'30' ;1 CALL DLY_1XuS ;94 DELAY 5x18+4=94 NOP MOVLW 08H ;1 MOVWF TIME2 ;1 SEND_1Loop CLRWDT 1 C C RRF Tx_data,1 ;1 =0 =1 BTFSC STATUS,0 ;┐6uS 2 1 GOTO SEND_2Loop ;│ 2 NOP ;│ 1 BCF GPIO,2 ;│ ----- 1 GOTO SEND_3Loop ;│ 2 SEND_2Loop BSF GPIO,2 ;│ --------- 1 NOP ;│ 1 NOP ;┘ 1 SEND_3Loop CLRWDT ;1 NOP NOP MOVLW D'27' ;1 CALL DLY_1XuS ;84 DELAY 5x16+4=84 CALL DLY_5uS ;4 DECFSZ TIME2,1 ;1 GOTO SEND_1Loop ;2 SEND "NEXT BIT" CALL DLY_5uS NOP NOP BSF GPIO,2 ;1 MOVLW D'30' ;1 SEND "STOP BIT" CALL DLY_1XuS ;94 DELAY 5x18+4=94 NOP NOP RETLW 00H ;2 DLY_1XuS MOVWF TIME1 DLY_1X1 DECFSZ TIME1,1 GOTO DLY_1X1 DLY_5uS: RETLW 00H
發表於: 2008/10/17 16:30
|
|||
|
Re: 這次是軟體UART問題請教
|
||||
---|---|---|---|---|
初級會員
|
Ryang 前輩你好
W401的文件我有找過。 第五章是在教硬體方式的串列傳輸 第六章是教I2C 我都找不到軟體UART的範例。 另外指令USART是否是指硬體? UART指令是否就是指軟體? PS:沒學過C語言,也不太會寫單晶片。所以得有範例參考才會修改編寫 ><
發表於: 2008/10/17 13:46
|
|||
|