要注意同时添加fputc和fputs两个函数。
int fputc(int ch, FILE *f)
{
// if (ch == ‘\n’)
//{
// send_char(0x0d) ;
//}
send_char(ch); //从串口发出数据
return (ch);
}
int fputs(const char *_ptr, register FILE *_fp)
{
uint16_t i, len;
len = strlen(_ptr);
for(i=0; i<len; i++)
{
EUSCI_A_UART_transmitData(EUSCI_A0_BASE,(unsigned char)_ptr[i] );
// while (!EUSCI_A_UART_getInterruptStatus(EUSCI_A0_BASE,
// EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG));
// EUSCI_A_CMSIS(EUSCI_A0_BASE)->IFG |= (EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG);
}
return len;
}
补充:EUSCI_A_UART_transmitData函数说明
//*****************************************************************************
//
//! \brief Transmits a byte from the UART Module.Please note that if TX
//! interrupt is disabled, this function manually polls the TX IFG flag waiting
//! for an indication that it is safe to write to the transmit buffer and does
//! not time-out
//!
//! This function will place the supplied data into UART transmit data register
//! to start transmission
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param transmitData data to be transmitted from the UART module
//!
//! Modified bits of \b UCAxTXBUF register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_transmitData(uint16_t baseAddress,
uint8_t transmitData);