Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

heart beat monitor based on pic16f877a

Status
Not open for further replies.

bouz00100

Newbie level 5
Newbie level 5
Joined
Oct 8, 2010
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,369
hi all ,
i face a problem while working with this project, i need a c code that can program pic to do these things;
1) count number of beats in the heart signal
2)display the result on lcd
3)how to connect lcd(16*2) with pic16f877a
plz help me ,because its very urgent
thank all
 

Where in the do you got stuck up with? The questions you have us to do are readily available in the net.Googling is enough for it. The first question which you have posted have an algorithm i.e the time period between the 2 beats is converted to BPM by a formula which i don't exactly remember. You can locate that too in the net.
Regards,
Jerin.
 
first of all thank u,
but my question about c code needed to program pic to do these things,because i don't have any idea how to deal with it.
Regards,
bouz.

---------- Post added at 21:50 ---------- Previous post was at 21:47 ----------

thank u pcup
 

first of all thank u,
but my question about c code needed to program pic to do these things,because i don't have any idea how to deal with it.
Regards,
bouz.


Refer : C Programming for Embedded Systems By Kirk Zurell
Microcontroller Programming The Microchip PIC By Julio Sanchez & Maria P. Canton
PIC Microcontroller Project Book By John Iovine
Above books are reference's for PIC beginner. Your application specific code and examples are available in Embedded Health Informatics Journals and eBooks do google

Best of Gluck
 

but my question about c code needed to program pic to do these things,because i don't have any idea how to deal with it.
Are you talking about the coding of the project or you don't know coding in C?
Regards,
Jerin.
 

Are you talking about the coding of the project or you don't know coding in C?
Regards,
Jerin.

hi,
i'm talking about code needed to programming pic , and this code written by c lang.
Regards,
booz
 

Do you have the flow chart of the project with you or have you prepared it?
Regards,
Jerin.
 

Attachments

  • photo 2.jpg
    photo 2.jpg
    154.6 KB · Views: 197
Last edited:

Fine..... Did you started writing the code with this flowchart?
Regards,
Jerin. ;-)
 

MikroC..... Thats nice.... Watz the status till now?
Just post the code & let me see the code. Just provide comments too as much you can along the code.
Regards,
Jerin. ;-)
 

MikroC..... Thats nice.... Watz the status till now?
Just post the code & let me see the code. Just provide comments too as much you can along the code.
Regards,
Jerin. ;-)

hi, this is my code
if you have any comments , tell me plz

/*Header******************************************************/
unsigned int inputsignal;
unsigned int firstRun = 1;
unsigned int cnt; // Define variable cnt == 1KHz clk
unsigned int HR;

void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 194; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}

void main() {
OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0x0C; // Pins AN2 and AN3 are configured as analog
TRISA = 0xFF; // All port A pins are configured as inputs
ANSELH = 0;
TRISC = 0; // All port C pins are configured as outputs
TRISD = 0; // All port D pins are configured as outputs
TRISB = 0;
PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
PORTB = 0x0;
ADCON1.F4 = 1 ; // Voltage reference is brought to the RA3 pin.
while (1){
inputsignal = ADC_Read(2); // Result of A/D conversion is copied to inputsignal
portd = inputsignal;
if (inputsignal>=64) { //64 is peak value of heart signal//
delay_ms(1000) ;//this dealy to make sure that signal goes down//
if (firstRun=1){//detect first pulse
firstRun = 0;
cnt = 0; // Variable cnt is assigned a 0
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
} else {//enter else if second pulse detected
//number of interrupt is time between two pulses in ms which is stored in cnt
HR=60000/cnt;

//send this value to lcd
// lcd code...................
//...................//
// i don't have lcd ,so to c the output i do this//
Portc = cnt;
Portb = HR;
//then start test again -reset timer and wait pulse from ad
cnt = 0 ;
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
}
}
}
i didn't c any output on port (b&c)
but ad is running
so i don't know the problem ?

regards;
booz ;)
 

Do one thing buddy. I see that you have written a step:
OPTION_REG = 0x84; // Prescalar is assigned to timer TMR0
Actually you should enable the internal pull up resisters on PORT B to get output @ PORT B which would be done by clearing the MSB of the OPTION_REG. So the value for OPTION_REG will be 0x04.
Then,
ANSEL = 0x0C; // Pins AN2 and AN3 are configured as analog
to set the PORT A pins as analog8/digital pins, there is a register called ADCON1 & ADCON0 is used for which channel to select for ADC to work. Also change ANSELH to ADRESH.
Refer the data sheet for 16F87XA for more details & simulate once again the code & see whether it is working or not.
Regards,
Jerin. ;-)
 

Do one thing buddy. I see that you have written a step:

Actually you should enable the internal pull up resisters on PORT B to get output @ PORT B which would be done by clearing the MSB of the OPTION_REG. So the value for OPTION_REG will be 0x04.
Then,

