PIC18F4431上的UART和内部时钟

时间:2015-09-16 07:51:46

标签: c embedded pic mplab

我在MPLABX上使用XC8在PIC18F4431上编写了一个程序。它根据它在UART上接收的值发送PWM(它是DMX,250000kbits / s)。该程序工作,它使用外部时钟(10MHz石英)运行。

配置位:

// CONFIG1H
#pragma config OSC = HSPLL      // Oscillator Selection bits (HS oscillator, PLL enabled (clock frequency = 4 x FOSC1))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switchover bit (Internal External Switchover mode disabled)

UART配置:

void Config_UART1 (void)
{
    BAUDCTLbits.BRG16 = 0;  // Générateur 8 bits
    SPBRG = 9; // Vitesse de transmission 250kbits/seconde
    TXSTAbits.BRGH = 1; //Haute vitesse
    TXSTAbits.SYNC = 0; // Asynchronous mode
    RCSTAbits.SPEN = 1; // Serial port enabled
    RCSTAbits.RX9 = 1; //Selects 9-bit reception
    RCSTAbits.CREN = 1; // Enables receiver
}

为了改进我的程序,我想使用内部时钟(8MHz)。我更改了配置位和UART配置;我的程序不起作用:你知道为什么吗?

配置位:

    // CONFIG1H
#pragma config OSC = IRC      // Oscillator Selection bits (Internal oscillator block, CLKO function on RA6 and port function on RA7)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switchover bit (Internal External Switchover mode disabled)

振荡器配置:

void Config_Oscill (void)
{
    OSCCONbits.IDLEN = 0b0; // Run mode enabled; CPU core is clocked in power-managed modes
    OSCCONbits.IRCF = 0x7; // 8 MHz (8 MHz source drives clock directly)
    OSCCONbits.SCS = 0x02; // Internal oscillator block (RC modes)
}

UART配置:

void Config_UART1 (void)
{
    BAUDCTLbits.BRG16 = 0;  // Générateur 8 bits
    SPBRG = 1; // Vitesse de transmission 250kbits/seconde
    TXSTAbits.BRGH = 1; //Haute vitesse
    TXSTAbits.SYNC = 0; // Asynchronous mode
    RCSTAbits.SPEN = 1; // Serial port enabled
    RCSTAbits.RX9 = 1; //Selects 9-bit reception
    RCSTAbits.CREN = 1; // Enables receiver
}

0 个答案:

没有答案