无法将字节传输到Docklight EUSART

时间:2018-11-14 08:53:03

标签: c pic

这是我的代码:

#include <xc.h>
#include "PIC.h"
#include <stdio.h>
#include <stdlib.h>
#include <pic18f45k80.h>

#define _XTAL_FREQ 16000000

// 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)
{

    TRISCbits.TRISC6 = 0 ;

    TXSTA1bits.SYNC = 0 ;
    TXSTA1bits.TX9 = 0 ;
    TXSTA1bits.TXEN = 1 ;

    RCSTA1bits.RX9 = 0 ;
    RCSTA1bits.CREN = 1 ;
    RCSTA1bits.SPEN - 1 ;

    BAUDCON1bits.BRG16 = 0 ;
    TXSTA1bits.BRGH = 0 ;
    SPBRG1 = 25 ;
}


void BASIC(void)
{
    while (TXSTA1bits.TRMT == 0) {}
    TXREG1 = "C" ;
}

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


void main(void)
{
    SYSTEM_Initialize();

    while (1)
    {
        __delay_ms (25);
        BASIC();
    }
}

我正在使用PIC18F45K80 MCU和XC8 MPLAB X IDE。我要设置的波特率为38400。我想发送一个字节(字符C)。当我从docklight上传代码后,得到的只是NUL,然后重复出现NUL。很快我想打印一句话。我相信TX的输出应该是EUSART1。

0 个答案:

没有答案