亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? nrf24l01.c

?? 介紹NRF24L01的多通道(Multiple Pipes),其中文件nrf24l01.c實現此射頻芯片在多通道下的通信
?? C
?? 第 1 頁 / 共 3 頁
字號:
/******************************************************************************
*
* File: nrf24l01.c
* 
* Copyright S. Brennen Ball, 2006-2007
* 
* The author provides no guarantees, warantees, or promises, implied or
*	otherwise.  By using this software you agree to indemnify the author
* 	of any damages incurred by using it.
*
*****************************************************************************/

#include "nrf24l01.h"

//Arguments except opt_rx_standby_mode fill the actual register they are named 
//  after. Registers that do not need to be initialized are not included here.
//The argument opt_rx_active_mode is only used if the user is initializing the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
//If the user wants to leave any 1-byte register in its default state, simply put
//  as that register's argument nrf24l01_<reg>_DEFAULT_VAL, where <reg> is the register
//  name.
//If the user wants to leave any of the 5-byte registers RX_ADDR_P0, RX_ADDR_P1, or 
//  TX_ADDR in its default state, simply put NULL in the argument for that address value.
void nrf24l01_initialize(unsigned char config,
						 unsigned char opt_rx_active_mode,  
						 unsigned char en_aa, 
						 unsigned char en_rxaddr, 
						 unsigned char setup_aw, 
						 unsigned char setup_retr, 
						 unsigned char rf_ch, 
						 unsigned char rf_setup, 
						 unsigned char * rx_addr_p0, 
						 unsigned char * rx_addr_p1, 
						 unsigned char rx_addr_p2, 
						 unsigned char rx_addr_p3, 
						 unsigned char rx_addr_p4, 
						 unsigned char rx_addr_p5, 
						 unsigned char * tx_addr, 
						 unsigned char rx_pw_p0, 
						 unsigned char rx_pw_p1, 
						 unsigned char rx_pw_p2, 
						 unsigned char rx_pw_p3, 
						 unsigned char rx_pw_p4, 
						 unsigned char rx_pw_p5)
{
	unsigned char data[5];

	data[0] = en_aa;
	nrf24l01_write_register(nrf24l01_EN_AA, data, 1);

	data[0] = en_rxaddr;
	nrf24l01_write_register(nrf24l01_EN_RXADDR, data, 1);

	data[0] = setup_aw;
	nrf24l01_write_register(nrf24l01_SETUP_AW, data, 1);

	data[0] = setup_retr;
	nrf24l01_write_register(nrf24l01_SETUP_RETR, data, 1);

	data[0] = rf_ch;
	nrf24l01_write_register(nrf24l01_RF_CH, data, 1);

	data[0] = rf_setup;
	nrf24l01_write_register(nrf24l01_RF_SETUP, data, 1);

	if(rx_addr_p0 != NULL)
		nrf24l01_set_rx_addr(rx_addr_p0, 5, 0);
	else
	{
		data[0] = nrf24l01_RX_ADDR_P0_B0_DEFAULT_VAL;
		data[1] = nrf24l01_RX_ADDR_P0_B1_DEFAULT_VAL;
		data[2] = nrf24l01_RX_ADDR_P0_B2_DEFAULT_VAL;
		data[3] = nrf24l01_RX_ADDR_P0_B3_DEFAULT_VAL;
		data[4] = nrf24l01_RX_ADDR_P0_B4_DEFAULT_VAL;
		
		nrf24l01_set_rx_addr(data, 5, 0);
	}

	if(rx_addr_p1 != NULL)
		nrf24l01_set_rx_addr(rx_addr_p1, 5, 1);
	else
	{
		data[0] = nrf24l01_RX_ADDR_P1_B0_DEFAULT_VAL;
		data[1] = nrf24l01_RX_ADDR_P1_B1_DEFAULT_VAL;
		data[2] = nrf24l01_RX_ADDR_P1_B2_DEFAULT_VAL;
		data[3] = nrf24l01_RX_ADDR_P1_B3_DEFAULT_VAL;
		data[4] = nrf24l01_RX_ADDR_P1_B4_DEFAULT_VAL;
		
		nrf24l01_set_rx_addr(data, 5, 1);
	}

	data[0] = rx_addr_p2;
	nrf24l01_set_rx_addr(data, 1, 2);

	data[0] = rx_addr_p3;
	nrf24l01_set_rx_addr(data, 1, 3);

	data[0] = rx_addr_p4;
	nrf24l01_set_rx_addr(data, 1, 4);

	data[0] = rx_addr_p5;
	nrf24l01_set_rx_addr(data, 1, 5);

	if(tx_addr != NULL)
		nrf24l01_set_tx_addr(tx_addr, 5);
	else
	{
		data[0] = nrf24l01_TX_ADDR_B0_DEFAULT_VAL;
		data[1] = nrf24l01_TX_ADDR_B1_DEFAULT_VAL;
		data[2] = nrf24l01_TX_ADDR_B2_DEFAULT_VAL;
		data[3] = nrf24l01_TX_ADDR_B3_DEFAULT_VAL;
		data[4] = nrf24l01_TX_ADDR_B4_DEFAULT_VAL;
		
		nrf24l01_set_tx_addr(data, 5);
	}

	data[0] = rx_pw_p0;
	nrf24l01_write_register(nrf24l01_RX_PW_P0, data, 1);

	data[0] = rx_pw_p1;
	nrf24l01_write_register(nrf24l01_RX_PW_P1, data, 1);

	data[0] = rx_pw_p2;
	nrf24l01_write_register(nrf24l01_RX_PW_P2, data, 1);

	data[0] = rx_pw_p3;
	nrf24l01_write_register(nrf24l01_RX_PW_P3, data, 1);

	data[0] = rx_pw_p4;
	nrf24l01_write_register(nrf24l01_RX_PW_P4, data, 1);

	data[0] = rx_pw_p5;
	nrf24l01_write_register(nrf24l01_RX_PW_P5, data, 1);

	if((config & nrf24l01_CONFIG_PWR_UP) != 0)
		nrf24l01_power_up_param(opt_rx_active_mode, config);
	else
		nrf24l01_power_down_param(config);
}

