Introduction
Analog-to-Digital Converters (ADC) are essential components in embedded systems that interact with real-world signals such as temperature, pressure, and light intensity. The 8051 microcontroller does not have a built-in ADC, so external ADCs such as the ADC0804, ADC0808, or ADC1210 are commonly used. This article focuses on interfacing an 8-bit ADC (ADC0804) with the 8051 microcontroller and demonstrates how to read analog signals and convert them into digital form.
Overview of ADC0804
ADC0804 is an 8-bit ADC that converts an analog input voltage (0-5V) into a digital equivalent. It uses successive approximation to perform conversion and requires an external clock signal. The converted data is available on an 8-bit parallel output.
Key Features of ADC0804:
- 8-bit resolution
- Single-channel input
- Conversion time of approximately 100 µs at a clock frequency of 640 kHz
- Requires an external clock
- Uses a reference voltage for precise conversion
Circuit Diagram and Interfacing
Components Required:
- 8051 microcontroller (AT89C51)
- ADC0804
- Potentiometer (for analog input simulation)
- 10kΩ resistors
- 10μF capacitor
- Crystal oscillator (11.0592 MHz)
- Breadboard and connecting wires
Pin Configuration of ADC0804:
Pin | Name | Description |
---|---|---|
1 | CS | Chip Select (Active Low) |
2 | RD | Read Data (Active Low) |
3 | WR | Write (Active Low, starts conversion) |
4 | CLK IN | External Clock Input |
5 | IN+ | Analog Input (+) |
6 | IN- | Analog Input (-) |
7 | VREF/2 | Reference Voltage |
8 | GND | Ground |
9-16 | D0-D7 | Digital Output |
17 | INTR | Interrupt (Goes low after conversion) |
18 | VCC | Power Supply (5V) |
19 | CLK R | External Clock Resistor |
20 | NC | No Connection |
Interfacing Connections:
8051 Pin | ADC0804 Pin |
P3.0 (CS) | 1 (CS) |
P3.1 (RD) | 2 (RD) |
P3.2 (WR) | 3 (WR) |
P3.3 (INTR) | 17 (INTR) |
P1.0 – P1.7 | D0 – D7 (Data Pins) |
GND | 8 (GND) |
VCC (5V) | 18 (VCC) |
Potentiometer Output | 5 (IN+) |
GND | 6 (IN-) |
Working Principle
- The potentiometer provides a variable analog voltage input to the ADC.
- The ADC0804 receives the analog input and converts it to an 8-bit digital value.
- The conversion starts when the WR pin goes low.
- When the conversion is complete, the INTR pin goes low to indicate data readiness.
- The microcontroller reads the digital output from ADC0804 via Port 1.
Code Implementation
The following C code demonstrates how to interface ADC0804 with the 8051 microcontroller using the Keil compiler:
#include <reg51.h>
#define ADC_DATA P1 // ADC Data Port
sbit CS = P3^0; // Chip Select
sbit RD = P3^1; // Read
sbit WR = P3^2; // Write
sbit INTR = P3^3; // Interrupt
void delay(unsigned int time) {
unsigned int i, j;
for (i = 0; i < time; i++)
for (j = 0; j < 1275; j++);
}
unsigned char read_ADC() {
unsigned char value;
WR = 0; // Start conversion
delay(1);
WR = 1;
while (INTR == 1); // Wait for conversion complete
RD = 0; // Enable reading
value = ADC_DATA; // Read digital value
RD = 1;
return value;
}
void main() {
unsigned char adc_value;
ADC_DATA = 0xFF; // Configure Port 1 as input
CS = 0; // Enable ADC
RD = 1;
WR = 1;
INTR = 1;
while (1) {
adc_value = read_ADC(); // Read ADC value
delay(500); // Small delay
}
}
Explanation of Code:
- ADC Interfacing: The data pins are connected to Port 1, and control signals (CS, RD, WR, and INTR) are assigned to Port 3.
- Reading ADC Data:
WR
is set low to start conversion.- The microcontroller waits for the
INTR
pin to go low, signaling conversion completion. - The digital output is read from Port 1.
- Loop Execution: The
read_ADC
function is called repeatedly to read analog values and store them.
Testing and Output
After uploading the program to the 8051 microcontroller, varying the potentiometer should produce different digital values that can be displayed using an LCD or transmitted via UART for monitoring.
Applications of ADC Interfacing with 8051
- Temperature sensing using LM35 sensor
- Light intensity measurement using LDR
- Sound level monitoring using a microphone
- Real-time monitoring systems