您现在的位置是:首页 > 传感器

12-Bit Thermometer Using an 8-

2020-03-02 02:09:13

12-Bit Thermometer Using an 8-Bit µC and Assembler

This applicaTIon note explains how to implement a 12-bit digital thermometer using a low-cost, 8-bit microcontroller (µC) and the MPASM free assembler. The thermometer displays temperature in the range of 0°C to 70°C with ±1°C accuracy (Figure 1). Typical applicaTIons include process-control fabs, hospitals, and food-storage areas.

Figure 1. With an assembly-language routine and the free assembler, this circuit allows an 8-bit ?C to implement a 12-bit digital thermometer.
Figure 1. With an assembly-language rouTIne and the free assembler, this circuit allows an 8-bit µC to implement a 12-bit digital thermometer.

U1 is a low-cost, 8-bit flash µC with only 35 instrucTIons. Unlike more expensive, multiply-friendly 16-bit µCs, this one has no multiply, divide, or even 16-bit math instructions. The result is a more challenging implementation of the thermometer! The µC (U1) receives a serial data word (Kcode) from the temperature sensor (U3). Using the following equations, it then converts Kcode to a binary representation of the temperature in degrees Celsius:

K = Kcode x 0.125, where K = temperature in degrees Kelvin.

°C = K - 273, where °C = degrees Celsius.

Table 1 shows the data as it appears after each of five steps in the conversion process, using the decimal-equivalent number 2384 as an example for Kcode. The first step reads both halves of the Kcode value from U3 (high byte and low byte), and stores that data in separate 8-bit file registers. The second step aligns the Kcode data by rotating the bits in both 8-bit file registers two places to the right, checking the carry flag each time to properly shift the LSB of the high byte to the MSB of the low byte. The third step multiplies Kcode by 0.125. Multiplying by 0.125 is a bit complicated, but the equivalent operation of division by 8 is much easier. Because 8 is the third power of 2, division by 8 can be accomplished (with our limited instruction set) by three consecutive right shifts.

To convert to degrees Celsius, the fourth step subtracts 273 from the Kelvin temperature K. Eight-bit arithmetic, however, supports integers only to 255. Because 273 exceeds the 8-bit boundary, a code routine for 16-bit subtraction was used to produce a binary representation of the temperature in degrees Celsius.

To take full advantage of the BCD register map internal to U2, the last (fifth) step converts the binary representation of temperature in degrees Celsius to the BCD data format. A 16-bit routine for binary-to-BCD conversion allows temperature to be displayed using the LED display driver U2.

An assembly-language program for the µC is can be downloaded from the Maxim website.

Table 1. Five steps allow an 8-bit µC to support 12-bit temperature data and display it.

µC's 8-bit File Register #1 (high byte)
Top