Reflection Technology
   

Getting Started with Microcontrollers

Microcontrollers are everywhere, there are dozens in your home: inside your TV, video recorder, fax, answering machine, microwave oven, washing machine, and then there's your car ...

They're used whenever you need something that will:

  • carry out a sequence of step
  • do something at a set time or after a time interval
  • communicate with something else
  • control a display (LCD) or react to a keyboard

All of these can be done with digital logic, or timer chips but the elegance of a microcontroller solution is that to make it do something different, you don't have to rewire, just reprogram.

Simple Problem - Multiple Solutions

As a simple example, consider that you need to make a pin do the following:

    -------         --------              ------
   | 1.6ms |  17ms  | 43ms |  one hour   |1.6ms
   |       |________|      |_____________|again

You could certain do this with timer chips but how much rewiring would it need to reverse the order (starting at step 5), or changing all the time constants.

Doing it with a Microcontroller

Below is the complete program to generate the above sequence on an AVR micrcontroller - even the baby 8 pin AVR costing a few dollars. The only other parts would be a crystal and a couple of capacitors.

But consider changing the sequence, repeating it 33 times and then stop ...

'----------------------------------------------------------------
' This Little Bascom Program Is To Repeated Generate
' the Timing Sequence:
'     -------         --------              ------
'    | 1.6ms |  17ms  | 43ms |  one hour   |1.6ms
'    |       |________|      |_____________|again
'----------------------------------------------------------------
$regfile = "2313def.dat"      ' Tell Bascom which micro
'I use a 8 MHz XTAL           ' Tell Bascom what Xtal on Micro
$crystal = 8000000
Dim Min , Sec As Byte         ' We need some counters
Config Portb = Output         ' Setup PORTB as an output
Portb.0 = 0                   ' Set all Port B Pins LOW
Do
  Portb.1 = 1                 ' Set Pin 0 (of 8) HIGH +5V
  Waitus(1600)                ' Simply wait for 1.6mS
  Portb.1 = 0                 ' Set it back to LOW (0V)
  Waitms(17)                  ' Stay low for 17mS 
  Portb.1 = 1                 ' HIGH for 43mS
  Waitms(43)                  ' do nothing for 4mS
  Portb.1 = 0                 ' Set Pin LOW
  For Min = 1 To 60           ' Wait For 60 minutes
    For Sec = 1 To 60         '   This loop delays 60 secs
      Waitms(1000)            '     Wait for 1000mS (1 Sec)
    Next Sec
  Next Min
Loop                          ' Now go and do it again

We're only using one pin of output pins and the micro is spending most of it's time waiting, but

  • it works
  • it's easy to get going
  • it's easy to change
  • it's very inexpensive,
  • has a low part count (4 parts: micro, xtal & 2 caps)

The easiest way to get started is by choosing a microcontroller that:

  • you can program in a high level language (Basic, C or Pascal)
  • can in reprogrammed repeated (Flash memory) so programming errors are easily fixed
  • is widely used (lots of free routines for LCD displays... and knowledgable people to ask ...)

The are many microcontroller families (the chips are programmed using the same language but have different numbers of I/O lines, times, serial ports ...

PIC or AVR

These are different, some are better for one job, some for another My suggestion is the AVR family - it's fast, inexpensive, has good software support and is widely used. The same can be said of the PIC but there's effort involved in learning how to use any new tool and the BASCOM compiler for the AVR family is the simplest development environment I've found - and the introductory version is FREE.

On to Getting started with BASCOM and AVR

On to Getting started with PIC

BACK    TOP  
 

All rights reserved 1999-2005 Giovanni Moretti Palmerston North, New Zealand

  Privacy Statement Contacting Reflection Technology Product Return details