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

📄 main.h

📁 Atmega8L控制CC1020 TI的另外一款使用很多的RF IC。
💻 H
字号:

/************************************************************************
      // This is the main.h file used by the Main.c  maybe others    
      // Data: 2006-8-25
      // Edit: LY      
************************************************************************/  
#define FALSE 0
#define TRUE (!FALSE)


#define StationID_i  PREAMBLE_LENGTH 
#define ALM_i        PREAMBLE_LENGTH+1
#define IDH_i         PREAMBLE_LENGTH+2
#define IDL_i          PREAMBLE_LENGTH+3  
#define CRCH_i          PREAMBLE_LENGTH+4
#define CRCL_i            PREAMBLE_LENGTH+5

#define Bytes_to_send      PREAMBLE_LENGTH+5
 
//unsigned char flag1=0xFF;
//unsigned char flagE=0x00;
eeprom  unsigned int Card_ID = 0x13;  //0b0000000000010011;  // (14?2???)?????Card??2exp(14)=16384?
//bit CRC_calculat_Flag  = 0;  // becuase the Card_ID is almost fixed,There is no need to 
                               //calculate the CRC everytime sending out the message frame.  
                                                             

/************************************************************************
         Frame structure / Protocol definition
************************************************************************/ 
//#define HEADER_SIZE 4           // 4 bytes header     
#define PREAMBLE_LENGTH   17      //Here the  PREAMBLE_LENGTH is the BYTES of the preamble.
#define PREAMBLE_BIT_REQ  90        
eeprom unsigned char  EEpromStationID=0x24;
unsigned char StationID=0x24;
// Index pointers for use with buffers 
//volatile char TXBufferIndex;            
//char RXBufferReadIndex;
//volatile char RXBufferWriteIndex;
// Unit address is not used
// Counter variables
unsigned char PreambleBitCount=0;
unsigned char PreambleError=0;
unsigned char ByteCounter=0;
unsigned char BitCounter=0;  
volatile bit  PreambleFound=FALSE;
volatile bit UI1_Found=FALSE;
// EEPROM unit address variable. Addressing is not yet implemented.
eeprom  char UnitAddress=0x24;

// Contains the total number of bytes to send in TX, including preamble and header
//char BytesToSend;
// The number of bytes of data to receive in RX
//char BytesToReceive;
// State variable stores the current state of the state machine
enum StateType {IDLE_STATE=0,WR1020_STATE=1,Rd1020_STATE=2} State; 

//ALM_Type defines the message type the Station send out.
char ALM_Type=0x00;  // Normal=0x00; Gas=0x01; Key=0x03; Ack=0x04                                       
// This variable stores the state to switch to
// It is updated by the interrupt routine, while the main program
// does the actual state switch
//volatile enum StateType NextState;   //no need. 
// This struct stores various flags in a space-efficient manner   
/*
volatile struct
  {
    unsigned char PreambleFound:1;     //
    unsigned char UI1Found:1;
    unsigned char LastPreambleBit:1;
    unsigned char LockAverage:1;       //
    unsigned char UnlockAverage:1;
  }StructControl; 
*/



// RAM variables that mirror the EEPROM variables above

//char PA_POWER=0x0f;  //

// RAM variables that mirror the EEPROM variables above
//char PreambleLength;                                   




/**********************************************************************************************  
CC1020 Buffer Definition
***********************************************************************************************/
#define Send_ID_Times 4  
#define Rd1020_Buffer_size 24
//#define Wr1020_Buffer_size 8 


volatile  char Rd1020_Buffer[Rd1020_Buffer_size];
volatile  char Wr1020_Buffer [PREAMBLE_LENGTH+6];   // Array, not Really Buffer!!
//char Wr1020_Buffer[Wr1020_Buffer_size];          //

// Use the if to save RAM space
#if Rd1020_Buffer_size<256
volatile unsigned char Rd1020_wr_index=0,Rd1020_rd_index=0,Rd1020_counter=0;
#else
volatile unsigned int Rd1020_wr_index=0,Rd1020_rd_index=0,Rd1020_counter=0;
#endif   

volatile unsigned char Wr1020_Buffer_Index=0;                          //
volatile unsigned char Send_ID_Times_count=0; 
char ShiftReg =0; 



