Building a Digital Temperature Monitor Using AT89C51ED2-RLTUM Microcontroller
by cashcc in Circuits > Electronics
2 Views, 0 Favorites, 0 Comments
Building a Digital Temperature Monitor Using AT89C51ED2-RLTUM Microcontroller
The AT89C51ED2-RLTUM is a powerful 8-bit microcontroller from Atmel (now part of Microchip), based on the 8051 architecture. It offers enhanced features compared to standard 8051 microcontrollers, including higher speed (up to 60 MHz), more memory, and additional peripherals, making it a suitable choice for a wide range of embedded applications.
In this project, we will design a Digital Temperature Monitoring System using the AT89C51ED2-RLTUM microcontroller. The system will read temperature data from a DS18B20 digital temperature sensor and display the temperature on a 16x2 LCD screen. The project will help you learn how to interface a microcontroller with a digital sensor, display data on an LCD, and build a simple embedded system.
Supplies
- AT89C51ED2-RLTUM Microcontroller
- DS18B20 Digital Temperature Sensor
- 16x2 LCD Display (compatible with HD44780 controller)
- 10kΩ Resistor (for the DS18B20 sensor)
- Capacitors (e.g., 33pF for microcontroller stability)
- Breadboard and Jumper Wires
- Power Supply (5V for microcontroller and components)
- Push-button (for resetting the system)
- Crystal Oscillator (e.g., 11.0592 MHz for microcontroller clock)
- Microcontroller Programmer (e.g., USB to parallel programmer)
System Design
1. Microcontroller Pin Configuration
The AT89C51ED2-RLTUM is a 40-pin microcontroller with several general-purpose I/O pins, memory, and communication interfaces. For this project, we'll use the following pins:
- P1.0-P1.7: General-purpose I/O pins for interfacing with the LCD and DS18B20 sensor.
- P0.0-P0.7: These pins can be used for debugging or additional I/O functions, but we'll use them minimally in this project.
- Reset Pin: Connected to a capacitor and resistor network for proper initialization.
2. DS18B20 Temperature Sensor Interface
The DS18B20 sensor uses the 1-Wire communication protocol, which means it only requires a single data line to communicate with the microcontroller. The DS18B20 will be connected as follows:
- Vcc: 5V from the power supply.
- GND: Ground.
- Data: Connected to a GPIO pin of the AT89C51ED2, say P1.0.
- A 10kΩ pull-up resistor will be connected between the Data line and Vcc to ensure proper signal levels during communication.
3. 16x2 LCD Display Interface
The 16x2 LCD is a common display module used in embedded projects. It communicates with the microcontroller using the 4-bit mode, which means only 4 data lines are required (RS, RW, E, and D4-D7). The LCD will be connected as follows:
- RS: Connected to P1.1.
- RW: Connected to ground (write-only mode).
- E: Connected to P1.2.
- D4-D7: Connected to P1.3 to P1.6 for sending data.
Circuit Diagram
Below is the circuit diagram for this project:
+5V
|
-----------------------
| |
DS18B20 Sensor LCD 16x2 Display
Vcc ----- 5V Vcc ----- 5V
GND ----- GND GND ----- GND
Data ----- P1.0 RS ----- P1.1
RW ----- GND
E ----- P1.2
D4 ----- P1.3
D5 ----- P1.4
D6 ----- P1.5
D7 ----- P1.6
4. Powering the System
The system is powered by a 5V DC supply. Ensure that all components are rated for 5V to avoid damage. The microcontroller will use an 11.0592 MHz crystal oscillator for the clock signal, and a 33pF capacitor will be placed across the crystal leads to stabilize the clock frequency.
Firmware Development
1. Initialization
- LCD Initialization: Configure the 16x2 LCD in 4-bit mode by sending initialization commands.
- DS18B20 Initialization: Start communication with the DS18B20 by sending a reset pulse and reading the device’s ROM code.
2. Temperature Reading
The temperature data from the DS18B20 sensor is obtained in two steps:
- Start Conversion: The microcontroller sends a command to the DS18B20 to begin measuring the temperature.
- Read Data: After a short delay, the microcontroller reads the 16-bit temperature data and processes it into a human-readable format (e.g., Celsius).
3. LCD Display
The LCD will display the measured temperature value in Celsius. The firmware will convert the raw temperature data from the DS18B20 to a suitable format and display it on the LCD screen. If the temperature exceeds a certain threshold, an alert message can be displayed.
4. Code Example
#include <reg51.h>
#include <stdio.h>
#include "lcd.h"
#include "ds18b20.h"
void main(void) {
char temperature[16];
// Initialize LCD
lcd_init();
// Initialize DS18B20
ds18b20_init();
while (1) {
// Start temperature conversion
ds18b20_start_conversion();
// Wait for conversion to complete
delay_ms(1000);
// Read temperature from DS18B20
int temp = ds18b20_read_temperature();
// Convert the integer temperature to a string
sprintf(temperature, "Temp: %d C", temp);
// Display temperature on LCD
lcd_clear();
lcd_print(temperature);
delay_ms(500); // Update every half-second
}
}
Key Functions:
- lcd_init(): Initializes the LCD to 4-bit mode.
- lcd_print(): Prints the given string to the LCD.
- ds18b20_init(): Initializes the DS18B20 sensor.
- ds18b20_start_conversion(): Initiates a temperature measurement on the DS18B20.
- ds18b20_read_temperature(): Reads the temperature data from the DS18B20 sensor.
5. Delay Function
void delay_ms(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 120; j++) {
// Empty loop for delay
}
}
}
Testing the System
- Connect the Components: Ensure all components (microcontroller, LCD, DS18B20 sensor) are properly wired according to the schematic.
- Program the Microcontroller: Use a programmer to upload the firmware to the AT89C51ED2-RLTUM microcontroller.
- Power the System: Provide a 5V DC power supply to the circuit.
- Observe Output: The LCD should display the current temperature value read from the DS18B20 sensor.
Conclusion
In this project, we built a Digital Temperature Monitor using the AT89C51ED2-RLTUM microcontroller. We interfaced a DS18B20 digital temperature sensor with the microcontroller using the 1-Wire protocol and displayed the temperature on a 16x2 LCD screen. This project demonstrates the capability of the AT89C51ED2 microcontroller to handle sensor data, interface with peripherals, and display information in real-time. This setup can be expanded with additional sensors, alerts, or even a network interface for remote monitoring, making it a valuable foundation for embedded systems and IoT projects.