Re: 請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
|
||||
---|---|---|---|---|
版主
|
我的想法是,既然 TxD 是輸出當然相對的 I/O 腳 RC6 就要設為輸出,而 RxD RC5 就設為輸入腳。就像 PWM 輸出一樣,I/O 腳沒設成輸出 PWM 會動作但不會有 PWM 輸出。
發表於: 2008/8/1 9:34
|
|||
|
Re: 請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
|
||||
---|---|---|---|---|
資深會員
|
你好:
應該TRISC6=0; //RC6=output Thanks.
發表於: 2008/7/31 16:19
|
|||
|
請教各位先進關於UART傳送資料之問題(利用Hi-Tech C)
|
||||
---|---|---|---|---|
新會員
|
各位先進好
小弟為初學者,採用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
|
|||
|