⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c.bak

📁 MSP430F2274单片机和CC2500的无线通信程序
💻 BAK
字号:
//----------------------------------------------------------------------------
//  Demo Application for MSP430/CC1100-2500 Interface Code Library v1.0
//
//  K. Quiring
//  Texas Instruments, Inc.
//  July 2006
//  IAR Embedded Workbench v3.41
//08年7月29日,弄了Lpm3中断响应,但是还是只能接收一次,
//----------------------------------------------------------------------------



#include "include.h"

//#define _TRANSMITTER
#define _RECEIVER

extern char paTable[];        //功率能量
extern char paTableLen;

char txBuffer1[] = {0x08,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; //第一个字节是发送的数据长度,第二个字节是地址
char txBuffer2[] = {0x08,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}; //第一个字节是发送的数据长度,第二个字节是地址

char rxBuffer[8];
char next;
unsigned int i;

void main (void)
{

   char  j = 0;
   char len1;    //Len of pkt to be RXed (only addr
   
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  
  TI_CC_GDO0_PxDIR &= ~TI_CC_GDO0_PIN;         //设GDOO为输入状
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO after random function
  DCOCTL = CALDCO_1MHZ;
  P2SEL &=0x00;
  IFG1 &= ~OFIFG;
  TI_CC_Wait(30);
  
  TI_CC_SPISetup();                         // Initialize SPI port -modify-

  TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx,TI_CC_SPI.c
  writeRFSettings();                        // Write RF settings to config reg
  //设置功率
  TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE  memory locations:TI_CCxxx0_PATABLE=0x3f
  TI_CC_LED_PxDIR |= TI_CC_LED1 + TI_CC_LED2;              //点亮LED1; 
  TI_CC_LED_PxOUT &= ~(TI_CC_LED1 + TI_CC_LED2);
  TI_CC_GDO0_PxDIR &= ~TI_CC_GDO0_PIN;       //设置GDO0为输入; 
  TI_CC_GDO0_PxSEL &= ~TI_CC_GDO0_PIN;       //设置P2.6脚为I/O端口; 
  TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       //下降沿触发中断; 
  TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // 清除中断标志; 
  TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // 使能中断总允许; 
  TI_CC_SPIStrobe(TI_CCxxx0_SIDLE);        ////设置芯片为空闲状态; 
  TI_CC_SPIStrobe(TI_CCxxx0_SPWD);        ////设置芯片为sleep状态;
  
  TI_CC_SW_PxIES = TI_CC_SW3;                     //按键选择下降沿触发    
  TI_CC_SW_PxIFG &= ~(TI_CC_SW3);                //清除按键中断请求    
  TI_CC_SW_PxIE = TI_CC_SW3;                     //按键中断使能    
  TI_CC_LED_PxDIR = TI_CC_LED1;                  //设定输出状态 
  
  


#ifdef _RECEIVER
  TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); 
  TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode. 
#endif 
  //如果接收到数据,则激活MCU                // When a pkt is received, it will 
                                            // signal on GDO0 and wake CPU 
  //_BIS_SR(LPM3_bits + GIE);                 //省电模式 Enter LPM3, enable interrupts 
#ifdef _SWOR
  TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); 
  TI_CC_SPIStrobe(TI_CCxxx0_SWORRST);       // Initialize CCxxxx WOR Timer.
  TI_CC_SPIStrobe(TI_CCxxx0_SWOR);          // Start off in WOR mode.
#endif /* _SWOR */  

  //TI_CC_LED_PxDIR &= ~TI_CC_SW1; 
