hal_uart.c
来自「该程序在IAR Embedded Workbench for MSP4303.4」· C语言 代码 · 共 30 行
C
30 行
#include "include.h"
//----------------------------------------------------------------------------
// Functions for sending debug strings to a UART. Although the same interfaces
// defined for SPI (USARTn, USCIxn, USI, and bit-bang) could be used for UART,
// only USART0/1 are defined.
//----------------------------------------------------------------------------
void halUARTSetup(void)
{
P2SEL |= 0x010; // P2.4 = USCI_A0 TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x6D; // 1MHz 9600
UCA0BR1 = 0x00; // 1MHz 9600
UCA0MCTL = 4; // Modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
void blastString(char string[], unsigned int len)
{
volatile unsigned int i;
for(i=0;i<len;i++)
{
while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready?
UCA0TXBUF = string[i]; // Output character
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?