Microcontrollers are hidden inside a surprising number of products these days . If your microwave oven oven has anLEDorLCDscreen and a keypad , it contains a microcontroller . All modern automobiles moderate at least one microcontroller , and can have as many as six or seven : The locomotive is controlled by a microcontroller , as are theanti - lock brakes , thecruise controland so on . Any gadget that has a remote control almost certainly contains a microcontroller : television , VCRsand high - destruction stereoscopic photograph systems all fall down into this family . NiceSLRanddigital cameras , cellphone phones , camcorders , resolve machines , optical maser pressman , telephones(the one with caller-out ID , 20 - number memory , etc . ) , beeper , and feature - laden icebox , dishwashing machine , washers and drier ( the ones with displays and computer keyboard ) … You get the thought . Basically , any product or twist that interacts with its user has a microcontroller bury deep down .

In this clause , we will look at microcontrollers so that you’re able to understand what they are and how they work . Then we will go one step further and talk over how you may begin working with microcontrollers yourself – we will make a digital clock with a microcontroller ! We will also work up a digital thermometer . In the operation , you will acquire an awful lot about how microcontrollers are used in commercial-grade products .

What is a Microcontroller?

A microcontroller is a figurer . All electronic computer – whether we are blab out about a personaldesktop computeror a largemainframe computeror a microcontroller – have several things in common :

The desktop data processor you are using is a " world-wide purpose computer " that can run any of thousands of programs . Microcontrollers are " special purpose computers . " Microcontrollers do one matter well . There are a identification number of other common characteristics that define microcontrollers . If a information processing system touch a bulk of these characteristic , then you may call it a " microcontroller " :

The actualprocessorused to enforce a microcontroller can motley widely . For object lesson , the jail cell earphone shown onInside a Digital Cell Phonecontains aZ-80 processor . The Z-80 is an 8 - bitmicroprocessordeveloped in the 1970s and originally used in home computers of the time . The Garmin GPS shown inHow GPS ReceiversWork contains a low-pitched - power variant of the Intel 80386 , I am told . The 80386 was originally used in desktop computers .

microcontroller

In many products , such as microwave oven , the requirement on the mainframe is fairly abject and price is an authoritative consideration . In these cases , manufacturers turn todedicated microcontroller chips– chip that were originally design to be low - toll , small , low - office , embedded CPUs . The Motorola 6811 andIntel 8051are both good examples of such chips . There is also a line of pop controller called " PIC microcontrollers " created by a company calledMicrochip . By today ’s standards , these mainframe are incredibly minimalistic ; but they are highly cheap when purchased in large quantity and can often meet the needs of a equipment ’s designer with just one chip .

A typical humiliated - end microcontroller crisp might have 1,000bytesof ROM and 20 bytes of RAM on the splintering , along with eight I/0 pins . In large amount , the cost of these chip can sometimes be just pennies . You for sure are never going to go Microsoft Word on such a chip – Microsoft Word requires perhaps 30 megabytes of RAM and a processor that can prevail millions of instructions per irregular . But then , you do n’t need Microsoft Word to verify a microwave oven , either . With a microcontroller , you have one specific task you are attempt to accomplish , and humiliated - price , low - baron carrying into action is what is important .

Using Microcontrollers

InHow Electronic Gates Work , you learned about 7400 - series TTL devices , as well as where to buy them and how to assemble them . What you found is that it can often take many gates to carry out simple devices . For example , in thedigital clock article , the clock we designed might contain 15 or 20 chips . One of the big advantages of a microcontroller is that software – a modest syllabus you compose and execute on the controller – can take the position of many Bill Gates . In this clause , therefore , we will utilise a microcontroller to create a digital clock . This is going to be a rather expensive digital clock ( almost $ 200 ! ) , but in the process you will accumulate everything you need to playact with microcontrollers for yr to come . Even if you do n’t actually create this digital clock , you will learn a great deal by reading about it .

The microcontroller we will use here is a exceptional - aim gimmick designed to make animation as simple as potential . The gimmick is called a " BASIC Stamp " and is created by a company calledParallax . A BASIC Stamp is a PIC microcontroller that has been customized to understand the introductory programming language . The use of the BASIC terminology makes it exceedingly easy to make software for the controller . The microcontroller chip can be purchased on a little carrier plank that accepts a 9 - voltbattery , and you could program it by punch it into one of the ports on your background figurer . It is unbelievable that any manufacturer would apply a BASIC Stamp in an factual production gimmick – Stamps are expensive and slow ( comparatively speaking ) . However , it is quite common to use Stamps for prototyping or for one - off demonstration products because they are so incredibly gentle to set up and expend .

