8051 Microcontroller ADC Interfacing

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:

PinNameDescription
1CSChip Select (Active Low)
2RDRead Data (Active Low)
3WRWrite (Active Low, starts conversion)
4CLK INExternal Clock Input
5IN+Analog Input (+)
6IN-Analog Input (-)
7VREF/2Reference Voltage
8GNDGround
9-16D0-D7Digital Output
17INTRInterrupt (Goes low after conversion)
18VCCPower Supply (5V)
19CLK RExternal Clock Resistor
20NCNo Connection

Interfacing Connections:

8051 PinADC0804 Pin
P3.0 (CS)1 (CS)
P3.1 (RD)2 (RD)
P3.2 (WR)3 (WR)
P3.3 (INTR)17 (INTR)
P1.0 – P1.7D0 – D7 (Data Pins)
GND8 (GND)
VCC (5V)18 (VCC)
Potentiometer Output5 (IN+)
GND6 (IN-)

Working Principle

  1. The potentiometer provides a variable analog voltage input to the ADC.
  2. The ADC0804 receives the analog input and converts it to an 8-bit digital value.
  3. The conversion starts when the WR pin goes low.
  4. When the conversion is complete, the INTR pin goes low to indicate data readiness.
  5. 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:

  1. ADC Interfacing: The data pins are connected to Port 1, and control signals (CS, RD, WR, and INTR) are assigned to Port 3.
  2. 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.
  3. 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
Categories: Uncategorized