skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: 8051 Tools Development Board Example Code Temperature

PJRC Store
8051 Board, $79
LCD 128x64 Pixel, $29
LCD 16x2 Char, $14
Serial Cable, $5
9 Volt Power, $6
More Components...
8051 Tools
Main Page
Development Board
Code Library
89C2051 Programmer
Other Resources

Using 1-Wire Temperature Sensors

Dallas Semiconductor (owned by Maxim Integrated Products) makes several 1-wire temperature sensors, and other devices using their "1 wire" communication protocol. This page shows how to interface some of these temperature sensors to the 8051 development board.

Photo: Temperature Sensors
Figure 1: DS18S20, DS18B20 and DS1822 Temperature Sensors

Connections To Port Pins

Even though they are called "one wire", you can see in the photo these sensors actually have 3 wires, where 2 are power and ground. You must connect at least the ground and signal lines. The power line is optional.

The easiest approach is to connect all 3 wires, so the sensor gets +5 volt power on its power pin. Then all that is necessary is a 4.7k pullup resistor on the signal line, and of course connecting the signal to a port pin (P1.7 for the example code below).

Figure 2: Connection With Normal Power

It is also possible to not use the power pin, and the sensor will get its power from the signal pin. However, the 4.7k resistor is not able to power the sensor while it makes the measurement. The standard 8051 port pins provide only a weak pullup, so a PNP transistor is needed to apply a strong pullup to the signal pin during the measurement. In the example code, this transistor is controlled by pin P1.6.

Figure 3: Connection With "Parasite" Power

If the sensor is used a long distance from the board, connecting 2 wires instead of 3 can be nice. However, if you are having difficulty getting the sensor to work, the 3 wire connection is a lot simpler and easier than using a PNP transistor.

Example Code

Figure 4: Screenshot, Running The Example Program

8051 Development System Circuit Board, Paul Stoffregen
Last updated: September 11, 2008
Status: work in progress, more info to come
Suggestions, comments, criticisms: <>