hal_uart.c
来自「这写C源代码是MSP430单片机的应用程序」· 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; // 调制
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE; // 使能 USCI_A0 接收中断
}
void blastString(char string[], unsigned int len)
{
volatile unsigned int i;
for(i=0;i<len;i++)
{
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = string[i];
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?