They are called " Stamps , " by the room , because they are about as big as a postage stamp stamp .

Article image

The specific BASIC Stamp we will be using in this article is call the " BASIC Stamp Revision D " .

The BASIC Stamp Revision D is a BS-1 mounted on mailman board with a 9 - volt battery bearer , a mogul regulator , a connexion for a programming line , header peg for the I / O lines and a low prototyping area . You could buy a BS-1 chip and wire the other components in on a breadboard . The Revision D simply makes life sentence easier .

you could see from the late table that you are n’t going to be doing anything alien with a BASIC tender . The 75 - line limitation ( the 256 bytes ofEEPROMcan restrain a BASIC program about 75 line long ) for the BS-1 is middling constraining . However , you’re able to make some moderately bang-up clobber , and the fact that the Stamp is so small and battery operated means that it can go almost anywhere .

Article image

Programming the BASIC Stamp

You program a BASIC Stamp using theBASIC programing oral communication . If you already make out BASIC , then you will come up that the BASIC used in a Stamp is straightforward but a small strip - down . If you do n’t know BASIC , but you do know another language likeC , Pascal orJava , then picking up BASIC will be trivial . If you have never programmed before , you in all probability desire to golearn programmingon a desktop machine first . Here is a quick summing up on the command usable in Stamp BASIC . ( For complete documentation , go to Parallax : BASIC Stamp Documentation . )

Standard BASIC instructions:

Instructions having to do with I/O pins:

Instructions specific to the BASIC Stamp:

Operations:

If statement logic:

=

< >

<

< =

=

AND

OR

Variables

All variable quantity in the BS-1 have pre - specify names ( which you’re able to substitute with public figure of your own ) . think back that there are only 14 bytes of RAM available , so variables are precious . Here are the standard name :

Because there are only 14 bytes of computer storage , w0 and b0 / b1 are the same locations in RAM , and w1 and b2 / b3 are the same , and so on . Also , bit0 through bit15 repose in w0 ( and therefore b0 / b1 as well ) .

I/O pins

you’re able to see that 14 of the instructions in the BS-1 have to do with the I / group O peg . The reason for this stress is the fact that the I / O pins are the only way for the BASIC Stamp to talk to the world . There are eight pins on the BS-1 ( come 0 to 7 ) and 16 pins on the BS-2 ( total 0 to 15 ) .

The stick arebi - directional , stand for that you may read comment values on them or send yield value to them . The well-off way to beam a value to a pin is to use theHIGHorLOWfunctions . The statement high 3 sends a 1 ( +5 volt ) out on PIN number 3 . LOW sends a 0 ( Ground ) . Pin 3 was chosen arbitrarily here – you could send number out on any pin from 0 to 7 .

There are a phone number of interesting I / O personal identification number instruction manual . For example , POT reads the setting on a potentiometer ( variable resistance ) if you cable it up with acapacitoras the POT direction expects . The PWM instruction transport out pulse - width modulate signal . pedagogy like these can make it a batch easy to attach controls and motors to the Stamp . See thedocumentationfor the language for item . Also , a record like Scott Edward’sProgramming and Customizing the BASIC Stamp Computercan be extremely helpful because of the example projects it contains .

Playing with a BASIC Stamp

If you would wish to play with a BASIC Stamp , it ’s very easy to get started . What you take is a desktop computer and aBASIC Stamp starter outfit . The starter kit includes the Stamp , a computer programing cable’s length and an covering that you race on your desktop computer to download BASIC programs into the Stamp .

you’re able to get a starter kit either fromParallax(the manufacturer ) or from a supplier likeJameco(who should be familiar to you from theelectronic gatesanddigital clockarticles ) . From Parallax , you may tell the BASIC Stamp D Starter Kit ( part number 27202 ) , or from Jameco you may say part number 140089 . You will receive the Stamp ( pictured below ) , a programming cable , computer software and instructions . The kit is $ 79 from both provider . once in a while , Parallax runs a exceptional called " We ’ve Bagged the Basics " that also includes Scott Edward’sProgramming and Customizing the BASIC Stamp Computer ] .

accost up the Stamp is easy . You connect it into theparallel portof your microcomputer . Then you run a DOS coating to edit your BASIC programme and download it to the Stamp .

