How Microcontrollers Work

by Marshall Brain
Browse the article How Microcontrollers Work

Inside Electronics Image Gallery

Introduction to How Microcontrollers Work
Microcontrollers are hidden inside a surprising number of products these days. If your microwave oven has an LED or LCD screen and a keypad, it contains a microcontroller. All modern automobiles contain at least one microcontroller, and can have as many as six or seven: The engine is controlled by a microcontroller, as are the anti-lock brakes, the cruise control and so on. Any device that has a remote control almost certainly contains a microcontroller: TVs, VCRs and high-end stereo systems all fall into this category. Nice SLR and digital cameras, cell phones, camcorders, answering machines, laser printers, telephones (the ones with caller ID, 20-number memory, etc.), pagers, and feature-laden refrigerators, dishwashers, washers and dryers (the ones with displays and keypads)... You get the idea. Basically, any product or device that interacts with its user has a microcontroller buried inside.

Microcontrollers are dedicated computers in electronics. See more pictures of what's inside electronics. HowStuffWorks

In this article, we will look at microcontrollers so that you can understand what they are and how they work. Then we will go one step further and discuss how you can start working with microcontrollers yourself -- we will create a digital clock with a microcontroller! We will also build a digital thermometer. In the process, you will learn an awful lot about how microcontrollers are used in commercial products.

DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates

DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates

What is a Microcontroller?
A microcontroller is a computer. All computers -- whether we are talking about a personal desktop computer or a large mainframe computer or a microcontroller -- have several things in common: All computers have a CPU (central processing unit) that executes programs. If you are sitting at a desktop computer right now reading this article, the CPU in that machine is executing a program that implements the Web browser that is displaying this page.

The CPU loads the program from somewhere. On your desktop machine, the browser program is loaded from the hard disk. The computer has some RAM (random-access memory) where it can store "variables." And the computer has some input and output devices so it can talk to people. On your desktop machine, the keyboard and mouse are input devices and the monitor and printer are output devices. A hard disk is an I/O device -- it handles both input and output. The desktop computer you are using is a "general purpose computer" that can run any of thousands of programs. Microcontrollers are "special purpose computers." Microcontrollers do one thing well. There are a number of other common characteristics that define microcontrollers. If a computer matches a majority of these characteristics, then you can call it a "microcontroller": Microcontrollers are "embedded" inside some other device (often a consumer product) so that they can control the features or actions of the product. Another name for a microcontroller, therefore, is "embedded controller." Microcontrollers are dedicated to one task and run one specific program. The program is stored in ROM (read-only memory) and generally does not change. Microcontrollers are often low-power devices. A desktop computer is almost always plugged into a wall socket and might consume 50 watts of electricity. A batteryoperated microcontroller might consume 50 milliwatts. A microcontroller has a dedicated input device and often (but not always) has a small LED or LCD display for output. A microcontroller also takes input from the device it is controlling and controls the device by sending signals to different components in the device. For example, the microcontroller inside a TV takes input from the remote control and displays output on the TV screen. The controller controls the channel selector, the speaker system and certain adjustments on the picture tube electronics such as tint and brightness. The engine controller in a car takes input from sensors such as the oxygen and knock sensors and controls things like fuel mix and spark plug timing. A microwave oven controller takes input from a keypad, displays output on an LCD display and controls a relay that turns the microwave generator on and off. A microcontroller is often small and low cost. The components are chosen to minimize size and to be as inexpensive as possible. A microcontroller is often, but not always, ruggedized in some way. The microcontroller controlling a car's engine, for example, has to work in temperature extremes that a normal computer generally cannot handle. A car's microcontroller in Alaska has to work fine in -30 degree F (-34 C) weather, while the same microcontroller in Nevada might be operating at 120 degrees F (49 C). When you add the heat naturally generated by the engine, the temperature can go as high as 150 or 180 degrees F (65-80 C) in the engine compartment. On the other hand, a microcontroller embedded inside a VCR hasn't been ruggedized at all. The actual processor used to implement a microcontroller can vary widely. For example, the cell phone shown on Inside a Digital Cell Phone contains a Z-80 processor. The Z-80 is an 8-bit microprocessor developed in the 1970s and originally used in home computers of the time. The Garmin GPS shown in How GPS Receivers Work contains a low-power version of the Intel 80386, I am told. The 80386 was originally used in desktop computers. In many products, such as microwave ovens, the demand on the CPU is fairly low and price is an important consideration. In these cases, manufacturers turn to dedicated microcontroller chips -- chips that were originally designed to be low-cost, small, low-power, embedded CPUs. The Motorola 6811 and Intel 8051 are both good examples of such chips. There is also a line of popular controllers called "PIC microcontrollers" created by a company called Microchip. By today's standards, these CPUs are incredibly minimalistic; but they are extremely inexpensive when purchased in large quantities and can often meet the needs of a device's designer with just one chip.

