📄 main.c
字号:
#include "mrfi.h"
#include "APP.h"
#include "LPC11xx.h"
#include "lpc11xx_gpio.h"
#include "lpc11xx_ssp.h"
#define SSP_BUFSIZE 16
#define FIFOSIZE 8
#define COUNTTIME 40
uint8_t u8GDO0Flag;
uint32_t u32ADCAverageValue = 0;
uint32_t u32ADCTotalValue = 0;
uint32_t u32ADCAveValOld = 0;
int iFameNum =0;
uint8_t txBuffer[10];
uint8_t rxBuffer[10];
#define SPIN_ABOUT_A_SECOND NWK_DELAY(1000) // NWK_DELAY(2000)//NWK_DELAY(1000)
int main(void)
{
int i=0, adc_value,adc_valueold=0;
uint8_t len = 10;
int16_t iTemp=0;
SystemInit();
/* Configuration for ADC :
* Frequency at 1Mhz
* ADC channel 5, no Interrupt */
ADC_Init(1000000);
ADC_PinsInit(ADC_CHANNEL_5);
ADC_ChannelCmd(ADC_CHANNEL_5,ENABLE);
//init the led port
LPC_GPIO2->DIR |= (0x1<<7)|(0x1<<8)|(0x1<<9);//2.2 2.1
//init cc2500
MRFI_Init();
LPC_GPIO2->DATA &= ~(0x1<<7);
LPC_GPIO2->DATA &= ~(0x1<<8);//led, used for test init is passed or not
NWK_DELAY(1000);
u32ADCAveValOld = 0;
while(1)
{
iTemp = RFReceivePacket(rxBuffer, &len);
if(iTemp)//get control infor
{
NWK_DELAY(1000);
}
if(rxBuffer[1] == 0)
{
LPC_GPIO2->DATA |= (0x1<<9)|(0x1<<8); //no pass, 2.8 is a led, 2.9 control the turn on or off.
}
else
{
LPC_GPIO2->DATA &= ~((0x1<<9)|(0x1<<8)); // pass
}
if( i < COUNTTIME/2 ) //LED7 represent the link time
{
LPC_GPIO2->DATA &= ~(0x1<<7);
NWK_DELAY(100);
}
else if( (i>=COUNTTIME/2) && (i<COUNTTIME))
{
LPC_GPIO2->DATA |= (0x1<<7);
NWK_DELAY(100);
}
else
{
//check 40 times send once
u32ADCAverageValue = u32ADCTotalValue/COUNTTIME;
if(u32ADCAverageValue > 6)
{
u32ADCAverageValue -= 6;
}
else
{
u32ADCAverageValue = 0;
}
iTemp = u32ADCAverageValue - u32ADCAveValOld;
//record the data
txBuffer[3] = u32ADCAverageValue/100;/*display the hundred position */
txBuffer[4] = u32ADCAverageValue % 100;
//send the electric current related infomation to E-Monitor.
SendCurInfo();
u32ADCAveValOld = u32ADCAverageValue;
//pepare for the next count
u32ADCTotalValue = 0;
i=0;
}
/* Start conversion */
ADC_StartCmd(ADC_START_NOW);
/* Wait conversion complete */
while (!(ADC_ChannelGetStatus(ADC_CHANNEL_5,ADC_DATA_DONE)));
adc_value = ADC_ChannelGetData(ADC_CHANNEL_5);
//here handle a siuation: when during the COUNTTIME, the current increased to much, so we think it have some true change, and will count again.
iTemp = adc_valueold-adc_value;
if( (iTemp >= 20) || (iTemp <= -20) )
{
u32ADCTotalValue = 0;
i=0;
}
adc_valueold = adc_value;
u32ADCTotalValue += adc_value;
i++;
NWK_DELAY(1000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -