📄 main.h
字号:
/********************************************
Main.h
*********************************************/
#define FALSE 0
#define TRUE (!FALSE)
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
#define HEADER_SIZE 4 // 4 bytes header
#define UI1 0xD3 /* First byte of unique identifier */
#define UI2 0x91 /* Second byte of unique identifier */
#define PREAMBLE_LENGTH 19 //13
volatile char PreambleError=0;
volatile bit UI1_Found=FALSE;
volatile bit PreambleFound=FALSE;
volatile unsigned char PreambleBitCount=0;
#define PREAMBLE_BIT_REQ 64 //90
volatile unsigned char TC1_interrupt_count=0;
unsigned int Card_ID = 0x13; //0b0000000000010011; // (14位2进制数)可以识别的Card数目2exp(14)=16384个
eeprom unsigned char tflag =0;
unsigned char flag=0xff;
//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.
/**********************************************************************************************
UART Buffer Definition
***********************************************************************************************/
#define RX_BUFFER_SIZE0 8
#define TX_BUFFER_SIZE0 8
// USART Receiver buffer这里的Buffer是UART收发数据的Buffer, 而不是读写CC1000的Buffer.
// 很重要!! 这两者能够合起来吗? CC1000参考设计是公用的, ∵那是RF_modem? 搞清楚什么是MODEM!!!
//所以初步估计, 在我们目前的应用, 这两者是不能混为一谈的!!!! 所以要另外定义读写CC1000的Buffer!
char rx_buffer0[RX_BUFFER_SIZE0];
#if RX_BUFFER_SIZE0<256
volatile unsigned char rx_wr_index0=0,rx_rd_index0=0,rx_counter0=0;
#else
volatile unsigned int rx_wr_index0=0,rx_rd_index0=0,rx_counter0=0;
#endif
// USART Transmitter buffer
char tx_buffer0[TX_BUFFER_SIZE0];
//tx_counter0 用来指示缓冲区已有的数据,若tx_counter0=0,表示缓冲区空
//tx_wr_index0 表示缓冲区的下一个空位, 也就是用来存储下一个缓冲数据的位置
//tx_rd_index0 缓冲区的读取指针, 指向要发送的下一个字符在缓冲区的位置.
#if TX_BUFFER_SIZE0<256
volatile unsigned char tx_wr_index0=0,tx_rd_index0=0,tx_counter0=0;
#else
volatile unsigned int tx_wr_index0=0,tx_rd_index0=0,tx_counter0=0;
#endif
// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow0;
/**********************************************************************************************
CC1000 Buffer Definition
***********************************************************************************************/
#define Rd1000_Buffer_size 16
//#define Wr1000_Buffer_size 8
char Rd1000_Buffer[Rd1000_Buffer_size];
char Wr1000_Buffer [PREAMBLE_LENGTH+6]; // Array, not Really Buffer!!
//char Wr1000_Buffer[Wr1000_Buffer_size]; //这里简单起见, WR不用Buffer, 只发送固定长度的ID加校验码
// Use the if to save RAM space
#if Rd1000_Buffer_size<256
volatile unsigned char Rd1000_wr_index=0,Rd1000_rd_index=0,Rd1000_counter=0;
#else
volatile unsigned int Rd1000_wr_index=0,Rd1000_rd_index=0,Rd1000_counter=0;
#endif
volatile unsigned char Wr1000_Buffer_Index=0;
#define REQ_Send_ID_Times 1 //每次处于发送状态时,发送ID的次数 用次数来保证可靠性.
volatile unsigned char Send_TD_Times_count=0;
//sfrb ShiftReg;
//char bdata shiftREG
/*
typedef struct {
unsigned char ShiftRegLSB:1;
unsigned char ShiftRegLSB1:1;
unsigned char ShiftRegLSB2:1;
unsigned char ShiftRegLSB3:1;
unsigned char ShiftRegLSB4:1;
unsigned char ShiftRegLSB5:1;
unsigned char ShiftRegLSB6:1;
unsigned char ShiftRegMSB:1;
}BitStruct;
union myunion{
unsigned char ShiftReg;
BitStruct ShiftStruct;
}Union1;
*/
volatile char ShiftReg=0;
// unsigned char rShiftReg=0;
//char rByteCounter=0;
//char rBitCounter=0;
/*
#if Wr1000_Buffer_size<256
volatile unsigned char Wr1000_wr_index=0,Wr1000_rd_index=0,Wr1000_counter=0;
#else
volatile unsigned int Wr1000_wr_index=0,Wr1000_rd_index=0,Wr1000_counter=0;
#endif
*/
/**********************************************************************************************
CC1000 T/R DATA Global Variables
***********************************************************************************************/
// Index pointers for use with buffers
//volatile char TXBufferIndex;
//char RXBufferReadIndex;
//volatile char RXBufferWriteIndex;
// Unit address is not used
// Counter variables
char PreambleCount=0;
//char PreambleError=0;
char ByteCounter=0;
char BitCounter=0;
// 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,WR1000_STATE=1,Rd1000_STATE=2} State;
// 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;
// This struct stores various flags in a space-efficient manner
/*
volatile struct
{
unsigned char PreambleFound:1; //后面的1表示是1bit
unsigned char UI1Found:1;
unsigned char LastPreambleBit:1;
unsigned char LockAverage:1; //搞清楚这个平均值滤波器到底是干什么的, 有什么用, LOCK与Free RUN的区别
unsigned char UnlockAverage:1;
}StructControl;
*/
/**********************************************************************************************
CC1000 Register configuration Array
***********************************************************************************************/
// Configures all the CC1000 registers according to the values stored in EEPROM
/* char EEPROMCC1000Config[34]={0x00,0x66,0xC0,0x00,0x41,
0xFB,0x2D,0x02,0x80,0x44,
0x12,0x0F,0x70,0x10,0x26,
0x8E,0x69,0x47,0x70,0x01,
0x1C,0x16,0x10,0x0A,0x06,
0x03,0x01,0x02,0x00,0x00,
0x00,0x3F}; */
/* const char DefaultConfig433[35] = {0x66,0xC0,0x00,0x41,0xFB,
0x2D,0x02,0x80,0x44,0x12,
0x0F,0x70,0x10,0x26,0x8E,
0x69,0x47,0x70,0x01,0x1C,
0x16,0x10,0x0A,0x06,0x03,
0x01,0x02,0x00,0x00,0x00,
0x3F,0x00};
*/
//M 2.4kB internal
/* char EEPROMCC1000Config[34]={0x00,0x66,0xC0,0x00,0x41,
0xFB,0x2D,0x02,0x80,0x44,
0x10,0x0F,0x70,0x10,0x26,
0x8E,0x69,0x27,0x70,0x01,
0x1C,0x16,0x10,0x0A,0x06,
0x03,0x01,0x02,0x00,0x00,
0x00,0x3F}; */ //last works
/* char EEPROMCC1000Config[34]={0x00,0x66,0xC0,0x00,0x41,
0xFB,0x2D,0x02,0x80,0x44,
0x12,0x0F,0x70,0x10,0x26,
0x8E,0x69,0x47,0x70,0x01,
0x1C,0x16,0x10,0x0A,0x06,
0x03,0x01,0x02,0x00,0x00,
0x00,0x00,0x00,0x00}; */
/* char EEPROMCC1000Config[34]={0x00,
0x66,0xC0,0x00,0x41,0xFB,
0x2D,0x02,0x80,0x44,0x12,
0x0F,0x70,0x10,0x26,0x8E,
0x69,0x47,0x70,0x01,0x1C,
0x16,0x10,0x0A,0x06,0x03,
0x01,0x02,0x00,0x00,0x00,
0x3F,0x00,0x00}; */
/*
char EEPROMCC1000Config[34]={0x00,
0x66,0xA0,0x00,0x41,0xF2,
0x4E,0x02,0x8A,0x81,0x10,
0x0F,0x48,0x10,0x26,0x8E,
0x6F,0x57,0x70,0x01,0x1C,
0x16,0x10,0x0A,0x06,0x03,
0x01,0x02,0x00,0x00,0x00,
0x3F,0x00,0x00}; */
/*
char EEPROMCC1000Config[34]={0x00,
0x66,0xA0,0x00,0x41,0xF3, // 0x01
0x7F,0x00,0x28,0x81,0x10, // 0x06
0x0F,0x48,0x00,0x26,0x8A, // 0x0b
0x6F,0x37,0x70,0x01,0x1C, // 0x10
0x16,0x10,0x0A,0x06,0x03, // 0x15
0x01,0x02,0x00,0x00,0x00, // 0x1a
0x25,0x00,0x00}; */ //4.8k good
/*
char EEPROMCC1000Config[34]={0x00,
0x66,0xA0,0x00,0x41,0xF3, // 0x01
0x7F,0x00,0x28,0x81,0x10, // 0x06
0x1F,0x48,0x00,0x26,0x8A, // 0x0b
0x6F,0x57,0x70,0x01,0x1C, // 0x10
0x16,0x10,0x0A,0x06,0x03, // 0x15
0x01,0x02,0x00,0x00,0x00, // 0x1a
0x3F,0x00,0x00}; //19.2k */ // bad
/*
char EEPROMCC1000Config[34]={0x00,
0x66,0xA0,0x00,0x41,0xF3, // 0x01
0x7F,0x00,0x28,0x81,0x10, // 0x06
0x0F,0x48,0x00,0x26,0x8A, // 0x0b
0x6F,0x57,0x70,0x01,0x1C, // 0x10
0x16,0x10,0x0A,0x06,0x03, // 0x15
0x01,0x02,0x00,0x00,0x00, // 0x1a
0x3F,0x00,0x00}; */
char EEPROMCC1000Config[34]={0x00,
0x58,0x00,0x00,0x41,0xFC, // 0x01
0x9C,0x02,0x80,0x81,0x10, // 0x06
0x0F,0x48,0x10,0x26,0x8E, // 0x0b
0x6F,0x57,0x70,0x01,0x1C, // 0x10
0x16,0x10,0x0A,0x06,0x03, // 0x15
0x01,0x02,0x00,0x00,0x00, // 0x1a
0x3F,0x00,0x00};
/* Contents of PLL register for TX and RX, use SmartRF(R) Studio */
/* to find values for your application */
#define TXPLL 0x48 //by LY
#define RXPLL 0x60 //by LY
/* Contents of CURRENT register for TX and RX, use SmartRF(R) Studio */
/* to find values for your application */
//#define TX_CURRENT 0xF3
//#define RX_CURRENT 0x8C
#define TX_CURRENT 0x81
#define RX_CURRENT 0x44
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -