|
PM2.5檢測儀設計硬件設計原理圖如下,整個項目基于瑞薩單片機
0.png (227.6 KB, 下載次數: 154)
下載附件
2016-6-5 00:02 上傳
pcb圖也有
0.png (63.97 KB, 下載次數: 158)
下載附件
2016-6-5 00:02 上傳
下面是PM2.5檢測儀設計源代碼:
0.png (79.08 KB, 下載次數: 165)
下載附件
2016-6-5 00:04 上傳
全部制作資料下載:
PM2.5檢測儀源代碼.zip
(136.12 KB, 下載次數: 97)
2016-5-20 21:14 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
PM2.5檢測儀設計硬件設計.zip
(484.55 KB, 下載次數: 110)
2016-5-20 21:13 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
部分源碼預覽(完整代碼請下載附件):
- /*******************************************************************************
- * DISCLAIMER
- * This software is supplied by Renesas Electronics Corporation and is only
- * intended for use with Renesas products. No other uses are authorized. This
- * software is owned by Renesas Electronics Corporation and is protected under
- * all applicable laws, including copyright laws.
- * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
- * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
- * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
- * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
- * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
- * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
- * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
- * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- * Renesas reserves the right, without notice, to make changes to this software
- * and to discontinue the availability of this software. By using this software,
- * you agree to the additional terms and conditions found by accessing the
- * following link:
- * http://www.renesas.com/disclaimer
- *
- * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
- *******************************************************************************/
- /*******************************************************************************
- * File Name : main.c
- * Version : 1.0
- * Device(s) : R7F0C001
- * H/W Platform : YCB15R7F0C001001B
- * Description : This file implements main function.
- ******************************************************************************/
- /******************************************************************************
- * History : DD.MM.YYYY Version Description
- * : 20.09.2015 1.00 First Release
- ******************************************************************************/
- /******************************************************************************
- Includes <System Includes> , <Project Includes>
- ******************************************************************************/
- #include "userdefine.h"
- #include "system.h"
- #include "adc.h"
- #include "timer.h"
- #include "lcd.h"
- #include "e2prom.h"
- #include "beep.h"
- #include "battery.h"
- #include "monitor.h"
- /******************************************************************************
- Exported global variables and functions(can be accessed by other files)
- ******************************************************************************/
-
- uint8_t g_fSwitchMonitorOnReq; /* Switch position (PM2.5 Monitor side = 1)*/
- uint8_t g_MainMode; /* Main mode */
- uint8_t g_OutLowPowerModeCounter; /* Exit low power mode counter */
- uint16_t g_ModeTimeOutCounter; /* Mode time out counter */
- uint8_t g_FnKeyCounter; /* [Fn] key pressed counter */
- uint8_t g_BellKeyCounter; /* [Bell] key pressed counter */
- uint8_t g_fFnReleaseReq; /* [Fn] key release request flag */
- uint8_t g_fBellReleaseReq; /* [Bell] key release request flag */
- uint8_t g_fSleepModeOn; /* Halt mode indicatior */
- uint8_t g_fLowPowerSleepOn; /* Halt mode indicatior in low power mode */
- extern uint8_t g_fSensorComputeReq;
- extern uint8_t g_aDataBuffer[];
- extern uint16_t g_DustDensityValue;
- extern uint16_t g_DustDensityMinValue;
- extern uint16_t g_BatterVoltage;
- extern uint8_t g_fChargeConnected;
- extern uint8_t g_fNewDataDispRq;
- extern uint16_t g_fSensorUpdateCounter;
- extern uint8_t g_fCheckAlarmDataReq;
- extern uint8_t g_fAlarmOnFlashOn;
- extern uint8_t g_fAlarmDataSetFlashOn;
- extern uint16_t g_fDispFlashCounter;
- extern uint8_t g_DustAlarmDataSetStep;
- extern uint16_t g_aSupplyVoltageBuf[];
- extern uint8_t g_SupplyVoltageSampleCounter;
- extern _DUST_ALARM_DATA g_sDustAlarmData;
- extern _DUST_ALARM_DATA g_sDustAlarmTempData;
- void main(void);
- static void Mode_Process(void);
- static void Initial_Process(void);
- /******************************************************************************
- * Function Name : main
- * Description : This function implements main function.
- * Arguments : none
- * Return Value : none
- ******************************************************************************/
- void main(void)
- {
- System_Init();
- Initial_Process();
- while(1)
- {
- Check_Charge_Status();
- Mode_Process();
- Battery_Process();
- Sensor_Process();
- Beep_Process();
- Display_Process();
- /* main loop period:T=100ms(TAU03)*/
- while(TMIF03 != 1); /* Wait the TAU03 interrupt flag set to 1*/
- TMIF03 = 0; /* TAU03 interrupt flag clear*/
- }
- }
- /******************************************************************************
- End of function main
- ******************************************************************************/
- /******************************************************************************
- * Function Name : Mode_Process
- * Description : This function implements mode process.
- * Arguments : none
- * Return Value : none
- ******************************************************************************/
- static void Mode_Process(void)
- {
- /* Mode process */
- switch(g_MainMode)
- {
- case INITIAL_MODE:
- if(g_ModeTimeOutCounter>0)
- {
- g_ModeTimeOutCounter--;
- }
- else
- {
- g_fSwitchMonitorOnReq = P13.7;
- if(1U == g_fSwitchMonitorOnReq)
- {
- if(1U == P13.7)
- {
- GoTo_NormalMode();
- }
- }
- else
- {
- if(0U == P13.7)
- {
- GoTo_BatteryMode();
- }
- }
- }
- break;
- case BATTERY_MODE:
- if(0U == g_fChargeConnected)
- {
- if(g_ModeTimeOutCounter>0)
- {
- g_ModeTimeOutCounter--;
- }
- else
- {
- g_fSleepModeOn = ON;
- LCD_Stop();
- HALT();
- }
- if(0U == FUNCTION_KEY)
- {
- NOP();
- NOP();
- if(0U == FUNCTION_KEY)
- {
- g_ModeTimeOutCounter = BATTERY_DISP_TIMEOUT_TIME;
- }
- }
- if(0U == BELL_KEY)
- {
- NOP();
- NOP();
- if(0U == BELL_KEY)
- {
- g_ModeTimeOutCounter = BATTERY_DISP_TIMEOUT_TIME;
- }
- }
- if(1U == g_fSleepModeOn)
- {
- g_fSleepModeOn = 0U;
- LCD_Start();
- g_fNewDataDispRq = ON;
- }
- }
- break;
- case NORMAL_MODE:
- /*Fn key process */
- if(1U == g_fFnReleaseReq) /* Make sure the key is released when enter into the normal mode*/
- {
- g_fFnReleaseReq = !FUNCTION_KEY;
- }
- else
- {
- if(0U == FUNCTION_KEY)
- {
- g_FnKeyCounter++;
- if(g_FnKeyCounter>=10) /* Fn key has been pressed for 1000ms*/
- {
- g_fFnReleaseReq = ON;
- g_FnKeyCounter = 0;
- g_BellKeyCounter = 0;
- Beep_Times_Set(1);
- GoTo_AlarmSettingMode();
- }
- }
- else
- {
- g_FnKeyCounter = 0;
- }
- }
- /*Bell key process */
- if(1U == g_fBellReleaseReq)
- {
- g_fBellReleaseReq = !BELL_KEY;
- }
- else
- {
- if(0U == BELL_KEY)
- {
- g_BellKeyCounter++;
- if(g_BellKeyCounter>=2) /* Bell key has been pressed for 200ms*/
- {
- g_fBellReleaseReq = ON;
- g_BellKeyCounter = 0;
- g_FnKeyCounter = 0;
- GoTo_AlarmStandbyMode();
- }
- }
- else
- {
- g_BellKeyCounter = 0;
- }
- }
- break;
- case ALARM_STANDBY_MODE:
- /*Bell key process */
- if(1U == g_fBellReleaseReq)
- {
- g_fBellReleaseReq = !BELL_KEY;
- }
- else
- {
- if(0U == BELL_KEY)
- {
- g_BellKeyCounter++;
- if(g_BellKeyCounter>=2) /*Bell key has been pressed for 200ms*/
- {
- g_fBellReleaseReq = ON;
- g_BellKeyCounter = 0;
- GoTo_NormalMode();
- }
- }
- else
- {
- g_BellKeyCounter = 0;
- }
- }
- /* Check alarm start or not */
- if(1U == g_fCheckAlarmDataReq)
- {
- g_fCheckAlarmDataReq = 0;
- Check_Alarm_Data();
- }
- break;
- case ALARM_SETTING_MODE:
- /* Setting time out period control */
- if(g_ModeTimeOutCounter>0)
- {
- g_ModeTimeOutCounter--;
- }
- else
- {
- /* Setting time out */
- g_BellKeyCounter = 0;
- g_FnKeyCounter = 0;
- g_DustAlarmDataSetStep = 0;
- GoTo_NormalMode();
- }
- /*Fn key process */
- if(1U == g_fFnReleaseReq)
- {
- g_fFnReleaseReq = !FUNCTION_KEY;
- }
- else
- {
- if(0U == FUNCTION_KEY)
- {
- g_FnKeyCounter++;
- if(g_FnKeyCounter>=2) /* Fn key has been pressed for 200ms*/
- {
- g_fFnReleaseReq = ON;
- g_FnKeyCounter = 0;
- /* Setting step control */
- g_DustAlarmDataSetStep++;
- if(g_DustAlarmDataSetStep<3)
- {
- Beep_Times_Set(1);
- g_ModeTimeOutCounter = ALARM_SETTING_TIMEOUT_TIME;
- g_fNewDataDispRq = ON;
- }
- else
- {
- Beep_Times_Set(2);
- /* Save the new data */
- g_sDustAlarmData.High = g_sDustAlarmTempData.High;
- g_sDustAlarmData.Middle = g_sDustAlarmTempData.Middle;
- g_sDustAlarmData.Low = g_sDustAlarmTempData.Low;
- g_BellKeyCounter = 0;
- g_FnKeyCounter = 0;
- g_DustAlarmDataSetStep = 0;
- GoTo_NormalMode();
- }
- }
- }
- else
- {
- g_FnKeyCounter = 0;
- }
- }
- /*Bell key process */
- if(1U == g_fBellReleaseReq)
- {
- g_fBellReleaseReq = !BELL_KEY;
- }
- else
- {
- if(0U == BELL_KEY)
- {
- g_BellKeyCounter++;
- if(g_BellKeyCounter>=2) /* Bell key has been pressed for 200ms*/
- {
- g_fBellReleaseReq = ON;
- g_BellKeyCounter = 0;
- /* Set the alarm data */
- switch(g_DustAlarmDataSetStep)
- {
- case 0:
- g_sDustAlarmTempData.High++;
- if(g_sDustAlarmTempData.High>4)
- {
- g_sDustAlarmTempData.High = 0;
- }
- break;
- case 1:
- g_sDustAlarmTempData.Middle++;
- if(g_sDustAlarmTempData.Middle>9)
- {
- g_sDustAlarmTempData.Middle = 0;
- }
- break;
- default:
- g_sDustAlarmTempData.Low++;
- if(g_sDustAlarmTempData.Low>9)
- {
- g_sDustAlarmTempData.Low = 0;
- }
-
- }
- g_ModeTimeOutCounter = ALARM_SETTING_TIMEOUT_TIME;
- g_fNewDataDispRq = ON;
- }
- }
- else
- {
- g_BellKeyCounter = 0;
- }
- }
- /* Display control */
- if(g_fDispFlashCounter>0)
- {
- g_fDispFlashCounter--;
- }
- else
- {
- g_fDispFlashCounter = SENSOR_DISP_FLASH_TIME;
- g_fAlarmDataSetFlashOn = 1 - g_fAlarmDataSetFlashOn;
- g_fNewDataDispRq = ON;
- }
- break;
- case ALARM_ON_MODE:
- /*Bell key process */
- if(1U == g_fBellReleaseReq)
- {
- g_fBellReleaseReq = !BELL_KEY;
- }
- else
- {
- if(0U == BELL_KEY)
- {
- g_BellKeyCounter++;
- if(g_BellKeyCounter>=2) /*Bell key has been pressed for 200ms*/
- {
- g_fBellReleaseReq = ON;
- g_BellKeyCounter = 0;
- GoTo_NormalMode();
- }
- }
- else
- {
- g_BellKeyCounter = 0;
- }
- }
- /* Display control */
- if(g_fDispFlashCounter>0)
- {
- g_fDispFlashCounter--;
- }
- else
- {
- g_fDispFlashCounter = SENSOR_DISP_FLASH_TIME;
- g_fAlarmOnFlashOn = 1 - g_fAlarmOnFlashOn;
- }
- break;
- default:
- /* Low power mode process */
- while(1)
- {
- g_BatterVoltage = ADC_Sample(BATTERY_ANI_CH,5)*2;
- if(g_BatterVoltage < (LOW_POWER_VOLTAGE_VALUE + 50)) /* "+ 50" In case of repeately enter the Low Power mode */
- {
- g_OutLowPowerModeCounter = 0;
- if(1U == g_fLowPowerSleepOn)
- {
- LCD_Stop();
- HALT();
- }
- else
- {
- if(1U == g_fNewDataDispRq)
- {
- LCD_Start();
- Display_Process();
- SEG24 = 0x0f;
- }
- }
- }
- else
- {
- g_OutLowPowerModeCounter++;
- if(g_OutLowPowerModeCounter>3)
- {
- Initial_Process();
- break;
- }
- }
- }
- }
- /* Key release process */
- if(1U == g_fFnReleaseReq)
- {
- g_fFnReleaseReq = !FUNCTION_KEY;
- g_FnKeyCounter = 0;
- }
- if(1U == g_fBellReleaseReq)
- {
- g_fBellReleaseReq = !BELL_KEY;
- g_BellKeyCounter = 0;
- }
-
- }
- /******************************************************************************
- End of function Mode_Process
- ******************************************************************************/
- /******************************************************************************
- * Function Name : Initial_Process
- * Description : This function Initial Process.
- * Arguments : none
- * Return Value : none
- ******************************************************************************/
- static void Initial_Process(void)
- {
- /* Initial process */
- DI();
- /* Variables initialize */
- g_sDustAlarmData.High = DUST_DENSITY_ALARM_VELUE_INIT/100;
- g_sDustAlarmData.Middle = (DUST_DENSITY_ALARM_VELUE_INIT%100)/10;
- g_sDustAlarmData.Low = (DUST_DENSITY_ALARM_VELUE_INIT%100)%10;
- g_fSleepModeOn = 0U;
- BATTEEY_LED = OFF;
- g_MainMode = INITIAL_MODE;
- g_ModeTimeOutCounter = 2000/MAIN_LOOP_TIME; /* 2000ms */
-
- /* Get data from EEPROM */
- I2C_Init();
- Delayms(5);
- EEPROM_ReadPage(0x0);
- g_DustDensityMinValue = *(uint16_t *)&g_aDataBuffer[0];
- if((0xff == g_DustDensityMinValue)||(g_DustDensityMinValue > AD_SENSOR_MIN_VALUE_INIT)) /*EEPROM has not been wrote before*/
- {
- g_DustDensityMinValue = AD_SENSOR_MIN_VALUE_INIT;
- *(uint16_t *)&g_aDataBuffer[0] = g_DustDensityMinValue;
- Delayms(5);
- Delayms(5);
- EEPROM_WritePage(0x0);
- Delayms(5);
- Delayms(5);
- }
- /* Get value of dust density */
- Sensor_Start();
- EI();
- while(0 == g_fSensorComputeReq);
- g_fSensorComputeReq = 0;
- Get_Dust_Density();
- DI();
- /* Get value of battery */
- g_BatterVoltage = ADC_Sample(BATTERY_ANI_CH,5)*2;
- g_SupplyVoltageSampleCounter = 0;
- g_aSupplyVoltageBuf[g_SupplyVoltageSampleCounter]= g_BatterVoltage;
- /* key initialize*/
- if(0U == FUNCTION_KEY)
- {
- NOP();
- NOP();
- g_fFnReleaseReq = !FUNCTION_KEY;
- }
- if(0U == BELL_KEY)
- {
- NOP();
- NOP();
- g_fBellReleaseReq = !BELL_KEY;
- }
- g_FnKeyCounter = 0;
- g_BellKeyCounter = 0;
- /* Lcd start */
- LCD_Start();
- g_fNewDataDispRq = 1;
- /* Prompt tone */
- Beep_Times_Set(2);
- /* Starts TAU03 */
- TS0 |= 0x0008;
- EI();
- }
- /******************************************************************************
- End of function Initial_Process
- ******************************************************************************/
復制代碼
|
評分
-
查看全部評分
|