历史上的今天
今天是:2024年10月17日(星期四)
2019年10月17日 | msp430f5529 uart pwm adc
2019-10-17 来源:eefocus
//msp430f5529的串口使用程序使用示例
//--------------------------------------------- uart 头文件 -------------------------------------------------------------//
#ifndef UART_H_
#define UART_H_
#include #include "config.h" //默认为115200 void USCIA0_Init(void); void USCIA0_SendChar(u8 c); u8 USCIA0_ReceiveChar(void); void USCIA0_SendString(u8 *str); void USCIA1_Init(void); void USCIA1_SendChar(u8 c); u8 USCIA1_ReceiveChar(void); void USCIA1_SendString(u8 *str); //void Uart1_Send_AF(void); #endif /* #ifndef USCI_A0_h */ /* //使用例程 void main(void) { volatile unsigned int i; u8 data; dog_Disable(); UCS_Init(); //key_Init(); USCIA0_Init(); while(1) { USCIA0_SendChar('A'); USCIA0_SendString(" luoxn28"); data = USCIA0_ReceiveChar(); if(data != 0) { USCIA0_SendChar(data); USCIA0_SendChar('r');USCIA0_SendChar('n'); } delay(10); } } */ //--------------------------------------------- uart 源文件 -------------------------------------------------------------// #include "msp430_UART.h" #if USCIA0_EN >0 /********************************************************* *名称:USCIA0_Init *功能:串口初始化 *入口参数:无 *出口参数:无 *说明:设置为P3.3和P3.4为串口通信端口 3.3-UCA0TXD 3.4-UCA0RXD **********************************************************/ void USCIA0_Init(void) { P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL__ACLK; // ACLK UCA0BR0 = 34; // 4MHz 115200 UCA0BR1 = 0; // 4MHz 115200 UCA0MCTL |= UCBRS_6 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** //IE2 |= UCA0RXIE + UCA0TXIE; // Enable USCI_A0 TX/RX interrupt //IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt //__bis_SR_register(GIE); // Enter LPM3 w/ interrupts enabled } //串口0发送字符函数 void USCIA0_SendChar(u8 c) { UCA0TXBUF=c; while(!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready? UCA0IFG &= ~UCTXIFG; } //串口0接收字符函数 u8 USCIA0_ReceiveChar(void) { u8 data = 0; //阻塞式返回值 while(!(UCA0IFG & UCRXIFG)); // USCI_A0 TX buffer ready? UCA0IFG &= ~UCRXIFG; data = UCA0RXBUF; return data; /* //非阻塞式返回值 if(UCA0IFG & UCRXIFG) { UCA0IFG &= ~UCRXIFG; data = UCA0RXBUF; } return data; */ } //串口0发送字符串函数 void USCIA0_SendString(u8 *str) { while(*str != '




