找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机+ST188脉搏体温测量源程序

[复制链接]
跳转到指定楼层
楼主
电路原理图如下:


元件清单
1、万用板
2、单片机
3、Lcd1602液晶屏
4、16p排针
5、16p排针母座
6、LM358芯片
7、40脚IC座
8、8脚IC座
9、ST188反射光电开关
10、防水型DS18B20
11、200欧电位器
12、220欧电阻*2
13、1k电阻*5
14、2k电阻
15、10k电阻*6
16、20k电阻
17、100k电阻
18、1uf电容*2
19、10uf电容*2
20、12m晶振
21、30pf电容*2
22、红色led灯*3
23、绿色led灯
24、黄色led灯
25、8550三极管
26、蜂鸣器
27、按键*4
28、自锁开关
29、DC3.5mm电源座
30、焊锡若干
31、导线若干
32、usb电源线

单片机源程序如下:
  1. #include<reg52.h>
  2. #include <intrins.h>
  3. #include <string.h>
  4. #include "lcd1602.h"
  5. #include "ds18b20.h"        
  6. #include "eeprom.h"        

  7. #define uchar unsigned char
  8. #define uint  unsigned int

  9. sbit rled = P1^0;
  10. sbit gled = P1^1;
  11. sbit trled = P1^2;
  12. sbit yled = P1^3;

  13. sbit beep = P1^4;

  14. sbit key1 = P1^5;
  15. sbit key2 = P1^6;
  16. sbit key3 = P1^7;


  17. sbit P32=P3^2;


  18. unsigned char i=0,timecount=0,displayOK=0,rate=0,aa=0;
  19. unsigned int time[6]={0};
  20. uint temp;
  21. uchar flag;
  22. uchar xl_h,xl_l,temp_h,temp_l;
  23. uint alt;
  24. bit S_flag;

  25. void delay(uint j)
  26. {
  27.         uint x,y;
  28.         for(x=0;x<j;x++)
  29.         for(y=0;y<110;y++);
  30. }


  31. /******************把数据保存到单片机内部eeprom中******************/
  32. void write_eeprom()
  33. {
  34.         SectorErase(0x2000);
  35.         byte_write(0x2000, xl_h);
  36.         byte_write(0x2001, xl_l);
  37.         byte_write(0x2002, temp_h);
  38.         byte_write(0x2003, temp_l);

  39.         byte_write(0x2058, a_a);        
  40. }

  41. /******************把数据从单片机内部eeprom中读出来*****************/
  42. void read_eeprom()
  43. {
  44.         xl_h = byte_read(0x2000);
  45.         xl_l = byte_read(0x2001);
  46.         temp_h = byte_read(0x2002);
  47.         temp_l = byte_read(0x2003);
  48.         a_a    = byte_read(0x2058);
  49. }

  50. /**************开机自检eeprom初始化*****************/
  51. void init_eeprom()
  52. {
  53.         read_eeprom();                //先读
  54.         if(a_a != 1||key2==0)                //新的单片机初始单片机内问eeprom
  55.         {
  56.                 xl_h = 90;
  57.                 xl_l = 50;
  58.                 temp_h =37;
  59.                 temp_l =15;
  60.                 a_a = 1;
  61.                 write_eeprom();           //保存数据
  62.         }        
  63. }

  64.          
  65. void display()
  66. {
  67.         if(flag==0)
  68.         {
  69.                 lcd1602_write(0,0x80);
  70.                 lcd1602_writebyte(" Temp:");
  71.                 lcd1602_write(1,0x30 + temp/100);
  72.                 lcd1602_write(1,0x30 + temp%100/10);
  73.                 lcd1602_write(1,'.');
  74.                 lcd1602_write(1,0x30 + temp%10);
  75.                 lcd1602_write(1,0xdf);
  76.                 lcd1602_writebyte("C    ");

  77.                
  78.                 lcd1602_write(0,0xc0);
  79.                 lcd1602_writebyte("Heart:");
  80.                 if(displayOK==1)
  81.                 {
  82.                         rate=60000/(time[1]/5+time[2]/5+time[3]/5+time[4]/5+time[5]/5);
  83.                         lcd1602_write(1,0x30 + rate/100);
  84.                         lcd1602_write(1,0x30 + rate%100/10);
  85.                         lcd1602_write(1,0x30 + rate%10);
  86.                 }
  87.                 else
  88.                 {
  89.                         lcd1602_writebyte("---");
  90.                 }
  91.                 lcd1602_writebyte("/min   ");
  92.   }
  93.         else
  94.         {
  95.                 lcd1602_write(0,0x80);
  96.                 lcd1602_writebyte(" XH:");
  97.                 if(S_flag==1&&flag==1)
  98.                   lcd1602_writebyte("   ");
  99.                 else
  100.                 {
  101.                 lcd1602_write(1,0x30 + xl_h/100);
  102.                 lcd1602_write(1,0x30 + xl_h%100/10);
  103.                 lcd1602_write(1,0x30 + xl_h%10);
  104.                 }
  105.                
  106.                 lcd1602_writebyte("  XL:");
  107.                 if(S_flag==1&&flag==2)
  108.                   lcd1602_writebyte("   ");
  109.                 else
  110.                 {
  111.                 lcd1602_write(1,0x30 + xl_l/100);
  112.                 lcd1602_write(1,0x30 + xl_l%100/10);
  113.                 lcd1602_write(1,0x30 + xl_l%10);
  114.                 }
  115.                
  116.                
  117.                
  118.                 lcd1602_write(0,0xc0);
  119.                 lcd1602_writebyte(" TH:");
  120.                 if(S_flag==1&&flag==3)
  121.                   lcd1602_writebyte("  ");
  122.                 else
  123.                 {
  124.                
  125.                 lcd1602_write(1,0x30 + temp_h/10);
  126.                 lcd1602_write(1,0x30 + temp_h%10);
  127.                 }
  128.                 lcd1602_writebyte("C ");
  129.                
  130.                 lcd1602_writebyte(" TL:");
  131.                 if(S_flag==1&&flag==4)
  132.                   lcd1602_writebyte("  ");
  133.                 else
  134.                 {
  135.                 lcd1602_write(1,0x30 + temp_l/10);
  136.                 lcd1602_write(1,0x30 + temp_l%10);
  137.                 }
  138.                 lcd1602_writebyte("C ");
  139.                
  140.                
  141.                
  142.                
  143.         }


  144. }

  145. void keyrc()
  146. {
  147.         if(key1==0)
  148.         {
  149.                 delay(10);
  150.                 if(key1==0)
  151.           {
  152.                         flag++;
  153.                         if(flag>4) flag=0;
  154.                 }
  155.                 while(!key1);
  156.         }
  157.         
  158.         if(key2==0)
  159.         {
  160.                 delay(10);
  161.                 if(key2==0)
  162.           {
  163.                         switch(flag)
  164.                         {
  165.                                 case 1: if(xl_h<160)          xl_h++;   break;         
  166.                                 case 2: if(xl_h>xl_l+1)       xl_l++;   break;        
  167.                                 case 3: if(temp_h<99)         temp_h++; break;  
  168.                                 case 4: if(temp_h>temp_l+1)   temp_l++; break;
  169.                         }
  170.                         write_eeprom();
  171.                 }
  172.                 while(!key2);
  173.         }
  174.         
  175.         if(key3==0)
  176.         {
  177.                 delay(10);
  178.                 if(key3==0)
  179.           {
  180.                         switch(flag)
  181.                         {
  182.                                 case 1: if(xl_h>xl_l+1)        xl_h--;   break;         
  183.                                 case 2: if(xl_l>0)             xl_l--;   break;        
  184.                                 case 3: if(temp_h>temp_l+1)    temp_h--; break;  
  185.                                 case 4: if(temp_l>0)           temp_l--; break;
  186.                         }
  187.                         write_eeprom();
  188.                 }
  189.                 while(!key3);
  190.         }
  191. }

  192. void clsp()
  193. {
  194.         alt++;
  195.         if(alt>15)
  196.         {
  197.                 alt=0;
  198.                 if(displayOK==1)
  199.                 {
  200.                         if(rate>xl_h) {rled=~rled;gled=1;}
  201.                         else if(rate<xl_l) {rled=1;gled=~gled;}
  202.                         else {rled=1;gled=1;}
  203.                 }
  204.                 else {rled=1;gled=1;}
  205.                
  206.                 if(temp>temp_h*10) {trled=~trled;yled=1;}
  207.                 else if(temp<temp_l*10) {trled=1;yled=~yled;}
  208.                 else {trled=1;yled=1;}
  209.                
  210.                 if(((rate>xl_h || rate<xl_l) && displayOK==1) || temp>temp_h*10 || temp<temp_l*10)
  211.                         beep=~beep;
  212.                 else
  213.                         beep=1;
  214.                 S_flag=~S_flag;
  215.         }
  216. }



  217. void main()
  218. {
  219.         P32=1;
  220.         lcd_init();//lcd初始化
  221.         init_eeprom();
  222.         TCON=0x01;//设置外部中断0
  223.         EX0=1;
  224.         
  225.         TMOD=0x01;//定时器0初始化

  226.         TL0 = 0xB0;                //设置定时初值
  227.         TH0 = 0x3C;                //设置定时初值
  228.         ET0=1;//开定时器中断
  229.         //显示基本文字
  230.         
  231.         temp=ReadTemperature();
  232.         
  233.         GoToXY_string(0,0," Welcome to use ");
  234.         GoToXY_string(1,0,"   Heart rate   ");
  235.         TR0=0;//定时器停止
  236.         EA=1;//开总中断
  237.         delay(2000);
  238.         temp=ReadTemperature();
  239.         while(1)
  240.         {
  241.                 temp=ReadTemperature();
  242.                 display();        
  243.                 keyrc();
  244.                 clsp();
  245.         }
  246. }
  247. ……………………

  248. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有代码51hei下载:
1-程序.rar (63.35 KB, 下载次数: 28)

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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