PIC16F18876 串口配置失败

PIC16F18876 uart config failing

我正在使用 PIC16F18875 和 XC8 编译器。我是第一次使用 PPS。我已经配置了 UART,但它无法正常工作。频率为8MHz。 我已经设置了输入 PPS 和输出 PPS 模式。

// CONFIG1
#pragma config FEXTOSC = OFF    // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1  // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled)

// CONFIG2
#pragma config MCLRE = ON       // Master Clear Enable bit (MCLR pin is Master Clear function)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF    // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = OFF      // Brown-out reset enable bits (Brown-out reset disabled)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF        // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
#pragma config PPS1WAY = OFF     // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)

// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF       // WDT operating mode (WDT Disabled, SWDTEN is ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC      // WDT input clock selector (Software Control)

// CONFIG4
#pragma config WRT = OFF        // UserNVM self-write protection bits (Write protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
#pragma config LVP = OFF         // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)

// CONFIG5
#pragma config CP = OFF         // UserNVM Program memory code protection bit (Program Memory code protection disabled)
#pragma config CPD = OFF        // DataNVM code protection bit (Data EEPROM code protection disabled)

#include <xc.h>
#include <stdint.h>

void InitUART1(void)
{
    TRISCbits.TRISC6 = 0;
    TRISCbits.TRISC7 = 1;
    RXPPS = 0x17;
    TXPPS = 0x10;
    
    TX1STA = 0X00;
    RC1STA = 0x90;
    BAUD1CON = 0X08;
//    SP1BRGL = 26;        
//    SP1BRGH = 0x00;
    SPBRG = 25;
    TX1STA |= 0X20;
}

void send_char_uart1(uint8_t c)
{
    TX1REG = c;
    while(PIR3bits.TXIF == 0);
}

void send_string_uart1(uint8_t *str)
{
    while(*str != '[=10=]')
    {
        send_char_uart1(*str++);
    }
}

void main(void) {
    OSCCON1 = 0x60;         //
    OSCFRQ = 0x03;          //8 MHZ
    ANSELC = 0X00;
    
    InitUART1();
    
        
    while(1)
    {
            send_char_uart1('s');
    }
    return;
}

我已经设置了输入引脚并尝试保留最少的功能。 在这里,我仅在轮询方法中使用 UART。

在你的配置中,TX pin RC6 所以开关:

TXPPS = 0x16;

0x10 是不正确的值

问题已解决。上面提到的代码 working.Problem 与硬件有关。引脚未正确焊接。