Here are the source codes of few sample programs (written in C) described in the textbook and included on the accompanying CD.
Software and Hardware required to compile and download these programs:
- The Compiler: The programs will compile using the Small Device C Compiler available here. SDCC is a free open source compiler for 8051 based microcontrollers.
- The IDE (Integrated Development Environment): We like to use Eclipse as the code editor frontend for SDCC (Integrated Development Environment or IDE)which is available here. Be sure to download the flavous meant for "C/C++ Developers"
- The IDE Plugin: To integrate SDCC with Eclipse, you will need a Eclipse plugin called eclipseSDCC.
- Runtime Environment for IDE: Since Eclipse is written in Java, you will require to install the Java Runtime Environment (JRE) before you can run Eclipse on your PC.
- Program Downloader: The programs have been written for execution on P89V51RD2 microcontroller. FlashMagic is a windows based tool which can be used to download the contents of a HEX file (.hex or .ihx) into the P89V51RD2 microcontroller via UART (i.e. Serial Port).
- The Hardware: The programs have been design to run on the UNI-51-SDK which is an 8051 based development system. The UNI-51-SDK includes a P89V51RD2 microcontroller. Please visit the UNI-51-SDK's companion page for Getting Started Guides, Datasheets, Schematics and Sample Programs: http://pc.lare.in/uni-51-sdk. Details for procuring the kit are here.
Some notes from the book's authors:
- Windows XP: All the software packages described above (SDCC, Eclipse IDE, eclipseSDCC, JRE, FlashMagic) have versions which will work on Windows XP. The Authors of the textbook themselves have developed the source codes attached below using a Windows XP based PC.
- Windows 7 64bit: All software packages described above will work on Windows 7 64-bit based PC except for eclipseSDCC which uses unix like tools in the backend. These unix like commandline tools are known to not work at all on Windows 7 based systems. To over come this, one can use VirtualBox to install Windows XP or ubuntu on a virtual machine within a Windows 7 based PC and run all these software packages on that virtual machine.
- ubuntu: All the software packages described above (SDCC, Eclipse IDE, eclipseSDCC, JRE, FlashMagic) have versions which will work on ubuntu. To run FlashMagic on ubuntu, you will require wine - refer this to know how to do this. Please take care of the letter case in source code filenames when using ubuntu as linuz is a case sensitive OS.
- USB-Serial Convertors: Modern laptops do not have builtin RS-232 Serial Ports. FlashMagic works without any problems with most USB-Serial Convertors as long as their drivers are installed correctly. We have tested many USB-Serial Convertors on Windows XP, Windows 7 64bit and ubuntu. The ones that work best reliably are those based on FTDI's FT232RL and Prolific's PL-2303 Chips. In case of Windows 7 64bit, all USB-Serial convertors failed except for FT232RL or PL-2303 based ones because only FTDI (manufacturer of FT232RL) and Prolific (manufacturer of PL-2303) have released proper/reliable drivers for Windows 7. In case of using USB-Serial convertors on ubuntu, please issue the command "ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1" before running FlashMagic using wine.
All the files below are ZIP compressed version of individual project folders present within an Eclipse Workspace. You are expected to extract each zip file into seperate folders and then import them into your own Workspace from within Eclipse. All folders also contain the compiled Intel Hex files (.ihx) which can be downloaded rightaway into the microcontroller using FlashMagic. If you want to assemble your own hardware circuit on a breadboard or a general purpose PCB, it will be beneficial to use the UNI-51-SDK's Schematics as reference while doing so.