Fork me on GitHub

Project Notes

#395 AT89C2051 Blinky

Simplest LED blinky program in C for the AT89C2051(8051/MCS51) microprocessor, built with the SDCC open-source toolchain on MacOSX.


Here’s a quick demo..



The main purpose of this program is simply to have something for testing the LEAP#394 AT89C2051 Programmer, and also my first trial of SDCC - Small Device C Compiler.

It is almost but not quite the simplest LED blinky program possible. It blinks an LED on P1_0, using a do-nothing loop to approximate 1Hz cycle time.

Installing SDCC

SDCC can be compiled from source or installed with a range of pre-compiled distributions available for Linux, Mac and Windows.

I am using a distribution for MacOSX.

Here’s a command line replay of what I installed:

tar -zxvf sdcc-snapshot-i386_universal-apple-macosx-20150214-9180.tar.bz2
rm sdcc-snapshot-i386_universal-apple-macosx-20150214-9180.tar.bz2
# optionally move the sdcc folder to a nice place now
export SDCC_HOME=./sdcc
export PATH=$PATH:${SDCC_HOME}/bin

If the sdcc folder is installed anywhere other than the current folder, it is necessary to set the SDCC_HOME environment variable so the compiler can find all its bits and pieces (like library header files).


See the Makefile for the couple of simple instructions that are used. It builds simply like this:

$ make
sdcc -mmcs51 --code-size 2048 Blinky.c -o Blinky.ihx
packihx Blinky.ihx > Blinky.hex
packihx: read 13 lines, wrote 17: OK.

I’ve checked-in all the products of the compilation for study purposes:

File Description
Blinky.asm Assembler source file created by the compiler
Blinky.c C source file
Blinky.hex Optional packed hex file created by packihx
Blinky.ihx The load module in Intel hex format linker options (I think)
Blinky.lst Assembler listing file created by the Assembler The memory map for the load module, created by the Linker
Blinky.mem A file with a summary of the memory usage
Blinky.rel Object file created by the assembler, input to Linkage editor
Blinky.rst Assembler listing file updated with linkedit information, created by linkage editor
Blinky.sym Symbol listing for the sourcefile, created by the assembler

Controlling the RST line

I haven’t found the definitive specification for this yet - but I quickly learned that you can’t just ground the RST pin and have the chip run!

The AT89C2051 data sheet actually specifies a RST pull-down of 50kΩ-300kΩ, but it seems to be important to also couple to VCC with a capacitor of say 2.2µF or more. Googling for 8051 circuit schematics, I see a common combination is 8.2kΩ pull-down and 2.2µF or 10µF to VCC.





Credits and References

Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.