oiyela
Junior Member level 3
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 and body temperature. the program displays the heart rate and the body temperature. my main issue is that the start button is not working, basically when i run the program it just goes straight to 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 . i.e when the push switch is not pressed it is at 4.86V and when pressed it goes to 0.4V. Thanks!
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;
}