/************************************************************************
       CC1020 State change Necessities
************************************************************************/ 
/* Contents of PLL register for TX and RX, use SmartRF(R) Studio */
/* to find values for your application */
//#define TX_PLL  0x48      //by LY
//#define RX_PLL  0x70     //by LY    
/* Contents of CURRENT register for TX and RX, use SmartRF(R) Studio */
/* to find values for your application */   
//#define TX_CURRENT 0x81
//#define RX_CURRENT 0x44  


/************************************************************************
       CC1020 Register configuration
************************************************************************/                                 
  //fsk     14.7456 internal 433.2700Mhz    2.4KBaud Manchester accurate Fsepration 50Khz 5ppm
/* char EEPROMCC1020Config[32] ={
  0x1F,  // 0x01, INTERFACE
  0xFF,  // 0x02, RESET
  0x8F,  // 0x03, SEQUENCING
  0x39,  // 0x04, FREQ_2A
  0xF1,  // 0x05, FREQ_1A
  0x67,  // 0x06, FREQ_0A
  0x38,  // 0x07, CLOCK_A
  0x39,  // 0x08, FREQ_2B
  0xFC,  // 0x09, FREQ_1B
  0x11,  // 0x0A, FREQ_0B
  0x38,  // 0x0B, CLOCK_B
  0x44,  // 0x0C, VCO
  0x51,  // 0x0D, MODEM
  0x59,  // 0x0E, DEVIATION
  0xDF,  // 0x0F, AFC_CONTROL
  0x22,  // 0x10, FILTER
  0x61,  // 0x11, VGA1
  0x55,  // 0x12, VGA2
  0x2F,  // 0x13, VGA3
  0x2F,  // 0x14, VGA4
  0x20,  // 0x15, LOCK
  0x78,  // 0x16, FRONTEND
  0x47,  // 0x17, ANALOG, RX=47/TX=47
  0x14,  // 0x18, BUFF_SWING
  0x22,  // 0x19, BUFF_CURRENT
  0xAE,  // 0x1A, PLL_BW
  0x34,  // 0x1B, CALIBRATE
  0x0F,  // 0x1C, PA_POWER
  0x00,  // 0x1D, MATCH
  0x00,  // 0x1E, PHASE_COMP
  0x00,  // 0x1F, GAIN_COMP
  0x00   // 0x20, POWERDOWN
  };   */
  
char EEPROMCC1020Config[32] ={
  0x1F,  // 0x01, INTERFACE
  0xFF,  // 0x02, RESET
  0x8F,  // 0x03, SEQUENCING
  0x39,  // 0x04, FREQ_2A
  0xF1,  // 0x05, FREQ_1A
  0x66,  // 0x06, FREQ_0A
  0x3A,  // 0x07, CLOCK_A
  0x39,  // 0x08, FREQ_2B
  0xFC,  // 0x09, FREQ_1B
  0x10,  // 0x0A, FREQ_0B
  0x3A,  // 0x0B, CLOCK_B
  0x44,  // 0x0C, VCO
  0x51,  // 0x0D, MODEM
  0x19,  // 0x0E, DEVIATION
  0xCA,  // 0x0F, AFC_CONTROL
  0x2B,  // 0x10, FILTER
  0x61,  // 0x11, VGA1
  0x55,  // 0x12, VGA2
  0x2E,  // 0x13, VGA3
  0x29,  // 0x14, VGA4
  0x00,  // 0x15, LOCK
  0x78,  // 0x16, FRONTEND
  0x47,  // 0x17, ANALOG, RX=47/TX=47
  0x14,  // 0x18, BUFF_SWING
  0x22,  // 0x19, BUFF_CURRENT
  0xAE,  // 0x1A, PLL_BW
  0x34,  // 0x1B, CALIBRATE
  0x0F,  // 0x1C, PA_POWER
  0x00,  // 0x1D, MATCH
  0x00,  // 0x1E, PHASE_COMP
  0x00,  // 0x1F, GAIN_COMP
  0x00   // 0x20, POWERDOWN
  };   
  
char TXANALOG=0x47;  //right
char RXANALOG=0x47;  //right
char PA_POWER=0x0F;  // 
    


 

⌨️ 快捷键说明

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