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 Start Push Switch 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 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;

  

}
 

The code below works on AVR (personally I tend to avoid PICs). However it would work on PIC too presumably, if you change the
code below register name from PINB to PORTB, and change the BUTTON definition to 0x10 to correspond to your RB4.

Code:
#define BUTTON 0x02

#define SWITCH_ON (PINB & BUTTON) == 0
#define SWITCH_OFF (PINB & BUTTON) != 0


// in your main function:
while (SWITCH_OFF) 
{
	// wait for the switch to be pressed
}

// ok switch was pressed if we got this far
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top