Install SDCC on your computer.
Make sure to check the box Add: C:\Program Files(x86)\SDCC\bin to the PATH. You want the SDCC software and includes files to be visible from other directories.
After computer restart
Open a command window. Create a new directory named sdcc. Change to the new directory.
Dir directory listing shows no files in the folder. We can clear the screen with cls<return>.
main.cOpen notepad (not word) and enter this text.
// sdcc example 8051 chip
#include <reg51.h>
void DELAY_ms(unsigned int ms_Count)
{
unsigned int i,j;
for(i=0;i<ms_Count;i++)
{
for(j=0;j<1000;j++);
}
}
int main()
{
while(1)
{
P0 = 0xff; /* Turn ON all the leds connected to Ports */
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
DELAY_ms(100);
P0 = 0x00; /* Turn OFF all the leds connected to Ports */
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
DELAY_ms(100);
}
return (0);
}
This simple c program tells an 8051 microcontroller to turn on all 4 of its ports, wait, turn off all 4 ports. Each port is 8 pins that can be used as inputs or outputs.
Save the notepad document as main.c in the sdcc folder we created earlier.
Return to the command prompt. A directory listing shows main.c has been added to the folder. Enter where sdcc.exe and we see that sdcc was added to the PATH during installation. We can run the compiler from anywhere in the computer.
Type sdcc.exe main.c and enter. Read the warnings printed on the screen. Warnings are not a good sign but we may still have an output.
Do a dir directory listing and we see several new files have been created. Our goal is to find an executable file, often with the extension .hex or .ihx.
Open the file main.ihx with notepad.
This is what we expect. A very short document file containing hexadecimal numbers. We call it a hex file and it is like those roller tapes that struck the keys on player pianos. These represent the on and off digits that will become commands and data in the MCU microcontroller unit.
UploadOur next step is to insert this code into a processor to run. It was compiled for the 8051 which have been manufactured since the 1980s. There are a lot of them. They have been used in millions of washing machines and coffee makers for decades.
Uploading needs a programming circuit and a software to move the hex file from your pc to the device. If you have used an Arduino then you were using avrdude.exe to upload. There are 8051 processors you can program with s51dude.exe.
SimulIDEOpen SimulIDE electronic simulator program. Open file explorer and locate Example/Micro/mcs-51/mcs-51_test.simu. We don't need to change any of the circuit.
Right click on the processor chip and select load firmware. locate our main.ihx file in the sdcc folder. Click open.
Click the red on/off button at the top of the screen.
Right click again on the 8051 MCU chip on the screen. Open MCU Monitor. In the Name column type in P0, P1, P2 and P3. It shows all 8 pins on all 4 ports being toggled on and off.
You may need to turn the simulator on, again. As a safety feature, SimulIDE will power down the circuit when you change circuits or software.
You can find more components and add them to your circuit. Try adding LEDs to some other pins.
Change the text in main.c so that P0 = 0xAA. Compile, reload firmware. Watch for changes in the monitor display. Change the delay numbers.
Try opening the other generated files with notepad. Some will be readable text mapping out the program and how it was compiled.
ExploreLook at the files and folders at C:\Program Files(x86)\SDCC\. Look at the include files. Right click, find open with and use notepad.
Our program code says to #include<reg51.h>. Look for it in the mcs51 folder. Open it with notepad and look at the contents.
We see folders for PIC14 and PIC16 8-bit MCUs and a few others. Can you find example code to compile for them?
Comments
Please log in or sign up to comment.