发送 不停的发的时候这个是在主函数while中实现的
#include <msp430.h>
typedef unsigned char uchar;
typedef unsigned int uint;
void Delays(void)
{
uchar i=20;
uint j;
while(i--)
{
j=2000;
while(j--);
}
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P4SEL |= BIT4+BIT5; // P3.3,4 = USCI_A0 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**复位使能
UCA1CTL1 |= UCSSEL_2; // SMCLK 选取SMLK时钟
UCA1BR0 = 9; // 1MHz 115200 (see User's Guide)1M/115200=8.68,四舍五入为9
UCA1BR1 = 0; // 1MHz 115200 高八位为零
UCA1MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
while(1)
{
UCA1TXBUF=0x01;
Delays();
// __bis_SR_register(GIE);
// __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
__no_operation(); // For debugger
}
}
接收部分
#include <msp430.h>
typedef unsigned char uchar;
typedef unsigned int uint;
void Delays(void)
{
uchar i=20;
uint j;
while(i--)
{
j=2000;
while(j--);
}
- 1
- 2
- 3
前往页