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.

HI-Tech Programming Help

Status
Not open for further replies.

oiyela

Junior Member level 3
Joined
Mar 7, 2012
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,554
Hi, I am using a PIC16f877a microcontroller and using MPLAB ICD3 on hi-tech complier. the aim of my project is to find the heart rate. i have done the software to count the number of pulses coming in. the main problem i have now is i want to count the number of pulse for 15 seconds and then multiple it by 4 and display it. i have been struggling to do that. here is my code so far, what this code does is to display the counter on the LCD. what i need is to take this reading for 15 seconds and multiply it and display.

Code:
#include <htc.h>
#include "lcd.h"
#define _XTAL_FREQ 	8000000

void pic_init(void);

main()
{
int heartrate[3];
int pulse;
pic_init();						//initialize PIC
lcd_init();						//initialize LCD
lcd_goto(0);						//select first line
for(;;){
	heartrate[0]=(int)(1* TMR0);	//
		
    lcd_goto(0);					//select first line
	lcd_string("BT = ");            //  
	lcd_number(heartrate[0]/10,10,3); // 
	lcd_string("."); 
	lcd_number(heartrate[0]%10,10,1); // 
	lcd_string("BPM");                   // 

}}

void pic_init(void)
{
TMR0=0;
PORTD=0x00;
PORTA=0xFF;
CMCON = 0x07;
OPTION_REG = 0b00101000;

  

}
Another issue i have is that the count is starting from 0.1 instead of 1

Please If You Can Help Me With This.. This Will be Greatly Appreciated.
 

:shock:
where is your code for counting pulses ..
where is 15 seconds ..
where is multiplication ..

why do you have the the DIV 10 and MOD 10 logic for displaying ..
thats how your count starts from 0.1

schematics of your hardware shall be helpful to verify code
 

TMR0 counting can't reach 15 seconds. You need to add variable ex counter.
For better, use TMR0 interrupt for increment counter.
 

here is my updated code. this one counts the heart rate and displays it. my main issue is that the start button is not working, basically when i run the program it just goes straight to displaying processing and then shows the heart rate and body temperature. what i want is that when the program starts running i want it to display press start and then wait for the user to press the start button then it displays the heart rate and body temperature. please would appreciate if you can look at my code and see if i put the IF statement wrongly for the start button

Code:
void pic_init(void);
void count(void);
int pulserate;
int tempread;
int temperature[3];
int heartrate[1];
#define	start PORTB,RB4


main()
{
pic_init();						//initialize PIC
lcd_init();	
lcd_goto(0);					//select first line
lcd_string("Press Start");
do{
if(!start){
count();					   //count starts
lcd_goto(0);						//select first line
for(;;){
	heartrate[0]=(int)(6* pulserate);	//10mV per Celsius
    temperature[0]=(int)(2.3100* tempread);
		
    lcd_goto(0);					//select first line
	lcd_string("HR = ");            // Heart Rate 
	lcd_number(heartrate[0],10,3); // Displays Heart Rate Reading 
	//lcd_string("."); 
	//lcd_number(heartrate[0]%10,10,1); // Displays Heart Rate Reading
	lcd_string("BPM");                   // Beats Per Minute
    
    lcd_goto(0x40);					//select Second line
	lcd_string("BT = ");            // Body Temperature 
	lcd_number(temperature[0]/10,10,3); // Displays Temperature Reading 
	lcd_string("."); 
	lcd_number(temperature[0]%10,10,1); // Displays Temperature Reading
	lcd_string("C");                   // Degree Celcius
}
}
}while(1);
}

void count(void)
{

TMR0=0;
pulserate=0;
lcd_goto(0);					//select first line
lcd_string("Processing..");
__delay_ms(20000);
pulserate = TMR0;
tempread = read_a2d(1);
}


void pic_init(void)
{

PORTD=0x00;
PORTA=0xFF;
CMCON = 0x07;
OPTION_REG = 0b00101000;
ADCON0=0b01001001 ;
ADCON1=0x81;

  

}
 

why do you give PSA to WDT (in your code you set the T0CS to the external clock cycle but you gave the PSA to WDT) , any reasons?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top