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.

Difference between C & Embedded C

Status
Not open for further replies.
if we use volatile modifier, this disables optimisation, forcing the program to fetch a new value from the variable every time variable is accessed.
every time variable is accessed? even we do not call this function?
void update(void)
{
time =time+1;
}
 
volatile is suitable for functions like ISR because these ISR are never called but the interrupt is generated. So when ever you enter the ISR routine the value will be updated automatically and will not be visible to other functions.
 
volatile is suitable for functions like ISR because these ISR are never called but the interrupt is generated. So when ever you enter the ISR routine the value will be updated automatically and will not be visible to other functions.

ahhhh okay.. I think I understand now.. Pls see the example below. I haven't put any incrementing instruction just to emphasize our discussion.. let see if I understand it correctly.. thanks
example:

PHP:
volatine variable;
void interrupt sample()
{
   if(variable==5)
    variable = 0;

}
 
I wish to know more things as
Volatile is used for variables whose value keeps changing frequently without the control of the program flow... in your case i dont see the variable value getting changed ..

you are just taking a variable and comparing it with 5. but somewhere the variable has to change to meet the condition
if (variable == 5)
where is this incremented and does it increment in the program or it is incremented only when ISR routine executes...
when would variable be equal to 5 in your case....
remember volatile should be global variable...
 
I wish to know more things as
Volatile is used for variables whose value keeps changing frequently without the control of the program flow... in your case i dont see the variable value getting changed ..

you are just taking a variable and comparing it with 5. but somewhere the variable has to change to meet the condition
if (variable == 5)
where is this incremented and does it increment in the program or it is incremented only when ISR routine executes...
when would variable be equal to 5 in your case....
remember volatile should be global variable...

let say for example that interrupt is a timer interrupt and we do something like this.

does it changed the value?

PHP:
volatine variable;
void interrupt sample()
{
   variable = variable; //Im thinking by calling just like this will increment the value
   if(variable==5)
    variable = 0;

}
 

It will not increment the value in that case, volatile variables do not change by itself as i said.. like there should be some statement that should change the value, or there should be some hadrware like ports or some hardware to change the value... volatile will just store the last updated value and would give the user only the last updated value.

With in ISR you may have to increment the value or the value has to be changed due to some parameters....

hope i answer.. if not, I would elaborate this reply...
 
When we use the word Optimise, we mean that the variable in the memory can be changed only by the compiler whenever the code is executed.

okay seems clear now..

Volatile modifiers cannot be optimised by the compiler, During linking process the code is allocated physical memory in the internal memory. so during the link process( generation of .lnk file during compilation) these variables are placed in the heap instead of main memory. Compiler cannot modify the variable until unless a copy is copied to RAM for execution. So the compiler allocates a different memory location for the variable. These are called un-optimised location. the variables in this location are not dependent on the compiler to change the value. instead interrupt, ports, serial, hardware are given permission to access these variables when ever they raise a request.

the variables in this location are not dependent on the compiler to change the value. instead interrupt, ports, serial, hardware are given permission to access these variables when ever they raise a request

confusing in my part.
can you Please give simple code snippet to summarize the theory we are discussing.?



It will not increment the value in that case, volatile variables do not change by itself as i said.. like there should be some statement that should change the value, or there should be some hadrware like ports or some hardware to change the value... volatile will just store the last updated value and would give the user only the last updated value.

okay Im confused now what's important of declaring volatile variable if we can still do it in ordinary variable.. I still dont see the advantage of volatile in a particular application that the ordinary variable cannot handle..
 
optimise means compiler controlled variable and changes the variable only when the code gets executed by function call or in other words the code knows that who is going to modify the variable as it knows which function will access the variable and which function updates..

but in case of volatile ports and interrupts changes the value without the control of software.and software does not know who updated the variable as it is done by ISR function.. the information of the ISR function is always hidden to other function which are called and controlled other functions...

So volatile is just a variable who work is to store the content of the data of the last modification.

take eg of rtc. (real time clock)... Power failure is an interrupt, but even then the time gets incremented. and when power is restored it gives only last updated value and not the history of changes done during the power failure time...

So handling the variable depends on the user, on what application he is using or how he wants this volatile to be used....

