“我们不做一锤子买卖,只做技术成长的长期伙伴!”
目录
一、视频展示
基于单片机便携式心率监测系统 -视频分享
二、项目简介
该设计由STM32F103C8T6作为主控芯片和蜂鸣器电路以及供电电路,0.96oled显示屏,3个独立按键,MAX30102心率血氧模块,DS18B20温度传感器模块。
本设计的功能:
1、 屏幕显示
用来显示当前心率血氧温度和阈值。
2、心率血氧检测
通过MAX30102心率血氧模块检测当前心率血氧。
3、阈值设置
在主页面按下设置键会进入阈值设置界面,有三个阈值设置界面,分别是是血氧设置下限,心率阈值设置上限,和温度阈值上限,在任意一个阈值设置界面按下+键会对对应的阈值进行数值增加操作,按下-键会对阈值数值进行减操作。当在第二个阈值修改界面时按下设置键会重新回到初始的数据显示页面。
4、警报系统
当任何一个测的数据不在阈值内,会触发警报,开启蜂鸣器报警,直到恢复正常阈值范围内。
三、原理图设计
四、PCB硬件设计
五、程序设计
#include "stm32f10x.h" // Device header
#include "delay.h"
#include "lcd.h"
#include "timer.h"
#include "IOput.h"
#include "max30102.h"
#include "myiic.h"
#include "algorithm.h"
#include "ds18b20.h"
#include "usart.h"
short zj;
float wd;
u8 show_flag;
uint32_t aun_ir_buffer[500]; //IR LED sensor data
int32_t n_ir_buffer_length; //data length
uint32_t aun_red_buffer[500]; //Red LED sensor data
int32_t n_sp02; //SPO2 value
int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;
u8 dis_hr=0,dis_spo2=0;
u8 max_hr = 140,min_spo2 = 90,max_wd = 38;
#define MAX_BRIGHTNESS 255
//variables to calculate the on-board LED brightness that reflects the heartbeats
uint32_t un_min, un_max, un_prev_data;
int i;
int32_t n_brightness;
float f_temp;
u8 temp_num=0;
u8 temp[6];
u8 str[100];
void dis_DrawCurve(u32* data,u8 x);
void MAX30102_Read_Data(void)
{
i=0;
un_min=0x3FFFF;
un_max=0;
//dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
for(i=100;i<500;i++)
{
aun_red_buffer[i-100]=aun_red_buffer[i];
aun_ir_buffer[i-100]=aun_ir_buffer[i];
//update the signal min and max
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i];
if(un_max<aun_red_buffer[i])
un_max=aun_red_buffer[i];
}
//take 100 sets of samples before calculating the heart rate.
for(i=400;i<500;i++)
{
un_prev_data=aun_red_buffer[i-1];
while(MAX30102_INT==1);
max30102_FIFO_ReadBytes(REG_FIFO_DATA,temp);
aun_red_buffer[i] = (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2]; // Combine values to get the actual number
aun_ir_buffer[i] = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5]; // Combine values to get the actual number
if(aun_red_buffer[i]>un_prev_data)
{
f_temp=aun_red_buffer[i]-un_prev_data;
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness-=(int)f_temp;
if(n_brightness<0)
n_brightness=0;
}
else
{
f_temp=un_prev_data-aun_red_buffer[i];
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness+=(int)f_temp;
if(n_brightness>MAX_BRIGHTNESS)
n_brightness=MAX_BRIGHTNESS;
}
//send samples and calculation result to terminal program through UART
if(ch_hr_valid == 1 && n_heart_rate<120)//**/ ch_hr_valid == 1 && ch_spo2_valid ==1 && n_heart_rate<120 && n_sp02<101
{
dis_hr = n_heart_rate;
dis_spo2 = n_sp02;
}
else
{
dis_hr = 0;
dis_spo2 = 0;
}
}
maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
//显示刷新
if(dis_hr == 0 && dis_spo2 == 0) //**dis_hr == 0 && dis_spo2 == 0
{
// sprintf((char *)str,"HR:--- SpO2:--- ");//**HR:--- SpO2:---
OLED_ShowString(48,2,"---",16);
OLED_ShowString(48,4,"---",16);
}
else{
// sprintf((char *)str,"HR:%3d SpO2:%3d ",dis_hr,dis_spo2);//**HR:%3d SpO2:%3d
OLED_ShowNum(48,2,dis_hr,3,16);
OLED_ShowNum(48,4,dis_spo2,3,16);
}
}
void Show_State(void)
{
OLED_ShowCHinese(0,0,0);
OLED_ShowCHinese(21,0,1);
OLED_ShowCHinese(42,0,2);
OLED_ShowCHinese(63,0,3);
OLED_ShowCHinese(84,0,4);
OLED_ShowCHinese(105,0,5); //夜间监控系统
OLED_ShowCHinese(0,2,0);
OLED_ShowCHinese(16,2,1);
OLED_ShowChar(40,2,':',16);
OLED_ShowCHinese(0,4,2);
OLED_ShowCHinese(16,4,3);
OLED_ShowChar(40,4,':',16);
OLED_ShowCHinese(0,6,6);
OLED_ShowCHinese(16,6,7);
OLED_ShowChar(40,6,':',16);
}
int main (void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
OLED_Init();
delay_ms(1);
OLED_Clear();
input_init();
output_init();
DS18B20_Init();
TIM2_Int_Init(71,9999);
max30102_init();
un_min=0x3FFFF;
un_max=0;
n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
//read the first 500 samples, and determine the signal range
for(i=0;i<n_ir_buffer_length;i++)
{
while(MAX30102_INT==1); //wait until the interrupt pin asserts
max30102_FIFO_ReadBytes(REG_FIFO_DATA,temp);
aun_red_buffer[i] = (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2]; // Combine values to get the actual number
aun_ir_buffer[i] = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5]; // Combine values to get the actual number
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i]; //update signal min
if(un_max<aun_red_buffer[i])
un_max=aun_red_buffer[i]; //update signal max
}
un_prev_data=aun_red_buffer[i];
//calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
while(1)
{
zj=DS18B20_Get_Temp();
wd=zj/10+(zj%10)*0.1;
key_scan(1,0,0);
if(set_flag == 1)
{
set_flag = 0;
show_flag ++;
if(show_flag >= 4)
show_flag = 0;
}
if(show_flag == 1)
{
OLED_ShowCH(0,0," 阈 值 修 改 ");
OLED_ShowCH(0,4,"心率:");
OLED_ShowNum(40,4,max_hr,3,16);
if(dec_flag == 1)
{
dec_flag = 0;
max_hr --;
}
if(add_flag == 1)
{
add_flag = 0;
max_hr ++;
}
}
if(show_flag == 2)
{
OLED_ShowCH(0,0," 阈 值 修 改 ");
OLED_ShowCH(0,4,"血氧:");
OLED_ShowNum(40,4,min_spo2,3,16);
if(dec_flag == 1)
{
dec_flag = 0;
min_spo2 --;
}
if(add_flag == 1)
{
add_flag = 0;
min_spo2 ++;
}
}
if(show_flag == 3)
{
OLED_ShowCH(0,0," 阈 值 修 改 ");
OLED_ShowCH(0,4,"温度:");
OLED_ShowNum(40,4,max_wd,3,16);
if(dec_flag == 1)
{
dec_flag = 0;
max_wd --;
}
if(add_flag == 1)
{
add_flag = 0;
max_wd ++;
}
}
if(show_flag == 0)
{
if((dis_hr > max_hr) || ((dis_spo2 > 0) && (dis_spo2 < min_spo2)) || (wd > max_wd)) //**dis_hr == 0 && dis_spo2 == 0
BEEP = 0;
else
BEEP = 1;
Show_State();
MAX30102_Read_Data();
OLED_Showdecimal(48,6,wd,2,2,16);
}
}
}
六、资料分享
点击即可查看当前资料分享。