Saturday, June 13, 2020

AT89C52 interfaces to a one wire DS18B20 digital thermometer

DS18X20 One-Wire Digital Temperature Sensor

DS1820 series is series of digital temperature sensor developed by Maxim Integrated. It uses one wire protocol. The master MCU accesses only one digital pin working in both direction. The slave ds18b20 has only three pins, two pins are supply voltage and one other is the data pin.

AT89C52 interfaces to a one wire DS18B20 digital thermometer


AT89C52 interfaces to a one wire DS18B20 digital thermometer
Two ds18b20 package I possess. 


AT89C52 interfaces to a one wire DS18B20 digital thermometer
DS18B20 TO-92 package. VDD and GND
are supply voltage. DQ is digital data pin.

The DS18B20 is one of its family. It could sample the temperature data between -55 to +125 degree Celsius.
The physical packages are available in TO-92, SMD and a probe-type. 
The temperature data is made of two 8-bit wide register giving a 16-bit temperature data. But it contain five signed bits. Temperature data has a 7-bit decimal and 4-bit fraction numbers.

AT89C52 interfaces to a one wire DS18B20 digital thermometer
S is signed indication

For full technical specification I can not show the full detail here. We can see the full specification from the datasheet. For programming example, we can get it from the application note done by the manufacturer. 

We can use multiple one wire devices on a single pin. Each device is identified by its 64-bit ROM ID.
Typically we need a pull-up resistor with a resistance between 4.7 k to 10 k Ohm depend on the data rate.

Programming in MikroC

MikroC is also available for 8051 devices family. It contains an extensive software and hardware libraries.
One wire library supports both ds18b20 and ds18s20. In MikroC it's called oneWire library. It contains some functions:
  • Ow_Reset
  • Ow_Read
  • Ow_Write
We need these three functions to access to the one wire devices.
In this example, I use AT89C52 to read the temperature data from a ds18b20 and display it to the multiplexed SSD.

AT89C52 interfaces to a one wire DS18B20 digital thermometer
AT89C52 CPU clocks at 24 MHz. Display is connected to P2 and P3. A single ds18b20
is connected to P1.2.

MikroC source code:


AT89C52 interfaces to a one wire DS18B20 digital thermometer
A negative temperature reading of -12.8 degree Celsius.


Click here to download this example.

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)