| 8051 | |
| programming | |
| Say hello to the most ubiquitous microcontroller in the world. | |
| The MCS-51 is probably the best known microcontroller out there. It seems | |
| to appear in the least expected places nowadays, like a BLE stack or other | |
| 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 - memory | |
| 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 port 1 | |
| Source code | |
| Makefile | |
| These should be self explanatory, P1 is the IO Port 1 register. Writes | |
| set outputs, reads load inputs. The makefile is also dead simple. | |
| After the makefile creates the intel hex file with the code, you need to | |
| somehow upload it to the microcontroller. If you have a programmer then | |
| you are good to go.. you can either program the microcontroller directly | |
| (if it has programmable flash/eeprom memory), or you can wire an external | |
| eeprom to the 8051. In the latter case remember to ground the /EA pin. | |
| You will also want to feed a clock signal to the 8051, the easiest is to | |
| feed a square-ish clock signal directly XTAL1 pin, for example from a 4 | |
| pin crystal oscillator. My code runs nicely at 3-ish MHz. The delays are | |
| more less calculated, you only have to adjust the constant. The magic | |
| numbers in the delays are cycle counts, so if they are still off, you | |
| might want to take a look at what assembly sdcc came up with... remember | |
| 8051 takes 12clks for almost anything, 24clks for branches (taken or not | |
| taken). | |
| That's all. I hope I sparked your interetest in 8051, even though it's a | |
| finnicky processor. | |
| Now maybe I'll move on to MCS-48 as I have a mysterious board with one of | |
| those ;) |