I have written this coding for heart rate and body temperature monitoring system using embedded C for AT89c51
i m getting output but the heart rate count is varying !!!
wat shall i do !!!
#include<reg51.h>
#include<intrins.h>
unsigned char beat,BPS,BPM;
unsigned char itime,B1,B2,B3,a,string,i,j,V,f,d;
void command (unsigned char);
void display (unsigned char);
void ready ();
void lcd ();
void delay (unsigned char );
void conversion_Ascii(unsigned char);
void conversion(unsigned char);
sbit RD_A=P2^5;
sbit WR_A=P2^6;
sbit INTR=P2^7;
unsigned char x,z,k,temp,q1,q2,q3,q;
unsigned char msg[]={"B.T:"};
unsigned char msg1[]={"H.B:"};
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
sbit BUSY=P0^7;
sbit HB=P3^0;
sbit BT=P3^1;
void main()
{
P0=0x00;
P1=0xff;
P2=0x00;
HB=0;
BT=0;
command(0x38);
command(0x01);
command(0x0e);
WR_A=0;
_nop_();
_nop_();
WR_A=1;
INTR=1;
while(INTR==1);
RD_A=1;
_nop_();
_nop_();
RD_A=0;
command(0x06);
command(0x80);
for(k=0;k<4;k++)
{
z=msg[k];
display(z);
}
x=P1;
x=((x*0x5*0x64)/0xff);
temp=x;
BT=0;
if (temp >= 35 && temp <= 40)
{
command(0x86);
conversion(x);
display('N');
display('o');
display('r');
display('m');
display('a');
display('l');
BT=0;
}
else if( temp <= 34)
{
command(0x86);
conversion(x);
display('L');
display('o');
display('w');
BT=1;
}
else if (temp>=41)
{
command(0x86);
conversion(x);
display('H');
display('i');
display('g');
display('h');
BT=1;
}
T0=1;
TMOD=0x06;
TL0=0;
TR0=1;
delay(1000);
beat=TL0;
while(TF0==0);
TR0=0;
TF0=0;
BPS=beat;
BPM=BPS*60;
BPM=BPS;
command(0x06);
command(0xc0);
for(f=0;f<4;f++)
{
d=msg1[f];
display(d);
}
HB=0;
if(BPM >=60 && BPM <=100)
{
lcd();
conversion_Ascii(BPM);
display('N');
display('o');
display('r');
display('m');
display('a');
display('l');
HB=0;
}
else if ( BPM <=60)
{
lcd();
conversion_Ascii(BPM);
display('l');
display('o');
display('w');
HB=1;
}
else if (BPM >= 100)
{
lcd();
conversion_Ascii(BPM);
display('H');
display('i');
display('g');
display('h');
HB=1;
}
while(1);
}
void lcd ()
{
command(0x06);
command(0xc6);
}
void command (unsigned char a)
{
ready();
RS=0;
RW=0;
P0=a;
EN=1;
_nop_();
_nop_();
EN=0;
}
void ready()
{
RS=0;
RW=1;
BUSY=1;
EN=0;
_nop_();
_nop_();
EN=1;
while(BUSY==1);
}
void display(unsigned char string)
{
ready();
RS=1;
RW=0;
P0=string;
EN=1;
_nop_();
_nop_();
EN=0;
}
void conversion_Ascii( unsigned char out)
{
V=out/10;
B1=out%10;
B2=V%10;
B3=V/10;
B3=B3+0x30;
B2=B2+0x30;
B1=B1+0x30;
display(B3);
display(B2);
display(B1);
}
void conversion(unsigned char m)
{
q=m/10;
q1=m%10;
q2=q%10;
q3=q/10;
q3=q3+0x30;
q2=q2+0x30;
q1=q1+0x30;
display(q3);
display(q2);
display(q1);
display('•');
display('c');
}
void delay(unsigned char itime)
{
for(i=0;i<itime;i++)
for(j=0;j<123;j++);
}