找回密码
 立即注册

QQ登录

只需一步,快速开始

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

51单片机+MAX30100心率传感器使用例程

[复制链接]
跳转到指定楼层
楼主
首先,希望管理员赏我些黑币,快21年电赛了,想能多下载写资料
话不多说
下面是我分享的MAX30100心率血氧模块

单片机源程序如下:
  1. # include <reg52.h>
  2. # include <stdio.h>
  3. # include <intrins.h>
  4. //??IIC??
  5. sbit IIC_SCL    =P3^5;     //IIC?SCL
  6. sbit IIC_SDA    =P3^7;     //IIC?SDA
  7. bit  IIC_ACK;              //IIC?ACK
  8. int  rda;                  //IIC??
  9. //-------------------------------------------------------------------------------------//
  10. //??:    delayms()
  11. //??:    ????
  12. //-------------------------------------------------------------------------------------//
  13. void delayms(unsigned int ms)
  14. {
  15. unsigned char i=100,j;
  16. for(;ms;ms--)
  17. {
  18.   while(--i)
  19.   {
  20.    j=10;
  21.    while(--j);
  22.   }
  23. }
  24. }
  25. //-------------------------------------------------------------------------------------//
  26. //??:    void iic_start();
  27. //??:    I2C????
  28. //-------------------------------------------------------------------------------------//
  29. //   SCL   --- --- ___
  30. //   SDA   --- ___ ___
  31. void iic_start()
  32. {  
  33. IIC_SDA=1;
  34. _nop_();
  35. _nop_();
  36. IIC_SCL=1;         
  37. _nop_();
  38. _nop_();
  39. IIC_SDA=0;
  40. _nop_();
  41. _nop_();
  42. IIC_SCL=0;
  43. _nop_();
  44. _nop_();
  45. }
  46. //-------------------------------------------------------------------------------------//
  47. //??:    void iic_stop();
  48. //??:    I2C????
  49. //???:
  50. //-------------------------------------------------------------------------------------//
  51. //   SCL   ___ --- ---
  52. //   SDA   ___ ___ ---
  53. void iic_stop()
  54. {  
  55. IIC_SCL=0;
  56. _nop_();
  57. _nop_();
  58. IIC_SDA=0;
  59. _nop_();
  60. _nop_();
  61. IIC_SCL=1;
  62. _nop_();
  63. _nop_();
  64. IIC_SDA=1;
  65. _nop_();
  66. _nop_();
  67. }
  68. //-------------------------------------------------------------------------------------//
  69. //??:    void iic_sendbyte(unsigned char c);
  70. //??:    ?? 8_BIT ??
  71. //-------------------------------------------------------------------------------------//
  72. void iic_sendbyte(unsigned char c)
  73. {
  74. unsigned char bitcnt;
  75. for(bitcnt=0;bitcnt<8;bitcnt++)
  76. {
  77. if((c<<bitcnt)&0x80)
  78. IIC_SDA=1;
  79. else
  80. IIC_SDA=0;
  81. _nop_();
  82. _nop_();
  83. IIC_SCL=1;
  84. _nop_();
  85. _nop_();
  86. IIC_SCL=0;
  87. }
  88. _nop_();
  89. _nop_();
  90. IIC_SDA=1;
  91. _nop_();
  92. _nop_();
  93. IIC_SCL=1;
  94. _nop_();
  95. _nop_();
  96. if(IIC_SDA==0)
  97. IIC_ACK=0;
  98. else
  99. IIC_ACK=1;
  100. IIC_SCL=0;
  101. _nop_();
  102. _nop_();
  103. }
  104. //-------------------------------------------------------------------------------------//
  105. //??:    int iic_rcvbyte_nack();
  106. //??:    ?? 8_BIT ??  ??ack??
  107. //-------------------------------------------------------------------------------------//
  108. int iic_rcvbyte_nack()
  109. {
  110. unsigned char retc;
  111. unsigned char bitcnt;
  112. retc=0;
  113. IIC_SDA=1;
  114. for(bitcnt=0;bitcnt<8;bitcnt++)
  115. {
  116. _nop_();
  117. _nop_();
  118. IIC_SCL=0;
  119. _nop_();
  120. _nop_();
  121. IIC_SCL=1;
  122. _nop_();
  123. _nop_();
  124. retc=retc<<1;
  125. if(IIC_SDA==1)
  126. retc=retc+1;
  127. _nop_();
  128. _nop_();
  129. }
  130. //??NACK??
  131. _nop_();
  132. _nop_();
  133. IIC_SCL=0;
  134. _nop_();
  135. _nop_();
  136. IIC_SDA=1;
  137. _nop_();
  138. _nop_();
  139. IIC_SCL=1;
  140. _nop_();
  141. _nop_();
  142. IIC_SCL=0;
  143. _nop_();
  144. _nop_();
  145. return(retc);
  146. }
  147. //-------------------------------------------------------------------------------------//
  148. //??:    int iic_rcvbyte_ack();
  149. //??:    ?? 8_BIT ?? ??ack??
  150. //-------------------------------------------------------------------------------------//
  151. int iic_rcvbyte_ack()
  152. {
  153. unsigned char retc;
  154. unsigned char bitcnt;
  155. retc=0;
  156. IIC_SDA=1;
  157. for(bitcnt=0;bitcnt<8;bitcnt++)
  158. {
  159. _nop_();
  160. _nop_();
  161. IIC_SCL=0;
  162. _nop_();
  163. _nop_();
  164. IIC_SCL=1;
  165. _nop_();
  166. _nop_();
  167. retc=retc<<1;
  168. if(IIC_SDA==1)
  169. retc=retc+1;
  170. _nop_();
  171. _nop_();
  172. }
  173. //??ACK??
  174. _nop_();
  175. _nop_();
  176. IIC_SCL=0;
  177. _nop_();
  178. _nop_();
  179. IIC_SDA=0;
  180. _nop_();
  181. _nop_();
  182. IIC_SCL=1;
  183. _nop_();
  184. _nop_();
  185. IIC_SCL=0;
  186. _nop_();
  187. _nop_();
  188. return(retc);
  189. }
  190. //-------------------------------------------------------------------------------------//
  191. //??:      wr_max30100_one_data()
  192. //??:      ???max30100??
  193. //address:   ?????
  194. //saddress:  ??????
  195. //w_data:    ????
  196. //-------------------------------------------------------------------------------------//
  197. void wr_max30100_one_data(int address,int saddress,int w_data )
  198. {
  199. _nop_();
  200. iic_start();
  201. _nop_();
  202. iic_sendbyte(address);
  203. _nop_();
  204. iic_sendbyte(saddress);
  205. _nop_();
  206. iic_sendbyte(w_data);
  207. _nop_();
  208. iic_stop();
  209. _nop_();
  210. }
  211. //-------------------------------------------------------------------------------------//
  212. //??:      rd_max30100_one_data()
  213. //??:      ???max30100??
  214. //address:   ?????
  215. //saddress:  ??????
  216. //rda:       ?????
  217. //-------------------------------------------------------------------------------------//
  218. void rd_max30100_one_data(int address,int saddress)
  219. {
  220. iic_start();
  221. _nop_();
  222. iic_sendbyte(address);
  223. _nop_();
  224. iic_sendbyte(saddress);
  225. _nop_();
  226. address=address+1;
  227. _nop_();
  228. iic_start();
  229. _nop_();
  230. iic_sendbyte(address);
  231. _nop_();
  232. rda=iic_rcvbyte_nack();
  233. _nop_();
  234. iic_stop();
  235. }
  236. //-------------------------------------------------------------------------------------//
  237. //??:      ???
  238. //??:      ?max30100????
  239. //-------------------------------------------------------------------------------------//
  240. main()
  241. {
  242. double temp,temp1,temp2;
  243. //temp       ????
  244. //temp1      30100??????
  245. //temp2      30100??????
  246. TMOD=0x21;   
  247. SCON=0x50;
  248. TH1=0xFD;
  249. TL1=0xFD;
  250. TR1=1;      
  251. TI=1;   
  252. //??51????? 9600 N 8 1
  253. //51???11.0592MHz
  254. while(1)
  255. {
  256. wr_max30100_one_data(0xae,0x06,0x0a);       // 0X06??B3?TEMP_EN?1
  257. delayms(20);                                // ????????,???,??????
  258. rd_max30100_one_data(0xae,0x16);            // ??????
  259. printf("temp1=%d\n",rda);                   // ????
  260. temp1=rda;
  261. rd_max30100_one_data(0xae,0x17);            // ??????????
  262. printf("temp2=%d\n",rda);                   // ????
  263. temp2=rda;
  264. temp=temp1+(temp2/100);
  265. printf("temp=%.2f\n",temp);                 // ????
  266. rd_max30100_one_data(0xae,0xff);            // ????ID
  267. printf("MAX30100 ID =%d\n",rda);            // ????
  268. delayms(100);   
  269. }
  270. }
复制代码

屏幕截图 2021-07-30 150838.png (20.84 KB, 下载次数: 69)

屏幕截图 2021-07-30 150838.png

评分

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

查看全部评分

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

使用道具 举报

沙发
ID:981552 发表于 2021-12-3 17:43 | 只看该作者
求一下心率传感器的代码。。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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