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.

Build

Here’s a quick demo..

clip

Notes

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:

wget https://excellmedia.dl.sourceforge.net/project/sdcc/snapshot_builds/i386_universal-apple-macosx/sdcc-snapshot-i386_universal-apple-macosx-20150214-9180.tar.bz2
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).

Compiling

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
Blinky.lk linker options (I think)
Blinky.lst Assembler listing file created by the Assembler
Blinky.map 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.

Construction

Breadboard

Schematic

Build

Credits and References

About LEAP#395 8051LED
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, 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 (IMHO!).

The projects are usually inspired by things found wild on the net, or ideas from the sources such as:

Feel free to borrow liberally, and if you spot any issues do let me know. See the individual projects for credits where due. There are even now a few projects contributed by others - send your own over in a pull request if you would also like to add to this collection.