#include "msp430x14x.h"
unsigned char flag;
void Init_Clk(void)
{
volatile unsigned char i;
BCSCTL1 &= ~XT2OFF; // XT2on
BCSCTL2 |= SELM_2 + SELS + DIVS_2; //MCLK=XT2,SMCLK=XT2/4=2MHz;
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
}
void Init_UART(void)
{
P3SEL |= BIT6;
P3SEL |= BIT7; // P3.6,7 = USART1 option select
P3DIR |= BIT6;
UCTL1 |= SWRST;
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0 + SSEL1;; // UCLK = SMCLK
U1BR0=0Xd0; //9600
U1BR1=0X00;
UMCTL1=0X40; // modulation
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
UCTL1 &= ~SWRST; // Initialize USART state machine
// IFG2 &= ~URXIFG1;
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
void Send_Byte(unsigned char data)
{
U1TXBUF = data;
while (!(IFG2 & UTXIFG1)); //USART1 TX buffer ready?
}
int main(void)
{
volatile unsigned int j;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
Init_Clk();
Init_UART();
_EINT();
for(;;)
{
if(flag == 1)
{
flag = 0;
Send_Byte(0x10);
for(j=0;j<5000;j++)
;
}
}
}
#pragma vector = UART1RX_VECTOR
__interrupt void uart1_rx_isr(void)
{
_DINT();
flag = 1;
_EINT();
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
_EINT();
串口接收中断难道不是开启这两个就行了?
一周热门 更多>