找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9036|回复: 7
打印 上一主题 下一主题
收起左侧

PM2.5检测仪设计硬件设计原理图及源代码

  [复制链接]
跳转到指定楼层
楼主
PM2.5检测仪设计硬件设计原理图如下,整个项目基于瑞萨单片机


pcb图也有


下面是PM2.5检测仪设计源代码:


全部制作资料下载:
PM2.5检测仪源代码.zip (136.12 KB, 下载次数: 92)
PM2.5检测仪设计硬件设计.zip (484.55 KB, 下载次数: 92)


部分源码预览(完整代码请下载附件):
  1. /*******************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only
  4. * intended for use with Renesas products. No other uses are authorized. This
  5. * software is owned by Renesas Electronics Corporation and is protected under
  6. * all applicable laws, including copyright laws.
  7. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  8. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
  9. * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  10. * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
  11. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
  12. * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
  13. * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
  14. * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
  15. * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  16. * Renesas reserves the right, without notice, to make changes to this software
  17. * and to discontinue the availability of this software. By using this software,
  18. * you agree to the additional terms and conditions found by accessing the
  19. * following link:
  20. * http://www.renesas.com/disclaimer
  21. *
  22. * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
  23. *******************************************************************************/
  24. /*******************************************************************************
  25. * File Name    : main.c
  26. * Version      : 1.0
  27. * Device(s)    : R7F0C001
  28. * H/W Platform : YCB15R7F0C001001B
  29. * Description  : This file implements main function.
  30. ******************************************************************************/
  31. /******************************************************************************
  32. * History : DD.MM.YYYY Version Description
  33. *         : 20.09.2015 1.00 First Release
  34. ******************************************************************************/

  35. /******************************************************************************
  36. Includes <System Includes> , <Project Includes>
  37. ******************************************************************************/
  38. #include "userdefine.h"
  39. #include "system.h"
  40. #include "adc.h"
  41. #include "timer.h"
  42. #include "lcd.h"
  43. #include "e2prom.h"
  44. #include "beep.h"
  45. #include "battery.h"
  46. #include "monitor.h"
  47. /******************************************************************************
  48. Exported global variables and functions(can be accessed by other files)
  49. ******************************************************************************/
  50.                                             

  51. uint8_t g_fSwitchMonitorOnReq;                        /* Switch position (PM2.5 Monitor side = 1)*/
  52. uint8_t g_MainMode;                                /* Main mode */
  53. uint8_t g_OutLowPowerModeCounter;                /* Exit low power mode counter */
  54. uint16_t g_ModeTimeOutCounter;                        /* Mode time out counter */
  55. uint8_t g_FnKeyCounter;                                /* [Fn] key pressed counter */
  56. uint8_t g_BellKeyCounter;                        /* [Bell] key pressed counter */
  57. uint8_t g_fFnReleaseReq;                        /* [Fn] key release request flag */
  58. uint8_t g_fBellReleaseReq;                        /* [Bell] key release request flag */
  59. uint8_t g_fSleepModeOn;                                /* Halt mode indicatior */
  60. uint8_t g_fLowPowerSleepOn;                        /* Halt mode indicatior in low power mode */

  61. extern uint8_t g_fSensorComputeReq;
  62. extern        uint8_t g_aDataBuffer[];
  63. extern        uint16_t g_DustDensityValue;
  64. extern        uint16_t g_DustDensityMinValue;
  65. extern uint16_t g_BatterVoltage;
  66. extern uint8_t g_fChargeConnected;
  67. extern uint8_t g_fNewDataDispRq;
  68. extern uint16_t g_fSensorUpdateCounter;
  69. extern uint8_t g_fCheckAlarmDataReq;
  70. extern uint8_t g_fAlarmOnFlashOn;
  71. extern uint8_t g_fAlarmDataSetFlashOn;
  72. extern uint16_t g_fDispFlashCounter;
  73. extern uint8_t g_DustAlarmDataSetStep;
  74. extern uint16_t g_aSupplyVoltageBuf[];
  75. extern uint8_t g_SupplyVoltageSampleCounter;
  76. extern _DUST_ALARM_DATA g_sDustAlarmData;
  77. extern _DUST_ALARM_DATA g_sDustAlarmTempData;

  78. void main(void);
  79. static void Mode_Process(void);
  80. static void Initial_Process(void);
  81. /******************************************************************************
  82. * Function Name : main
  83. * Description   : This function implements main function.
  84. * Arguments     : none
  85. * Return Value  : none
  86. ******************************************************************************/
  87. void main(void)
  88. {
  89.         System_Init();
  90.         Initial_Process();
  91.         while(1)
  92.         {        
  93.                 Check_Charge_Status();
  94.                 Mode_Process();
  95.                 Battery_Process();
  96.                 Sensor_Process();
  97.                 Beep_Process();
  98.                 Display_Process();
  99.                 /* main loop period:T=100ms(TAU03)*/
  100.                 while(TMIF03 != 1);                /* Wait the TAU03 interrupt flag set to 1*/
  101.                     TMIF03 = 0;                        /* TAU03 interrupt flag clear*/        
  102.         }        
  103. }
  104. /******************************************************************************
  105. End of function main
  106. ******************************************************************************/

  107. /******************************************************************************
  108. * Function Name : Mode_Process
  109. * Description   : This function implements mode process.
  110. * Arguments     : none
  111. * Return Value  : none
  112. ******************************************************************************/
  113. static void Mode_Process(void)
  114. {
  115.         /* Mode process */
  116.         switch(g_MainMode)
  117.             {
  118.                 case INITIAL_MODE:
  119.                         if(g_ModeTimeOutCounter>0)
  120.                         {
  121.                                 g_ModeTimeOutCounter--;
  122.                         }
  123.                         else
  124.                         {
  125.                                 g_fSwitchMonitorOnReq = P13.7;
  126.                                 if(1U == g_fSwitchMonitorOnReq)        
  127.                                 {
  128.                                         if(1U == P13.7)
  129.                                         {
  130.                                                 GoTo_NormalMode();
  131.                                         }
  132.                                 }
  133.                                 else
  134.                                 {
  135.                                         if(0U == P13.7)
  136.                                         {
  137.                                                 GoTo_BatteryMode();
  138.                                         }
  139.                                 }
  140.                         }
  141.                         break;
  142.                 case BATTERY_MODE:
  143.                         if(0U == g_fChargeConnected)
  144.                         {
  145.                                 if(g_ModeTimeOutCounter>0)
  146.                                 {
  147.                                         g_ModeTimeOutCounter--;
  148.                                 }
  149.                                 else
  150.                                 {
  151.                                         g_fSleepModeOn = ON;
  152.                                         LCD_Stop();
  153.                                         HALT();
  154.                                 }
  155.                                 if(0U == FUNCTION_KEY)
  156.                                 {
  157.                                         NOP();
  158.                                         NOP();
  159.                                         if(0U == FUNCTION_KEY)
  160.                                         {
  161.                                                 g_ModeTimeOutCounter = BATTERY_DISP_TIMEOUT_TIME;
  162.                                         }
  163.                                 }
  164.                                 if(0U == BELL_KEY)
  165.                                 {
  166.                                         NOP();
  167.                                         NOP();
  168.                                         if(0U == BELL_KEY)
  169.                                         {
  170.                                                 g_ModeTimeOutCounter = BATTERY_DISP_TIMEOUT_TIME;
  171.                                         }
  172.                                 }
  173.                                 if(1U == g_fSleepModeOn)
  174.                                 {
  175.                                         g_fSleepModeOn = 0U;
  176.                                         LCD_Start();
  177.                                         g_fNewDataDispRq = ON;
  178.                                 }
  179.                         }
  180.                         break;
  181.                 case NORMAL_MODE:
  182.                         /*Fn key process */
  183.                         if(1U == g_fFnReleaseReq)                /* Make sure the key is released when enter into the normal mode*/
  184.                         {
  185.                                 g_fFnReleaseReq = !FUNCTION_KEY;
  186.                         }
  187.                         else
  188.                         {
  189.                                 if(0U == FUNCTION_KEY)
  190.                                 {
  191.                                         g_FnKeyCounter++;
  192.                                         if(g_FnKeyCounter>=10)        /* Fn key has been pressed for 1000ms*/
  193.                                         {
  194.                                                 g_fFnReleaseReq = ON;
  195.                                                 g_FnKeyCounter = 0;
  196.                                                 g_BellKeyCounter = 0;
  197.                                                 Beep_Times_Set(1);
  198.                                                 GoTo_AlarmSettingMode();
  199.                                         }
  200.                                 }
  201.                                 else
  202.                                 {
  203.                                         g_FnKeyCounter = 0;
  204.                                 }        
  205.                         }
  206.                         /*Bell key process */
  207.                         if(1U == g_fBellReleaseReq)
  208.                         {
  209.                                 g_fBellReleaseReq = !BELL_KEY;
  210.                         }
  211.                         else
  212.                         {
  213.                                 if(0U == BELL_KEY)
  214.                                 {
  215.                                         g_BellKeyCounter++;
  216.                                         if(g_BellKeyCounter>=2)        /* Bell key has been pressed for 200ms*/
  217.                                         {
  218.                                                 g_fBellReleaseReq = ON;
  219.                                                 g_BellKeyCounter = 0;
  220.                                                 g_FnKeyCounter = 0;
  221.                                                 GoTo_AlarmStandbyMode();
  222.                                         }
  223.                                 }
  224.                                 else
  225.                                 {
  226.                                         g_BellKeyCounter = 0;
  227.                                 }
  228.                         }
  229.                         break;
  230.                 case ALARM_STANDBY_MODE:
  231.                         /*Bell key process */
  232.                         if(1U == g_fBellReleaseReq)
  233.                         {
  234.                                 g_fBellReleaseReq = !BELL_KEY;
  235.                         }
  236.                         else
  237.                         {
  238.                                 if(0U == BELL_KEY)
  239.                                 {
  240.                                         g_BellKeyCounter++;
  241.                                         if(g_BellKeyCounter>=2)        /*Bell key has been pressed for 200ms*/
  242.                                         {
  243.                                                 g_fBellReleaseReq = ON;
  244.                                                 g_BellKeyCounter = 0;
  245.                                                 GoTo_NormalMode();
  246.                                         }
  247.                                 }
  248.                                 else
  249.                                 {
  250.                                         g_BellKeyCounter = 0;
  251.                                 }
  252.                         }
  253.                         /* Check alarm start or not */
  254.                         if(1U == g_fCheckAlarmDataReq)
  255.                         {
  256.                                 g_fCheckAlarmDataReq = 0;
  257.                                 Check_Alarm_Data();
  258.                         }
  259.                         break;
  260.                 case ALARM_SETTING_MODE:
  261.                         /* Setting time out period control */
  262.                         if(g_ModeTimeOutCounter>0)
  263.                         {
  264.                                 g_ModeTimeOutCounter--;
  265.                         }
  266.                         else
  267.                         {
  268.                                 /* Setting time out */
  269.                                 g_BellKeyCounter = 0;
  270.                                 g_FnKeyCounter = 0;
  271.                                 g_DustAlarmDataSetStep = 0;
  272.                                 GoTo_NormalMode();
  273.                         }
  274.                         /*Fn key process */
  275.                         if(1U == g_fFnReleaseReq)
  276.                         {
  277.                                 g_fFnReleaseReq = !FUNCTION_KEY;
  278.                         }
  279.                         else
  280.                         {
  281.                                 if(0U == FUNCTION_KEY)
  282.                                 {
  283.                                         g_FnKeyCounter++;
  284.                                         if(g_FnKeyCounter>=2)        /* Fn key has been pressed for 200ms*/
  285.                                         {
  286.                                                 g_fFnReleaseReq = ON;
  287.                                                 g_FnKeyCounter = 0;
  288.                                                 /* Setting step control */
  289.                                                 g_DustAlarmDataSetStep++;
  290.                                                 if(g_DustAlarmDataSetStep<3)
  291.                                                 {
  292.                                                         Beep_Times_Set(1);
  293.                                                         g_ModeTimeOutCounter = ALARM_SETTING_TIMEOUT_TIME;
  294.                                                         g_fNewDataDispRq = ON;
  295.                                                 }
  296.                                                 else
  297.                                                 {
  298.                                                         Beep_Times_Set(2);
  299.                                                         /* Save the new data */
  300.                                                         g_sDustAlarmData.High = g_sDustAlarmTempData.High;
  301.                                                         g_sDustAlarmData.Middle = g_sDustAlarmTempData.Middle;
  302.                                                         g_sDustAlarmData.Low = g_sDustAlarmTempData.Low;
  303.                                                         g_BellKeyCounter = 0;
  304.                                                         g_FnKeyCounter = 0;
  305.                                                         g_DustAlarmDataSetStep = 0;
  306.                                                         GoTo_NormalMode();
  307.                                                 }
  308.                                         }
  309.                                 }
  310.                                 else
  311.                                 {
  312.                                         g_FnKeyCounter = 0;
  313.                                 }        
  314.                         }
  315.                         /*Bell key process */
  316.                         if(1U == g_fBellReleaseReq)
  317.                         {
  318.                                 g_fBellReleaseReq = !BELL_KEY;
  319.                         }
  320.                         else
  321.                         {
  322.                                 if(0U == BELL_KEY)
  323.                                 {
  324.                                         g_BellKeyCounter++;
  325.                                         if(g_BellKeyCounter>=2)        /* Bell key has been pressed for 200ms*/
  326.                                         {
  327.                                                 g_fBellReleaseReq = ON;
  328.                                                 g_BellKeyCounter = 0;
  329.                                                 /* Set the alarm data */
  330.                                                 switch(g_DustAlarmDataSetStep)
  331.                                                 {
  332.                                                         case 0:
  333.                                                                 g_sDustAlarmTempData.High++;
  334.                                                                 if(g_sDustAlarmTempData.High>4)
  335.                                                                 {
  336.                                                                         g_sDustAlarmTempData.High = 0;
  337.                                                                 }
  338.                                                                 break;
  339.                                                         case 1:
  340.                                                                 g_sDustAlarmTempData.Middle++;
  341.                                                                 if(g_sDustAlarmTempData.Middle>9)
  342.                                                                 {
  343.                                                                         g_sDustAlarmTempData.Middle = 0;
  344.                                                                 }
  345.                                                                 break;
  346.                                                         default:
  347.                                                                 g_sDustAlarmTempData.Low++;
  348.                                                                 if(g_sDustAlarmTempData.Low>9)
  349.                                                                 {
  350.                                                                         g_sDustAlarmTempData.Low = 0;
  351.                                                                 }
  352.                                                         
  353.                                                 }
  354.                                                 g_ModeTimeOutCounter = ALARM_SETTING_TIMEOUT_TIME;
  355.                                                 g_fNewDataDispRq = ON;        
  356.                                         }
  357.                                 }
  358.                                 else
  359.                                 {
  360.                                         g_BellKeyCounter = 0;
  361.                                 }
  362.                         }
  363.                         /* Display control */
  364.                         if(g_fDispFlashCounter>0)
  365.                         {
  366.                                 g_fDispFlashCounter--;        
  367.                         }
  368.                         else
  369.                         {
  370.                                 g_fDispFlashCounter = SENSOR_DISP_FLASH_TIME;
  371.                                 g_fAlarmDataSetFlashOn = 1 - g_fAlarmDataSetFlashOn;
  372.                                 g_fNewDataDispRq = ON;
  373.                         }
  374.                         break;
  375.                 case ALARM_ON_MODE:
  376.                         /*Bell key process */
  377.                         if(1U == g_fBellReleaseReq)
  378.                         {
  379.                                 g_fBellReleaseReq = !BELL_KEY;
  380.                         }
  381.                         else
  382.                         {
  383.                                 if(0U == BELL_KEY)
  384.                                 {
  385.                                         g_BellKeyCounter++;
  386.                                         if(g_BellKeyCounter>=2)        /*Bell key has been pressed for 200ms*/
  387.                                         {
  388.                                                 g_fBellReleaseReq = ON;
  389.                                                 g_BellKeyCounter = 0;
  390.                                                 GoTo_NormalMode();
  391.                                         }
  392.                                 }
  393.                                 else
  394.                                 {
  395.                                         g_BellKeyCounter = 0;
  396.                                 }
  397.                         }
  398.                         /* Display control */
  399.                         if(g_fDispFlashCounter>0)
  400.                         {
  401.                                 g_fDispFlashCounter--;        
  402.                         }
  403.                         else
  404.                         {
  405.                                 g_fDispFlashCounter = SENSOR_DISP_FLASH_TIME;
  406.                                 g_fAlarmOnFlashOn = 1 - g_fAlarmOnFlashOn;
  407.                         }
  408.                         break;
  409.                 default:
  410.                         /* Low power mode process */
  411.                         while(1)
  412.                         {
  413.                                 g_BatterVoltage = ADC_Sample(BATTERY_ANI_CH,5)*2;
  414.                                 if(g_BatterVoltage < (LOW_POWER_VOLTAGE_VALUE + 50))        /* "+ 50" In case of repeately enter the Low Power mode */
  415.                                 {
  416.                                         g_OutLowPowerModeCounter = 0;
  417.                                         if(1U == g_fLowPowerSleepOn)
  418.                                         {
  419.                                                 LCD_Stop();
  420.                                                 HALT();
  421.                                         }
  422.                                         else
  423.                                         {
  424.                                                 if(1U == g_fNewDataDispRq)
  425.                                                 {
  426.                                                         LCD_Start();
  427.                                                         Display_Process();
  428.                                                         SEG24 = 0x0f;
  429.                                                 }
  430.                                         }
  431.                                 }
  432.                                 else
  433.                                 {
  434.                                         g_OutLowPowerModeCounter++;
  435.                                         if(g_OutLowPowerModeCounter>3)
  436.                                         {
  437.                                                 Initial_Process();
  438.                                                 break;
  439.                                         }
  440.                                 }
  441.                         }
  442.                 }        
  443.                 /* Key release process */        
  444.                 if(1U == g_fFnReleaseReq)
  445.                 {
  446.                         g_fFnReleaseReq = !FUNCTION_KEY;
  447.                         g_FnKeyCounter = 0;
  448.                 }
  449.                 if(1U == g_fBellReleaseReq)
  450.                 {
  451.                         g_fBellReleaseReq = !BELL_KEY;
  452.                         g_BellKeyCounter = 0;
  453.                 }
  454.                                                         
  455. }
  456. /******************************************************************************
  457. End of function Mode_Process
  458. ******************************************************************************/

  459. /******************************************************************************
  460. * Function Name : Initial_Process
  461. * Description   : This function Initial Process.
  462. * Arguments     : none
  463. * Return Value  : none
  464. ******************************************************************************/
  465. static void Initial_Process(void)
  466. {
  467.         /* Initial process */
  468.         DI();
  469.         /* Variables initialize */
  470.         g_sDustAlarmData.High = DUST_DENSITY_ALARM_VELUE_INIT/100;
  471.         g_sDustAlarmData.Middle = (DUST_DENSITY_ALARM_VELUE_INIT%100)/10;
  472.         g_sDustAlarmData.Low = (DUST_DENSITY_ALARM_VELUE_INIT%100)%10;
  473.         g_fSleepModeOn = 0U;
  474.         BATTEEY_LED = OFF;
  475.         g_MainMode = INITIAL_MODE;
  476.         g_ModeTimeOutCounter = 2000/MAIN_LOOP_TIME; /* 2000ms */
  477.         
  478.         /* Get data from EEPROM */
  479.         I2C_Init();
  480.         Delayms(5);
  481.              EEPROM_ReadPage(0x0);
  482.         g_DustDensityMinValue = *(uint16_t *)&g_aDataBuffer[0];
  483.         if((0xff == g_DustDensityMinValue)||(g_DustDensityMinValue > AD_SENSOR_MIN_VALUE_INIT))        /*EEPROM has not been wrote before*/
  484.         {
  485.                 g_DustDensityMinValue = AD_SENSOR_MIN_VALUE_INIT;
  486.                  *(uint16_t *)&g_aDataBuffer[0] = g_DustDensityMinValue;
  487.                  Delayms(5);
  488.                  Delayms(5);
  489.                  EEPROM_WritePage(0x0);
  490.                  Delayms(5);
  491.                  Delayms(5);
  492.         }
  493.         /* Get value of dust density */
  494.         Sensor_Start();
  495.         EI();
  496.         while(0 == g_fSensorComputeReq);
  497.         g_fSensorComputeReq = 0;
  498.         Get_Dust_Density();
  499.         DI();
  500.         /* Get value of battery */
  501.         g_BatterVoltage = ADC_Sample(BATTERY_ANI_CH,5)*2;        
  502.         g_SupplyVoltageSampleCounter = 0;
  503.         g_aSupplyVoltageBuf[g_SupplyVoltageSampleCounter]= g_BatterVoltage;
  504.         /* key initialize*/
  505.         if(0U == FUNCTION_KEY)
  506.         {
  507.                 NOP();
  508.                 NOP();
  509.                 g_fFnReleaseReq = !FUNCTION_KEY;
  510.         }
  511.         if(0U == BELL_KEY)
  512.         {
  513.                 NOP();
  514.                 NOP();
  515.                 g_fBellReleaseReq = !BELL_KEY;
  516.         }
  517.         g_FnKeyCounter = 0;
  518.          g_BellKeyCounter = 0;
  519.         /* Lcd start */
  520.         LCD_Start();
  521.         g_fNewDataDispRq = 1;
  522.         /* Prompt tone */
  523.         Beep_Times_Set(2);
  524.         /* Starts TAU03 */
  525.         TS0 |= 0x0008;               
  526.         EI();
  527. }
  528. /******************************************************************************
  529. End of function Initial_Process
  530. ******************************************************************************/
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:166904 发表于 2017-2-27 14:36 | 只看该作者
好东西啊,黑币不够,努力赚钱去了,
回复

使用道具 举报

板凳
ID:170706 发表于 2017-3-15 18:33 | 只看该作者
亲  你这是用的什么气体检测仪啊
回复

使用道具 举报

地板
ID:189551 发表于 2017-4-14 15:00 | 只看该作者
请问原理是什么?
回复

使用道具 举报

5#
ID:170423 发表于 2017-4-17 09:24 | 只看该作者
真是好东西  谢谢楼主分享
回复

使用道具 举报

6#
ID:193375 发表于 2017-4-25 13:09 | 只看该作者
pm2.5电路设计需要什么材料,本人就买了个灰尘传感器,求大神指教
qq2206747542
回复

使用道具 举报

7#
ID:233936 发表于 2017-9-18 19:23 | 只看该作者
黑币不够,努力赚黑币去
回复

使用道具 举报

8#
ID:246783 发表于 2020-2-22 21:56 来自手机 | 只看该作者
可以做个通风检测仪,空气清新电离机
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表