To run away the programme in this editor , you off ALT - R. The editor app watch the BASIC program and then send out it down the wire to the EEPROM on the Stamp . The Stamp then execute the program . In this case , the program produce a straight wafture on I / O personal identification number 3 . If you hook up a logic investigation or LED to flag 3 ( see theelectronic gates articlefor details ) , you will see the LED flash on and off twice per minute ( it changes state every 250 msec because of the PAUSE statement ) . This broadcast would run for several weeks off of a 9 - volt battery . You could save mightiness by shortening the clock time that the LED is on ( perhaps it is on for 50 milliseconds and off for 450 milliseconds ) , and also by using the NAP instruction rather of suspension .

Creating a Really Expensive Digital Clock

Spending $ 79 to scud anLEDmay seem prodigal to you . What you would likely like to do is create something useful with your introductory postage stamp . By spend about $ 100 more you’re able to create a really courteous digital clock ! This may seemextremelyextravagant , until you realize that the parts are reusable in a salmagundi of other projects that you may want to build later .

Let ’s say that we would like to use the I / O pin on the BASIC Stamp to exhibit numeral values . In thedigital clock clause , we saw how to interface to a 7 - segment LED display using a 7447 chip . 7447s would work just as well with the BASIC Stamp . You could electrify four of the I / O pins straight into a 7447 and easily display a number between 0 and 9 . Since the BS-1 Stamp has eight I / O pins , it is loose to force back two 7447s directly like this .

For a clock , we call for a lower limit of four digits . To repulse four 7447s with eight I / O pin tumbler , we have to be slightly more creative . The following diagram shows you one attack :

In this diagram , the eight I / O lines from the Stamp enter from the left hand . This attack uses four lines that flow to all four 7447s . Then the other four crease from the Stamp activate the 7447s in sequence ( " east " on the chips means " Enable " – on a 7447 , that would be the blank input on thole 5 ) . To make this arrangement work , the BASIC program in the Stamp would output the first fingerbreadth on the four information lines and aerate the first 7447 by toggling its E peg with the first control condition phone line . Then it would send out out the value for the second digit and activate the 2d 7447 , sequencing through all four of the 7447s like this repeatedly . By electrify thing slightly otherwise , you could actually do this with only one 7447 . By using a 74154 demultiplexer chip and some driver , you could repulse up to 16 digits using this approach shot .

This is , in fact , a standard way to control LED displays . For example , if you have an old LED calculator , move around it on and shake it while watching the show . You will in reality be able to see that only one figure is ever illuminated at once . The approach is calledmultiplexingthe display .

While this approach works alright for alfileria and calculators , it has two important problems :

An substitute access is to use anLCD screen . As it change state out , LCDs are widely available and can be easily hooked to a Stamp . For example , the two - line by 16 - grapheme alphanumerical presentation shown below is available from bothJameco(part telephone number 150990 ) andParallax(part turn 27910 ) . A typical presentation is shown here , mounted on a breadboard for easier interfacing :

This sort of LCD has several advantages :

The only problem is that one of these displays costs $ 59 . plainly , you would not imbed one of these in atoaster oven . If you were designing a toaster oven , however , you would likely prototype with one of these displays and then produce impost chips and software to drive much cheaper LCD in the final product .

To repulse a display like this , you simply append it with +5 volts and ground ( the Stamp supply both from the 9 - V battery ) and then hook one of the I / type O pin from the Stamp to the display ’s remark line . The easiest way I have find to connect the Stamp ’s I / atomic number 8 pins to a gadget like an LCD is to use a telegram - wrap puppet ( Jamecopart number 34577 ) and 30 - calibre conducting wire wrapping wire ( Jameco part number 22541 is distinctive ) . That way , no soldering is involved and the connections are heavyset and true .

The following BASIC course of study will cause a BASIC Stamp to comport like a clock and output the meter on the LCD ( take over the LCD is connected to I / O pin 0 on the Stamp ):

In this program , the SEROUT commands send information to the LCD . The sequence ( 254 , 1 ) clears the LCD ( 254 is the relief valve character and 1 is the command to sort out the screen ) . The sequence ( 254 , 135 ) positions the cursor . The other two SEROUT commands simply send text string to the showing .

This approach will create a reasonably exact clock . By tweaking the PAUSE program line you could get the truth to within a few seconds a day . apparently , in a substantial clock you would like to cable up a thrust - clit or two to make place it easy – in this plan , you preset the time before you download the program to the Stamp .

While this approach is wide-eyed and works , it is not incredibly accurate . If you want better truth , one proficient approach would be to wire areal - clip clock chipup to your Stamp . Then , every second or so , you may read the metre from the bit and expose it . A veridical - fourth dimension clock chip utilize aquartz crystalto give it first-class truth . Clock chips also normally check day of the month entropy and handleleap yearcorrection mechanically .