1 de 8

a connection for a programming cable. then you will find that the BASIC used in a Stamp is straightforward but a little stripped-down.read serial data on an input pin serout . However. you don't need Microsoft Word to control a microwave oven.read a potentiometer on an I/O pin pulsin . Using Microcontrollers In How Electronic Gates Work. . The device is called a "BASIC Stamp" and is created by a company called Parallax. go to Parallax: BASIC Stamp Documentation. but in the process you will accumulate everything you need to play with microcontrollers for years to come.go to a subroutine goto .assignment (optional) return .send a pulse of a specific duration out on an output pin pwm ." by the way. The DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates microcontroller chip can be purchased on a small carrier board that accepts a 9-volt battery.normal if/then decision let . because they are about as big as a postage stamp. in the digital clock article. But then. In this article.normal looping statement gosub .set the direction of an I/O pin to output pot .g.return from a subroutine end . we will use a microcontroller to create a digital clock. but you do know another language like C.reverse the direction of an I/O pin serin .set the direction of an I/O pin to input low . Here is a quick rundown on the instructions available in Stamp BASIC.then . If you already know BASIC.000 bytes of ROM and 20 bytes of RAM on the chip.write serial data on an output pin sound . If you don't know BASIC. The specific BASIC Stamp we will be using in this article is called the "BASIC Stamp Revision D".. a power regulator.Microsoft Word requires perhaps 30 megabytes of RAM and a processor that can run millions of instructions per second. They are called "Stamps.A typical low-end microcontroller chip might have 1.a small program you write and execute on the controller -. Even if you don't actually create this digital clock. a rather expensive digital clock (almost $200!). In large quantities. You certainly are never going to run Microsoft Word on such a chip -. the cost of these chips can sometimes be just pennies. you learned about 7400-series TTL devices. you have one specific task you are trying to accomplish. The microcontroller we will use here is a special-purpose device designed to make life as simple as possible. along with eight I/0 pins.. DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates Programming the BASIC Stamp You program a BASIC Stamp using the BASIC programming language.) Standard BASIC instructions: for. then picking up BASIC will be trivial. For example.read a button on an input pin. One of the big advantages of a microcontroller is that software -. (For complete documentation.next .."label:") if.send a sound of a specific frequency to an output pin 2 de 8 . you probably want to go learn programming on a desktop machine first. The BASIC Stamp Revision D is a BS-1 mounted on carrier board with a 9-volt battery holder. You can see from the previous table that you aren't going to be doing anything exotic with a BASIC stamp. The 75-line limit (the 256 bytes of EEPROM can hold a BASIC program about 75 lines long) for the BS-1 is fairly constraining.set an I/O pin high input . and low-cost.. However. What you found is that it can often take many gates to implement simple devices. low-power performance is what is important.set an I/O pin low output . The use of the BASIC language makes it extremely easy to create software for the controller. A BASIC Stamp is a PIC microcontroller that has been customized to understand the BASIC programming language. as well as where to buy them and how to assemble them. the clock we designed might contain 15 or 20 chips. With a microcontroller. and you can program it by plugging it into one of the ports on your desktop computer. If you have never programmed before.can take the place of many gates. It is unlikely that any manufacturer would use a BASIC Stamp in an actual production device -. The Revision D simply makes life easier. Pascal or Java. with debounce and auto-repeat high .end the program and sleep Instructions having to do with I/O pins: button .goto a label in the program (e. This is going to be A BASIC Stamp is a PIC microcontroller that has been customized to understand the BASIC programming language. therefore. it is quite common to use Stamps for prototyping or for one-off demo products because they are so incredibly easy to set up and use.perform pulse width modulation on an output pin reverse . you will learn a great deal by reading about it. you can create some pretty neat stuff. header pins for the I/O lines and a small prototyping area. either. You could buy a BS-1 chip and wire the other components in on a breadboard.read the duration of a pulse coming in on an input pin pulsout . and the fact that the Stamp is so small and battery operated means that it can go almost anywhere.Stamps are expensive and slow (relatively speaking).

