Introduction: 8051 Programming Using Small Device C Compiler (SDCC)

Picture of 8051 Programming Using Small Device C Compiler (SDCC)

A short instructable on how to configure Small Device C Compiler (SDCC) for developing software for 8051 derivatives like

  • AT89S51
  • P89V51RD2
  • W78E052DDG

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 unlike other software's like Keil uVision .

You can find the original article about 8051 programming using SDCC here

Step 1: 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 SDCC from here.

Step 2: Compiling C File Using SDCC for 8051 Architecture

Picture of Compiling C File Using SDCC for 8051 Architecture

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

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

#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

Step 3:

Picture of

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

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

Step 4: Converting Ihx Format to Hex Format

Picture of 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(Above Image) .

Which you can then download into your 8051 microcontroller.

Step 5: 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.

Do visit our site for original article.

Comments

About This Instructable

354views

3favorites

Bio: We are a website specializing in building cool projects using MSP430 microcontrollers,occasionally we do sell what we make online on our store . You can ... More »
More by xanthium-enterprises:8051 programming using Small Device C Compiler (SDCC)8051 Programming Using Keil UVision IDEBidirectional control of 4 DC motors using ATtiny Microcontroller and L293D
Add instructable to: