Print a message through EUSART PIC18F45K80

不问归期 提交于 2019-12-02 19:31:24

问题


I am trying to send a message to serial to Docklight but I get a null the whole time. I am using a PIC18F45K80 with XC8 MPLAB X. All seems correct in my code but I guess I am wrong. How can I fix it?

#include <xc.h>
#include "PIC.h"

// INITIAL PIN SETUP

void PIN_MANAGER_Initialize(void)
{
    /**
    LATx registers
    */
    LATE = 0x00;
    LATD = 0x00;
    LATA = 0x00;
    LATB = 0x00;
    LATC = 0x00;

    /**
    TRISx registers
    */
    TRISE = 0x07;
    TRISA = 0x08;
    TRISB = 0x01;
    TRISC = 0b00010000;
    TRISD = 0xEF;

    PORTC = 0b00010010 ;

    /**
    ANSELx registers
    */
    ANCON0 = 0x00;
    ANCON1 = 0x00;

    /**
    WPUx registers
    */
    WPUB = 0x00;
    INTCON2bits.nRBPU = 1; 

}

// INITIAL SETUP SPI

void SPI_Initialize(void)
{

    // SMP Middle; CKE Idle to Active; 
    SSPSTAT = 0x00;

    // SSPEN enabled; WCOL no_collision; CKP Idle:High, Active:Low; SSPM FOSC/4; SSPOV no_overflow; 
    SSPCON1 = 0x30;

    // SSPADD 0; 
    SSPADD = 0x00;
}

// INITIAL SETUP EUSART

void EUSART_Initialize(void)
{

    // ABDOVF no_overflow; TXCKP async_noninverted_sync_fallingedge; BRG16 16bit_generator; WUE disabled; ABDEN disabled; RXDTP not_inverted; 
    BAUDCON1 = 0x08;

    // SPEN enabled; RX9 8-bit; RX9D 0; CREN disabled; ADDEN disabled; SREN disabled; 
    RCSTA1 = 0x80;

    // TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC master_mode; 
    TXSTA1 = 0xA4;

    // 
    SPBRG1 = 0x19;

    // 
    SPBRGH1 = 0x00;
}

void SYSTEM_Initialize(void)
{
    PIN_MANAGER_Initialize();
    SPI_Initialize();
    EUSART_Initialize();
}

void main(void)
{
    int i;
    unsigned char data[] = "HELLO";

    {
        SYSTEM_Initialize();
        while (1)
        {
            for (i=0 ; i < 5; i++)
            {
                while(TXIF == 0);
                TXREG = data[i];
            }
            __delay_ms(25);
        }    
    }
}

I would like to have serial out through pin

#define RSOUT PORTBbits.RB5
#define RSTEST TRISBbits.TRISB5 = 0

as I do not want the Rx to be connected.

来源:https://stackoverflow.com/questions/53223235/print-a-message-through-eusart-pic18f45k80

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!