目录
资料下载地址:基于51单片机脉搏体温设计
一、项目功能
1、通过MPX4115模拟测量脉搏
2、通过DS18B20测量体温
3、按键设置报警阈值,超限报警
二、仿真
温度显示界面
脉搏测量界面
三、程序
main.c代码
void main() //主函数
{
SCON_init();
InitLcd();
while(1) //进入循环
{
counts ++;
sprintf(mStrBloodPressure,"%.1f 1\r\n",mBloodPressure);
KEY_SCAN();
getdata=Adc0832(0);
mBloodPressure = (getdata * 10 / 2 - 50) / 10;
if(counts >= 4)
{
counts = 5;
send(mStrBloodPressure,1);
delay5ms();
delay5ms();
delay5ms();
delay5ms();
send(mStrBloodPressure+1,1);
delay5ms();
delay5ms();
delay5ms();
delay5ms();
send(mStrBloodPressure+2,1);
delay5ms();
delay5ms();
delay5ms();
delay5ms();
send(mStrBloodPressure+3,1);
delay5ms();
delay5ms();
delay5ms();
delay5ms();
//send((char *)mStrBloodPressure,11);
}
temp=getdata/2-5;
if( temp > Xintiao_H )
{
speaker = 0;
}
else
{
speaker = 1;
}
temp = 0;
if( KEY_Set_TIMES == 0 )
{
if( KEY_TIMES == 1 )//血压显示
{
getdata=Adc0832(0);
if(14<getdata<243) //当压力值介于15kpa到115kpa之间时,遵循线性变换
{
// int vary=getdata; //y=(115-15)/(243-13)*X+15kpa
temp=getdata*10/2-50; //测试时补偿值为9.3
// mBloodPressure = temp;
// temp=(int)(press*10); //放大10倍,便于后面的计算
if(temp != ppress)
{
ppress = temp;
OverFlg = 1;
}
dispbuf[3]=temp/1000; //取压力值百位
dispbuf[2]=(temp%1000)/100; //取压力值十位
dispbuf[1]=((temp%1000)%100)/10; //取压力值个位
dispbuf[0]=((temp%1000)%100)%10; //取压力值十分位
LCD_WriteCom( 0x80 );
LCD1602_Write_char( "blood pressure 1" );
LCD_WriteCom( 0x80 + 0x40 );
LCD1602_Write_char(" Rate:");
LCD_WriteData( 0x30 + dispbuf[3] );
LCD_WriteData( 0x30 + dispbuf[2] );
LCD_WriteData( 0x30 + dispbuf[1] );
LCD_WriteData( '.' );
LCD_WriteData( 0x30 + dispbuf[0] );
}
}
if( KEY_TIMES == 0 )
{
lcd_1602_word(0x80,16," temperature "); //初始化显示
wendu=ReadTemperature();
lcd_1602_word(0xc0,10," Temp: ");//显示第二行数据
LCD_WriteCom(0x80+0x40+10);
LCD_WriteData(wendu/100+0x30);
LCD_WriteData(wendu%100/10+0x30);
LCD_WriteData('.');
LCD_WriteData(wendu%100%10+0x30);
LCD_WriteData(0xdf);
LCD_WriteData('C');
}
}
else
{
KEY_Set_Rate();
dispbuf[3]=Xintiao_H/100; //取设置压力值百位
dispbuf[2]=Xintiao_H%100/10; //取设置压力值十位
dispbuf[1]=Xintiao_H%10; //取设置压力值个位
LCD_WriteCom( 0x80 );
LCD1602_Write_char( " Set heart rate " );
LCD_WriteCom( 0x80 + 0x40 );
LCD1602_Write_char("warning:");
LCD_WriteData( 0x30 + dispbuf[3] );
LCD_WriteData( 0x30 + dispbuf[2] );
LCD_WriteData( 0x30 + dispbuf[1] );
}
}
}
/**Adress_Com显示地址,Num_Adat显示字符数量,Adress_Data显示字符串内容**/
void lcd_1602_word(uchar Adress_Com,uchar Num_Adat,uchar *Adress_Data)
{
uchar a=0;
uchar Data_Word;
LCD_WriteCom(Adress_Com); //选中地址
for(a=0;a<Num_Adat;a++) //for循环决定显示字符个数
{
Data_Word=*Adress_Data; //读取字符串数据
LCD_WriteData(Data_Word); //显示字符串
Adress_Data++; //显示地址加一
}
}