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

📄 wireless_cc1100rx.c.bak

📁 CC1100做呼叫器的程序(C语言)用8051与CC1100接口,语音压缩,频率在916.5MHZ
💻 BAK
📖 第 1 页 / 共 5 页
字号:
   XBR1   |= 0x40;                     // Enable crossbar, CEX0 at port pin
  
   P0MDIN &= ~0x0D;                    // set P0.0 to analog input
   P1MDIN &= ~0x08;                    // set P1.3 to analog input
   
 //  P0MDOUT = 0xf2;
 //  P1MDOUT = 0xf7;
   
   P0SKIP = 0x0F;                     // skip ADC input P0.0,P0.1, I/O pins P0.4
   P1SKIP = 0xFF;                      // skip all port 1 pins
   
}

//-----------------------------------------------------------------------------
// SPI_Init
//-----------------------------------------------------------------------------
//
// Set SPI to master, CKPHA = 0, CKPOL = 1.  Set SPI to 4 wire mode, and
// enable SPI.  SPI0CKR = 11, SCLK = 24.5Mhz / 12 = 1.021 MHz.
//
void SPI_Init(void)
{
   SPI0CFG = 0x40;                     // Master disable, CKPOL = 0
   SPI0CN  = 0x08;                     // clear all flags
   SPI0CKR  = 0x05;                    // 2MHz      0x02=4MHz
   SPIEN = 1;                          // leave SPI enable
   P0MDIN |=0xF0;
   P0MDOUT |= 0x70;
  // P1MDIN |=0xff;
  
 //  IE |= 0x40;                         // enable SPI interrupts
 //  IP |= 0x40;
   
}


//-----------------------------------------------------------------------------
// IDAC0_Init
//-----------------------------------------------------------------------------
//
// Configure IDAC to update with every Timer 3 overflow, using 2.0 mA
// full-scale output current.
//

void IDAC0_Init(void)
{
   IDA0CN &= ~0x70;                    // Clear Update Source Select Bits
   IDA0CN |=  0x30;                    // Set DAC to update on Tmr 3 Overflows
   IDA0CN |=  0x80;                    // Enable DAC

}

//-----------------------------------------------------------------------------
// Timer1_Init
//-----------------------------------------------------------------------------
//
// Configure Timer1 
// using SYSCLK/12 as its time base.  Interrupts are enabled.  Timer1 controls
// the RF data pocket output time.
//
void Timer1_Init(void)
{
   TMOD  |= 0x10;                      // configure Time0 work mode;

   CKCON |= 0x02;                      // select the clock resouce;
   PT1 = 1;
}

//----------------------------------------------------------------------------
// Timer2_Init
//----------------------------------------------------------------------------
//
// Timer 2 is used as the start of conversion clock source for the ADC,
// and controls the audio sampling rate.
//
void Timer2_Init(unsigned int counts)
{
   TMR2CN = 0x00;                      // resets Timer 2, sets to 16 bit mode
   CKCON |= 0x10;                      // use system clock
   TMR2RL = -counts;                   // Initial reload value
   TMR2 = -counts;                     // init timer
   ET2 = 0;                            // disable Timer 2 interrupts
   TR2 = 1;                            // start Timer 2
}
//-----------------------------------------------------------------------------
// Timer3_Init
//-----------------------------------------------------------------------------
//
// Configure Timer3 to auto-reload at interval specified by <counts>
// using SYSCLK as its time base.  Interrupts are enabled.  Timer 3 controls
// the DAC output rate.
//
void Timer3_Init(unsigned int counts)
{
   TMR3CN  = 0x00;                     // resets Timer 3, sets to 16 bit mode
   CKCON  |= 0x40;                     // use system clock
   TMR3RL  = -counts;                  // Initial reload value

   TMR3    = -counts;                  // init timer
   EIE1   |= 0x80;                     // enable Timer 3 interrupts
   TMR3CN  = 0x04;                     // start Timer 3
}


//-----------------------------------------------------------------------------
// Variables_Init
//-----------------------------------------------------------------------------
//
void Variables_Init(void)
{
   Audio_LocalState = Audio_Loud;
   Audio_RemoteState = Audio_Loud;

   CLEAR_FIFOS();
}


//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//  void TIMER1_ISR(void)
//
//  DESCRIPTION:
//      Everytime a Timer1 interrupt occurs, the duty cycle of the
//              PWM is adjusted
//-------------------------------------------------------------------------------------------------------
void TIMER1_ISR(void) interrupt 3 
{
	Timer1_Loader(7.0);  
}

/*

void SPI0_ISR(void) interrupt 6
{
	
	SPI0CN = SPI0CN&0x88;                     // clear all flags
	
	}
*/

//-----------------------------------------------------------------------------
// Timer3_ISR
//-----------------------------------------------------------------------------
// This ISR updates the DAC output at a rate of DACUPDATERATE.  It also
// fetches the most recently captured local ADC sample, attenuates the sample,
// and adds the signal to the DAC output for a loop back.
//
 
