51单片机:温度采集、显示和发射接收

发射:TX

接收:RX

NRF24L01.c

#include "typedef.h"

#include <intrins.h>

#include <string.h>

#include "NRF24L01.h"

#include "delay.h"

#define uchar unsigned char

uchar const TX_ADDRESS[TX_ADR_WIDTH]  = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address

idata uchar rx_buf[TX_PLOAD_WIDTH];

idata uchar tx_buf[TX_PLOAD_WIDTH];

uchar flag;

unsigned char bdata sta;

sbit  RX_DR     =sta^6;

sbit  TX_DS      =sta^5;

sbit  MAX_RT  =sta^4;

/**************************************************/

void init_nrf24l01_io(void)

{

         CE=0;                         // chip enable

         CSN=1;                      // Spi disable  

         SCK=0;                       // Spi clock line init high

}

/**************************************************

Function: SPI_RW();

Description:

  Writes one byte to nRF24L01, and return the byte read

  from nRF24L01 during write, according to SPI protocol

/**************************************************/

bdata unsigned char st=0;

sbit st_1=st^0;

sbit st_2=st^1;

sbit st_3=st^2;

sbit st_4=st^3;

sbit st_5=st^4;

sbit st_6=st^5;

sbit st_7=st^6;

sbit st_8=st^7;

bdata unsigned char st1=0;

sbit st_11=st1^0;

sbit st_12=st1^1;

sbit st_13=st1^2;

sbit st_14=st1^3;

sbit st_15=st1^4;

sbit st_16=st1^5;

sbit st_17=st1^6;

sbit st_18=st1^7;

/*

uchar SPI_RW(uchar byte)

{

         uchar bit_ctr;

     for(bit_ctr=0;bit_ctr<8;bit_ctr++)   // output 8-bit

     {

              MOSI = (byte & 0x80);         // output 'byte', MSB to MOSI

              byte = (byte << 1);           // shift next bit into MSB..

              SCK = 1;                      // Set SCK high..

                  MISO=1;

              byte |= MISO;                     // capture current MISO bit

              SCK = 0;                          // ..then set SCK low again

     }

    return(byte);                           // return read byte

}

*/

uchar SPI_RW(uchar byte)

{

         //uchar bit_ctr;

    st=byte;

    MOSI=st_8;

    SCK = 1;

    st_18=MISO;

    SCK = 0;

    MOSI=st_7;

    SCK = 1;

    st_17=MISO;

    SCK = 0;

    MOSI=st_6;

    SCK = 1;

    st_16=MISO;

    SCK = 0;

    MOSI=st_5;

    SCK = 1;

    st_15=MISO;

    SCK = 0;

    MOSI=st_4;

    SCK = 1;

    st_14=MISO;

    SCK = 0;

    MOSI=st_3;

    SCK = 1;

    st_13=MISO;

    SCK = 0;

    MOSI=st_2;

    SCK = 1;

    st_12=MISO;

    SCK = 0;

    MOSI=st_1;

    SCK = 1;

    st_11=MISO;

    SCK = 0;

    return(st1);                              // return read byte

}

/**************************************************/

/**************************************************

Function: SPI_RW_Reg();

Description:

  Writes value 'value' to register 'reg'

/**************************************************/

uchar SPI_RW_Reg(BYTE reg, BYTE value)

{

         uchar status;

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值