8051 | |
programming | |
Say hello to the most ubiquitous microcontroller in the world. | |
The MCS-51 is probably the best known microcontroller out there. It | |
to appear in the least expected places nowadays, like a BLE stack o | |
stuff like that. | |
The 8051 (which is just another, one of probably 50, names for the | |
MCS-51) has defined the form and programming interface of modern | |
microcontrollers. The idea of SFRs - special function registers - m | |
addresses which do not act as general purpose RAM but configuration | |
registers for peripherals, are found in almost all other kinds of | |
microcontrollers. | |
The 8051 can be easily programmed under *nix with SDCC and a bit of | |
patience. | |
Below is some example code that will blink a led on any pins of por | |
Source code | |
Makefile | |
These should be self explanatory, P1 is the IO Port 1 register. Wri | |
set outputs, reads load inputs. The makefile is also dead simple. | |
After the makefile creates the intel hex file with the code, you ne | |
somehow upload it to the microcontroller. If you have a programmer | |
you are good to go.. you can either program the microcontroller dir | |
(if it has programmable flash/eeprom memory), or you can wire an ex | |
eeprom to the 8051. In the latter case remember to ground the /EA p | |
You will also want to feed a clock signal to the 8051, the easiest | |
feed a square-ish clock signal directly XTAL1 pin, for example from | |
pin crystal oscillator. My code runs nicely at 3-ish MHz. The delay | |
more less calculated, you only have to adjust the constant. The mag | |
numbers in the delays are cycle counts, so if they are still off, y | |
might want to take a look at what assembly sdcc came up with... rem | |
8051 takes 12clks for almost anything, 24clks for branches (taken o | |
taken). | |
That's all. I hope I sparked your interetest in 8051, even though i | |
finnicky processor. | |
Now maybe I'll move on to MCS-48 as I have a mysterious board with | |
those ;) |