void TIMER3_ISR(void) interrupt 14
{
    static unsigned short new_value;
    unsigned short Counter;
      USHORT tempvalue;
      TMR3CN &= ~0xC0;                 // acknowledge interrupt
	 

      if(ReciveCompress_Bytes>0)
       {
       	 ReciveCompress_Bytes --;
         DPCM_Decompress ();
       }
         new_value = DACTXFIFO_Pull();
    
         // only play received audio if the remote endpoint as determined
         // that the audio is of audible amplitude
         if(Audio_RemoteState == Audio_Loud)
         {
         // 	Counters_DAC ++;
            // DAC output must be left-justified, and loaded
            // low byte first
            tempvalue.S = new_value;
//            tempvalue.S = tempvalue.S + ADCRXFIFO_Newest()>>4;
            tempvalue.S = tempvalue.S << 6;

            IDA0L = tempvalue.C[1];
            IDA0H = tempvalue.C[0];

         }
       
   
 }

//-----------------------------------------------------------------------------
// RF State Machine Functions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// RXTX_InitSlave(void)
//-----------------------------------------------------------------------------
//
// This function switches the RF transceiver to receive and sets variables
// to indicate that the endpoint is designated as slave.
//


//-----------------------------------------------------------------------------
// CC1100_Init
//-----------------------------------------------------------------------------
// This function will initialize the transceiver and calibrate it to
// transmit and receive on a defined frequency.
//

void CCxxx0_Init(void)
{
    unsigned char i;
    i = 0;
    // Write register settings
    halSpiWriteReg(CCxxx0_FSCTRL1,  RegValue[i++]);//pRfSettings->FSCTRL1);
    halSpiWriteReg(CCxxx0_FSCTRL0,  RegValue[i++]);//pRfSettings->FSCTRL0);
    //halSpiWriteReg(CCxxx0_FIFOTHR,  0x33);//pRfSettings->FREQ2);
    halSpiWriteReg(CCxxx0_FREQ2,    RegValue[i++]);//pRfSettings->FREQ2);
    halSpiWriteReg(CCxxx0_FREQ1,    RegValue[i++]);//pRfSettings->FREQ1);
    halSpiWriteReg(CCxxx0_FREQ0,    RegValue[i++]);//pRfSettings->FREQ0);
    halSpiWriteReg(CCxxx0_MDMCFG4,  RegValue[i++]);//pRfSettings->MDMCFG4);
    halSpiWriteReg(CCxxx0_MDMCFG3,  RegValue[i++]);//pRfSettings->MDMCFG3);
    halSpiWriteReg(CCxxx0_MDMCFG2,  RegValue[i++]);//pRfSettings->MDMCFG2);
    halSpiWriteReg(CCxxx0_MDMCFG1,  RegValue[i++]);//pRfSettings->MDMCFG1);
    halSpiWriteReg(CCxxx0_MDMCFG0,  RegValue[i++]);//pRfSettings->MDMCFG0);
    halSpiWriteReg(CCxxx0_CHANNR,   RegValue[i++]);//pRfSettings->CHANNR);
    halSpiWriteReg(CCxxx0_DEVIATN,  RegValue[i++]);//pRfSettings->DEVIATN);
    halSpiWriteReg(CCxxx0_FREND1,   RegValue[i++]);//pRfSettings->FREND1);
    halSpiWriteReg(CCxxx0_FREND0,   RegValue[i++]);//pRfSettings->FREND0);
    halSpiWriteReg(CCxxx0_MCSM0 ,   RegValue[i++]);//pRfSettings->MCSM0 );
    halSpiWriteReg(CCxxx0_FOCCFG,   RegValue[i++]);//pRfSettings->FOCCFG);
    halSpiWriteReg(CCxxx0_BSCFG,    RegValue[i++]);//pRfSettings->BSCFG);
    halSpiWriteReg(CCxxx0_AGCCTRL2, RegValue[i++]);//pRfSettings->AGCCTRL2);
    halSpiWriteReg(CCxxx0_AGCCTRL1, RegValue[i++]);//pRfSettings->AGCCTRL1);
    halSpiWriteReg(CCxxx0_AGCCTRL0, RegValue[i++]);//pRfSettings->AGCCTRL0);
    halSpiWriteReg(CCxxx0_FSCAL3,   RegValue[i++]);//pRfSettings->FSCAL3);
    halSpiWriteReg(CCxxx0_FSCAL2,   RegValue[i++]);//pRfSettings->FSCAL2);
    halSpiWriteReg(CCxxx0_FSCAL1,   RegValue[i++]);//pRfSettings->FSCAL1);
    halSpiWriteReg(CCxxx0_FSCAL0,   RegValue[i++]);//pRfSettings->FSCAL0);
    halSpiWriteReg(CCxxx0_FSTEST,   RegValue[i++]);//pRfSettings->FSTEST);
    halSpiWriteReg(CCxxx0_TEST2,    RegValue[i++]);//pRfSettings->TEST2);
    halSpiWriteReg(CCxxx0_TEST1,    RegValue[i++]);//pRfSettings->TEST1);
    halSpiWriteReg(CCxxx0_TEST0,    RegValue[i++]);//pRfSettings->TEST0);
    halSpiWriteReg(CCxxx0_IOCFG2,   RegValue[i++]);//pRfSettings->IOCFG2);
    halSpiWriteReg(CCxxx0_IOCFG0,   RegValue[i++]);//pRfSettings->IOCFG0);    
    halSpiWriteReg(CCxxx0_PKTCTRL1, RegValue[i++]);//pRfSettings->PKTCTRL1);
    halSpiWriteReg(CCxxx0_PKTCTRL0, RegValue[i++]);//pRfSettings->PKTCTRL0);
    halSpiWriteReg(CCxxx0_ADDR,     RegValue[i++]);//pRfSettings->ADDR);
    halSpiWriteReg(CCxxx0_PKTLEN,   RegValue[i]);  //pRfSettings->PKTLEN);

}

