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


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 這次是軟體UART問題請教
#12
新會員
新會員


查看用戶資訊
[quote]
sam_fang 寫道:
已抓取成功,程式寫法最下面所示:
使用:4MHz,Baud:2400。
只是對於下列公式有疑問
因為如果使用4MHz,Baud:2400,DelayTXBitUART
計算出需要delay 405.16 Cycle才是2400 Baud。
可是程式的i卻得設定為24
(看程式應該是i=1是一個cycle吧???)
還請高手解惑
謝謝
(另外什麼是DelayRXHalfBitUART和DelayRXBitUART的意思)
---------------------------------------------------------
因為for loop跑一圈並不是一個機械週期
他啟動需要17個週期
+1需要16個
因此forloop的機械週期數公式為
17+16i (i是forloop的迴圈數)

(405-17)/16 = 24.25

所以其實你還需在forloop後加上4次Nop();

發表於: 2009/8/19 16:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#11
版主
版主


查看用戶資訊
參照:
另外什麼是DelayRXHalfBitUART和DelayRXBitUART的意思


ㄧ個是 Delay 接收速度的一半時間,另一個是 Delay 一個位元的接收時間。
接收是 delay 0.5 bit time 後開始取樣接收,每次取樣都延遲 1 bit 時間。

到底程式延遲了多少時間請自行用 MPLAB SIM 底下的 STOPWATCH 去量一下真正的時間。用算的可能會錯。

發表於: 2008/10/27 9:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#10
初級會員
初級會員


查看用戶資訊
已抓取成功,程式寫法最下面所示:
使用: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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#9
初級會員
初級會員


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


Re: 這次是軟體UART問題請教
#8
初級會員
初級會員


查看用戶資訊
參照:

Ryang 寫道:
參照:

sam_fang 寫道:
Ryang 前輩你好
W401的文件我有找過。
第五章是在教硬體方式的串列傳輸
第六章是教I2C
我都找不到軟體UART的範例。

另外指令USART是否是指硬體?
UART指令是否就是指軟體?


PS:沒學過C語言,也不太會寫單晶片。所以得有範例參考才會修改編寫 ><


第六章的練習 6-1 就有 UART 的程式。I2C 為主,而 UART 為輔功能為自 RS-232 收近資料。


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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#7
初級會員
初級會員


查看用戶資訊
謝謝 Ryang 版主

當我把usart和timer0的問題解決後,我會努力研究第六章的範例。

非常謝謝您

發表於: 2008/10/18 16:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#6
版主
版主


查看用戶資訊
參照:

sam_fang 寫道:
Ryang 前輩你好
W401的文件我有找過。
第五章是在教硬體方式的串列傳輸
第六章是教I2C
我都找不到軟體UART的範例。

另外指令USART是否是指硬體?
UART指令是否就是指軟體?


PS:沒學過C語言,也不太會寫單晶片。所以得有範例參考才會修改編寫 ><


第六章的練習 6-1 就有 UART 的程式。I2C 為主,而 UART 為輔功能為自 RS-232 收近資料。

發表於: 2008/10/18 8:58
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#5
初級會員
初級會員


查看用戶資訊
謝謝 leowang 指教。
不過組語我看不懂 =.=..

而且現在也不太會用C18內崁組語。

發表於: 2008/10/18 0:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 這次是軟體UART問題請教
#4
新會員
新會員


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


Re: 這次是軟體UART問題請教
#3
初級會員
初級會員


查看用戶資訊
Ryang 前輩你好
W401的文件我有找過。
第五章是在教硬體方式的串列傳輸
第六章是教I2C
我都找不到軟體UART的範例。

另外指令USART是否是指硬體?
UART指令是否就是指軟體?


PS:沒學過C語言,也不太會寫單晶片。所以得有範例參考才會修改編寫 ><

發表於: 2008/10/17 13:46
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... ]

教育訓練中心

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