to set the PORT A pins as analog8/digital pins, there is a register called ADCON1 & ADCON0 is used for which channel to select for ADC to work. Also change ANSELH to ADRESH.
Refer the data sheet for 16F87XA for more details & simulate once again the code & see whether it is working or not.
Regards,
Jerin. ;-)

hi, there is no problem with A/D
i have connect lcd with circuit , but i think there is problem in calculation of heart rate , c the code plz and till me if u found any thing important



/*Header******************************************************/

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned inputsignal=0;
unsigned int firstRun = 1;
unsigned int cnt=0; // Define variable cnt == 1KHz clk
long HR=0;
char *text;
unsigned char outlcd;

void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 194; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}

void main() {
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0x02; // Pins AN1 is configured as analog
TRISA = 0xFF; // All port A pins are configured as inputs
ANSELH = 0;
TRISC = 0; // All port C pins are configured as outputs
TRISD = 0; // All port D pins are configured as outputs
PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
ADCON1.F4 = 0 ; // VSS voltage reference
ADCON1.F7 = 1 ; //A/D Conversion Result Format Select bit adfm=1
ADCON0 = 0x07; // A/D is enabled and AN1 is analog input

text = "instantaneous"; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,text); // Write the first message in the first line
text ="heart rate test";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="1)connect";
Lcd_Out(1,1,text);
text="electrodes";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="2)relax please";
Lcd_Out(1,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);


while (1){
inputsignal = ADC_Read(1); // Result of A/D conversion is copied to inputsignal
portd = ADRESL;
portc = ADRESH;
if (inputsignal>=600) {
delay_ms(500);
if (firstRun==1)
{
firstRun = 0;
cnt = 0; // Variable cnt is assigned a 0
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
else {
//find heart rate
Lcd_Cmd(_LCD_CLEAR);
text="Heart rate=";
Lcd_Out(1,1,text);
//number of interrupt is time between two pulses in ms
HR=60000/cnt;
outlcd=HR/100 ; //hundreds digit in HR
Lcd_Chr(1,12,48+outlcd); // Write result in ASCII format
outlcd=(HR/100)%10;//tens digit in HR
Lcd_Chr_CP(48+outlcd);
outlcd=(HR)%10 ;//ones digit in HR
Lcd_Chr_CP(48+outlcd);
Lcd_out(2,5,"puls/min.");

//rest vlaue of counter
//and start next test
cnt = 0 ;
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
}
}
}
 
hi, there is no problem with A/D
i have connect lcd with circuit , but i think there is problem in calculation of heart rate , c the code plz and till me if u found any thing important



/*Header******************************************************/

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned inputsignal=0;
unsigned int firstRun = 1;
unsigned int cnt=0; // Define variable cnt == 1KHz clk
long HR=0;
char *text;
unsigned char outlcd;

void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 194; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}

void main() {
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0x02; // Pins AN1 is configured as analog
TRISA = 0xFF; // All port A pins are configured as inputs
ANSELH = 0;
TRISC = 0; // All port C pins are configured as outputs
TRISD = 0; // All port D pins are configured as outputs
PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
ADCON1.F4 = 0 ; // VSS voltage reference
ADCON1.F7 = 1 ; //A/D Conversion Result Format Select bit adfm=1
ADCON0 = 0x07; // A/D is enabled and AN1 is analog input

text = "instantaneous"; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,text); // Write the first message in the first line
text ="heart rate test";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="1)connect";
Lcd_Out(1,1,text);
text="electrodes";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="2)relax please";
Lcd_Out(1,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);


while (1){
inputsignal = ADC_Read(1); // Result of A/D conversion is copied to inputsignal
portd = ADRESL;
portc = ADRESH;
if (inputsignal>=600) {
delay_ms(500);
if (firstRun==1)
{
firstRun = 0;
cnt = 0; // Variable cnt is assigned a 0
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
else {
//find heart rate
Lcd_Cmd(_LCD_CLEAR);
text="Heart rate=";
Lcd_Out(1,1,text);
//number of interrupt is time between two pulses in ms
HR=60000/cnt;
outlcd=HR/100 ; //hundreds digit in HR
Lcd_Chr(1,12,48+outlcd); // Write result in ASCII format
outlcd=(HR/100)%10;//tens digit in HR
Lcd_Chr_CP(48+outlcd);
outlcd=(HR)%10 ;//ones digit in HR
Lcd_Chr_CP(48+outlcd);
Lcd_out(2,5,"puls/min.");

//rest vlaue of counter
//and start next test
cnt = 0 ;
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
}
}
}

Some corrections in the code:
PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
Always do write:
PORTC = 0 or 0x00; // Reset port C
PORTD = 0 or 0x00; // Reset port D

ADCON1.F4 = 0 ; // VSS voltage reference
ADCON1.F7 = 1 ; //A/D Conversion Result Format Select bit adfm=1
Don't assign the bits of a register like ADCON1. It is always desirable to give away a value to the register like, ADCON1 = 0x10;
Can you please post me the logic of writing the code posted here?
Regards,
Jerin. :)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top