51 MCU with nrf905 header file

Publisher:幸福时光Latest update time:2021-03-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction: This article provides a code for a 51 microcontroller using the nrf905 header file.

#define nRFMainDev //Main device

//#define SysWaitTime 20//0.5*20=10S, stop flashing if no key is pressed

#define SysWaitTime 6 //0.5*20=3S, no key press, stop flashing

#define SysPushKeyTime 150 //Long press key 150 * 20mS = 3.0S

#define T2_5mS -921.6*5//5ms 12MHz

/*------------------------------------------------

AT89S5X

--------------------------------------------------*/

sfr   AUXR    = 0x8e;

sfr   WDTRST  = 0xa6;

sfr16 TIMEER2 = 0xcc;

sfr16 RCAP    = 0xca;

//Global variable definition

typedef struct Systemstruct{//system data structure

// unsigned char SystemFlage; //system flag

  unsigned char TimeCount;

  unsigned int RamTest;

  unsigned char TestTime;

  unsigned char WaitTime;

  unsigned char KeyCount[4];

  unsigned char nRFTxCount;

  unsigned char nRFRxCount;

  unsigned char nRFTxBuff[32];

  unsigned char nRFRxBuff[32];

}SystemData;

//Global variable definition

typedef struct Siostruct{//system data structure

  unsigned char SioTxBuff[32];

  unsigned char SioRxBuff[32];

  unsigned char SioTXCount;

  unsigned char SioRXCount;

}SioData;

/*-----------------------------------------------

        nrf905 pin definition

------------------------------------------------*/

sbit TX_EN = P2^6;//0

sbit TRX_CE = P2^5;//0

sbit PWR_UP = P2^4;//1

sbit MISO = P2^3;//1

sbit MOSI = P2^2;//1

sbit SCK = P2^1;//0

sbit CSN = P2^0;//1

sbit AM  = P3^2;//1

sbit DR = P3^3;//1

sbit CD = P3^5;//1

sbit KEY0 = P0^0;

sbit KEY1 = P0^1;

sbit KEY2 = P0^2;

sbit KEY3 = P0^3;

sbit LED0 = P0^4;

sbit LED1 = P0^5;

sbit LED2 = P0^6;

sbit LED3 = P0^7;

#define Status_AM 0x80

#define Status_DR 0x20

/*-----------------------------------------------

        nrf905 command control word

------------------------------------------------*/

#define WC  0x00   // Write configuration register command

#define RC  0x10    // Read  configuration register command

#define WTP  0x20    // Write TX Payload  command

#define RTP  0x21   // Read  TX Payload  command

#define WTA  0x22   // Write TX Address  command

#define RTA  0x23   // Read  TX Address  command

#define RRP  0x24   // Read  RX Payload  command

#define CC      0x80            // fast config

/*-------------------------------------------------------------------------------------------

        nrf905 configuration register (10Byte)

Operating frequency f=(422.4+CH_NO/10)*(1+HFREQ_PLL)MHz

-------------------------------------------------------------------------------------------*/

#ifdef  nRFMainDev

#define RX_ADDRESS 0x00000000 //Receive valid address

//#define TX_ADDRESS 0x12345678 //Send valid address

//#define TX_ADDRESS 0x02345678 //Send valid address

#else

//#define RX_ADDRESS 0x12345678 //Receive valid address

#define RX_ADDRESS 0x12345678 //Receive valid address

//#define TX_ADDRESS 0x00000000 //Send valid address

#endif

#define CH_NO_FREQ_422_4MHz 0x000 //Working frequency 422.4MHz (lowest frequency in 433MHz band)

#define CH_NO_FREQ_422_5MHz 0x001 //Working frequency 422.5MHz

#define CH_NO_FREQ_425_0MHz 0x01a //Working frequency 425.0MHz

#define CH_NO_FREQ_427_5MHz 0x033 //Working frequency 427.5MHz

#define CH_NO_FREQ_430_0MHz 0x04c //Working frequency 430.0MHz