w6 . w0 and b0/b1 are the same locations in RAM.XOR &/ . a book like Scott Edward's Programming and Customizing the BASIC Stamp Computer can be extremely helpful because of the example projects it contains.8-bit byte variables bit0. w2.you can send bits out on any pin from 0 to 7. 3 de 8 ...NOR ^/ . See the documentation for the language for details. Remember that there are only 14 bytes of RAM available.OR ^ . b1.toggle . and w1 and b2/b3 are the same.. w1.delay for the specified time random .power down for the specified time write .. LOW sends a 0 (Ground).multiplication (high-word) / .b13 .NAND |/ . and so on. POT reads the setting on a potentiometer (variable resistor) if you wire it up with a capacitor as the POT instruction expects. Here are the standard names: w0.multiplication (low-word) ** . b2. The pins are bi-directional. bit2.return the index of a value in a list lookup . The statement high 3 sends a 1 (+5 volts) out on pin 3. There are eight pins on the BS-1 (numbered 0 to 7) and 16 pins on the BS-2 (numbered 0 to 15). Also. The reason for this emphasis is the fact that the I/O pins are the only way for the BASIC Stamp to talk to the world.addition .read a branching table debug .division // .AND | .read a value from EEPROM sleep .XNOR If statement logic: = <> < <= > >= AND OR Variables All variables in the BS-1 have pre-defined names (which you can substitute with names of your own).. Pin 3 was chosen arbitrarily here -.toggle the bit on an output pin Instructions specific to the BASIC Stamp: branch .bit15 . meaning that you can read input values on them or send output values to them.write data to EEPROM Operations: + . bit0 through bit15 reside in w0 (and therefore b0/b1 as well)..array lookup using an index nap .pick a random number read .download a program to EEPROM lookdown ..subtraction * . Instructions like these can make it a lot easier to attach controls and motors to the Stamp. Also. bit1.1-bit bit variables Because there are only 14 bytes of memory.send a debugging string to the console on the desktop computer eeprom .16-bit word variables b0. For example. The PWM instruction sends out pulse-width modulated signals. so variables are precious.sleep for a short time pause . The easiest way to send a value to a pin is to use the HIGH or LOW functions.return minimum of 2 values & .mod max .return maximum of 2 values min . I/O pins You can see that 14 of the instructions in the BS-1 have to do with the I/O pins. There are a number of interesting I/O pin instructions.

