你好!最近在用msp430g2553单片机,遇到串口可以接收数据但是无法发出数据的问题,下面是在proteus上的仿真程序,根据官方例程写的,请大神来指点下,谢谢!急急急。。。
#include <MSP430.h>
#include "LCD.h"
#include "i2c.h"
#include "LCD.h"
#include "i2c.h"
CHAR BUFF[10] = {'A'};
int main (void)
{ WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
lcd_init ();
// Write your code here
calc_display (BUFF);
P1DIR |= BIT4;
P1IE |= BIT0; // P1.4 interrupt enabled
P1IES |= BIT0; // P1.4 Hi/lo edge
P1IFG &= ~BIT0; // P1.4 IFG cleared
_BIS_SR(GIE);
while (1)
;
return 0;
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= BIT4; // P1.0 = toggle
P1IFG &= ~BIT0; // P1.4 IFG cleared
while (!(IFG2&UCA0TXIFG));
UCA0TXBUF = 0X30;
}
int main (void)
{ WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
lcd_init ();
// Write your code here
calc_display (BUFF);
P1DIR |= BIT4;
P1IE |= BIT0; // P1.4 interrupt enabled
P1IES |= BIT0; // P1.4 Hi/lo edge
P1IFG &= ~BIT0; // P1.4 IFG cleared
_BIS_SR(GIE);
while (1)
;
return 0;
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= BIT4; // P1.0 = toggle
P1IFG &= ~BIT0; // P1.4 IFG cleared
while (!(IFG2&UCA0TXIFG));
UCA0TXBUF = 0X30;
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
BUFF[0] = UCA0RXBUF;
calc_display (BUFF);
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = BUFF[0]; // TX -> RXed character
}
__interrupt void USCI0RX_ISR(void)
{
BUFF[0] = UCA0RXBUF;
calc_display (BUFF);
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = BUFF[0]; // TX -> RXed character
}
灰小子:
calc_display (BUFF);
这个函数是实现什么功能的?
你用官网的例程可以发送数据吗?
zhenwei liu1:
回复 灰小子:
这个可以忽略,这是我显示用的