📄 uart.c
字号:
#include <msp430x12x.h>
#include "uart.h"
#include "main.h"
void uart_org(void)
{
U0CTL|= CHAR;
U0TCTL|= SSEL0; // UCLK = ACLK
UBR00= 0x03; // 32768/9600
UBR10= 0x00;
UMCTL0= 0x4a;
ME2|= UTXE0 + URXE0; // Modulation
IE2|=URXIE0;
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10;
UCTL0&=~SWRST;
IE2|=URXIE0;
/*U0CTL|= CHAR;//8bit 字符长度
UTCTL0|=SSEL0;//外部时钟
UBR00=0xc0;//
UBR10= 0x00;////
UMCTL0= 0x00;//
ME2|=UTXE0+URXE0;//波特率=brclk/(ubr+(M7+M6+....+M0)/8)=7.3728/192=0.0384
IE2|=URXIE0;//
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10;
UCTL0&=~SWRST;
IE2|=URXIE0;*/
}
void UartStr(unsigned char *p)
{
unsigned char i;
for (i=0;*p!=0;i++)//准备要发送的数据
{
while (!(IFG2 & UTXIFG0));// USART0 TX buffer ready?
TXBUF0 =*p++; // RXBUF0 to TXBUF0
while ((UTCTL0 & TXEPT) == 0);
}
_NOP();
}
void Uart_Str(unsigned char number,unsigned char *p)
{
unsigned char i;
for (i=0;i<number;i++)//准备要发送的数据
{
while (!(IFG2 & UTXIFG0));// USART0 TX buffer ready?
TXBUF0 =*p++; // RXBUF0 to TXBUF0
while ((UTCTL0 & TXEPT) == 0);
}
_NOP();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -