8051 Software Development using SDCC

Pinterest icon

8051 programming using small device c compiler tutorial

Small Device C Compiler (SDCC) is a free opensource (GPL) C compiler for 8051 based microcontrollers .It consists of linker, assembler, simulator and debugger for developing software for the 8051 architecture.

SDCC is completely free and there is no restriction on code size.

In this Tutorial ,we will learn how to configure,compile and generate hex file using Small Device C compiler (SDCC) for the 8051 architecture.

Downloading Small Device C compiler (SDCC)

Small Device C compiler can be easily downloaded from its Sourceforge page ,No registeration is required compared to Keil.

The compiler is crossplatform and is available for Windows,Linux and Mac OSX platforms.Here we will be mainly dealing with the Windows Platform .

You can download the SDCC installer for Windows Platform from here.

Compiling C file using SDCC for 8051 architecture

After installing SDCC ,you can type on the windows prompt sdcc -v to check its version.

checking sdcc is properly installed on windows

Now create a folder called LedBlink to store your C files.

Now copy the below C code and save it in the LedBlink folder as LedBlink.c

8051 Code (LedBlink.c)

#include <8052.h>
 
void delay(void);
 
void main(void)
{
    while(1)
    {
         P1 = 0xFF// Turn ON all LED's connected to Port1
         delay();
         P1 = 0x00// Turn OFF all LED's connected to Port1
         delay();
    }
}
 
void delay(void)
{
    int i,j;
    for(i=0;i<0xff;i++)
         for(j=0;j<0xff;j++);
}

Open cmd.exe and navigate to LedBlink Folder. Type the following command to compile the C file.

sdcc LedBlink.c

If there are no errors ,the code will compile and generate several files as shown in the below image.

compiling c file for 8051 architecture using small device c compiler (SDCC)

Here the LedBlink.ihx is the hex file created by SDCC .

Converting ihx format to Hex Format

Now most of the hex file downloaders will not recognize the .ihx format.To convert the ihx format to hex format you have to use another program called packihx which will repackage ihx to hex format.

Now  type the following commands to create the hex file .

packihx LedBlink.ihx > LedBlink.hex

After running this command you can see the new hex file (LedBlink.hex) inside your folder .Which you can then download into your 8051 microcontroller.

converting ihx format to hex format using sdcc

Downloading Hex file to 8051 

After you have generated your hex code using SDCC ,You can upload the code into your 8051 derivative.Uploading hex code is specific to the 8051 derivative you are using.