#define CH_NO_FREQ_433_0MHz 0x06a //Working frequency 433.0MHz (433MHz band reference frequency)

#define CH_NO_FREQ_433_1MHz 0x06b //Working frequency 433.1MHz

#define CH_NO_FREQ_433_2MHz 0x06c //Working frequency 433.2MHz

#define CH_NO_FREQ_434_7MHz 0x07b //Working frequency 434.7MHz

#define CH_NO_FREQ_473_5MHz 0x1ff //Working frequency 473.5MHz (highest frequency in 433MHz band)

#define CH_NO_FREQ_844_8MHz 0x000 //Working frequency 844.8MHz (the lowest frequency in the 868MHz band)

#define CH_NO_FREQ_862_0MHz 0x056 //Working frequency 862.0MHz

#define CH_NO_FREQ_868_0MHz 0x074 //Working frequency 868.0MHz (868MHz band reference frequency)

#define CH_NO_FREQ_868_2MHz 0x075 //Working frequency 868.2MHz

#define CH_NO_FREQ_868_4MHz 0x076 //Working frequency 868.4MHz

#define CH_NO_FREQ_869_8MHz 0x07d //Working frequency 869.8MHz

#define CH_NO_FREQ_895_8MHz 0x0ff //Working frequency 895.8MHz

#define CH_NO_FREQ_896_0MHz 0x100 //Working frequency 896.0MHz

#define CH_NO_FREQ_900_0MHz 0x114 //Working frequency 900.0MHz

#define CH_NO_FREQ_902_2MHz 0x11f //Working frequency 902.2MHz

#define CH_NO_FREQ_902_4MHz 0x120 //Working frequency 902.4MHz

#define CH_NO_FREQ_915_0MHz 0x15f //Working frequency 915.0MHz (915MHz band reference frequency)

#define CH_NO_FREQ_927_8MHz 0x19f //Working frequency 927.8MHz

#define CH_NO_FREQ_947_0MHz 0x1ff //Working frequency 947.0MHz (highest frequency in 915MHz band)

#define CH_NO_FREQ CH_NO_FREQ_430_0MHz //Operating frequency 433.0MHz


#define CH_NO_BYTE CH_NO_FREQ & 0xff //Low 8 bits of operating frequency Byte0 01101100

#define AUTO_RETRAN 0x20 //Resend data packet Byte1.5 0

#define RX_RED_PWR 0x10 //Receive low power mode Byte1.4 0

#define PA_PWR__10dBm 0x00 //Output power -10dBm Byte1.3~2 00

#define PA_PWR_2dBm 0x04 //Output power +2dBm Byte1.3~2

#define PA_PWR_6dBm 0x08 //Output power +6dBm Byte1.3~2

#define PA_PWR_10dBm 0x0c //Output power +10dBm Byte1.3~2  

#define HFREQ_PLL_433MHz 0x00 //Work in 433MHz frequency band Byte1.1 0

#define HFREQ_PLL_868MHz 0x02 //Work in 868MHz frequency band Byte1.1

#define HFREQ_PLL_915MHz 0x02 //Work in 915MHz frequency band Byte1.1

#define CH_NO_BIT8 CH_NO_FREQ >> 8 //9th bit of operating frequency Byte1.0 0

#define TX_AFW_1BYTE 1 * 16 //Send address width 1 byte Byte2.7~4

#define TX_AFW_2BYTE 2 * 16 //Send address width 2 bytes Byte2.7~4

#define TX_AFW_3BYTE 3 * 16 //Send address width 3 bytes Byte2.7~4

#define TX_AFW_4BYTE 4 * 16 //Transmit address width 4 bytes Byte2.7~4 100

#define RX_AFW_1BYTE 1 //Receive address width 1 byte Byte2.3~0

#define RX_AFW_2BYTE 2 //Receive address width 2 bytes Byte2.3~0

#define RX_AFW_3BYTE 3 //Receive address width 3 bytes Byte2.3~0

