What is Embedded C ?

Embedded C is an Extension of general purpose C language that provides flexibility to write programs for Target Machines. It also allows to write controller specific code which will perform some dedicated control operations.
Embedded C is widely used while writing software's for Embedded Systems. Embedded C uses most of the syntax and semantics of standard C, e.g., main() function, variable definition, datatype declaration, conditional statements (if, switch, case), loops (while, for), functions, arrays and strings, structures and union, bit operations, macros, etc.

To write Processor specific code or to write software for Embedded system we use Assembly Language (Machine language) conventionally, it has few disadvantages which are listed below:-

*  To write processor specific code in Assembly Language one must have the complete knowledge of     each and every instructions supported by the processor or controller.
*  Machine language commands are few and primitive, making programs hard to write.
*  It is very difficult to write code for big Projects
*  Assembly language are hard to maintain and debug
*  Coding is a Tedious Job. 
*  Machine language has no mathematical functions available (we need to create our own code for         these routines every time we write a new program).
*  It is very difficult to write modular code in Assembly language.

In order to make programming easier, computer scientists developed more "human readable like" languages to communicate with the machines. Keep in mind, however, that machine language is still what the computer uses. The other languages that we learn about must be translated (interpreted or compiled) into machine language for computer use.
Embedded C is support programming in Scripting format that provides flexibility to programmers to write human understandable code, that will further interpreted and converted to Machine understandable code by the compiler.

Example: Benefits of Embedded C over Assembly Lanuage

* Simple program for toggling of LED connected to a Port Pin

Assembly Code

org 0000h
START: CPL P1.0
       ACALL WAIT  
       SJMP START

WAIT:  MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
        DJNZ R3,WAIT2
        DJNZ R4,WAIT1
        RET

Embedded C Code

#include<AT89x51.h> // header for AT89c51 microcontroller
#define LED_PIN P2_0 // LED is connected to P2.0 pin
void main(void)
{
   LED_PIN=0; // configuring port pin as Output
while(1)
{
LED_PIN= ~ LED_PIN;
   }
}

From the above Example, it is clear that while writing code in assembly we need to have the information about thee device hardware such as internal Registers as well as instructions set. 
But, while writing code in Embedded C, one need not to worry about the Internal architecture and its registers as well as the instructions set. The programmer need to have a good command over C language only.

No comments: