找回密码
 立即注册

QQ登录

只需一步,快速开始

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

瑞萨单片机+TN905非接触式红外感应体温计(源程序电路图全套资料)

[复制链接]
跳转到指定楼层
楼主


红外测温模块选用 ZyTemp 公司的 TN905 红外测温模块,其测温原理应用斯特凡-玻尔兹曼定律和维恩位移定律,是一种集成的红外探测器, TN905 模块采用 3V 供电, 数字输出接口为 SPI 接口。



电路原理图如下:


单片机源程序如下:
  1. /***********************************************************************/
  2. /*                                                                     */
  3. /*  FILE        :Main.c                                                */
  4. /*  DATE        :                                                      */
  5. /*  DESCRIPTION :Main Program                                          */
  6. /*  CPU TYPE    :                                                      */
  7. /*                                                                     */
  8. /*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
  9. /*                                                                     */
  10. /***********************************************************************/
  11. /******************************************************************************
  12. Includes   <System Includes> , "Project Includes"
  13. ******************************************************************************/
  14. #include "iodefine.h"
  15. #include "userdefine.h"
  16. #include "system.h"
  17. #include "lcd.h"
  18. #include "sensor.h"
  19. #include "key_led_buzzer.h"
  20. #include "ad.h"
  21. #include "e2prom.h"
  22. #include "timer.h"
  23. /******************************************************************************
  24. Macro definitions
  25. ******************************************************************************/
  26. #define        ALARM_DEGREE        3700        /* Body temperature alarm value 37  degree Celsius  */
  27. /******************************************************************************
  28. Global Variables
  29. ******************************************************************************/
  30. _Bool g_AlarmFlag;                /* g_AlarmFlag is true if body "temperature > ALARM_DEGREE" */

  31. uint8_t g_RunMode;                /* MCU run mode:MODE_WAIT,MODE_READY,MODE_SETTING,MODE_SET_FINISH,MODE_MEASURE,MODE_CALCULATE,MODE_DISPLAY */
  32. uint8_t g_MeasureMode;                /* Measure mode: object temperature or ambiant temperature */
  33. uint8_t g_AlarmCounter;                /* Alarm counter if body "temperature > ALARM_DEGREE" */
  34. uint8_t g_WaitCounter;                /* Wait counter, MCU will enter halt mode if no any action after 30s */
  35. uint8_t g_SetData;                /* Temperature calibration data */
  36. uint8_t g_ObjectTemp[5];        /* Object temperature original data */
  37. uint8_t g_AmbiantTemp[5];        /* Ambiant temperature original data */
  38. uint8_t *g_DataPoint;                /* Data point for temperature data */
  39. uint8_t g_DataNum;                /* Temperature data counter */
  40. uint8_t g_ObjCount;                /* Object temperature calculate data counter */
  41. uint8_t g_AmbiCount;                /* Ambiant temperature calculate data counter */

  42. uint32_t g_ObjectData;                /* Object temperature calculate data */
  43. uint32_t g_AmbiantData;                /* Ambiant temperature calculate data */
  44. uint32_t g_ObjectDataTemp[5];        /* Object temperature calculate data array for average */
  45. uint32_t g_AmbiantDataTemp[5];        /* Ambiant temperature calculate data array for average */
  46. uint32_t g_DisplayData;                /* Temperature data for LCD display */

  47. /******************************************************************************
  48. Extern global Variables defined in other files
  49. ******************************************************************************/
  50. extern uint8_t g_KeyEnable;
  51. extern uint8_t g_KeyStatus;
  52. extern uint8_t g_KeyOldStatus;
  53. extern uint8_t g_KeyReturn;
  54. extern uint8_t g_aDataBuffer[];

  55. /******************************************************************************
  56. Private Function Prototypes
  57. ******************************************************************************/
  58. static uint32_t Calculate_Temperature( uint32_t * DataPoint);
  59. static void ModeTransferByKey(void);

  60. /******************************************************************************
  61. * Function Name : main
  62. * Description : main loop.
  63. * Arguments : none
  64. * Return Value : none
  65. ******************************************************************************/
  66. void main(void)
  67. {
  68.         /* Local variables */
  69.         uint8_t t_tempdata;
  70.         /* Initialize global variables */
  71.         g_RunMode = MODE_READY;                                /* Initial run mode */
  72.         g_MeasureMode = MEASURE_OBJ;                        /* Initial measure mode */
  73.         g_AlarmFlag = FALSE;                                /* Alarm flag is set to 0 */
  74.         /* System initialize */
  75.         System_Init();
  76.         /* Get temperature calibration data*/
  77.         EEPROM_ReadRandom(0x0000,0x01,g_aDataBuffer);        
  78.         g_SetData = g_aDataBuffer[0];
  79.         /* Main loop */
  80.         while(1)
  81.         {
  82.                 /* Transfer run mode according to pressing key */
  83.                 ModeTransferByKey();
  84.                 /* Run mode handle */
  85.                 switch( g_RunMode )
  86.                 {
  87.                         case MODE_WAIT:        
  88.                                 LCD_Stop();                        /* Close LCD display brefore enter to halt mode */
  89.                                 __halt();                        /* Enter to halt mode */
  90.                         break;
  91.                         case MODE_READY:
  92.                                 LCD_Start();
  93.                         break;                        
  94.                         case MODE_SETTING:                                
  95.                                 BLON = 1;                        /* Blink LCD when calibration data is setting */        
  96.                         break;               
  97.                         case MODE_SET_FINISH:        
  98.                                 BLON = 0;                        /* Close blink LCD when calibration data setting is finished */
  99.                                 EEPROM_WriteByte(0x0000, g_SetData); /* Get calibration data */
  100.                                 /* Transfer to MODE_READY after MODE_SET_FINISH */
  101.                                 g_RunMode = MODE_READY;
  102.                         break;
  103.                         case MODE_MEASURE:                        /* Get the original data of temperature */
  104.                                 {
  105.                                         t_tempdata = g_ObjectTemp[0] + g_ObjectTemp[1] + g_ObjectTemp[2];
  106.                                         if ( (g_ObjectTemp[0] == 0x4c) && (g_ObjectTemp[4] == 0x0D) && (t_tempdata == g_ObjectTemp[3]) )
  107.                                         {
  108.                                                 g_ObjectData = g_ObjectTemp[1];
  109.                                                 g_ObjectData = ( g_ObjectData<<8 ) + g_ObjectTemp[2];
  110.                                                 g_ObjectData *= 100;
  111.                                                 g_ObjectData =  ( g_ObjectData/16 - 27315 );
  112.                                                 
  113.                                                 g_ObjectDataTemp[g_ObjCount] = g_ObjectData;
  114.                                                 g_ObjCount++;
  115.                                                 if( g_ObjCount > 4 )        /* Get data 5 times */
  116.                                                 {
  117.                                                         g_RunMode = MODE_CALCULATE;
  118.                                                         g_ObjCount = 0;                                                        
  119.                                                 }
  120.                                         }
  121.                                         t_tempdata = g_AmbiantTemp[0] + g_AmbiantTemp[1] + g_AmbiantTemp[2];
  122.                                         if ( (g_AmbiantTemp[0] == 0x66) && (g_AmbiantTemp[4] == 0x0D) && (t_tempdata == g_AmbiantTemp[3]) )
  123.                                         {
  124.                                                 g_AmbiantData = g_AmbiantTemp[1];
  125.                                                 g_AmbiantData = ( g_AmbiantData<<8 ) + g_AmbiantTemp[2];
  126.                                                 g_AmbiantData *= 100;
  127.                                                 g_AmbiantData =  ( g_AmbiantData/16 - 27315 );
  128.                                                 g_AmbiantDataTemp[g_AmbiCount] = g_AmbiantData;
  129.                                                 g_AmbiCount++;
  130.                                                 if( g_AmbiCount > 4 )        /* Get data 5 times */
  131.                                                 {
  132.                                                         g_RunMode = MODE_CALCULATE;
  133.                                                         g_AmbiCount = 0;                                                        
  134.                                                 }
  135.                                         }               
  136.                                 }
  137.                         
  138.                         break;
  139.                         case MODE_CALCULATE:                        /* Calculate the real data of temperature */
  140.                                 if( g_MeasureMode == MEASURE_OBJ )
  141.                                         g_DisplayData = Calculate_Temperature( g_ObjectDataTemp );                                
  142.                                        
  143.                                 else
  144.                                         g_DisplayData = Calculate_Temperature( g_AmbiantDataTemp );
  145.                                 /* Adjust temperature according to setting data */
  146.                                 if( g_SetData >= 0x80)
  147.                                 /* Calibration data is minus if data >= 0x80 */
  148.                                         g_DisplayData = g_DisplayData -  (uint16_t)( (g_SetData&0x7f)*10);
  149.                                 else
  150.                                 /* Calibration data is plus if data > 0x80 */
  151.                                         g_DisplayData = g_DisplayData + (uint16_t)( (g_SetData&0x7f)*10);
  152.                                        
  153.                                 if( g_MeasureMode == MEASURE_OBJ )
  154.                                 {
  155.                                         /* g_AlarmFlag is true if body "temperature > ALARM_DEGREE" */
  156.                                         if( g_DisplayData > ALARM_DEGREE )
  157.                                                 g_AlarmFlag = TRUE;
  158.                                 }
  159.                                        
  160.                                 g_RunMode = MODE_DISPLAY;                        
  161.                         break;                        
  162.                 }
  163.                 /* LCD display process */
  164.                 Display_Process();
  165.         }
  166. }
  167. /******************************************************************************
  168. End of function main
  169. ******************************************************************************/

  170. /******************************************************************************
  171. * Function Name : Calculate_Temperature
  172. * Description : This function calculate the real temperature.
  173. * Arguments : none
  174. * Return Value : uint32_t-
  175.                         the temperature data*100(for example: 3200 means 32 Celsius degree)
  176. ******************************************************************************/
  177. static uint32_t Calculate_Temperature( uint32_t * DataPoint)
  178. {
  179.         /* Local variables */
  180.         uint8_t i = 0;
  181.         uint32_t t_max_data,t_min_data;
  182.         uint32_t t_TempData;
  183.         t_max_data = *DataPoint;
  184.         t_min_data = *DataPoint;
  185.         t_TempData = 0;
  186.         while(i++ < 5)
  187.         {
  188.                 if( *DataPoint > t_max_data )
  189.                         t_max_data = *DataPoint;
  190.                 if( *DataPoint < t_min_data )
  191.                         t_min_data = *DataPoint;
  192.                         
  193.                 t_TempData += *DataPoint;
  194.                 DataPoint++;
  195.         }
  196. /* Get the average value after delete the max data and min data */        
  197.         t_TempData = ( t_TempData - t_max_data - t_min_data );
  198.         t_TempData = t_TempData/3;
  199.         return(t_TempData);
  200. }
  201. /******************************************************************************
  202. End of function Calculate_Temperature
  203. ******************************************************************************/

  204. /******************************************************************************
  205. * Function Name : ModeTransferByKey
  206. * Description : This function enter run mode according to pressing key.
  207. * Arguments : none
  208. * Return Value : none
  209. ******************************************************************************/
  210. static void ModeTransferByKey(void)
  211. {
  212.         /* Key handle when confirm key is pressed */
  213.         if(g_KeyEnable == KEY_PRESS)                        
  214.                 {
  215.                         if(g_KeyReturn == KEY_GAUGE)
  216.                         {
  217.                                 if( g_RunMode != MODE_SETTING)                /* Enter MODE_MEASURE if gauge key is pressed not in setting mode */
  218.                                 {
  219.                                         g_RunMode = MODE_MEASURE;
  220.                                         g_WaitCounter = 0;
  221.                                         BUZZER = LOW;                        /* Buzzzer on when press "measure" key */
  222.                                         LED = HIGH;                        /* LED on when press "measure" key */        
  223.                                 }
  224.                                 else
  225.                                         g_RunMode = MODE_SET_FINISH;
  226.                         }
  227.                         if(g_KeyReturn == KEY_OBJECT)
  228.                         {
  229.                                 if( g_RunMode != MODE_SETTING)
  230.                                 {
  231.                                         g_MeasureMode = MEASURE_OBJ;        /* Enter to MEASURE_OBJ mode */
  232.                                 }
  233.                                 else
  234.                                 {
  235.                                         /* Calibration data -1 in setting mode */
  236.                                         g_SetData--;
  237.                                 }
  238.                         }
  239.                         if(g_KeyReturn == KEY_AMBIANT)
  240.                         {
  241.                                 if( g_RunMode != MODE_SETTING)
  242.                                 {
  243.                                         g_MeasureMode = MEASURE_AMBI;
  244.                                 }
  245.                                 else
  246.                                 {
  247.                                         /* Calibration data +1 in setting mode */
  248.                                         g_SetData++;
  249.                                 }
  250.                         }

  251.                         g_KeyEnable = KEY_RELEASE;                        /* Release key staus after key handling */
  252.                 }
  253. }
  254. /******************************************************************************
  255. End of function ModeTransferByKey
  256. ******************************************************************************/
复制代码

所有资料51hei提供下载:
非接触式红外感应体温计(全套资料).7z (3.04 MB, 下载次数: 46)


评分

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

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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