#define RX_AFW_4BYTE 4 //Receive address width 4 bytes Byte2.3~0 100

#define RX_PW_1BYTE 1 //Receive data width 1 byte Byte3.5~0

#define RX_PW_32BYTE 32 //Receive data width 32 bytes Byte3.5~0 00100000

#define TX_PW_1BYTE 1 //Send data width 1 byte Byte4.5~0

#define TX_PW_32BYTE 32 //Send data width 32 bytes Byte4.5~0 00100000

#define RX_ADDRESS_0 RX_ADDRESS >> 24 //Receive the first byte of the effective address Byte5 11100111

#define RX_ADDRESS_1 (RX_ADDRESS >> 16) & 0xff //Receive the second byte of the effective address Byte6 11100111

#define RX_ADDRESS_2 (RX_ADDRESS >> 8) & 0xff //Receive the third byte of the effective address Byte7 11100111

#define RX_ADDRESS_3 RX_ADDRESS & 0xff //Receive the effective address 4th byte Byte8 11100111

      

#define CRC_MODE_16BIT 0x80 //CRC16 mode Byte9.7 1

#define CRC_MODE_8BIT 0x00 //CRC8 mode Byte 9.7    

#define CRC_EN 0x40 //CRC enable Byte9.6 1

#define CRC16_EN 0xc0 //CRC16 mode enable Byte9.7~6 11

#define CRC8_EN 0x40 //CRC8 mode enable Byte 9.7~6

#define XOF_20MHz 0x20 //Crystal oscillator frequency 20MHz Byte9.5~3

#define XOF_16MHz 0x18 //Crystal oscillator frequency 16MHz Byte9.5~3 100

#define XOF_12MHz 0x10 //Crystal oscillator frequency 12MHz Byte9.5~3

#define XOF_8MHz 0x08 //Crystal oscillator frequency 8MHz Byte9.5~3

#define XOF_4MHz 0x00 //Crystal oscillator frequency 4MHz Byte9.5~3

#define UP_CLK_EN 0x40 //Output clock enable Byte9.2 1

#define UP_CLK_FREQ_500kHz 0x03 //Output clock frequency 500kHz Byte9.1~0 11

#define UP_CLK_FREQ_1MHz 0x02 //Output clock frequency 1MHz Byte9.1~0

#define UP_CLK_FREQ_2MHz 0x01 //Output clock frequency 2MHz Byte9.1~0

#define UP_CLK_FREQ_4MHz 0x00 //Output clock frequency 4MHz Byte9.1~0

#define UP_CLK_EN_500kHz 0x43 //Output clock frequency 500kHz Byte9.2~0 111

#define UP_CLK_EN_1MHz 0x42 //Output clock frequency 1MHz Byte9.2~0

#define UP_CLK_EN_2MHz 0x41 //Output clock frequency 2MHz Byte9.2~0

#define UP_CLK_EN_4MHz 0x40 //Output clock frequency 4MHz Byte9.2~0

//#define TX_ADDRESS_0 TX_ADDRESS >> 24 //Send and receive valid address 1st byte

//#define TX_ADDRESS_1 (TX_ADDRESS >> 16) & 0xff //Send the second byte of the effective address

//#define TX_ADDRESS_2 (TX_ADDRESS >> 8) & 0xff //Send the third byte of the effective address

//#define TX_ADDRESS_3 TX_ADDRESS & 0xff //Send the 4th byte of the effective address

/*-----------------------------------------------

        nrf905 library function definition

------------------------------------------------*/

extern unsigned char SpiReadWrite(unsigned char);

extern void WriteTXAddr(unsigned long);

extern void WriteTXBuffer(const unsigned char []);

extern unsigned char ReadStatus(void);

extern void nRF905PowerUP(void);


Reference address:51 MCU with nrf905 header file

Previous article:51 MCU receiving array knowledge
Next article:Design and implementation of GPRS data transmission module

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号