• 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: RS232與終端機溝通不起來,請求幫忙
#8
版主
版主


查看用戶資訊
void High_INT_SER (void)
{
char C_Temp;
if ( DataRdyUSART() )
{
C_Temp = getcUSART(); <-收資料
putcUSART(C_Temp); <-傳資料

}

試著將 C_Temp 送到 Watch Window 下顯示一下所收到的值為多少,這樣就知道你的接收是否正確。

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


Re: RS232與終端機溝通不起來,請求幫忙
#7
高級會員
高級會員


查看用戶資訊
我設中斷觀察完的結果是他執行完
void F_Initial(void);
void F_Enable_High_Interrupts ( void );

void High_INT_SER ( void );

這三段函數以後就停在

void main (void)
{
F_Initial();
F_Enable_High_Interrupts();
while(1); 停在這裡
}
他是在等待中斷
#pragma code High_Interrupt_Vector=0x08
有資料從RS232進來以後繼續執行
void High_INT_SER (void)
{
char C_Temp;
if ( DataRdyUSART() )
{
C_Temp = getcUSART(); <-收資料
putcUSART(C_Temp); <-傳資料

}
}
應該整段程式是沒有問題的,但是為什麼PIC鮑率4800跟終端機4800卻還是溝通不起來 ?? 也應該算是有溝通啦,只是我按鍵盤他會回亂碼給我就是了…

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


Re: RS232與終端機溝通不起來,請求幫忙
#6
版主
版主


查看用戶資訊
有關 ICD2 的使用方式,可以參考 ICD2 使用手冊。

http://www.microchip.com/stellent/idc ... me=en010046&part=DV164005

也有中為簡體版。

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


Re: RS232與終端機溝通不起來,請求幫忙
#5
高級會員
高級會員


查看用戶資訊
嗯 ~ 因為是自學的所以不是很了解如何用斷點設定來判斷錯誤呢 ! 目前是靠學51的經驗去摸的,雖然一直有再等待台北的W401開課,但因專題的關係還真的是頭很大很大 ...

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


Re: RS232與終端機溝通不起來,請求幫忙
#4
版主
版主


查看用戶資訊
那可以用 ICD2 除錯一下,先設一下斷點看一下接收到底收到了什麼資料?

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


Re: RS232與終端機溝通不起來,請求幫忙
#3
高級會員
高級會員


查看用戶資訊
嗯 ~ 我是使用 ICD2 沒錯! 圓圓的那個盒子USB接到電腦電話線接到版子的那個東西 ...

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


Re: RS232與終端機溝通不起來,請求幫忙
#2
版主
版主


查看用戶資訊
基本上 4800bps 的設定值是對的,沒有 ICD2 等除錯工具是很辛苦的,要學好PIC還是要用ICD2 來除錯的。
請問你是用何種工具做燒錄的? 不會是 ICD2 吧!

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


RS232與終端機溝通不起來,請求幫忙
#1
高級會員
高級會員


查看用戶資訊
實驗板:APP001
開發程式:MPLAB IDE v7.30
使用IC:P18F452
實驗需求:
GPRS模組─>RS232->PIC->RS232->電腦終端機
需要設定的鮑率:4800
16M / 4800 = 16*(SPBRG+1)
SPBG = 207 <-覺得很奇怪
目前實驗階段:
PIC <-> RS232 <-> 電腦終端機
程式碼如下:(課本範例宏友PIC18FXX2微控制器原理與實作使用組合與言語C語言)

#include <p18f452.h>
#include <usart.h>

#define BaudRate 207

void F_Initial(void);
void F_Enable_High_Interrupts ( void );

void High_INT_SER ( void );

#pragma code High_Interrupt_Vector=0x08
void High_INT_VEC (void)
{
_asm
goto High_INT_SER
_endasm
}
#pragma code

#pragma interrupt High_INT_SER
void High_INT_SER (void)
{
char C_Temp;
if ( DataRdyUSART() )
{
C_Temp = getcUSART();
putcUSART(C_Temp);

}
}

void main (void)
{
F_Initial();
F_Enable_High_Interrupts();
while(1);
}

void F_Initial(void)
{
TXSTAbits.BRGH = 1;
TXSTAbits.TXEN = 1;
RCSTAbits.CREN = 1;
RCSTAbits.SPEN = 1;
IPR1bits.RCIP = 1;
PIE1bits.RCIE = 1;
SPBRG = BaudRate;
}

void F_Enable_High_Interrupts (void)
{
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
}

以上程式應該只是簡單的PIC對終端機RX收TX傳吧,這是課本測試範例,照道理說我把程式裡面鮑率調成4800燒進去實驗板以後然後拿RS232的線跟電腦連接以後,我應該是可以在終端機打什麼回傳什麼給我的,可是卻發生以下情形 ~
1, 終端機跟PIC一樣都設定成4800開始打字試傳,可傳的卻都是亂碼回來
2, 若將終端機這邊每秒傳輸位元調成115200就可以打什麼傳什麼回來,但矛
盾的是我PIC這邊應該是4800的呀!4800怎麼可以跟115200通勒 ?
3, 幾次下來我覺得不對於是我放空IC進去跑,卻依然可以弄出來上敘1&2的敘述 ?? 那什麼情形哩 ? 難道我程式沒有燒進去 ? 可是這也不合理阿,我改燒簡單的跑馬燈都可以燒進去,RS232的範例程式也只是課本的我連動都沒動過呀?請問是哪裡有錯誤呢 ?

發表於: 2008/8/11 16:27
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... ]

教育訓練中心

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