聚豐項目 > 空氣質量監測儀
隨著經濟的增長,我們賴以生存的環境受到了不同程度的污染,尤其是與我們息息相關的控制質量,不管是無孔不入的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;
/* 3初始化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 ?÷oˉêy
* @param ?T
* @retval ?T
*/
int main(void)
{
/* LED初始化 */
LED_GPIO_Config();
/*串口初始化*/
//Debug_USART_Config();
USART3_Config();
/*3串口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();
}
}
/*ó?óú2aê??÷??òo?§μ?oˉêy*/
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* )"???è?aaè");
//LCD_DisplayStringLine_EN_CH(LINE(0),(uint8_t* )" %.2f",temperature);
//LCD_DisplayStringLineEx(0,50,32,32,(uint8_t* )"±ü?eF429 32*32 ",0);
//LCD_DisplayStringLineEx(0,82,48,48,(uint8_t* )"±ü?eF429 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* )"?-??D?:");
//
//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* )"ì?3???D?:");
// 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* )"?-?2:");
//
//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);
// /*填充圓2*/
//LCD_SetTextColor(LCD_COLOR_BLUE);
//LCD_ClearLine(LINE(8));
//LCD_DisplayStringLine_EN_CH(LINE(8),(uint8_t* )"ì?3??2:");
//
//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* )"??2?í??÷D§1?£o");
//
///*不透明度設置*/
//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)下載