注意蓝牙模块的接法!
1 #include <msp430x14x.h> 2 char data[100]; 3 int k=0; 4 void int_clk() 5 { 6 BCSCTL1 &= ~XT2OFF; 7 BCSCTL2 |= SELM_2 + SELS; 8 do 9 { 10 IFG1 &= ~OFIFG; 11 for(int i=0;i<100;i++) 12 _NOP(); 13 }while((IFG1 & OFIFG)!=0); 14 IFG1 &= ~OFIFG; 15 } 16 void int_usart() 17 { 18 U0CTL |= SWRST; 19 U0CTL |= CHAR; 20 21 U0TCTL |= SSEL1; 22 U0BR1 = 0X03; 23 U0BR0 = 0X41; 24 U0MCTL = 0X00; 25 26 ME1 |= UTXE0 + URXE0; 27 U0CTL &= ~SWRST; 28 IE1 |= URXIE0; 29 30 P3SEL |= BIT4 + BIT5; 31 P3DIR |= BIT4; 32 } 33 void Sent_Byte() 34 { 35 while((IFG1 & UTXIFG0)==0); 36 U0TXBUF = data[k++]; 37 if(k == 100) 38 k = 0; 39 } 40 #pragma vector=USART0RX_VECTOR 41 __interrupt void USAR_RX() 42 { 43 char flag; 44 flag = U0RXBUF; 45 if(flag == 1) 46 { 47 for(int j=0;j<100;j++) 48 Sent_Byte(); 49 } 50 } 51 void main() 52 { 53 WDTCTL = WDTPW + WDTHOLD; 54 int i; 55 for(i=0;i<100;i++) 56 data[i]=i; 57 int_clk(); 58 int_usart(); 59 _EINT(); 60 }
时间: 2024-10-14 00:48:40