|
我在初始化MSP430f149的时候,在打开总断的下一步,程序就会跑飞掉。我是菜鸟,不知到是什么原因。程序:
void Init_Mcu(void) //config GPIO
{
WDTCTL = WDTPW + WDTHOLD;
//close all gpio
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
P6DIR |= BIT2;P6OUT |= BIT2; //关闭电平转换
/*------选择系统主时钟为8MHz-------*/
BCSCTL1 &= ~XT2OFF; //打开XT2高频晶体振荡器
do
{
IFG1 &= ~OFIFG; //清除晶振失败标志
for (int i = 0xFF; i > 0; i--); //等待8MHz晶体起振
}
while ((IFG1 & OFIFG)); //晶振失效标志仍然存在?
BCSCTL2 |= SELM_2 + SELS; //MCLK和SMCLK选择高频晶振
//config uart
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x0D; // 32k/2400 - 13.65
UBR10 = 0x00; //
UMCTL0 = 0x6B; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
//计数时钟选择SMLK=8MHz,1/8分频后为1MHz
TBCTL |= TBSSEL_2 + ID_3;
TACTL |= TASSEL_2 + ID_3;
TBCTL |= TBIE;
TBCCTL0 = CCIE;
TBCCR0 =1800;
TBCTL |= MC_1;
//打开全局中断
_EINT();
}
以上是初始化程序;
主程序:
void main()
{
unsigned char temp[4];
Init_Mcu();
while(1)
{
*temp=Do1Convert();
packFrame(temp,sizeof(temp));
for(unsigned char i=0;i<8;i++)
{
TXBUF0 = destData; // RXBUF0 to TXBUF0
}
}
|
|