1

在 MPLAB X IDE v5.10 中,我使用的是 dspic33ep512mu810 微控制器。

我有以下一段 C 代码:

#include "xc.h"

_FOSCSEL(FNOSC_FRCPLL) //INT OSC with PLL (always keep this setting)
_FOSC(OSCIOFNC_OFF & POSCMD_NONE) //disable external OSC
_FWDT(FWDTEN_OFF) //watchdog timer off
_FICD(JTAGEN_OFF & 0b11); //JTAG debugging off

void UART2TX(char c) {
    if (U2STAbits.UTXEN == 0)
        U2STAbits.UTXEN = 1; //enable UART TX

    while (U2STAbits.UTXBF == 1); //if buffer is full, wait
    U2TXREG = c;
}

int main(void) {

    //setup internal clock for 80MHz/40MIPS
    //7.37/2=3.685*43=158.455/2=79.2275
    CLKDIVbits.PLLPRE = 0; // PLLPRE (N2) 0=/2 
    PLLFBD = 41; //pll multiplier (M) = +2
    CLKDIVbits.PLLPOST = 0; // PLLPOST (N1) 0=/2
    while (!OSCCONbits.LOCK); //wait for PLL ready

    _U2TXIF = 0;
    _U2TXIE = 0;
    _U2RXIF = 0;
    _U2RXIE = 0;
    //setup UART
    U2BRG = 85; //86@80mhz, 85@79.xxx=115200
    U2MODE = 0; //clear mode register
    U2MODEbits.BRGH = 1; //use high percison baud generator
    U2STA = 0; //clear status register

    //DSPIC33EP512MU810T-I/PT, RP96 as TX pin
    RPOR7bits.RP96R = 3; //

    while (1) {
        UART2TX('H'); 
    }
 }

我正在尝试通过 UART2 以 115200 的波特率发送“H”,但它不起作用。

4

1 回答 1

0

您必须切换 RF0 (RP96) aus 输出:

TRISFbits.TRISF0 = 0;     //make F0 an onput

而且您必须将 RFO 切换为数字:

ANSELFbits.ANSF0 = 0;      //make F0 digital
于 2019-01-18T07:58:01.747 回答