From Parallax. Obviously. the program produces a square wave on I/O pin 3. For a clock. so only one I/O pin is needed. it's very easy to get started. You could wire four of the I/O pins straight into a 7447 and easily display a number between 0 and 9. The approach is called multiplexing the display. Let's say that we would like to use the I/O pins on the BASIC Stamp to display numeric values. What you would probably like to do is create something useful with your BASIC stamp. Since the BS-1 Stamp has eight I/O pins. a programming cable. mounted on a breadboard for easier interfacing: This sort of LCD has several advantages: The display can be driven by a single I/O pin. a standard way to control LED displays. If you hook up a logic probe or LED to pin 3 (see the electronic gates article for details). The editor application checks the BASIC A screenshot of a typical BASIC program editor program and then sends it down the wire to the EEPROM on the Stamp. In this case. if you have an old LED calculator. While this approach works fine for clocks and calculators. By wiring things slightly differently. DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates Creating a Really Expensive Digital Clock Spending $79 to flash an LED may seem extravagant to you. turn it on and shake it while watching the display. In addition. Then you run a DOS application to edit your BASIC program and download it to the Stamp. you could actually do this with only one 7447. In the digital clock article. The following diagram shows you one approach: In this diagram. The LCD can display alphanumeric text: letters. you would not embed one 4 de 8 . What you need is a desktop computer and a BASIC Stamp starter kit. By spending about $100 more you can create a really nice digital clock! This may seem extremely extravagant. The LCD consumes very little power -. An alternative approach is to use an LCD screen. you hit ALT-R. we need a minimum of four digits. By using a 74154 demultiplexer chip and some drivers. The only problem is that one of these displays costs $59. You could save power by shortening the time that the LED is on (perhaps it is on for 50 milliseconds and off for 450 milliseconds). You connect it into the parallel port of your PC. Parallax runs a special called "We've Bagged the Basics" that also includes Scott Edward's Programming and Customizing the BASIC Stamp Computer]. so talking to the display is simple. software and instructions. 7447s would work just as well with the BASIC Stamp. You can get a starter kit either from Parallax (the manufacturer) or from a supplier like Jameco (who should be familiar to you from the electronic gates and digital clock articles). The display contains logic that lets a Stamp communicate with it serially. Occasionally. you could drive up to 16 digits using this approach. You will actually be able to see that only one digit is ever illuminated at once. For example. Then the other four lines from the Stamp activate the 7447s in DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates sequence ("E" on the chips means "Enable" -. or from Jameco you can order part number 140089. To drive four 7447s with eight I/O pins. you will see the LED flash on and off twice per second (it changes state every 250 milliseconds because of the PAUSE commands). The Stamp then executes the program. As it turns out. that would be the blanking input on pin 5).Playing with a BASIC Stamp If you would like to play with a BASIC Stamp. To make this arrangement work. numbers and even custom characters. the SEROUT command in Stamp BASIC handles serial communication easily. You will receive the Stamp (pictured below). the eight I/O lines from the Stamp enter from the left. The starter kit includes the Stamp. we saw how to interface to a 7-segment LED display using a 7447 chip. To run the program in this editor.only 3 milliamps. Hooking up the Stamp is easy. A typical display is shown here. it is easy to drive two 7447s directly like this. This is. a programming cable and an application that you run on your desktop computer to download BASIC programs into the Stamp. it has two important problems: LEDs consume a lot of power. LCDs are widely available and can be easily hooked to a Stamp. Then it would send out the value for the second digit and activate the second 7447. we have to be slightly more creative. This program would run for several weeks off of a 9-volt battery. This approach uses four lines that run to all four 7447s. the two-line by 16-character alphanumeric display shown below is available from both Jameco (part number 150990) and Parallax (part number 27910). until you realize that the parts are reusable in a variety of other projects that you may want to build later.on a 7447. sequencing through all four of the 7447s like this repeatedly. the BASIC program in the Stamp would output the first digit on the four data lines and activate the first 7447 by toggling its E pin with the first control line. you can order the BASIC Stamp D Starter Kit (part number 27202). 7-segment LEDs can only display numeric values. For example. The kit is $79 from both suppliers. in fact. and also by using the NAP instruction instead of PAUSE.