while(1)
{
   // Len of pkt to be RXed (only addr
                                          // plus data; size byte not incl b/c
     
   
#ifdef _TRANSMITTER
 if(j) 
 {
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   RFSendPacket(txBuffer1, 9);                 // Send value over RF
   TI_CC_LED_PxOUT  |= TI_CC_LED2 + TI_CC_LED1;
   TI_CC_Wait(30000);
   TI_CC_LED_PxOUT  &= ~(TI_CC_LED2 + TI_CC_LED1);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   j = 0;
 }
 else
  {
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   RFSendPacket(txBuffer2, 9);                 // Send value over RF
   TI_CC_LED_PxOUT  |= TI_CC_LED2 + TI_CC_LED1;
   TI_CC_Wait(30000);
   TI_CC_LED_PxOUT  &= ~(TI_CC_LED2 + TI_CC_LED1);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   j = 1;
 } 
#endif 
#ifdef _RECEIVER
  //RFReceivePacket(rxBuffer,&len1);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);
   TI_CC_Wait(30000);    
   _BIS_SR(LPM3_bits + GIE);
   TI_CC_SPIStrobe(TI_CCxxx0_SRX); 
    ///TI_CC_Wait(30);
   /*
     if (RFReceivePacket(rxBuffer,&len1))       // Fetch packet from CCxxxx
      next++;  
         // Toggle LEDs according to pkt data
 TI_CC_SPIStrobe(TI_CCxxx0_SFRX);//不能和RFReceivePacket()分得太远
  TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); 
 
    // _EINT();                              // Enable interrupts
    //_BIS_SR(LPM3_bits + GIE);*/
#endif 
  ///if (RFReceivePacket(rxBuffer,&len))       // Fetch packet from CCxxxx
 ///  TI_CC_LED_PxOUT ^= rxBuffer[1];        // Toggle LEDs according to pkt data
  //for(j = 2;j >=0;j--)
 // {rxBuffer[j] = 0;}*/
 // txBuffer[0] = 0x02;                           // Packet length
 // j = txBuffer[0];
 // txBuffer[1] = 0x01;                        // Packet address
  //j = txBuffer[1];
  //txBuffer[2] = (~TI_CC_SW3) & 0x0F;// Load four switch inputs
 // j = txBuffer[2];

}
  /*
  // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
  TI_CC_SW_PxIES = TI_CC_SW3;///+TI_CC_SW2+TI_CC_SW1+TI_CC_SW4;//Int on falling edge
  TI_CC_SW_PxIFG &= ~(TI_CC_SW3//TI_CC_SW1+TI_CC_SW2++TI_CC_SW4//);//Clr flags
  TI_CC_SW_PxIE = TI_CC_SW3;///+TI_CC_SW2+TI_CC_SW1+TI_CC_SW4;//Activate enables
  TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2;/// + TI_CC_LED3 + TI_CC_LED4; //Outputs
  TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
  TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // Clear flag
  TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // Enable int on end of packet

  TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
                                            // When a pkt is received, it will
                                            // signal on GDO0 and wake CPU
  ////TI_CC_SPIStrobe(TI_CCxxx0_SIDLE);
  ////TI_CC_SPIStrobe(TI_CCxxx0_SPWD);
  _BIS_SR(LPM3_bits + GIE);*/                 // Enter LPM3, enable interrupts
  
}


// The ISR assumes the interrupt came from a press of one of the four buttons
// and therefore does not check the other four inputs.
/*#pragma vector=PORT1_VECTOR
__interrupt void port1_ISR (void)
{
  // Build packet
  TI_CC_LED_PxDIR |= TI_CC_LED2 ; //led green 
  txBuffer[0] = 2;                           // Packet length
  txBuffer[1] = 0x01;                        // Packet address
  txBuffer[2] = (~TI_CC_SW_PxIN >> 4) & 0x0F;// Load four switch inputs
  TI_CC_SPIStrobe(TI_CCxxx0_SIDLE);           // 切到空闲状态
  RFSendPacket(txBuffer, 3);                 // Send value over RF
  
  P1IFG &= ~(TI_CC_SW3  //TI_CC_SW1+TI_CC_SW2++TI_CC_SW4);//Clr flag that caused int
  P2IFG &= ~TI_CC_GDO0_PIN;                  // After pkt TX, this flag is set.
  
}      */                                      // Clear it.



// The ISR assumes the int came from the pin attached to GDO0 and therefore
// does not check the other seven inputs.  Interprets this as a signal from
// CCxxxx indicating packet received.
#ifdef _RECEIVER
#pragma vector=PORT2_VECTOR
__interrupt void port2_ISR (void)
{ 
                               // disEnable interrupts
  char len; // Len of pkt to be RXed (only addr
                                          // plus data; size byte not incl b/c
                                           // stripped away within RX function)
  
  if (RFReceivePacket(rxBuffer,&len))       // Fetch packet from CCxxxx
   next++;        // Toggle LEDs according to pkt data
  //TI_CC_SPIStrobe(TI_CCxxx0_SFRX);//不能和RFReceivePacket()分得太远
 // TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); 
 
  
    
  P2IFG &= ~TI_CC_GDO0_PIN;                 // Clear flag
  _DINT(); 
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -