

我采用的8M晶振,波特率为19200;把寄存器配置好后无法进入中断!!希望帮忙看看!谢谢
今天用示波器打下波形,单片机发送波形有,但电脑的发送波形无
#include "msp430x14x.h"
//#include "SystemConfigure.h"
//#include "SerialCommunication.h"
void Uart0Init()
{
UCTL0 |=SWRST;
UCTL0 |=CHAR;
UTCTL0 |=SSEL1+TXEPT;
U0BR0=0xa0; //8M 频率 波特率19200
U0BR1=0x01;
UMCTL0=0x00;
ME1 |=URXE0+UTXE0;
U0CTL &=~SWRST;
IE1 |=URXIE0;
P3SEL |=BIT4+BIT5;//串口使能
P3DIR |=BIT4;
IFG1 &=0x3f;
}
void SendByte(char Data)
{
while(!(IFG1 & UTXIFG0));
U0TXBUF=Data;
}
void SystemClockInit()
{
BCSCTL1 &=~XT2OFF;
do{
IFG1 &=~OFIFG;
__delay_cycles(100);
}while((IFG1 & OFIFG));
IFG1 &=~OFIFG;
BCSCTL2 |=SELM_2+SELS;//SMCLK为8M
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
SystemClockInit();
Uart0Init();
_EINT();
P2DIR |=BIT0+BIT1;//使能LED灯
P2OUT &=~BIT1;
P2OUT |=BIT0;
//P2OUT &=~BIT0;
while(1);
}
#pragma vector=UART0RX_VECTOR
__interrupt void UART0_RX()
{
uchar Data=0;
P2OUT &=~BIT0;
while (!(IFG1 & UTXIFG0));
Data=U0RXBUF;
if(Data=='1')
P2OUT &=~BIT0;
SendByte('a');
}
[
本帖最后由 拒绝 于 2012-7-30 15:51 编辑 ]
此帖出自
小平头技术问答
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_3; // MCLK = LFXT1 (safe)
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x74; // 3.58Mhz/9600 - 372
UBR10 = 0x01; //
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
一周热门 更多>