Practical Embedded C || Introduction || Chapter 1


Welcome to Practical Embedded C series. In this series we will learn how embedded C is used in embedded system along with basics of topic (e.g. you will learn basics of pointers as well as how pointers are used in embedded system). ARM cortex M3 (LPC 176X) micro-controller is considered for reference to explain Embedded C topics throughout the series.

1. What is Embedded C ?

You all must be aware of that C language is developed by Dennis Ritchie in early 1970s. Embedded C is an extension of the standard C language.  This extension is to support the features required for embedded software development which are missing from C language and these are :

1. Fixed Point Arithmetic : C language does not support Fixed point arithmetic. Embedded C
supports fixed point arithmetic by adding _Fract and _Accum  keywords and saturating fixed point type Specifier _Sat.  For this <stdfix.h> header file is used.

2. Named Address Spaces : C language supports  generic or linear address space. Embedded C supports Named Address Space.  Address Space nothing but different  memory regions. Micro-controllers have different memory areas and embedded  applications uses them e.g. a memory area for GPIO or  memory area for code and constants.

If an implementation provides intrinsic address spaces with names _X the following are valid declarations:

_X char varible_char;

3  Named Storage Registers : Using Embedded C it is possible to access processor resistors that are not addressable in any of the address space.

Assuming _DP and _CC are the names of intrinsic registers, the following are possible valid declarations:
 register _DP volatile unsigned char direct_page_reg;

4. IO Hardware Addressing : Embedded C supports IO registers, using which we can access IO devices e.g. LDC. 

Embedded C is used for development of micro-controller based programs. Embedded C uses libraries ( header files) to access micro-controllers registers or memory or peripherals. Library files depends on micro-controller and changes micro-controller to micro-controller.

2. Why Embedded C?

Initially to program micro-processors Assembly language was used, but assembly is bit difficult to understand and debugging is also difficult in Assembly language. As processor architecture to architecture Assembly instruction changes to it is difficult to make program portable in assembly language. 

To overcome these difficulties C languages used. C is easy to understand and debugging is easy, also codes can be made portable from platform to platform using C language.

3. Structure of  Embedded C Program :

In this section you will learn what is structure of embedded C program. The structure is same of C program,but while including header files, micro-controller specific files are included. And inside main function micro-controller related resistors are accessed as per features defined in point 1 (described above in this blog).

#include <lpc17xx.h> /*Micro-controller specific header file*/

#define SBIT_RESULT 4u /*Macro Declaration*/

int main()
unsigned char adc_result ; /*local variable declarations*/
LPC_PINCON->PINSEL1|= 0x01<<14; /* Select the P0_23 AD0[0] for ADC function */

   LPC_ADC->ADCR |= 0x01;
Some Code lines
adc_result = (LPC_ADC->ADGDR >> SBIT_RESULT) & 0xfff;
return 0;


Post a Comment

Post a Comment (0)
To Top