How to Program Microprocessors
Microprocessors are programmable devices that can take input signals, perform logic operations and provide output signals. Stand-alone microprocessors can provide a high level of control over simple integrated circuits, motors, actuators and LEDs. Once programmed, they can repeatedly perform the same task with precision and accuracy, making them an integral part of mechatronic engineering design.
Things You'll Need
- Stand-alone universal programmer
- Integrated development environment software
Purchase a microprocessor, available from many manufacturers and commonly found online or from an electronics store. To keep costs down, purchase a microprocessor that does what you need but not more. Also select a microprocessor that has an internal oscillator; otherwise, the chip will require an external clock. If you plan to input or output analog signals, get a microprocessor with a digital-to-analog (A/D) converter and pulse-width modulation. Download the datasheet for your microprocessor, as it contains all the specifications and even some sample code to program the chip.
Write the program. Microprocessors understand machine code, but you will use a higher level programming language such as "C" or "Assembly." Write the program in the Integrated Development Environment (IDE) software for your microprocessor, which will compile the code into a language the machine can understand. If you have little experience with the Assembly programming language, the datasheet for your microcontroller should have the keywords and instruction set, and the manufacturer's website should have example codes.
Test the program using the IDE simulation package. Once you have embedded the program into your microprocessor, you will find it extremely difficult to debug and find errors. Therefore, most IDE packages have an option to simulate the code on your computer screen. The IDE simulator allows line-by-line execution, as well as a visual representation of the variables defined by the code. Debugging the code through the simulation software plays an integral role in avoiding frustration later if your program does not behave as expected.
Acquire and hook up a universal stand-alone programmer to your computer. This device connects to your serial port and has a socket that fits up to 60-pin microprocessors. The universal programmer requires that you remove the microprocessor from your circuit; use a socket to connect between the microprocessor and the rest of the circuit. Zero insertion force (ZIF) sockets make it very easy to remove the microprocessors without damaging the pins of the chip.
Embed your program onto your microprocessor. In the IDE software, select your programmer from the drop-down menu. Before adding your program, erase the previous program from the chip. Some older microprocessors with a glass window on top have UV-erasable memory. To erase these devices, place the chip under a UV lamp for 20 minutes. Flash memory is erasable by software. Depending on the size of your program, it may take anywhere from several seconds to several minutes to transfer your program to the microprocessor.
Tips & Warnings
- Zero insertion force (ZIF) sockets make it easier to remove and replace your microprocessor into your circuit without damaging pins.
- Avoid frustration by using the IDE's simulator to debug your program.