8051 Microcontroller User's Manual


1) Download and setup SDCC  (C and Assembly compiler)

 

 

Step 1: Download  SDCC (Freeware C and Assembly complier)

Step 2: Unzip the downloaded SDCC  to your favorite directory then move extracted SDCC folder to C:\

 

This is recommended, because it's convenient to locate and set the path when SDCC is at the root directory. If you did that, your SDCC directory should look like below in MS-DOS.

 


2) How to compile a code using SDCC compiler

 

Your source code can be turned into a ".hex" file by using an Assembly or C Compiler depending on your favorite of programming language. A freeware C and Assembly compiler can be downloaded from Sourceforge (more about SDCC). You can use other compilers, such as the Keil uVision2 and etc... 

SDCC is a command line application, which is usually run in "MS-DOS Prompt" window. To run these, you should follow the steps below.

 

Step 1: Set path for SDCC:

You need to type this command: "Path=C:/ SDCC/BIN"  in "MS-DOS Prompt" window. This is needed because SDCC has to know where its libraries and share files are located.

 

Step 2: A) To compile your C code by SDCC compiler:

In "MS-DOS Prompt" window, navigate to your C code directory then type: SDCC "yourcode.c"

 

Example: C:/SDCC led.C

After that command, a "led.ihx" file is created, but FLIP programming tool uses ".hex" file for its input, so you need to convert the "led.ihx" file to "led.hex" by the following command:

C:/packihx led.ihx > led.hex.

Now you have an "led.hex" file ready for programming.

 

Example: To compile and build a target file "led.hex" from "led.C" code, all you need to do is shown in the figure below. In this example, the "led.C" file is in "LED" directory.

  

You also can do this easily by making a batch file as following. When you execute the batch file, it will do all steps for you.

Step 2: B) To compile your Assembly code by SDCC compiler:

In "MS-DOS Prompt" window, navigate to your Assembly code directory then use the following commands: (or make a batch file)

 

- ASX8051  -losg  "yourcode.ASM"  ( This command will generate a "yourcode.rel" file)

- SDCC  "yourcode.rel" (Compile the generated ".rel" file)

- PACKIHX  "yourcode.ihx" > "yourcode.hex"   (This will make an Intel format  ".hex" file)

 

Now you have an "led.hex" file ready for programming.

 

Example: To compile and build a target file "test.hex" from "test.ASM" code, all you need to do is shown in the figure below. In this example, the "test.ASM" file is in "LED" directory.