What is Embedded System Programming & Its Languages

Introduction

A system is a collection of interconnected units that work together to perform specific tasks. An embedded system is a combination of hardware and software designed to perform a dedicated function within a specified time frame. For example, a washing machine is an embedded system that performs a specific task automatically.

The main advantage of using an embedded system is that it reduces the size and cost of the device while improving reliability and efficiency. This article explains embedded system programming, its components, programming languages, and applications.

Components of Embedded Systems

The main components of an embedded system are:

Embedded Software

Embedded software, also known as embedded system programming, is computer software used to control devices by providing a set of instructions. It is also referred to as firmware. Embedded software allows devices to perform specific functions while meeting design constraints such as response time, strict deadlines, and limited memory. The final program is stored in memory such as RAM or ROM. Embedded software is used in various electronic devices such as:

These systems often run on small microcontrollers, sometimes with only a few kilobytes of memory.

Embedded System Programming Languages

Embedded software typically runs on a real-time operating system (RTOS) that performs multiple tasks simultaneously. The choice of programming language depends on several factors. Common embedded programming languages include:

Embedded operating systems include:

Factors for Selecting an Embedded Language

Assembly Language Programming

In embedded systems, assembly language is sometimes used for programming. The assembly code is converted into machine code using an assembler.

Example: Addition of Two Numbers

Input (Assembly Code)

HERE: MOV R0, #01H
MOV R1, #02H
MOV A, R0
ADD A, R1
MOV P0, A
SJMP HERE

Output (Machine Code)

Address   Opcode   Operand
0000      78       01
0002      79       02
0004      E8       --
0005      29       --
0006      F5       80
0008      80       00

Assembly language produces small and fast code, but it is difficult to use for large programs and lacks portability. Therefore, high-level languages such as Embedded C are more commonly used.

Programming Languages Used in Embedded Systems

C Programming

The C language was developed by Dennis Ritchie. It is a structured programming language that provides efficient memory usage and direct access to hardware. It is widely used in embedded systems as well as large computing systems.

Embedded C

Embedded C is an extension of the C language designed specifically for embedded systems. Its syntax is similar to standard C, but it includes features for hardware interaction, fixed-point operations, and memory-mapped I/O.

Advantages of C in Embedded Systems:

C++

C++ is an object-oriented programming language used in advanced embedded applications. However, some features like virtual functions and exception handling may increase memory usage and reduce speed.

Java

Embedded systems can be programmed in Java using the Java Virtual Machine (JVM). It is mainly used in high-end embedded applications such as smartphones. However, it is not suitable for small embedded devices due to higher resource requirements.

Embedded C Programming Example

#include <reg51.h>

void delay(int);

void main(void)
{
    P1 = 0x00;

    while(1)
    {
        P1 = 0xFF;
        delay(1000);
        P1 = 0x00;
        delay(1000);
    }
}

void delay(int d)
{
    unsigned int i;

    for (; d > 0; d--)
    {
        for (i = 250; i > 0; i--);
        for (i = 248; i > 0; i--);
    }
}

Advantages of Embedded Software

Disadvantages of Embedded Software

Applications of Embedded Systems