mainc.c
#include "DELAY/Delay.h"
#include "ADC/ADC.h"
#include "DHT11/DHT11.h"
#include "LED/LED.h"
#include "UART/uart.h"
#include "RELAY/Relay.h"
#include "IIC/IIC.h"
#include "OLED/OLED.h"
#include "SPIx/SPIx.h"
#include "SX1278/SX1278.h"
#include "NodeBus.h"
DeviceBlock DeviceBlock_Structure;
unsigned char Ackbuffer1[9];
int main(void)
{
u8 i = 0,j = 0;
u16 cache;
initSysTick();
initADC();
initUART();
initDHT11();
initLED();
initRelay();
initIIC();
initOLED();
initSPIx(SPI2);
initSX1278();
formatScreen(0x00);
for(i=0;i<=128;i+=2)
{
showImage(0,0,i,8,FM_LOGO_ENUM);
}
formatScreen(0x00);
showCNString(32,0,"风媒电子",FONT_16_CN);
showString(0,2,"Hum :",FONT_16_EN);
showString(0,4,"Temp:",FONT_16_EN);
showString(0,6,"Lux :",FONT_16_EN);
while (1)
{
if(++j==10)
{
j = 0;
cache = readDHT11();
}
DeviceBlock_Structure.Temperature = cache&0x00FF;
DeviceBlock_Structure.Humidity = cache>>8;
DeviceBlock_Structure.Lux = getConvValueAve(10,1000);
processMasterAsk(&DeviceBlock_Structure);
if(DeviceBlock_Structure.Coils&0x01)
{
setRelay(RELAY1,RELAY_CLOSE);
}else
{
setRelay(RELAY1,RELAY_OPEN);
}
if(DeviceBlock_Structure.Coils&0x02)
{
setRelay(RELAY2,RELAY_CLOSE);
}else
{
setRelay(RELAY2,RELAY_OPEN);
}
showNumber(40,2,DeviceBlock_Structure.Humidity,DEC,3,FONT_16_EN);
showNumber(40,4,DeviceBlock_Structure.Temperature,DEC,3,FONT_16_EN);
showNumber(40,6,DeviceBlock_Structure.Lux,DEC,4,FONT_16_EN);
toggleLED();
Delay_ms(100);
}
}