//initializes the 24L01 to all default values except the PWR_UP and PRIM_RX bits
//this function also disables the auto-ack feature on the chip (EN_AA register is 0)
//bool rx is true if the device should be a receiver and false if it should be
//  a transmitter.
//unsigned char payload_width is the payload width for pipe 0.  All other pipes
//  are left in their default (disabled) state.
//bool enable_auto_ack controls the auto ack feature on pipe 0.  If true, auto-ack will
//  be enabled.  If false, auto-ack is disabled.
void nrf24l01_initialize_debug(bool rx, unsigned char p0_payload_width, bool enable_auto_ack)
{
	unsigned char config;
	unsigned char en_aa;
	
	config = nrf24l01_CONFIG_DEFAULT_VAL | nrf24l01_CONFIG_PWR_UP;
	
	if(enable_auto_ack != false)
		en_aa = nrf24l01_EN_AA_ENAA_P0;
	else
		en_aa = nrf24l01_EN_AA_ENAA_NONE;
	
	if(rx == true)
		config = config | nrf24l01_CONFIG_PRIM_RX;
		
	nrf24l01_initialize(config, 
						true,
						en_aa, 
						nrf24l01_EN_RXADDR_DEFAULT_VAL, 
						nrf24l01_SETUP_AW_DEFAULT_VAL, 
						nrf24l01_SETUP_RETR_DEFAULT_VAL, 
						nrf24l01_RF_CH_DEFAULT_VAL, 
						nrf24l01_RF_SETUP_DEFAULT_VAL,  
						NULL, 
						NULL, 
						nrf24l01_RX_ADDR_P2_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P3_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P4_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P5_DEFAULT_VAL, 
						NULL, 
						p0_payload_width, 
						nrf24l01_RX_PW_P1_DEFAULT_VAL, 
						nrf24l01_RX_PW_P2_DEFAULT_VAL, 
						nrf24l01_RX_PW_P3_DEFAULT_VAL, 
						nrf24l01_RX_PW_P4_DEFAULT_VAL, 
						nrf24l01_RX_PW_P5_DEFAULT_VAL);
}

//initializes only the CONFIG register and pipe 0's payload width
//the primary purpose of this function is to allow users with microcontrollers with
//  extremely small program memories to still be able to init their 24L01.  This code
//  should have a smaller footprint than the above init functions.
//when using this method, the 24L01 MUST have its default configuration loaded
//  in all registers to work.  It is recommended that the device be reset or
//  have its power cycled immediately before this code is run.
//in normal circumstances, the user should use nrf24l01_initialize() rather than this
//  function, since this function does not set all of the register values.
void nrf24l01_initialize_debug_lite(bool rx, unsigned char p0_payload_width)
{
	unsigned char config;
	
	config = nrf24l01_CONFIG_DEFAULT_VAL;
	
	if(rx != false)
		config |= nrf24l01_CONFIG_PRIM_RX;
		
	nrf24l01_write_register(nrf24l01_RX_PW_P0, &p0_payload_width, 1);
	nrf24l01_power_up_param(true, config);
}

