// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_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;
char uart_rd;
char uart_rd1[15];
void call();
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
ADCON0=0X81; // Pins AN1 is configured as analog
TRISA = 0xFF; // All port A pins are configured as inputs
ADCON1=0X00;
//TRISC = 0; // All port C pins are configured as outputs
TRISD = 0; // All port D pins are configured as outputs
//PORTC = 0x00; // Reset port C
PORTD = 0x00; // Reset port D
UART1_Init(9600);
delay_ms(100);
//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
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "WELCOME...... "; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,text); // Write the first message in the first line
text ="HEART BEAT METER";
Lcd_Out(2,1,text);
delay_ms(100);
delay_ms(100);
delay_ms(100);
delay_ms(100);
delay_ms(100);
while(1)
{
inputsignal = ADC_Read(1);
if (inputsignal>=64)
{
delay_ms(50);
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.");
//Lcd_Cmd(_LCD_CLEAR);
//rest vlaue of counter
//and start next test
cnt = 0 ;
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
}
}
}
/*
Project: Measuring heart rate through fingertip
Copyright @ Rajendra Bhatt
January 18, 2011
PIC16F628A at 4.0 MHz external clock, MCLR enabled
*/
sbit IR_Tx at RA3_bit;
sbit DD0_Set at RA2_bit;
sbit DD1_Set at RA1_bit;
sbit DD2_Set at RA0_bit;
sbit start at RB7_bit;
unsigned short j, DD0, DD1, DD2, DD3;
unsigned short pulserate, pulsecount;
unsigned int i;
//-------------- Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0xC0;
case 1 : return 0xF9;
case 2 : return 0xA4;
case 3 : return 0xB0;
case 4 : return 0x99;
case 5 : return 0x92;
case 6 : return 0x82;
case 7 : return 0xF8;
case 8 : return 0x80;
case 9 : return 0x90;
} //case end
}
void delay_debounce(){
Delay_ms(300);
}
void delay_refresh(){
Delay_ms(5);
}
void countpulse(){
IR_Tx = 1;
delay_debounce();
delay_debounce();
TMR0=0;
Delay_ms(15000); // Delay 1 Sec
IR_Tx = 0;
pulsecount = TMR0;
pulserate = pulsecount*4;
}
void display(){
DD0 = pulserate%10;
DD0 = mask(DD0);
DD1 = (pulserate/10)%10;
DD1 = mask(DD1);
DD2 = pulserate/100;
DD2 = mask(DD2);
for (i = 0; i<=180*j; i++) {
DD0_Set = 0;
DD1_Set = 1;
DD2_Set = 1;
PORTB = DD0;
delay_refresh();
DD0_Set = 1;
DD1_Set = 0;
DD2_Set = 1;
PORTB = DD1;
delay_refresh();
DD0_Set = 1;
DD1_Set = 1;
DD2_Set = 0;
PORTB = DD2;
delay_refresh();
}
DD2_Set = 1;
}
void main() {
CMCON = 0x07; // Disable Comparators
TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P only
TRISB = 0b10000000; // RB7 input, rest output
OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 for counter mode
pulserate = 0;
j = 1;
display();
do {
if(!start){
delay_debounce();
countpulse();
j= 3;
display();
}
} while(1); // Infinite loop
}
Thank you, may I use directly a laser as light source ?
And, LDR as signal receiver, lm358 to get square wave ?
and how should I count the pulses can you explain a little bit detail (Should I record the pulses in one minute )?
Dear tpetar , my teacher gave this project (heart beat measuring) with laser instead of led. The all circuit is still valid ??
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?