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.

[SOLVED] [help]function call problem

Status
Not open for further replies.

romel_emperado

Advanced Member level 2
Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,061
guys i need help ... How do i call the function mx_cal(); ?? what is that u8 line parameter? i dont have idea how do i call that from the function i made below which is burned_cal();


// system
#include "project.h"

// driver
#include "display.h"
#include "ports.h"

// logic
#include "romel.h"
#include "clock.h"
#include "date.h"
#include "user.h"

// Global Variable section
struct br mel;
s8 weight2, time;
s8 met2;
float kcal;


// Prototypes section



void display_romel(u8 line, u8 update)
{
if (update == DISPLAY_LINE_UPDATE_FULL)
{
display_chars(LCD_SEG_L2_5_0, (u8 *)" CAL0", SEG_ON);
}
}



void mx_cal(u8 line)
{
u8 select;
s32 weight;
s32 met;

// Clear display
clear_display_all();

// Convert global variables to local variables
//kcalories = mel.calories/1000;
met = mel.met_value/1000;
if (sys.flag.use_metric_units) weight = mel.user_weight;
else weight = ((s32)mel.user_weight * 2205) / 1000; // Convert kg to lb

// Init value index
select = 0;


// Loop values until all are set or user breaks set
while(1)
{
// Idle timeout : exit without saving
if (sys.flag.idle_timeout) break;

// Button STAR (short): save, then exit
if (button.flag.star)
{
// Store local variables in global structure
//mel.calories = kcalories*1000;
//mel.user_sex = sex;
mel.met_value = met*1000;
if (sys.flag.use_metric_units) mel.user_weight = weight;
else mel.user_weight = (weight * 1000) / 2205;

// Set display update flag
display.flag.line1_full_update = 1;

break;
}

switch (select)
{

case 0: // Set user weight
clear_line(LINE2);
if (sys.flag.use_metric_units)
{
display_chars(LCD_SEG_L2_1_0, (u8 *)"KG", SEG_ON);
set_value(&weight, 3, 2, USER_WEIGHT_MIN_KG, USER_WEIGHT_MAX_KG, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);

}
else
{
display_chars(LCD_SEG_L2_1_0, (u8 *)"LB", SEG_ON);
set_value(&weight, 3, 2, USER_WEIGHT_MIN_LB, USER_WEIGHT_MAX_LB, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);
weight2 = weight;
}
select = 1;
break;

case 1: //Set MET
display_chars(LCD_SEG_L2_1_0, (u8 *)"ME", SEG_ON);
set_value(&met, 3, 2, USER_WEIGHT_MIN, USER_METS_MAX, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);
met2 = met;
select = 0;
break;


}
}

// Clear button flags
button.all_flags = 0;
}


//calorie expernditure forMULa

void burned_cal(void)
{
if(sTime.second == 60)
{
time++;
}

kcal = ((met2 * 3.5 * (weight2/2.2)) / 200) * time;
}
 
Last edited:

Hi,

In mx_cal(), I didn't see the parameter 'line' being used at all. So, u can supply any value when call it.

e.g. just call mx_cal(5) will do in your routine.

Regards,
Tom
 
yes that is my problem i didnt see the parameter.. i dont know where that u8 line from..

does it perform if i put any value?? thanks


another question.. as what u can see in my burned_cal function is it possible to get the value of weight2 and met2 from the mx_cal() function above?
 

Hi,

I have a quick look,
Ya, u can put any value when call mx_cal. The value is simply not used in the function.

mx_cal() contain an infinite loop which will exit only when idle timeout and Button STAR. So, it will get stuck inside until any of the two condition is meet. As the weight2 and met2 are global variable, they will be updated by any functions that access them, so it is able to be updated by mx_cal() function. I would advice you to initialize them to NULL first, incase mx_call() has not updated them and get exit after power-on.

Regards,
Tom
 
thanks tom...... :) thanks very much... :D

how about if i'll do declare like this in the separate *.h file


struct br
{

// User settings
u16 user_weight;

u32 calories;
u16 met_value;
u8 mode;
u8 met2;
u8 weight2;
u8 duration;
};
extern struct br mel;

and then use like this in a function.. does mx_cal(); function can still update the variables namely duration and met2??

void burned_cal(void)
{
if(mel.mode == 1)
{
if(sTime.second == 60)
{
mel.duration++;
}
mx_cal(2);
kcal = ((mel.met2 * 3.5 * (mel.weight2/2.2)) / 200) * mel.duration;
}

}
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top