在线时间2209 小时
UID2073122
注册时间2016-1-12
NXP金币122
TA的每日心情 | 开心 2020-6-18 08:45 |
---|
签到天数: 812 天 连续签到: 1 天 [LV.10]以坛为家III
金牌会员
 
- 积分
- 6324
- 最后登录
- 2025-8-6
|
本帖最后由 原来的你 于 2016-9-11 13:53 编辑
今天终于解决无线照明程序编写,中间遇到很多问题,KE02Z的资料太少,只能一点 一点摸索,先附上程序后面具体阐释一下设计原理.
#include "common.h"
#include "gpio.h"
#include "spi.h"
#include "spi_app.h"
#include "kbi.h"
#include "uart.h"
#include "NRF24L01.h"
#include "sysinit.h"
//******************************************************************************************
uint8_t RxBuf[5];
int main(void)
{
uint8_t k;
sysinit();
printf("\nRunning the SPI_MasterInt_demo project.\n");
UART_WaitTxComplete(TERM_PORT);
LED0_Init();
LED1_Init();
LED2_Init();
INIT_NRF24L01(); //NRF24L01初始化
while(NRF_Check()) //检查NRF24L01是否在位.
{
printf("\nNRF24L01 Error.\n");
}
printf("\nNRF24L01 OK.\n");
NRF_RX_Mode();
GPIO_PinInit(GPIO_PTC2, GPIO_PinOutput); //继电器控制引脚
//NRE24L01_IRQ();
while(1)
{
if(NRF_RxPacket(RxBuf) == 0)//一旦接收到信息,则显示出来
{
for(k = 0; k < 5; k++)
{
printf("0x%x.\n", RxBuf[k]);
}
if((RxBuf[0]==0x01)&&(RxBuf[1]==0x02)&&(RxBuf[2]==0x03)&&(RxBuf[3]==0x04)&&(RxBuf[4]==0x05))
{
GPIO_PinSet(GPIO_PTC2);//开灯
}
else if((RxBuf[0]==0x06)&&(RxBuf[1]==0x07)&&(RxBuf[2]==0x08)&&(RxBuf[3]==0x09)&&(RxBuf[4]==0x0A))
{
GPIO_PinClear(GPIO_PTC2);//关灯
}
}
}
}
|
|