Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to design and implement a simple interface ?

Status
Not open for further replies.

jani12

Member
// Some_Filename.c - This file already exists
/* This function fetches two bytes from Non-Volatile Memory(NVM) and returns to the calling library.
signed short GetDeltaMin ( void ) */
{
signed short param;
NVM_Read ( ( unsigned char * ) &param );
return (signed short) param;
}

// New File - Activate_Deactive_I.c

void Enable_Disable ( Boolean State)
{
/* user will pass 1 or 0 to this function. */
/* If State =1, there is no change to GetDeltaMin ( ). It'll still pass two byte value from NVRAM to calling library. */
/* If State = 0, GetDeltaMin ( ) needs to pass 0 to calling library instead of two byte value from
from NVRAM. */
/* Please write this function and modify GetDeltaMin ( ). */
}

// New File - Activate_Deactivate.h

extern void Enable_Disable ( Boolean State); /* This header file must be included in file from where Enable_Disable ( ) will be called. */
/* I don't think Activate_Deactive_I.c needs to include this header file ? */
 
Yes, there is a question. When Enable_Disable( ) is called, I can assign value of state to a global variable. Then, in GetDeltaMin( ), I can use the value of global variable to decide whether to return value from NVM or 0 to the calling library.

I'm asking for a better solution than a global variable.
 
Global variables are fine, why would you need to use anything else... If you are using a variable in more than one function, then a global variable is the way to go... Static variables are local variables that keep their value, but cannot be used in any other function....

If you want to go objective, you could bundle all NVM variables in a single struct and use pointers!
 
>> If you want to go objective, you could bundle all NVM variables in a single struct and use pointers!
Please explain what you mean by objective. Does it apply to 'c' language ? Please provide code for implementing this in objective.
 
Objective!!! Surely you have heard of object programming! You don't have to use high level languages to use objects.

The idea is... Take an object, your NVRam for example, group all its features together and then you can access it as an object... It is still global but organized....
Please provide code for implementing this in objective.
Just google "C style structs"
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top