One easy way to interface a real - sentence clock to a stamp is to employ a constituent called thePocket Watch B.

The Pocket Watch B is available from bothJameco(part issue 145630 ) andParallax(part number 27962 ) . This part is about as self-aggrandising as a one-fourth and contains the clock chip , crystal and a nonparallel interface so that only one I / O pin is necessary to communicate with it . This part cost about $ 30 – again , not something you require to embed in a wassailer oven , but promiscuous to play with when constructing prototypes .

Building a Digital Thermometer

Now that you understand a small bit about your Stamp and the LCD , we can add another factor and make a digital thermometer . To create a thermometer , we will use a chip called the DS1620 . This chip check :

The DS1620 has two modes : In one mode , it acts as a stand - alone thermostat micro chip , and in the other mode you hook it up to a reckoner and practice it as athermometer . The EEPROM remembers the current mode as well as the set temperatures for the thermostat .

Hooking up the DS1620 to the Stamp is very sluttish . The DS1620 derive in an 8 - peg scrap . Supply +5 V from the Stamp to immobilise 8 of the DS1620 . provision ground to pin 4 of the DS1620 . You then use three I / O rowlock from the Stamp to force three pins on the DS1620 :

For this example code , it is assumed that :

The fill out wiring await like this :

you could get a DS1620 either fromJameco(part number 146456 ) orParallax(part telephone number 27917 ) in an " diligence kit " that include the microprocessor chip , the electrical condenser , some right software documentation and sample computer code . Or you’re able to buy the chip on its own fromJameco(part number 114382 ) . I would suggest have the program kit the first time you sample using the DS1620 because the certification is very useful .

you could set up the DS1620 in the image area of the Stamp carrier board or on a separate bread board . Once you have assembled it , hook your LCD display up to I / O peg 3 of the Stamp , and then charge and melt the following program :

If you head for the hills this program , you will find that it displays the centigrade temperature with an accuracy of one - one-half degree .

The DS1620 measures temperatures in centigrade half - grade . It generate the temperature in a 9 - number 2s - full complement number with a range of -110 to 250 F ( -55 to 125 C ) . You split the number you receive by 2 to get the real temperature.2s - complement binary numbersare a commodious mode to representnegative values . The follow list shows the values for a 4 - bit 2s - complement phone number :

­ you’re able to see that rather of the 4 bits representing values from 0 to 15 , the 4 bits in a 2s - complement bit represent the values -8 to 7 . you could look at the left - most bit to determine if the routine is negative or positive . If the number is negative , you may reverse the bits and add 1 to get the confident mental representation of the number .

Here ’s what goes on with the digital thermometer programme show here :

The program then enters aloop . Every secondly , it station a instruction to the DS1620 telling the DS1620 to return the current temperature , and then it reads the 9 - snatch value that the DS1620 render into the w0 variable . The Stamp commit and receives data point 1 bit at a time by toggle the CLK credit line on the DS1620 . think of that the w0 ( 16 - bit ) variable star overlays the b0 / b1 ( 8 - bit ) variable quantity , which cover the bit0 / bit1/ … /bit15 ( 1 - routine ) variable , so when you inclose a bit from the DS1620 into bit 8 and divide w0 by 2 , what you are doing is shifting each bit to the right field to store the 9 - bit temperature from the DS1620 into w0 . Once the temperature has been bring through in w0 , the display subroutine shape whether the number is positive or negatively charged and displays it suitably on the LCD as a centigrade temperature . The conversion from degrees C to degrees F is :

At this point , we have succeeded in creating an extremely expensive thermometer . What might you do with it ? Here ’s one idea . Let ’s say you work for a drug company and you are shipping expensive drugs across the nation that MUST continue at a certain temperature the total way of life or the drug will bilk . What you could do with a Stamp is create adata logging thermometer . BothJameco(part number 143811 ) andParallax(part number 27960 ) sell a gadget call the " RAM Pack module . " It contains a low - power 8 - kilobyte ( or optionally 32 - kilobyte ) RAM chip with a serial user interface . You could bring this element ( or something similar ) to your postage and drop a line code that bring through temperature readings to the random memory every minute . You could then splay your legal tender into the drug shipment , and at the other ending of the trip retrieve the Stamp . The RAM mental faculty would arrest the temperature account of the entire misstep and you would know whether or not the drug ever thawed out .

There are all kind of corking , useful devices like this that you’re able to build with a Stamp now that you know how microcontrollers turn !

For more information on microcontrollers and related to topics , check out the data link on the next page .

Lots More Information

FAQs