termometr


A Digital Thermometer Using the
AT89C2051 Microcontroller
AT89C2051
and handles the newline character by
Introduction
advancing the cursor to the beginning of
Flash
The system presented in this application
the next line.
note implements a simple digital ther-
PositionLcd simply sets the cursor
Microcontroller
mometer that includes a built-in LCD and
address to the value specified by the
RS-485 communication port. It is
caller. The ClearLcd function is used to
designed around Atmel s AT89C2051
clear the entire LCD and home the cur-
processor, a DS1620 digital thermome-
Application
sor.
ter/thermostat from Dallas Semiconduc-
tor, a small 8 X 2 LED backlit LCD, and The functions that follow concern them-
Note
an RS485 line interface. The system, selves with actual physical communica-
shown in Figure 1, can be used as the tion to the LCD. Since there is not a
basis for developing custom solutions for direct correspondence between the
networked and stand alone data collec- LSI s data RAM and the LCD s physical
tion and control equipment. It can be mapping, it is necessary to keep watch
centrally powered due to its low current for certain boundary conditions. When a
requirement and its small size allows it to boundary is encountered, the cursor
be placed almost anywhere. must be repositioned in order to keep the
output contiguous. Since all displayable
data must pass through DataWr, it
Software
makes sense to contain the corrective
The LCD driver is written entirely in C
actions here. To handle this problem,
and compiles under Micro-C (from Dun-
keep track of the logical cursor position
field Development Systems) using the
and invoke a remedial maneuver when-
tiny memory model. Although a canoni-
ever discontinuity may occur. There are
cal stack-based implementation, Micro-C
two ways you can accomplish this:
includes a number of special features
" Read the LCD s status register (to get
that make it quite suitable for generating
the cursor address) or
ROMable code for small systems. The
" Keep a local copy just for your
overhead incurred performing stack
reference.
manipulations is made up by the library
functions that are all hand coded in an Not wanting to waste a pin to control the
highly optimized assembler. As an LCD s read/write line (it runs in write-only
added benefit, Micro-C comes with fully mode), the latter approach was adopted.
documented library source code so spe- Here, the global register (IRAM actually)
cial modifications can be made as cir- variable Cursor is used for this purpose.
cumstances arise. Cursor is consulted prior to any data
write operation. If a correction is neces-
The first few functions contained in the
sary, a new cursor address is generated
LCD driver module are conventional C
and dispatched to the LCD control regis-
library implementations. PutString dis-
ter via CommandWr.
plays a null terminated string by merely
passing characters off to PutChar until a Following this, DataWr splits the data
null byte is encountered. PutChar out- byte into nibbles (remember the LCD
0597A-B 12/97
puts a character at a time to the LCD operates using a 4-bit bus) and falls
5-59
through to handle the actual physical transfer. Using Micro- nated by pulling \RST low which forces DQ into a high
C s extended preprocessor allows bit manipulation macros impedance state and concludes the transfer. Temperature
that expand directly to 8051 SETB and CLR instructions. data is transmitted over the 3-wire bus in lsb first format. A
Here, clearing DRS selects the LCD s data register and total of nine bits are transmitted where the most significant
DEN is toggled to generate the data strobe. CommandWr bit is the sign bit. If all nine bits are not of interest, the trans-
operates similarly but does not have to deal with any cursor fer can be terminated at any time by asserting \RST.
entanglements. It selects the command register as its desti-
The DS1620 support routines are coded in assembly. The
nation by setting DRS high prior to clocking the nibbles
DS1620 also has nonvolatile EEPROM configuration regis-
across the interface.
ters that hold thermostatic and operational control informa-
The initialization function InitLcd begins at a more rudimen- tion. TempConfig is hardcoded to set the mode for opera-
tary nibble oriented level since no assumption can be made tion under CPU control and continuous temperature con-
as to the operational status of the LCD at this time. The first version. Once in continuous conversion mode, the actual
three sequences ensure that the transfer mode is set to conversion process is started by issuing the start conver-
operate over a 4-bit bus. Repeating the sequence three sion command through TempConvert. Now the DS1620
times ensures that the command will be recognized regard- can be read at any time and the last temperature conver-
less of the operational mode of the LSI. (It is wise to make sion that was performed will be returned. This is accom-
no assumptions when performing any low-level initializa- plished by calling TempRead. The result is returned in the
tion.) Following this, the actual operating parameters are 16 bit accumulator as defined by Micro-C consisting of the
transferred to the LCD using the standard CommandWr B (msb) and ACC (lsb) registers.
function. Software for this application note may be down-
loaded from Atmel s Web Site or BBS.
Mainline Glue
Coordination of the support drivers is managed by the main
Digital Temperature
module. This module takes control after the Micro-C startup
Temperature acquisition is handled using the DS1620 ther- routine finishes. On entry, the code initializes the serial
mometer/thermostat IC from Dallas Semiconductor. The port, instructs the DS1620 to start performing temperature
DS1620 contains all temperature measurement and signal conversions, initializes the LCD, displays a log on mes-
conditioning circuitry on-chip and presents the processor sage, and enters into an endless loop. This loop continu-
with a 3-wire digital interface composed of a bi-directional ously reads the DS1620, performs a Celsius to Fahrenheit
data line DQ, a reset input \RST, and a clock input CLK. conversion, translates the resulting binary number to an
The temperature reading is provided in a 9 bit, two s com- ASCII string, and displays the conversion result on the
plement format. The measurement range spans from -55°C LCD. Periodically the code falls through and toggles an
to +125°C in .5°C increments. LED and transmits the temperature data serially.
Data transfers into and out of the DS1620 are initiated by The Celsius to Fahrenheit conversion is performed using
driving \RST high. Once the DS1620 s reset is released, a the familiar equation: F = C * 9/5 + 32. Since the DS1620
series of clock pulses is emitted by the processor to actu- returns temperature in .5°C increments the value is first
ally transfer the data. For transmission to the DS1620, data divided by 2. Unlike the often impenetrable gyrations that
must be valid during the rising edge of the clock pulse. result when working with numbers in assembler, the C rep-
Data bits received by the processor are output on the fall- resentation of this calculation is perfectly clear in intent and
ing edge of the clock and remain valid through the rising function. A short sequence of divisions, modulos, and logi-
edge. Taking the clock high results in DQ assuming a high cal OR operations results in decimal ASCII values that
impedance state. The sequence can be immediately termi- make up the output string.
5-60 Microcontroller
Microcontroller
5-61


Wyszukiwarka

Podobne podstrony:
Termometr z termoparami J lub K(AVT918)
Termometr
NE035 TERMOMETR CYFROWY 20°C÷ 99°C LEDICLq07
Termometr elektroniczny Thermocont TC 01a
J 202 Mikroprocesorowy termometr regulator
termomiks instrukcjatermomix
4 Termometr cyfrowy – dioda półprzewodnikowa ochładzanie w azocie, śr 205,883
zegar ze stuletnim kalendarzem dwukanałowym termometrem cz 2
Termometr dynamiczny
Termometry
4 Termometr cyfrowy – dioda półprzewodnikowa kalib 0
Termometr pokojowy z lampami NIXIE
czterokanałowy termometr cyfrowy
[ATMEGA8] Cyfrowy termometr i kalkulator
Termometr cyfrowy z wyświetlaczem LCD

więcej podobnych podstron