#include <msp430f5529.h>
/*
* main.c
*/
/*int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
return 0;
}*/
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P4SEL = BIT4+BIT5; // P5_6和P5_7第二功能打开,设置方向
UCA1CTL1 |= UCSWRST; // 首先使RST位置位,只有这样后面的设置才有效
UCA1CTL1 |= UCSSEL_2; // SMCLK,为系统时钟4MHz
UCA1BR0 = 0x02; // 4MHz 115200
UCA1BR1 = 0; // 4MHz 115200
UCA1MCTL |= UCBRS_3 + UCBRF_2 + UCOS16; // 设置调整参数UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // RST复位
UCA1IE |= UCRXIE + UCTXIE;
_EINT();
while (1)
{
//
}
* main.c
*/
/*int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
return 0;
}*/
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P4SEL = BIT4+BIT5; // P5_6和P5_7第二功能打开,设置方向
UCA1CTL1 |= UCSWRST; // 首先使RST位置位,只有这样后面的设置才有效
UCA1CTL1 |= UCSSEL_2; // SMCLK,为系统时钟4MHz
UCA1BR0 = 0x02; // 4MHz 115200
UCA1BR1 = 0; // 4MHz 115200
UCA1MCTL |= UCBRS_3 + UCBRF_2 + UCOS16; // 设置调整参数UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // RST复位
UCA1IE |= UCRXIE + UCTXIE;
_EINT();
while (1)
{
//
}
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break;
case 2:
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = UCA1RXBUF;
break;
case 4:break;
default: break;
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break;
case 2:
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = UCA1RXBUF;
break;
case 4:break;
default: break;
}
}
}
为什么这段代码运行的时候 用串口通信助手发数据没有回复= =
灰小子:
没看到SMCLK是怎么配置为4MHz。没配置的话,默认应该是DCO的1MHz