聚丰项目 > 空气质量监测仪
随着经济的增长,我们赖以生存的环境受到了不同程度的污染,尤其是与我们息息相关的控制质量,不管是无孔不入的PM2.5还是家装残余的甲醛,都会对我们的健康造成很大的影响,因此,我们需要一台空气质量检测仪来提示我们这些潜在的威胁,保护健康。 项目开发计划分五步: 1.学习和了解物联网模块,并能熟练应用,目前已经在使用机智云的gokit模组学习物联网模块。 2.利用labview强大的虚拟仪表功能,先将空气质量检测模块接入PC,接收传感器的数据,经过处理后,与当前环境的实际值对比,进一步优化算法。 3.在labview的调试优化完成后,将传感器接入STM32将数据处理后,通过串口输出到PC与labview处理的数值进行对比,并优化算法,并且预留一些I/O接口,以便后期可以扩展功能。以上完成后,接入物联网模块,将STM32处理后的数据通过物联网模块发到机智云的云端,再由定制的手机软件接收数据,实现远程监测空气质量。 4.物联网功能完成后,可以利用Altiumdesigener重新设计PCB,将开发板小型化,以便于外观优化。 5.通过预留的I/O接口,接入外围设备,例如LCD显示屏,使设备能够现场显示,接入空调,空气净化器等,温度不适宜的时候开始空调,空气质量差时开启空气净化器等。 项目特点: 1. 空气质量检测仪能够现场和远程实时显示 2. 通过预留的I/O接口,接入外围设备,例如LCD显示屏,使设备能够现场显示,接入空调,空气净化器等,温度不适宜的时候开始空调,空气质量差时开启空气净化器等。 3. 空气质量检测仪能够实现组网,实现可应用于工厂的多节点空气质量检测,并且可以通过云端后台,对空气质量数据进行分析。 4.后期对硬件优化后,利用自身能够自行绘制PCB的优势,将空气质量检测仪小型化,外观美化,方便做成产品,
geekslt
分享geekslt
团队成员
师留涛 学生
王迎春 学生
杜梦欣 学生
传感器采用瑞兰斯的一款空气质量检测模块,开始的时候用的是mbed开发,但是nucleo接lcd太过于复杂,需要的引脚太多,故采用stm32fa429+lcd显示屏进行开发,传感器通过串口向stm32发送数据,32接收数据处理后,再通过物联网模块发送到云端。传感器的数据是每秒发送一帧17个16进制的数组,MCU需要判断帧头,开始接收,最后通过CRC16校验,确认数据的正确性,再经过lcd显示出来。
物联网模块是用来将传感器的数据处理后发送到云端,方便在手机上查看。
STlink用来仿真和下载,以及在仿真时实时查看MCU里的数据,验证代码的可靠性。
1.串口配置以及将数据判断存储至全局变量
#include "./usart/usart3.h"
#include
extern unsigned char shuju[17];
/**
* @brief USART GPIO
* @param
* @retval
*/
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
/* 发送一个字符到USART */
USART_SendData(pUSARTx,ch);
/* 等待发送寄存器为空 */
while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
}
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* 嵌套中断控制 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* 配置USART为中断源 */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
/* 抢占优先级*/
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
/* 子优先级 */
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
/* 使能中断 */
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/* ³初始化NVIC */
NVIC_Init(&NVIC_InitStructure);
}
extern float temperatures;
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(USART3_RX_GPIO_CLK|USART3_TX_GPIO_CLK,ENABLE);
/*使能USART时钟*/
USART3_CLOCKCMD(RCC_APB1Periph_USART3, ENABLE);
/* GPIO初始化 */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/* 配置TX脚为复用功能 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = USART3_TX_PIN ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(USART3_TX_GPIO_PORT, &GPIO_InitStructure);
/* 配置RX脚为复用功能 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = USART3_RX_PIN;
GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStructure);
/* 连接PX到USARTx_Tx*/
GPIO_PinAFConfig(USART3_RX_GPIO_PORT,USART3_RX_SOURCE,USART3_RX_AF);
/* 连接RXx 到USARTx__Rx*/
GPIO_PinAFConfig(USART3_TX_GPIO_PORT,USART3_TX_SOURCE,USART3_TX_AF);
/* 配置串口DEBUG_USART模式 */
/* 波特率设置DEBUG_USART_BAUDRATE */
USART_InitStructure.USART_BaudRate = USART3_BAUDRATE;
/* 字长(数据位+校验位)8 */
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
/* 停止位1 */
USART_InitStructure.USART_StopBits = USART_StopBits_1;
/* 校验位选择 NO */
USART_InitStructure.USART_Parity = USART_Parity_No;
/*硬件流控制 NO*/
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
/* USART模式控制:同时收发*/
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* 完成USART初始化配置 */
USART_Init(USART3, &USART_InitStructure);
NVIC_Configuration();
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
/*使能串口 */
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3, USART_FLAG_RXNE);
}
///重定向函数
int fgetc(FILE *f)
{
/* 等待串口输入数据*/
while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART3);
}
unsigned char sensor_data[17];
unsigned char air_data[17];
unsigned char r_cnt;
unsigned char r_done;
unsigned char test;
void USART3_IRQHandler(void)
{
if(USART_GetFlagStatus(USART3,USART_FLAG_RXNE)!=RESET)
{
USART_ClearFlag(USART3,USART_FLAG_RXNE);
/*test = (USART3->DR & (uint16_t)0x01FF);
Usart_SendByte(USART3,test);*/
sensor_data[r_cnt] = (USART3->DR & (uint16_t)0x01FF);
/*if((r_cnt==0)&&(r_data[0]==0x01))
{
r_cnt=1;
// continue;
}
else if((r_cnt==1)&&(r_data[1]==0x03))
{
r_cnt=2;
}
else if((r_cnt==2)&&(r_data[1]==0x0C))
{
r_cnt=3;
}
else if(r_cnt>=3&&r_cnt<=16)
{
r_cnt++;
}
else
r_cnt=0;*/
/*if((r_cnt>=3)&&(r_cnt<=16))
{
r_cnt++;
// continue;
}
else if((r_cnt==2)&&(r_data[1]==0x0C))
{
r_cnt=3;
}
else if((r_cnt==1)&&(r_data[1]==0x03))
{
r_cnt=2;
}
else if((r_cnt==0)&&(r_data[0]==0x01))
{
r_cnt=1;
}
else
r_cnt=0;
if(r_cnt==17)
{
r_done = 1;
r_cnt = 0;
}*/
switch(r_cnt)
{
case 0: if(sensor_data[0]==0x01)
{
r_cnt = 1;
break;
}
else
{
r_cnt = 0;
break;
}
case 1: if(sensor_data[1]==0x03)
{
r_cnt = 2;
break;
}
else
{
r_cnt = 0;
break;
}
case 2: if(sensor_data[2]==0x0c)
{
r_cnt = 3;
break;
}
else
{
r_cnt = 0;
break;
}
case 3: r_cnt = 4;
break;
case 4: r_cnt = 5;
break;
case 5: r_cnt = 6;
break;
case 6: r_cnt = 7;
break;
case 7: r_cnt = 8;
break;
case 8: r_cnt = 9;
break;
case 9: r_cnt = 10;
break;
case 10: r_cnt = 11;
break;
case 11: r_cnt = 12;
break;
case 12: r_cnt = 13;
break;
case 13: r_cnt = 14;
break;
case 14: r_cnt = 15;
break;
case 15: r_cnt = 16;
break;
case 16: r_cnt = 17;
break;
default: r_cnt = 0;
break;
}
if(r_cnt==17)
{
memcpy(shuju,sensor_data,17);
//r_done = 1;
r_cnt = 0;
}
//Usart_SendByte(USART3,r_data);
}
}
2.mian函数部分,将全局变量里的数据在LCD上显示
#include "stm32f4xx.h"
#include "./led/bsp_led.h"
#include "./usart/bsp_debug_usart.h"
#include "./sdram/bsp_sdram.h"
#include "./lcd/bsp_lcd.h"
#include
#include "./usart/usart3.h"
extern unsigned char sensor_data[17];
extern unsigned char air_data[17];
extern unsigned char r_cnt;
extern unsigned char r_done;
unsigned char data[17];
int i,j;
int a;
int b1;
int b2;
float co2;
float tvoc;
float ch2o;
float pm25;
float humidity;
float temperature;
unsigned char shuju[17];
unsigned char w_num;
void Delay(__IO u32 nCount);
void LCD_Test(void);
/**
* @brief Ö÷º¯Êý
* @param ÎÞ
* @retval ÎÞ
*/
int main(void)
{
/* LED初始化 */
LED_GPIO_Config();
/*串口初始化*/
//Debug_USART_Config();
USART3_Config();
/*³串口3初始化*/
LCD_Init();
LCD_LayerInit();
LTDC_Cmd(ENABLE);
/*液晶初始化*/
LCD_SetLayer(LCD_BACKGROUND_LAYER);
LCD_Clear(LCD_COLOR_BLUE2);
/*背景层刷色*/
LCD_SetLayer(LCD_FOREGROUND_LAYER);
/*初始化后默认使用前景层*/
LCD_SetTransparency(0x001F);
LCD_Clear(LCD_COLOR_BLUE2);
LED_BLUE;
Delay(0xfff);
LCD_Test();
//LCD_Clear(LCD_COLOR_BLUE2);/* 清屏 */
while(1)
{
LCD_Test();
}
}
/*ÓÃÓÚ²âÊÔ¸÷ÖÖÒº¾§µÄº¯Êý*/
void LCD_Test(void)
{
static uint8_t testCNT=0;
char dispBuff[100];
testCNT++;
/*使用不透明前景层*/
LCD_SetLayer(LCD_FOREGROUND_LAYER);
LCD_SetTransparency(0xff);
// LCD_Clear(LCD_COLOR_BLUE2);/*清屏*/
/*设置字体颜色等*/
LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLUE2);
// LCD_SetFont(&Font16x24);
//LCD_DisplayStringLineEx(0,5,16,16,(uint8_t* )"co2 = ",0);
//LCD_DisplayStringLine_EN_CH(LINE(0),(uint8_t* )"ζÈΪªÈ");
//LCD_DisplayStringLine_EN_CH(LINE(0),(uint8_t* )" %.2f",temperature);
//LCD_DisplayStringLineEx(0,50,32,32,(uint8_t* )"±ü»ðF429 32*32 ",0);
//LCD_DisplayStringLineEx(0,82,48,48,(uint8_t* )"±ü»ðF429 48*48 ",0);
#if 1
/*把变量转换成字符串*/
//sprintf(dispBuff,显示变量例子: testCount = %d ",testCNT);
//LCD_ClearLine(LINE(7));
/*显示字符串,其他类同*/
//LCD_DisplayStringLine_EN_CH(LINE(7),(uint8_t* )dispBuff);
//memcpy(data,r_data,17);
//temperature = 0.2;
co2 = ((float)shuju[3]*256+(float)shuju[4]);
tvoc = ((float)shuju[5]*256+(float)shuju[6]);
ch2o = ((float)shuju[7]*256+(float)shuju[8]);
pm25 = ((float)shuju[9]*256+(float)shuju[10]);
humidity = (((float)shuju[11]*256 + (float)shuju[12])/65536*125-6);
temperature = (((float)shuju[13]*256 + (float)shuju[14])/65536*175.72-46.85);
sprintf(dispBuff,"空气质量检测: co2 = %.2f ",co2);
//LCD_ClearLine(LINE(1));
LCD_DisplayStringLine_EN_CH(LINE(1),(uint8_t* )dispBuff);
sprintf(dispBuff,"空气质量检测:: tvoc = %.2f ",tvoc);
//LCD_ClearLine(LINE(2));
LCD_DisplayStringLine_EN_CH(LINE(2),(uint8_t* )dispBuff);
sprintf(dispBuff,"空气质量检测:: ch2o = %.2f ",ch2o);
//LCD_ClearLine(LINE(3));
LCD_DisplayStringLine_EN_CH(LINE(3),(uint8_t* )dispBuff);
sprintf(dispBuff,"空气质量检测:: pm25 = %.2f ",pm25);
//LCD_ClearLine(LINE(4));
LCD_DisplayStringLine_EN_CH(LINE(4),(uint8_t* )dispBuff);
sprintf(dispBuff,"空气质量检测:: humidity = %.2f ",humidity);
//LCD_ClearLine(LINE(5));
LCD_DisplayStringLine_EN_CH(LINE(5),(uint8_t* )dispBuff);
sprintf(dispBuff,"空气质量检测:: temperature = %.2f ",temperature);
LCD_DisplayStringLine_EN_CH(LINE(6),(uint8_t* )dispBuff);
//r_done=0;
//reset_r_done();
// /* 画直线 *
// LCD_SetTextColor(LCD_COLOR_BLUE);
//
//LCD_ClearLine(LINE(8));
// LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"»Ïß:");
//
//LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
// LCD_DrawUniLine(50,250,750,250);
// LCD_DrawUniLine(50,300,750,300);
//
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_BLACK);
// LCD_DrawUniLine(300,250,400,400);
// LCD_DrawUniLine(600,250,600,400);
//
// Delay(0xFFFFFF);
//
//LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
// LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
//
//
// /*画矩形*/
// LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
// LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"»¾ØÐÎ:");
//
//LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
// LCD_DrawRect(200,250,200,100);
//
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_BLACK);
// LCD_DrawRect(350,250,200,50);
//
//LCD_SetColors(LCD_COLOR_BLUE,LCD_COLOR_BLACK);
// LCD_DrawRect(200,350,50,200);
//
// Delay(0xFFFFFF);
//
//
//LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
// LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
//
// /*填充矩形*/
// LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
//LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"Ìî³ä¾ØÐÎ:");
// LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
// LCD_DrawFullRect(200,250,200,100);
//
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_BLACK);
// LCD_DrawFullRect(350,250,200,50);
//
//LCD_SetColors(LCD_COLOR_BLUE,LCD_COLOR_BLACK);
// LCD_DrawFullRect(200,350,50,200);
//
// Delay(0xFFFFFF);
//
//LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
// LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
//
// /* 画圆*/
//LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
//LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"»Ô²:");
//
//LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_RED);
// LCD_DrawCircle(200,350,50);
//
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_GREEN);
// LCD_DrawCircle(350,350,75);
//
// Delay(0xFFFFFF);
//
//LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
// LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
// /*填充圆²*/
//LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
//LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"Ìî³äÔ²:");
//
//LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
// LCD_DrawFullCircle(300,350,50);
//
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_BLACK);
// LCD_DrawFullCircle(450,350,75);
//
// Delay(0xFFFFFF);
//
//LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
// LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
//
//LCD_ClearLine(LINE(8));
/
//{
//LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
//LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"Ë«²ã͸Ã÷Ч¹û£º");
//
///*不透明度设置*/
//LCD_SetLayer(LCD_FOREGROUND_LAYER);
//LCD_SetTransparency(200);
//
///*画一个红色圆*/
//LCD_SetColors(LCD_COLOR_RED,LCD_COLOR_BLACK);
//LCD_DrawFullCircle(400,350,75);
//
//}
//
//LCD_SetLayer(LCD_BACKGROUND_LAYER);
//LCD_SetTransparency(0xff);
//LCD_Clear(LCD_COLOR_BLACK);
//LCD_SetColors(LCD_COLOR_GREEN,LCD_COLOR_BLACK);
//LCD_DrawFullCircle(450,350,75);
//LCD_SetColors(LCD_COLOR_BLUE,LCD_COLOR_BLACK);
//LCD_DrawFullCircle(350,350,75);
//}
Delay(0xFFFFFF);
LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
LCD_DrawFullRect(0,200,LCD_PIXEL_WIDTH,LCD_PIXEL_HEIGHT-200);
#endif
}
void Delay(__IO uint32_t nCount) //简单的延时函数
for(; nCount != 0; nCount--);
}
3.CRC16数据校验部分
CRC 校验计算方法:
/*CRC 校验表高位*/
unsigned char auchCRCHi[] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40
};
/* CRC 校验表低位 */
unsigned char auchCRCLo[] = {
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,
0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
0x40
};
/*CRC 校验凼数,生成 CRC*/
u32 CRC_Compute(u8 * pushMsg,u8 usDataLen)
{
u8 uchCRCHi = 0xff;//高 CRC 字节初始化
u8 uchCRCLo = 0xff;//低 CRC 字节初始化
u8 uIndex; //CRC 循环中的索引
while(usDataLen--)
{
uIndex = uchCRCLo^ *pushMsg++;//计算 CRC
uchCRCLo = uchCRCHi^ auchCRCHi[uIndex];
uchCRCHi = auchCRCLo[uIndex];
}
return (((u16)uchCRCHi) << 8 | uchCRCLo);
}
4.关于物联网的部分,代码有bug,目前只能显示温度的数据,就先不贴出来了
开发平台是MBED+CUBEMX+KEIL,因为对mbed不太熟悉,主要用的是keil进行开发。
5.数据处理,buff-全局变量的处理,CRC16校验等关键程序已经用蓝色标出。
目前基于stm32f429和labview的开发已经基本结束,LCD上已经能实时正常显示传感器的数据,labview上也能通过visa控件读取传感器数据,并且显示出来。物联网的部分数据已经读出来,但是对传输协议了解好不够,因此联网功能暂时还没有实现。
由于时间有限,白天有课,目前只将计划的任务完成了2/3,还没有接入云端,比赛结束后,我会继续完成计划,优化labview和stm32的代码,使之更加美观,并且将数据通过物联网模块发送到云端,配合手机APP进行显示,这些完成后,将所有代码移植到NUCLEO上。希望自己目前做的这些没有让各位评委失望,我会继续努力。将我申报时所列的计划全部完成,不辜负贵公司对比赛的投入。我会继续深入的学习MBED和物联网,将来如果可以投身物联网方向工作的话,希望能够与你们共同进步学到更多。
(15.63 MB)下载