Beginners Guide To Micro Controllers
Beginners Guide To Micro Controllers
200713
Beginning with microcontrollers might look a bit intimidating at first thought. The reason is that there
are lots of microcontrollers to choose from, each with its own instruction set, architecture and programming
tools. But believe me it isn’t that hard at all.
My suggestion is that you should learn to program as many microcontrollers as you can because that
would give you the greatest degree of freedom in the embedded systems world and besides that it will add a
few extra lines on your CV :). So don’t listen to people saying that 8051 is better than the PIC or the AVR
beats the PIC. You can perform any task on a microcontroller that can be done on any other microcontroller.
The only difference will be in the “way” it is done because all microcontrollers have different instruction sets
and architectures.
The following is a brief introduction into the world of microcontrollers. I might leave out some points
so please forgive me if you find this article insufficient. And I might also sound a bit biased towards PICs
simply because I like them. But this doesn’t mean that only PICs are the ultimate microcontrollers. It’s
because that’s that only thing that I have learnt thoroughly so far :)
Atmel
Atmel first produced the AT89C51 microcontroller which was an 8051 with programmable flash
memory. This is ideal for fast development because flash memory can be erased and written easily and lesser
1 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
time as compared to other types of memory. Currently Atmel has a huge product line based on the 8051 core.
It produces Flash, One time programmable (OTP) and Mask ROM 8051s thereby addressing the needs of a
wide variety of developers. From a student/hobbyist point of view the AT89S5X microcontrollers are the
most ideal because of their In System Programmable capability. Surf around Atmel’s website
http://www.atmel.com/products/8051/ and you will find alot to start with.
Intel
Although the 8051 was originally designed by Intel, I haven’t seen any Intel 8051 as of yet. But they
still do have a valuable collection of documents related to the 8051 at
http://developer.intel.com/design/mcs51/docs_mcs51.htm
Maxim’s 8051
Maxim (Dallas Semiconductor) also has a small line of products featuring the 8051 core. They claim
upto 33 times the performance of the original 8051. That was made possible by a redesigned processor core
that executes every 8051 instruction upto 12 times faster than the original 8051 giving it speeds of up to a
maximum of 33 MIPS at 33MHz. Have a look at the 8051-compatible products from Maxim at
http://www.maxim-ic.com/products/microcontrollers/high_speed.cfm
Analog Microcontroller
Don’t be deceived by the name as a microcontroller cannot be analog in its operation. The ADuC800
series of analog microcontrollers is a product of Analog Devices which features high speed ADCs and DACs,
a voltage reference and a temperature sensor with a 8052 core. Have a look at it
http://www.analog.com/en/index.html
Phillips
Phillips, in addition to producing the ARM based LPC2000, LPC900 and LPC700 series of
microcontrollers, also manufactures 8-bit 8051 derivatives. Go to
http://www.standardics.philips.com/products/microcontrollers/ to see the various products available from
Phillips.
Microchip PIC
Microchip, the second largest 8-bit microcontroller supplier in the world, (Motorola is ranked No: 1)
is the manufacturer of the PIC microcontroller and a number of other embedded control solutions. Check out
the following links for an overview of the history of Microchip and PIC microcontrollers.
http://forum.microchip.com/tm.asp?m=19407
http://www.jpixton.dircon.co.uk/pic/history.html
Microchip offers four families of PIC microcontrollers, each designed to address the needs of different
designers.
You might be asking that how can an 8-bit microcontroller have a 12, 14 or 16 bit instruction word
2 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
length? The reason lies within the fact that PIC microcontrollers are based on Harvard architecture. Harvard
architecture has the program memory and data memory as separate memories which are accessed from
separate buses. This improves bandwidth over traditional von Neumann architecture in which program and
data are fetched from the same memory using the same bus. PIC microcontrollers have a data memory bus of
8-bit and a program memory bus of 12, 14 or 16 bit length depending on the family. All PIC microcontrollers
have a mix of different on-chip peripherals like A/D converters, Comparators, weak pull-ups, PWM modules,
UARTs, Timers, SPI, I2C, USB, LCD, CAN etc.
PIC microcontrollers come in various sizes, from the 6-pin smallest microcontroller in the world to
the high pin count, high memory devices. But from a student’s/hobbyist’s perspective the 16F series of PICs
are the most ideal to start with and out of them the PIC16F84 seems to be the most popular microcontroller.
Although the PIC16F84 and the PIC16F84A (later silicon revision of the PIC16F84) have been replaced by
the higher spec, lower priced PIC16F628 and the PIC16F628A, there are still lots of tutorials on the internet
and books that use the PIC16F84 as a starting point. My suggestion is that you should start with the
PIC16F628 or the PIC16F628A. Then you can move on the high end PICs like the PIC16F876 or the
PIC16F877. If you don’t want to program in assembly and you prefer C then you should start with the 18F
series because they have a C friendly architecture. In that case I would suggest you to start with the
PIC18F452.
By now your mind would have filled with numerous questions like where to start? what would I need
to program a PIC? what hardware should I use? what software should I use? Well, I will try to answer all
those questions.
First of all I would suggest that you go to Nigel Goodwin’s site which has all the answers to your
questions. There you would find schematics for the programmer, the programming software and a great series
of tutorials based on the PIC16F628 plus a support forum! The most popular, fastest and the easiest to build
programmer is the Parallel David Tait PIC programmer which is commonly know as the father of all PIC
programmers. Although David Tait no longer provides support for his design there are a number of variants
of his design available on the internet. The P16PRO40 by Bojan Dobaj or the PLMS OziPICer and others are
all variants of the original David Tait Design. Some people use another very popular programmer known as
the JDM programmer because it works on the serial port and requires no external power supply whereas all
variants of the David Tait programmer work connect to the parallel port of a PC and require an external
power supply. But one thing I would want to say here is that the simplicity of the JDM programmer comes at
a cost of unreliability. The JDM programmer draws power from the serial port and most serial ports are not
designed for such a task (especially laptop serial ports). There are some versions of the JDM programmer
which use an external supply. So, if someone wants to build a JDM programmer he should look for versions
with an external power supply. But even then I wouldn’t recommend a serial port programmer like the JDM.
If you want to build or buy a serial port programmer then go for a “proper” serial port programmer. By
“proper” I mean one that has an embedded microcontroller that does the programming.
Okay that was a little intro to the hardware tools, now for the software tools. The first thing you would
need is an assembler. The assembler for PICs is known as MPASM and it comes with MPLAB. The MPLAB
integrated development environment (IDE) is a free, integrated toolset for the development of embedded
applications employing Microchip's PICmicro and dsPIC microcontrollers. MPLAB also has a simulator for
PIC microcontrollers known as MPSIM. Check Microchip’s website for the latest version of MPLAB.
MPLAB will assemble your code into a “.HEX” file. Then next step is copying the contents of the “.HEX”
file to the program memory of your PIC microcontroller. If you are using a David Tait programmer then
either Nigel Goodwin’s WinPicProg or ICProg will work. If you are using the JDM programmer ICProg will
be your first choice. For those of you who want to develop code in C there are a number of compilers
available for PIC microcontrollers. Even if you plan to develop code in C I would recommend a basic
knowledge of assembly as it gives you a closer insight into the architecture of the microcontroller you are
programming. Microchip has only made a compiler for the 18-series of PIC microcontrollers and another one
for dsPIC microcontrollers. There is a student version of the C18 compiler available at Microchip’s website.
If you want to program the 12, and 16 series of PICs with C, you would have to look for third party tools like
3 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
the ones from IAR (very very expensive), HiTech, CCS and mikroElektronika. The compilers from these
companies are very expensive but luckily all of them offer free evaluation versions. Check their websites for
more info.
In addition to the assembler and C compilers available for PIC microcontrollers there are also Basic
compilers like the PIC Basic Compiler from MELABS or Proton Plus Compiler from Crownhill or
mikroBasic from mikroElektronika. There is even a Pascal compiler for PIC microcontrollers from
mikroElektronika. If that’s not enough, there is a compiler for JAL (just another language) for PICs as well.
Third party simulation software for PIC microcontrollers are also available like the Proteus VSM.
As you will move on with developing applications using the PIC microcontroller you will find
yourself debugging your code most of the time. For that you would need an In Circuit Debugger (ICD). The
ICD in addition to being a normal programmer, debugs the code you have developed “in-circuit”. The latest
ICD2 from Microchip has a hefty price tag of $299 excluding shipping and taxes. An alternative is to make
one yourself. The ICD2 clone by Lothar Stolz is the simplest of all the ICD2 clones I have seen on the
internet. PIC microcontrollers with ICD capability can be programmed and debugged directly from within
MPLAB using an ICD so that there is no need for a multitude of programming tools.
Once you get familiar with programming PIC microcontrollers you will feel the need to view code
developed by other programmers. For that go to the PICList which is the biggest archive of PIC code on the
internet. You should also download the Midrange Reference Manual and the 18C Family Reference Manual
from Microchip’s website. And in addition to that you should have the datasheet (and its Errata) of whichever
PIC microcontroller you are working on.
Atmel AVR
The AVR microcontroller is the biggest contender against the PIC microcontroller for the rank of
THE best microcontroller. Some fans of PIC microcontrollers even say that Atmel used a
three-lettered-acronym (TLA) to name the AVR so as to compete with the PIC. According to Atmel the
acronym AVR stands for nothing, its just a name and it isn’t supposed to mean anything. Have a look at the
page http://partsandkits.com/avr-faq.htm if you are curious about what AVR stands for.
The AVR is also based on the Harvard architecture and it too features on-chip peripherals such as
internal oscillators, timers, UART, SPI, pull-up resistors, pulse width modulation, ADC and analog
comparators etc. The AVR microcontrollers have a RISC core running single cycle instructions as opposed to
PICs which require four cycles per instruction. That usually doesn’t imply that the AVR is four times faster
than the PIC because they have completely different architectures. But at times you will see people arguing on
discussion forums that AVRs are faster than PICs. In embedded control applications speed isn’t the only
requirement. For most of the time the microcontroller is waiting for something to happen or wasting cycles.
The main concern here is the efficient architecture, ease of programming, available programming tools and
on-chip peripherals. In that regard both PICs and AVRs go side by side. There are three families of AVR
microcontrollers that Atmel offers;
1. tinyAVR
2. Classic AVR
3. MegaAVR
All three families of microcontrollers have the same instruction set and memory organization. The
only difference is in the available features. The tinyAVR is the one that has the least of features and comes in
lower pin-count packages while the MegaAVR comes with the most features and the highest pin-count
packages. Whereas the Classic AVR is somewhere between these two families. Another feature of the AVR
microcontrollers is that the instruction set is highly optimized for C compilers. And as all of the AVRs have
the same core you only need one compiler for all the AVR devices.
4 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
As with PICs, to start developing applications based on the AVR microcontroller you would need a
couple of hardware and software tools. The AVR studio is a complete development suite that contains an
editor and a simulator and it comes free of cost. You can download the AVR Studio from Atmel’s Website.
The most famous development board for AVRs is the STK500. You can also make your own home made
programmer like the PonyProg but such programmers have been known to be quite unreliable. The STK500
development board is the most recommended programmer for AVRs. Just as with other microcontrollers you
will also need to download the instruction set manual and the datasheet of the particular microcontroller you
are working on.
The best part of AVR microcontrollers is that there is a completely free C compiler available.
WinAVR (pronounced "whenever") is a suite of executable, open source software development tools for the
Atmel AVR series of RISC microprocessors hosted on the Windows platform. It includes the GNU GCC
compiler for C and C++. In addition to the AVR GCC other C compilers are also available for AVR
microcontrollers. These include IAR, Codevision AVR and ImageCraft. For fans of Basic there is the
BASCOM AVR compiler for AVR microcontrollers.
The most common AVRs are the AT90S2313 and the AT90S8515. But if you want to go for big
projects where you would need lots of program memory and on-chip peripherals you should consider using
the ATMega16 (with 16K Flash) or the ATMega32 (with 32K of Flash) or higher.
Maxim’s MAXQ
The MAXQ microcontroller from Maxim-Dallas Semiconductor is another newly developed product
aimed at acquiring a share of the market dominated by the 8051, PIC and AVR. The MAXQ is also a 16-bit
5 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
RISC microcontroller based on the Harvard architecture featuring high performance at low power
consumption figures.
There is an Integrated Development Environment available at Maxim’s website for developing
applications using the MAXQ microcontrollers. It features an integrated JTAG port for easy in-circuit
debugging. Evaluation kits for the MAXQ have became available only recently. The MAXQ microcontroller
is a new product and there aren’t much people using it. So I wouldn’t recommend a student or a hobbyist to
start with the MAXQ.
Maxim has performed some benchmarks and compared the MAXQ with other competitors in the
market. The hilarious part of these benchmarks is that they are actually comparing 16-bit microcontrollers
with 8-bit microcontrollers. That’s like comparing apples with oranges! But nevertheless the MAXQ
microcontrollers have some serious amount of potential and we might start seeing it in consumer products
soon.
6 of 7 11/13/2007 4:24 PM
Beginners Guide to Microcontrollers http://www.geocities.com/shahzadahmadmalik/guide.html?200713
developed. If you want a career in embedded systems you must be good in C. But there is a saying that
technology is good if it works right for you, and Basic is good technology! So if you like to write code in
Basic and if it serves your needs then you should use Basic.
Conclusion
Microcontrollers are termed as “computers on a chip” because unlike microprocessors they have
integrated memory and peripherals. This reduces the chip count to a great level. Most of the time only a few
more components (in addition to the power supply) are needed for a microcontroller based design. If you have
been building projects based on 74-series logic ICs then you seriously need to consider switching to
microcontrollers. A project that might consume tens of logic ICs can be replaced with a single
microcontroller. The best part is that you can write your own program into microcontrollers and make it do
any function. Nowadays the distance between digital signal processors and microcontrollers is greatly
reducing with devices coming in the market that can do the job of both.
A survey states that the microprocessors used in PCs are only 2% of all the microprocessors that are
made in a year. The rest 98% goes into embedded systems in the form of microcontrollers and FPGAs etc. So
you can well imagine the number of microcontrollers that are developed each year by literally hundreds of
manufacturers. Microcontrollers are here to stay! So, don’t get left behind!
7 of 7 11/13/2007 4:24 PM
Yahoo! GeoCities http://www.geocities.com/js_source/tab04.html
1 of 1 11/13/2007 4:24 PM
Yahoo! GeoCities http://www.geocities.com/js_source/adframe07.html
SPONSORED LINKS
Advatech Embedded Industrial
PC
Single Board Computer,
Embedded PC. Customize Your
Own! Shop Online.
www.eplatformpro.com/advantech
1 of 1 11/13/2007 4:24 PM