//powers up the 24L01 with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PWR_UP 
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
//note: if the read value of the CONFIG register already has the PWR_UP bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_power_up(bool rx_active_mode)
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) != 0)
		return;
		
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);
	
	delay_us(1500);
	
	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}

//powers up the 24L01 with all necessary delays
//this function allows the user to set the contents of the CONFIG register, but the function
//  sets the PWR_UP bit in the CONFIG register, so the user does not need to.
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
void nrf24l01_power_up_param(bool rx_active_mode, unsigned char config)
{
	unsigned char test, test2;
	
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	delay_us(1500);

	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}

//powers down the 24L01
//this function takes the existing contents of the CONFIG register and simply
//  clears the PWR_UP bit in the CONFIG register.
//note: if the read value of the CONFIG register already has the PWR_UP bit cleared, this 
//  function exits in order to not make an unecessary register write.
void nrf24l01_power_down()
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) == 0)
		return;
	
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}

//powers down the 24L01
//this function allows the user to set the contents of the CONFIG register, but the function
//  clears the PWR_UP bit in the CONFIG register, so the user does not need to.
void nrf24l01_power_down_param(unsigned char config)
{
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}


//sets up the 24L01 as a receiver with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PRIM_RX 
//  bit in the CONFIG register.
//if the argument rx_active_mode is false, the receiver will remain in standby mode
//  and not monitor for packets.  If the argument is true, the CE pin will be set 
//  and the 24L01 will monitor for packets.
//note: if the read value of the CONFIG register already has the PRIM_RX bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_set_as_rx(bool rx_active_mode)
{
	unsigned char config;
	unsigned char status;
	
	status = nrf24l01_read_register(0, &config, 1);

	if((config & nrf24l01_CONFIG_PRIM_RX) != 0)
		return;

	config |= nrf24l01_CONFIG_PRIM_RX;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	if(rx_active_mode != false)
		nrf24l01_set_ce();
	else
		nrf24l01_clear_ce();
}