//-------------------------------------------------------------------------------------------------------
//  BYTE halSpiReadReg(BYTE addr)
//
//  DESCRIPTION:
//      This function gets the value of a single specified CCxxx0 register.
//
//  ARGUMENTS:
//      BYTE addr
//          Address of the CCxxx0 register to be accessed.
//
//  RETURN VALUE:
//      BYTE
//          Value of the accessed CCxxx0 register.
//-------------------------------------------------------------------------------------------------------
unsigned char halSpiReadReg(unsigned char addr)
 {
    unsigned char x;
   // SPI0CN  = 0x08;                     // clear all flags
    NSSMD0 = 0;
    while (SO_data);
  //  {SO_data = 0;}
    SPI0DAT = (addr | READ_SINGLE);
    SPI_WAIT();
    SPI0DAT = 0;
    SPI_WAIT();
    x = SPI0DAT;
    NSSMD0 = 1;
    SO_data = 0;
    return x;
}// halSpiReadReg
//-------------------------------------------------------------------------------------------------------
//  void halSpiWriteReg(BYTE addr, BYTE value)
//
//  DESCRIPTION:
//      Function for writing to a single CCxxx0 register
//
//  ARGUMENTS:
//      BYTE addr
//          Address of a specific CCxxx0 register to accessed.
//      BYTE value
//          Value to be written to the specified CCxxx0 register.
//-------------------------------------------------------------------------------------------------------
void halSpiWriteReg(unsigned char addr,unsigned char value) {
  //  SPI0CN  = 0x08;                     // clear all flags
    NSSMD0 = 0;
    while (SO_data);
 //   {SO_data = 0;}
    SPI0DAT = addr;
    SPI_WAIT();
    SPI0DAT = value;
    SPI_WAIT();
    NSSMD0 = 1;
    SO_data = 0;
}// halSpiWriteReg

//-----------------------------------------------------------------------------
// FIFO Routines
//-----------------------------------------------------------------------------
// All FIFO functions pass a pointer to the fifo.  Pull functions return
// either a short or a char, and push functions have the data to be pushed
// as an additional parameter.
// Pushes and pulls update EMPTY, COUNT, and OF variables.
//
unsigned char TransmitFIFO_Pull(void)
{
   unsigned char output;

   if(TransmitFIFO_EMPTY)
   {
      // if buffer is empty, set the underflow flag and exit function
      TransmitFIFO_UF = 1;
      return 0;
   }
   else
   {
      TransmitFIFO_FULL = 0;                // if byte is pulled, buffer can no
                                       // longer be full

      // wrap FIFO pointer if necessary
      if (TransmitFIFO_FIRST==TransmitFIFO_FIFOSIZE-1) TransmitFIFO_FIRST = 0;
      else (TransmitFIFO_FIRST)++;

      // pull value from fifo
      output = TransmitFIFO_FIFO[TransmitFIFO_FIRST];

      // set empty indicator if necessary
      if (--(TransmitFIFO_COUNT) == 0) TransmitFIFO_EMPTY = 1;

      return output;
   }
}

void TransmitFIFO_Push(unsigned char num)
{
   TransmitFIFO_EMPTY = 0;                  // buffer is no longer empty


   if (!TransmitFIFO_FULL) {
      (TransmitFIFO_LAST)++;                // increment, wrap if necessary
      if (TransmitFIFO_LAST == TransmitFIFO_FIFOSIZE)
      {
         TransmitFIFO_LAST = 0;
      }

      TransmitFIFO_FIFO[TransmitFIFO_LAST]=num;  // push value to FIFO


      TransmitFIFO_COUNT++;                 // increment count

      // check for full buffer
      if ( TransmitFIFO_COUNT == TransmitFIFO_FIFOSIZE)
      {
         TransmitFIFO_FULL = 1;
      }
   }
   else // buffer is full
   {
      // if buffer is full, do not push byte, just set overflow flag
      // and exit
      TransmitFIFO_OF = 1;
   }
}

unsigned char ReceiveFIFO_Pull(void)
{
   unsigned char output;

   if(ReceiveFIFO_EMPTY)
   {
      // if buffer is empty, set underflow flag and exit
      ReceiveFIFO_UF = 1;

      return 0;
   }
   else
   {
      ReceiveFIFO_FULL = 0;                // buffer is no longer full

⌨️ 快捷键说明

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