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


Browsing this Thread:   1 Anonymous Users






Re: 請問各位大大有關uart接收資料的問題
#9
中級會員
中級會員


查看用戶資訊
你的主程序和中斷可能有一些問題。原因是主程序和中斷有可能在同一個時候都要用到tx。我建議你先別用中斷來接收。

大致上如下:
main()
{
    ...
    ...

    while (
1)
    {
        if (
RCIF)
        {
            
TXREG RCREG;
        }
    }
}


你用的應該是hi-tech picc吧。我不懂hi-tech的編程器。所以無法給你完整的程序。自己查一下syntax和加進錯誤處理吧!



發表於: 2006/9/21 5:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問各位大大有關uart接收資料的問題
#8
新會員
新會員


查看用戶資訊
樓上的大大感謝您熱心的回覆,我已經把INTCON=0B11000000
但是在超級終端機傳字元時還是沒有反應(同時我也用示波器量RX那支角,也沒有電位的改變)。到底是那裡出問題呢?
以下是我的程式,請各位大大幫我看一下,謝謝!
----------------------------------------------------------------------
#include <pic.h>

__CONFIG (UNPROTECT & DEBUGEN & MCLRDIS & BOREN & PWRTEN & INTIO & WDTDIS & IESODIS & FCMDIS);//

#define ClearScreen PutStr("\x1B[2J");

void InitPIC16F913(void);
void PutStr(const char *data);
void Show(void);
void interrupt isr_rx(void);

/*******************************************/

main()
{
InitPIC16F913();
ClearScreen
while(1)
{
Show();
while(1)
{
if(!RB0)//按RB0傳"TXOK"
{
PutStr("TXOK");
while(!RB0);
};
};
}

}

/*******************************************/

void InitPIC16F913(void)
{
OPTION = 0x07;
OSCCON=0b01100101;
OSCTUNE=0b00000000;
TRISA = 0b00000000;
TRISC = 0b10000000;
TXSTA = 0b00100100;
RCSTA = 0b10010000;
SPBRG = 25; //9600,4Mhz,high speed baud rate
PIE1=0b00100000;
INTCON=0b11000000;
};

/*******************************************/

void Show(void)
{
PutStr("\x1B[1;1H"); //goto col:1,row:1
PutStr("hello!!");
PutStr("\x1B[2;1H");
};

/*******************************************/

void PutStr(const char *data)
{
do
{
while(!(TXSTA & 0x02));
TXREG = *data;
} while( *data++ );
};

/*******************************************/

void interrupt isr_rx(void)//若有收到字元將收到的字元傳出
{
unsigned char tempres0;

tempres0=RCREG;
if(OERR || FERR)
CREN=0;
RCIF=0;

while(!(TXSTA & 0x02));
TXREG = tempres0;
};
----------------------------------------------------------------

發表於: 2006/9/14 14:21
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問各位大大有關uart接收資料的問題
#7
中級會員
中級會員


查看用戶資訊
參照:

justin 寫到:
INTCON=0b10000000;


你只是啓動GLOBAL中斷,外設中斷還沒有被啓動!

發表於: 2006/9/13 17:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問各位大大有關uart接收資料的問題
#6
新會員
新會員


查看用戶資訊
使用PIC 16F913 UART的功能連接PICDEM 2 PLUS DEMO BOARD與PC的超級終端機,可以很順利的從PIC 傳資料給PC並在超級終端機秀出來,但是始終無法從PC端傳送資料給PIC。超級終端機是否可在連線時直接由按KEYBOARD的方式傳送字元給COM PORT呢?
設定如下
PIC16F913
__CONFIG (UNPROTECT & DEBUGEN & MCLRDIS & BOREN & PWRTEN & INTIO & WDTDIS & IESODIS & FCMDIS);
OPTION = 0x07;
OSCCON=0b01100101;
OSCTUNE=0b00000000;
TRISA = 0b11111111;
TRISC = 0b10000000;
ADCON1 = 0x00;
TXSTA = 0x24;
RCSTA = 0x90;
SPBRG = 25; BAUD RATE 9600
PIE1=0b00100000;
INTCON=0b10000000;
但始終我的RCIF都不會等於1,到底是那裡出問題呢?請各位大大幫幫忙,感激不盡!

發表於: 2006/9/13 11:47
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... ]

教育訓練中心

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