概述
main.c
/******************************************************************************/
/* --安信可科技有限公司-- */
/*
// 函数说明:main.c
// 说明:该lora模块程序用于测试
// 编写人员: sky
// 编写日期: 2016-11-24
// 版本号:V1.0
// 维护日志:
//
//
*/
// 免责声明:该程序仅供参考学习,若自定义其他功能,请查看参考手册
// (c) Anxinke Corporation. All rights reserved.
/******************************************************************************/
#include "typedef.h"
#include "gpio.h"
#include "string.h"
#include "uart.h"
#include "SX1278.h"
//#include "delay.h"
void main(void) {
unsigned char RF_REC_RLEN_i = 0;
int flag = 0;
int led = 0;
unsigned char recv[30];
uartInit();
//uartSendString("READY!rn");
P1M1 = 0X03;
P1M0 = 0XFC;
P3M1 &= 0XFC;
P3M0 |= 0X04;
//uartSendString("HERE!rn");
register_rf_func(&ctrlTypefunc);
SX1276Reset();
SX1276LORA_INT();
uartSendString("READY!rn");
P32 = 1;
P17 = 1;
while (1) {
if (P30 == 0 || P31 == 0) {
P17 = 1;
P32 = 0;
SX1276WriteBuffer( REG_LR_IRQFLAGS, 0xff);
uartSendString("hello world!rn");
FUN_RF_SENDPACKET("ai-thinker", 10);
Delay1s(1000);
SX1276WriteBuffer( REG_LR_IRQFLAGS, 0xff);
} else {
P32 = 1;
RF_EX0_STATUS = SX1276ReadBuffer( REG_LR_IRQFLAGS);
if (RF_EX0_STATUS > 0) {
if ((RF_EX0_STATUS & 0x40) == 0x40) {
//GPIO_OUTPUT_SET(GPIO_ID_PIN(2),0);
CRC_Value = SX1276ReadBuffer( REG_LR_MODEMCONFIG2);
if (CRC_Value & 0x04 == 0x04) {
SX1276WriteBuffer(REG_LR_FIFOADDRPTR, 0x00);
SX1278_RLEN = SX1276ReadBuffer(REG_LR_NBRXBYTES);
//uartSendString("recvieve data num=%drn",SX1278_RLEN);
lpTypefunc.lpSwitchEnStatus(enOpen);
lpTypefunc.lpByteWritefunc(0x00);
for (RF_REC_RLEN_i = 0; RF_REC_RLEN_i < SX1278_RLEN;
RF_REC_RLEN_i++) {
recv[RF_REC_RLEN_i] = lpTypefunc.lpByteReadfunc();
}
lpTypefunc.lpSwitchEnStatus(enClose);
recv[RF_REC_RLEN_i] = '