Discussion in "Electronics" started by    AMINOR    Feb 15, 2011.
Thu Feb 20 2014, 07:35 am
#11


Let’s use this heart beat sensor and build a digital heart beat monitor. When a finger is put in the
sensor, it displays the beats per minute (BPM) rate.





The pulse signal is applied to the P1.0 input of U2 that is AT89S52 (Can be any 8051 type) which is

monitored by the program whenever this input goes high. Internally to U2, there is a counter which

counts how many 1ms intervals there are between two high going heart beat pulses. This number is

then divided by 60,000 and the result is the pulse rate. For example, if the pulse rate is 60 BPM

(beats per minute) there will be a pulse every second.

The duration of one heart beat
will be one seconds or 1000 x 1ms. Dividing 60,000 by 1000 will give the correct result of 60 which is shown on the display. If there is invalid result (BPM>200) it is invalid and waits for next cycle.

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Hardware Defines -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sbit SENSOR = P1^0; //sensor is connected to this pin
unsigned int beatms;
float bpm;
char buf[20];
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Main Program -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void main()
{
// -=-=- Intialize variables -=-=-=
lcdInit();
// -=-=- Welcome LCD Message -=-=-=
lcdClear();
lcdGotoXY(0,0); // 1st Line of LCD
// "xxxxxxxxxxxxxxxx"
lcdPrint("DIGITAL HEART");
lcdGotoXY(0,1); // 2nd Line of LCD
// "xxxxxxxxxxxxxxxx"
lcdPrint("BEAT MONITOR");
beatms=0; // will store duration between two pulses
// -=-=- Program Loop -=-=-=
while(1)
{
while(SENSOR==0);// wait for high pulse from sensor
DelayNmS(10); // 10ms delay so that it does not listen to any noise
beatms = 10; // start counting beatms from 10ms since we have delay after pulse
while(SENSOR==1)// wait until signal is high
{
DelayNmS(1); //wait 1msec
beatms++; //keep incrementing counter each 1ms
}
while(SENSOR==0) //keep looping till signal goes back high, wait for next
{
DelayNmS(1); //wait 1msec
beatms++; //keep incrementing counter each 1ms
}
// beatms variable will now have time in ms between two high edge pulse
lcdClear();
lcdGotoXY(0,0);
lcdPrint("HEART RATE : ");
bpm = (float)60000/beatms; // see document of #1157 for this calculation
if(bpm >
 200)
{
lcdGotoXY(0,1);
sprintf (buf, "Processing......"); // Invalid, Wait for next cycle
lcdPrint(buf);
} else {
lcdGotoXY(0,1);
sprintf (buf, "%0.0f BPM", bpm); // Display reading in BPM
lcdPrint(buf);
}
}
}


for more info see its data sheet all this is given in it..... read it carefully...

coolmirza143


Can the above code be wrote in Keil?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am