//sets up the 24L01 as a receiver with all necessary delays
//this function allows the user to set the contents of the CONFIG register, but the function
//  sets the PRIM_RX bit in the CONFIG register, so the user does not need to.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
青青草国产精品97视觉盛宴| 亚洲线精品一区二区三区| 欧美日韩国产综合一区二区| aa级大片欧美| 成人一区二区三区视频在线观看| 久久99久久99小草精品免视看| 爽好久久久欧美精品| 一区二区三区不卡视频在线观看 | 中文字幕av不卡| 久久夜色精品一区| 久久蜜桃av一区二区天堂| 精品国产1区二区| 久久这里只有精品首页| 国产日韩欧美亚洲| 亚洲天堂免费看| 日韩美女视频一区二区 | 在线成人午夜影院| 7777精品伊人久久久大香线蕉的| 欧美另类videos死尸| 欧美一级欧美三级在线观看| 日韩一区二区三区高清免费看看| 欧美精品 国产精品| 日韩欧美国产精品一区| 久久你懂得1024| 亚洲色图.com| 亚洲国产综合视频在线观看| 日本不卡在线视频| 成人小视频免费观看| 一本到高清视频免费精品| 欧美性极品少妇| 久久久久久久久蜜桃| 国产精品九色蝌蚪自拍| 亚洲国产欧美在线| 国产一区二区中文字幕| 99久久99久久免费精品蜜臀| 在线观看一区日韩| 精品成人私密视频| 亚洲免费观看在线观看| 日韩激情中文字幕| 成人影视亚洲图片在线| 欧美天堂亚洲电影院在线播放| 欧美一区二区网站| 亚洲视频一区二区在线| 欧美bbbbb| 91在线观看成人| 精品福利av导航| 亚洲欧洲综合另类| 久久不见久久见免费视频1| 91日韩精品一区| 精品电影一区二区三区| 亚洲一区二区三区国产| 国产成人在线免费观看| 在线欧美小视频| 久久精品人人爽人人爽| 视频一区二区中文字幕| av在线不卡网| 欧美精品一区二区三| 一区二区三区在线免费| 国产丶欧美丶日本不卡视频| 日韩一区二区在线观看视频播放| 亚洲日本成人在线观看| 久草精品在线观看| 91精品国产丝袜白色高跟鞋| 亚洲欧美aⅴ...| 国产成人免费av在线| 精品日产卡一卡二卡麻豆| 午夜精品aaa| 欧美日韩一卡二卡| 亚洲欧美一区二区三区久本道91| 久久99日本精品| 欧美男生操女生| 亚洲亚洲人成综合网络| 色狠狠色噜噜噜综合网| 中文字幕中文字幕一区二区| 国产69精品久久99不卡| 久久这里只有精品视频网| 开心九九激情九九欧美日韩精美视频电影 | 激情综合网天天干| 91精选在线观看| 午夜精彩视频在线观看不卡| 在线观看一区二区精品视频| 亚洲欧美日本在线| 在线精品观看国产| 亚洲国产aⅴ天堂久久| 欧美三级中文字幕在线观看| 亚洲一区二区三区爽爽爽爽爽 | 国产精品一区二区三区99| 91精品婷婷国产综合久久竹菊| 亚洲综合图片区| 欧美男生操女生| 久久精品久久99精品久久| 欧美成va人片在线观看| 国产在线观看一区二区| 国产欧美日本一区视频| 99久久精品国产麻豆演员表| 亚洲欧美日韩国产成人精品影院| 日本韩国一区二区三区视频| 一个色在线综合| 欧美一区二区三区日韩视频| 久久国产精品一区二区| 亚洲精品一区二区三区影院| 国产剧情一区二区三区| 国产精品色一区二区三区| 97精品电影院| 偷窥国产亚洲免费视频| 精品剧情v国产在线观看在线| 国产美女精品在线| 亚洲激情图片一区| 日韩一区二区免费视频| 国产成人免费视频一区| 亚洲天堂福利av| 欧美一卡二卡三卡四卡| 国产成人小视频| 亚洲777理论| 国产欧美日韩一区二区三区在线观看| 99久久免费国产| 日产精品久久久久久久性色| 欧美国产日本视频| 欧美乱妇23p| 高清在线观看日韩| 午夜精品福利一区二区蜜股av| 久久你懂得1024| 欧美视频一区二区在线观看| 久久精品国产99久久6| 最新日韩在线视频| 日韩一区二区三区av| 91麻豆国产香蕉久久精品| 麻豆成人免费电影| 亚洲毛片av在线| 久久久久久黄色| 欧美丰满少妇xxxxx高潮对白| 成人午夜激情影院| 蜜臀av在线播放一区二区三区| 亚洲国产精品成人久久综合一区| 欧美精品成人一区二区三区四区| 成人一级片网址| 精品一区二区久久久| 亚洲中国最大av网站| 国产精品久久久久四虎| 欧美大片在线观看一区二区| 色狠狠桃花综合| av中文字幕不卡| 国产精品影音先锋| 亚洲va欧美va人人爽| 中文字幕一区二区三区在线播放| 日韩欧美国产三级| 欧美一级一级性生活免费录像| 色综合久久久久久久| 成人av免费在线| 国产精品主播直播| 九九在线精品视频| 欧美bbbbb| 日本欧美大码aⅴ在线播放| 亚洲国产wwwccc36天堂| 亚洲精品老司机| 亚洲色图另类专区| 国产精品二区一区二区aⅴ污介绍| 久久久天堂av| 日韩精品自拍偷拍| 91精品蜜臀在线一区尤物| 欧美日韩你懂的| 欧美日韩小视频| 欧美日韩精品一区视频| 欧美午夜在线一二页| 一本大道久久a久久综合婷婷| 99久久精品情趣| 99re66热这里只有精品3直播| 国产不卡高清在线观看视频| 国产一区欧美二区| 成人性生交大片免费看中文| 成人福利视频网站| 不卡的电影网站| 91在线播放网址| 在线观看国产一区二区| 在线观看日韩av先锋影音电影院| 91久久久免费一区二区| 欧美喷潮久久久xxxxx| 日韩一区二区三区视频在线 | 色一情一乱一乱一91av| 色狠狠色噜噜噜综合网| 欧美日韩免费一区二区三区视频| 欧美日韩国产一二三| 欧美一区二区视频在线观看| 日韩欧美一区在线| 久久久久久久久久电影| 国产精品久久久久久久久搜平片 | 久久久国产精品不卡| 国产精品天美传媒| 一区二区三区.www| 日韩—二三区免费观看av| 国产麻豆精品在线| eeuss鲁片一区二区三区在线观看| 91麻豆国产香蕉久久精品| 欧美日韩精品欧美日韩精品一| 欧美一区二区三区日韩| 中文字幕av一区二区三区高| 一区2区3区在线看| 久久成人av少妇免费| 99麻豆久久久国产精品免费| 欧美日韩视频在线观看一区二区三区 |