A real-time clock chip uses a quartz crystal to give it excellent accuracy. n2400. This component costs about $30 -. Then. The sequence (254. however. the SEROUT commands send data to the LCD. The Pocket Watch B is available from both Jameco (part number 145630) and Parallax (part number 27962).again. Pin 3 on the DS1620 is the reset/select pin. The sequence (254. Hooking up the DS1620 to the Stamp is very easy. To drive a display like this. Pocket Watch B Module Building a Digital Thermometer Now that you understand a little bit about your Stamp and the LCD. it is assumed that: 5 de 8 . every second or so. Obviously. One easy way to interface a real-time clock to a stamp is to use a component called the Pocket Watch B. You read and write data bits on this pin. The EEPROM remembers the current mode as well as the set temperatures for the thermostat. but easy to play with when constructing prototypes. ("time:") 'Paint "time:" on the display 'preset before loading program b0 = 0 'seconds b1 = 27 'minutes b2 = 6 'hours again: b0 = b0 + 1 if b0 < 60 then minutes b0 = 0 b1 = b1 + 1 minutes: if b1 < 60 then hours b1 = 0 b2 = b2 + 1 hours: if b2 < 13 then show b2 = 1 'increment seconds 'if seconds=60 ' then increment minutes 'if minutes=60 ' then increment hours 'if hours=13 reset to 1 show: serout 0. The easiest way I have found to connect the Stamp's I/O pins to a device like an LCD is to use a wire-wrap tool (Jameco part number 34577) and 30-gauge wire wrap wire (Jameco part number 22541 is typical). one good approach would be to wire a real-time clock chip up to your Stamp. you would likely prototype with one of these displays and then create custom chips and software to drive much cheaper LCDs in the final product. If you were designing a toaster oven. If you want better accuracy. That way. 135) 'position cursor on display. you can read the time from the chip and display it. #b1. Supply ground to pin 4 of the DS1620. You set pin 3 high to select the chip and communicate with it. This chip contains: A temperature-sensing device An analog-to-digital (A/D) converter for the temperature-sensing device A shift register to read the data out of the A/D converter A little EEPROM (electrically erasable programmable read-only memory) to remember settings The DS1620 has two modes: In one mode. you simply supply it with +5 volts and ground (the Stamp supplies both from the 9-volt battery) and then hook one of the I/O pins from the Stamp to the display's input line. (254. (254. 1) 'clear the display serout 0. How Java Works Boolean Logic Electronic Gates Pin 2 on the DS1620 is the clock pin. #b0. you preset the time before you download the program to the Stamp.of these in a toaster oven. The following BASIC program will cause a BASIC Stamp to behave like a clock and output the time on the LCD (assuming the LCD is connected to I/O pin 0 on the Stamp): pause 1000 'wait for LCD display to boot serout 0. Supply +5 volts from the Stamp to pin 8 of the DS1620. we will use a chip called the DS1620. n2400. 135) positions the cursor. The DS1620 comes in an 8-pin chip. we can add another component and create a digital thermometer. This part is about as big as a quarter and contains the clock chip. it acts as a stand-alone thermostat chip. (#b2. not something you want to embed in a toaster oven. By tweaking the PAUSE statement you can get the accuracy to within a few seconds a day. This approach will create a reasonably accurate clock. ":". Clock chips also usually contain date information and handle leap year correction automatically. ":". 'then display time serout 0. 1) clears the LCD (254 is the escape character and 1 is the command to clear the screen). To create a thermometer. crystal and a serial interface so that only one I/O pin is necessary to communicate with it. The other two SEROUT commands simply send text strings to the display. You then use three I/O pins from the Stamp to drive three pins on the DS1620: DIGITAL LOGIC Pin 1 on the DS1620 is the data pin. no soldering is involved and the connections are compact and reliable.in this program. n2400. in a real clock you would like to wire up a push-button or two to make setting it easier -. " ") pause 950 'pause 950 milliseconds goto again 'repeat In this program. it is not incredibly accurate. You clock data in and out of the shift register with this pin. n2400. While this approach is simple and works. and in the other mode you hook it up to a computer and use it as a thermometer. For this example code.

n2400. some good documentation and sample code. The reset/select pin goes to I/O pin 0 on the Stamp. low CLK ' ask 1620 for next bit bit8 = DQ_PIN ' read the bit high CLK ' toggle clock pin next return ' Displays the temperature in degrees C display: if bit8 = 0 then pos ' if bit8=1 ' then temp is negative b0 = b0 &/ b0 ' invert b0 by NANDing it ' with itself b0 = b0 + 1 pos: serout LCD. You can assemble the DS1620 in the prototype area of the Stamp carrier board or on a separate breadboard. The completed wiring looks like this: You can get a DS1620 either from Jameco (part number 146456) or Parallax (part number 27917) in an "application kit" that includes the chip. The clock pin goes to I/O pin 1 on the Stamp. Once you have assembled it. hook your LCD display up to I/O pin 3 of the Stamp. the capacitor. 1) ' clear the LCD serout LCD. gosub display ' display the temp in degrees C pause 1000 ' wait a second goto main_loop ' The shift_out subroutine sends whatever is in ' the b0 byte to the 1620 shift_out: output DQ ' set the DQ pin to ' output mode for b2 = 1 to 8 low CLK ' prepare to clock the bit ' into 1620 DQ_PIN = bit0 ' Send the data bit high CLK ' latch data bit into 1620 b0 = b0/2 ' shift all bits right ' toward bit 0 next return ' The shift_in subroutine gets a 9-bit ' temperature from the 1620 shift_in: input DQ ' set the DQ pin to ' input mode w0 = 0 ' clear w0 for b5 = 1 to 9 w0 = w0/2 ' shift input right.The data pin goes to I/O pin 2 on the Stamp. ("Temp = ") ' display "Temp=" ' on the display bit9 = bit0 ' save the half degree b0 = b0 / 2 ' convert to degrees if bit8 = 1 then neg ' see if temp is negative serout LCD. I would suggest getting the application kit the first time you try using the DS1620 because the documentation is very useful. #b0)' display negative temp half: if bit9 = 0 then even serout LCD.reads and displays temperature every second main_loop: high RST ' select the 1620 b0 = $AA ' $AA is the 1620 command byte ' for reading temperature gosub shift_out ' send it to the 1620 gosub shift_in ' read the temperature ' from the 1620 low RST ' deselect the DS1620. (254. n2400. Or you can buy the chip on its own from Jameco (part number 114382). (". n2400. ("-".5 C") ' display the half degree goto done 6 de 8 . (#b0) ' display positive temp goto half neg: serout LCD. n2400. and then load and run the following program: symbol symbol symbol symbol symbol RST = 0 ' select/reset line on 1620 CLK = 1 ' clock line for shift registers on 1620 DQ = 2 ' data line on 1620 DQ_PIN = pin2 ' pin representation for DQ LCD = 3 ' data line for LCD ' deselect the 1620 unless talking to it ' clock pin on 1620 should default high ' wait for the thermometer and LCD to boot select the 1620 $0c is the 1620 command byte saying "Write Config" send it to the 1620 %10 is the 1620 command byte to set thermometer mode send it to the 1620 deselect the 1620 delay 50ms for EEPROM $EE is the 1620 command byte to start conversions select the 1620 send it to the 1620 deselect the 1620 begin: low RST high CLK pause 1000 setup: high RST b0 = $0C ' ' ' gosub shift_out ' b0 = %10 ' ' gosub shift_out ' low RST ' pause 50 ' start_convert: b0 = $EE ' ' high RST ' gosub shift_out ' low RST ' ' This is the main loop ' . n2400.

Remember that the w0 (16-bit) variable overlays the b0/b1 (8-bit) variables. it sends a command to the DS1620 telling the DS1620 to return the current temperature.$EE is 238 in decimal) to tell the thermometer to start up its conversion process. you can invert the bits and add 1 to get the positive representation of the number. what you are doing is shifting each bit to the right to store the 9-bit temperature from the DS1620 into w0. Here's what goes on with the digital thermometer program shown here: 1. Once the temperature has been saved in w0. The following list shows the values for a 4-bit 2s-complement number: 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 : : : : : : : : : : : : : : : : 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 You can see that instead of the 4 bits representing values from 0 to 15. The conversion from degrees C to degrees F is: dF = dC * 9/5 + 32 At this point. useful devices like this that you can build with a Stamp now that you know how microcontrollers work! For more information on microcontrollers and related topics. The program sends the command $EE ("$" means "hexadecimal number" -. you only have to do it once. 4... What might you do with it? Here's one idea. 3. The program then enters a loop. you will find that it displays the centigrade temperature with an accuracy of one-half degree. It writes a command byte to the EEPROM on the DS1620 to tell the chip to operate in "thermometer mode. It uses the symbol keyword to set up several constants that make the program slightly easier to read (and also make it easy for you to move the chip to different I/O pins on the Stamp). 2s-complement binary numbers are a convenient way to represent negative values." It contains a low-power 8-kilobyte (or optionally 32-kilobyte) RAM chip with a serial interface. Every second. You can look at the left-most bit to determine if the number is negative or positive. The DS1620 measures temperatures in centigrade half-degrees. check out the links on the next page. ("./bit15 (1-bit) variables. It sets the CLK and RST pins on the DS1620 to their expected values. The RAM module would contain the temperature history of the entire trip and you would know whether or not the drugs ever thawed out. and then it reads the 9-bit value that the DS1620 returns into the w0 variable.0 C") ' display the half degree done: return If you run this program. If the number is negative. 2. It returns the temperature in a 9-bit 2s-complement number with a range of -110 to 250 F (-55 to 125 C). There are all kinds of neat. Both Jameco (part number 143811) and Parallax (part number 27960) sell a device called the "RAM Pack module. DIGITAL LOGIC How Java Works Boolean Logic Electronic Gates Lots More Information Related Articles How Boolean Logic Works How Electronic Gates Work How Digital Clocks Work How Bits and Bytes Work How Java Works How LEDs Work How LCDs Work BASIC Stamp Links Parallax: BASIC Stamp Documentation Acroname: Interfacing a Sharp GP2D02 to a Basic Stamp II Dontronics: Basic Stamp Page PIC Links Spread Spectrum Scene: PIC Stuff PIC Microprocessor Sites 7 de 8 ." Because the mode is stored in EEPROM. You divide the number you receive by 2 to get the actual temperature. so you could technically take this section of the code out of the program after you run the program once (to save program space). The Stamp sends and receives data 1 bit at a time by toggling the CLK line on the DS1620. the 4 bits in a 2s-complement number represent the values -8 to 7. which overlay the bit0/bit1/.even: serout LCD. You could then slip your Stamp into the drug shipment. we have succeeded in creating an extremely expensive thermometer. What you can do with a Stamp is create a data logging thermometer. and at the other end of the trip retrieve the Stamp. You could add this component (or something similar) to your Stamp and write code that saves temperature readings to the RAM every minute. Let's say you work for a drug company and you are shipping expensive drugs across the country that MUST remain at a certain temperature the entire way or the drugs will spoil. the display subroutine determines whether the number is positive or negative and displays it appropriately on the LCD as a centigrade temperature. so when you insert a bit from the DS1620 into bit 8 and divide w0 by 2. n2400.

lots of good information on the 8052 microcontroller Embedded Linux Journal 8 de 8 .FAQs Microcontroller FAQ BASIC Stamp FAQ 8051 microcontroller FAQ 68HC11 microcontroller FAQ Other Links The 8052 Online Resource .