• 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傳送資料之問題(利用Hi-Tech C)
#4
版主
版主


查看用戶資訊
我的想法是,既然 TxD 是輸出當然相對的 I/O 腳 RC6 就要設為輸出,而 RxD RC5 就設為輸入腳。就像 PWM 輸出一樣,I/O 腳沒設成輸出 PWM 會動作但不會有 PWM 輸出。

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


Re: 請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
#3
新會員
新會員


查看用戶資訊
謝謝j大的回應

根據您的說法
我有疑問如下

我參考PIC16F873a之spec.
其中有一段話是這樣的
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be
set in order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter
看起來應是將TRISC7,TRISC6設為1
請問SPEC當中所謂的set
是將暫存器設為1?
或是設為0?

因為我是新手
懇請j大或其他先進幫助我
謝謝

發表於: 2008/7/31 17:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
#2
資深會員
資深會員


查看用戶資訊
你好:
應該TRISC6=0; //RC6=output
Thanks.

發表於: 2008/7/31 16:19
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
#1
新會員
新會員


查看用戶資訊
各位先進好

小弟為初學者,採用PIC16F873a進行專案製作
程式主體如下:

#define BAUD 9600 (設定Baud Rate)
#define FOSC 4000000

unsigned char btBuf[9];
unsigned int i=0;
unsigned int nXOR=0;
int nSN;
int DIVIDER;

// port B:input from MCU (將port B之所有接點設定為輸入端)

TRISB0=1;
TRISB1=1;
TRISB2=1;
TRISB3=1;
TRISB4=1;
TRISB5=1;
TRISB6=1;
TRISB7=1;


//set up UART(暫存器設定)

TRISC6=1; //set RC6
TRISC7=1; //set RC7
SPEN=1;
TXEN=1; //transmitted enable
CREN=1; //received enable
BRGH=1;
SYNC=0;
DIVIDER=FOSC/(16*BAUD)-1;
SPBRG=DIVIDER;

// active input

if(RB0==0)
{
nSN++;
btBuf[0]=0x80+(0x0F&nSN);
btBuf[1]=0x7F;
btBuf[2]=0x00;
btBuf[3]=0x32;
btBuf[4]=0x04;
btBuf[5]=0xAD;
btBuf[6]=0x00;
btBuf[7]=0x00;
btBuf[8]=0x01;

for(i=0,nXOR=0;i<9;i++)
{
nXOR^=btBuf[i];
}

btBuf[9]=nXOR;
for(i=0;i<=9;i++)
{
TXIF=1;
TXREG=btBuf[i]; //transmitted data
(將資料透過UART之相關暫存器TXREG傳出)
TXIF=0;
}
}

我利用MPLAB SIM進行模擬
可見TXREG收到btBuf[i]
但利用示波器及其他輔助工具
發現UART(TX)並無任何信號傳出
我已確認接線無誤
請各位先進指導
到底原因為何?
我的程式錯在哪裏
應該如何修正?

謝謝各位先進的幫忙

發表於: 2008/7/31 15:13
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... ]

教育訓練中心

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