its compiler independent...
 
The use of a 'volatile' variable will stop the compiler from optimization of access to that variable but also any code restructure changes will also be stopped for the entire statement or subroutine. The code restructure optimizations will usually also be stopped by use of inline assembly instructions and some types of some pointer operations within that routine.

it prevents any optimization that might re-order the evaluation of volatile variables relative to other volatile variables.

Microsoft example: volatile (C++)
 

So volatile is just a variable who work is to store the content of the data of the last modification.

take eg of rtc. (real time clock)... Power failure is an interrupt, but even then the time gets incremented. and when power is restored it gives only last updated value and not the history of changes done during the power failure time...

got it! thanks so much sentences above gave me an idea what is a volatile vatiable mean.. thanks so much
 

C is a widely used general purpose high level programming language mainly intended for system programming.

Embedded C is an extension to C programming language that provides support for developing efficient programs for embedded devices.It is not a part of the C language

You can also refer for more differance

**broken link removed**
 
Can i compile Embedded C programs in normal C compilers.

What do you consider a normal C compiler?

And what is the target embedded device, x86, PIC, ARM, AVR, 8051, etc?

It dependents on the capabilities of your compiler, whether you need to cross compile for a target which is a different device than the host.

BigDog
 
TURBO C++ we used it in school for studying C++.
If we are writing a program for an AVR can i compile it in PC (x86). How are the ports mentioned?

Which compiler software do you recommend.
 
Last edited:

Can i compile Embedded C programs in normal C compilers.

I guess, you meant a regular ANSI-C compiler used for application programs, and without any proprietary extensions.
Such a compiler would compile Embedded-C programs for as long as it is a proper subset of ANSI-C, and doesn't use any unusual or invalid pragmas.
Also it should find the header files required, but then your Embedded-C program may bring with itself several target-specific, non-standard header files, which your ANSI-C compiler might not find. Finally, modern C compilers invoke the linker automatically and any target specific libraries that are shipped with Embedded-C toolchain, might not be found by ANSI-C linker.
 
I guess, you meant a regular ANSI-C compiler used for application programs, and without any proprietary extensions.
Such a compiler would compile Embedded-C programs for as long as it is a proper subset of ANSI-C, and doesn't use any unusual or invalid pragmas.
Also it should find the header files required, but then your Embedded-C program may bring with itself several target-specific, non-standard header files, which your ANSI-C compiler might not find. Finally, modern C compilers invoke the linker automatically and any target specific libraries that are shipped with Embedded-C toolchain, might not be found by ANSI-C linker.

That was what i really meant.
 

TURBO C++ we used it in school for studying C++.
If we are writing a program for AVR can i compile it in PC (x86). How are the ports mentioned?

Which compiler software do you recommend.

You could use TURBO C++ to develop embedded code for x86 targets, like uC/OS-II an RTOS which has been ported to x86.

However, developing code for the AVR on a PC requires a cross compiler. There are several available, some are Open Source and free, others are commercial and vary in price.



Probably the most common AVR Open Source Cross Compiler is some variant of the AVR-GCC:

WINAVR

Atmel AVR Studio 4

Atmel AVR Studio 5

The majority of the differences between the various AVR-GCC distros are not with the compiler, but the Integrated Development Environment (IDE) which may or may not be Open Source and the code libraries.


Some examples of commercial/fee based AVR compilers:

MikroC Pro for AVR



Many of the commercial compilers have a trial version which can be freely downloaded.


I recommend trying out several AVR compilers and selecting the one you feel most comfortable.


BigDog
 
Recently came to use the CCS C Compiler (for PIC). It has very good help file. No need to remember any instructions. It provide a help file where we can search and it will explain the instruction with example.
Is there any compiler like this for C/C++.
 

WriteDataXLCD(data); //write to LCD

Why used keyword "Write"? Does it means PICC18 C compiler does not support "Input"?
 

The name of a C routine/function is arbitrary and at the discretion of the coder and the "rules" of the relevant C compiler and C standards.

The routine, WriteDataXLCD(), is not consider a keyword unless it is spelled exactly as a keyword, no more, no less.

BigDog
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top