msp430G2553蓝牙通讯代码
          
            时间:11-30 14:40 阅读:2550次
*温馨提示:点击图片可以放大观看高清大图
                
         
        
		  
               简介:本文给大家介绍了一个msp430G2553蓝牙通讯代码。
               
                        
          
            #include <msp430g2553.h>
#include <in430.h>
#define uchar  unsigned char
#define uint unsigned int
void UartPutchar(unsigned char c);
void delay_Nus(uint n);
void delay_1ms(void);
void delay_Nms(uint n);
unsigned char UartGetchar();
unsigned char temp=0;
unsigned char number[2]={0};
void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  DCOCTL = 0;
  BCSCTL1 = CALBC1_1MHZ;
  DCOCTL = CALDCO_1MHZ;
  P1DIR|=BIT6;
  P1OUT&=~BIT6;
  P1SEL=BIT1+BIT2;        //P1.1 RXD   P1.2=TXD
  P1SEL2=BIT1+BIT2;
  UCA0CTL1|=UCSSEL_2;
  UCA0BR0 = 106;   //1MHZ  9600
  UCA0BR1 = 0;
  UCA0MCTL = UCBRS2 + UCBRS0 ;
  UCA0CTL1 &=~UCSWRST;
  IE2|=UCA0RXIE;
  while(1)
  {
    UartPutchar(9);
    //display_int(temp,0);
    delay_Nms(100);
    //_delay_cycles(10000);
  }
}
/*******************UART 接受中断*************/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIRX_ISR(void)
{
  //while(!(IFG2&UCA0TXIFG));
  //UCA0TXBUF = UCA0RXBUF; 
  temp=UCA0RXBUF;
}
/***************************UART发送字节函数***********/
void UartPutchar(unsigned char c)
{
  while(!(IFG2&UCA0TXIFG));
  UCA0TXBUF = c;
  IFG2  &=~UCA0RXIFG;
}
/*************************UART接受字节函数************/
unsigned char UartGetchar()
{
  unsigned char c;
  while(!(IFG2&UCA0RXIFG))
    ;
  c = UCA0RXBUF;
  IFG2 &=~UCA0TXIFG;
  return c;
}
/*******************************************
函数名称:delay_Nus
功    能:延时N个us的时间
参    数:n--延时长度
返回值  :无
********************************************/
void delay_Nus(uint n)
{
    uchar i;
    for(i = n;i > 0;i--)
        _NOP();
} 
/*******************************************
函数名称:delay_1ms
功    能:延时约1ms的时间
参    数:无
返回值  :无
********************************************/
void delay_1ms(void)
{
    uchar i;
    for(i = 150;i > 0;i--)    _NOP();
}  
/*******************************************
函数名称:delay_Nms
功    能:延时N个ms的时间
参    数:无
返回值  :无
********************************************/  
void delay_Nms(uint n)
{
    uint i = 0;
    
    for(i = n;i > 0;i--)
        delay_1ms();
}