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

📄 main.c

📁 该程序在IAR Embedded Workbench for MSP4303.41A环境下编写
💻 C
字号:
//----------------------------------------------------------------------------
//  Demo Application for MSP430/CC1100-2500 Interface Code Library v1.0
//
//  K. Quiring
//  Texas Instruments, Inc.
//  July 2006
//  IAR Embedded Workbench V3.42A
//----------------------------------------------------------------------------



#include "include.h"

extern char paTable[];
extern char paTableLen;

char txBuffer[4];
char rxBuffer[4];
unsigned int i,j;

void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  TI_CC_SPISetup();                         // Initialize SPI port

  TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
  writeRFSettings();                        // Write RF settings to config reg
  TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE

  // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
  TI_CC_SW_PxIES = ~(TI_CC_SW1+TI_CC_SW2);      // Int on falling edge
  TI_CC_SW_PxIFG &= ~(TI_CC_SW1+TI_CC_SW2);  // Clear flags
  TI_CC_SW_PxIE = TI_CC_SW1+TI_CC_SW2;       // Activate enables
  TI_CC_LED_PxDIR = TI_CC_LED1 + TI_CC_LED2; // Port to LED set to Outputs
  TI_CC_LED_PxOUT = TI_CC_LED1 + TI_CC_LED2; // Turn on LED at the beginning
  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
  for (i=0;i<20;i++)
  {
    for(j=0;j<5000;j++)
    {}
      TI_CC_LED_PxOUT ^=(TI_CC_LED1 + TI_CC_LED2);// LED flashing during startup
  }
  TI_CC_LED_PxOUT =0;                       // Initialize LED to OFF    
  _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)
{
  if (P1IFG & BIT0 || P1IFG & BIT1)            // One of the Switches pressed
  {                                            // Transmit mode 
    txBuffer[0] = 2;                           // Packet length
    txBuffer[1] = 0x1;                         // Packet address

    if (P1IFG & BIT1)                          // SW1 pressed
    {
      txBuffer[2] = BIT2;                      // Set LED1 to high 
      for (i=0;i<10000;i++)                     // Software delay for debounce 
      {}  
      P1IFG &= ~BIT1;                          // Clear the Switch 1 interrupt   
    }                                          // flag 
    else
    {
      txBuffer[2] = BIT1;                      // Set LED1 to high
      for (i=0;i<10000;i++)                     // Software delay for debounce 
      {}
      P1IFG &= ~BIT0;                          // Clear the Switch 2 interrupt 
    }                                          // flag 

    RFSendPacket(txBuffer, 3);                 // Send value over RF
    P1IFG &= ~TI_CC_GDO0_PIN;                  // After pkt TX, this flag is set.
                                               // Clear it.
  }

  else if(P1IFG & TI_CC_GDO0_PIN)              // Command received from RF
  {                                            // RX active
    char len=2;                                // 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
      TI_CC_LED_PxOUT ^= rxBuffer[1];          // Toggle LEDs according to pkt data

    P1IFG &= ~TI_CC_GDO0_PIN;                  // Clear Receive flag
  }

}

// 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.



⌨️ 快捷键说明

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