8051 – ADC0808 Interfacing

We had already seen ADC0804 Interfacing in our previous tutorial. So this Tutorial is all about ADC0808 Interfacing with 8051.

Suggestion to read

Introduction

In embedded systems microcontrollers needs to take analog input. Most of the sensors & transducers such as temperature, humidity, pressure, are analog. For interfacing these sensors to microcontrollers we require to convert the analog output of these sensors to digital so that the controller can read it. Some microcontrollers have built-in Analog to Digital Convertor (ADC) so there is no need for external ADC. For microcontrollers that don’t have internal ADC external ADC is used.

Why we are using ADC for 8051 Microcontroller?

Well. 8051 doesn’t have an inbuilt ADC. So we have to use external ADC. There are many ADCs available.

  • ADC 0804

  • ADC 0808

ADC0808

One of the most commonly used ADC is ADC0808. ADC 0808 is a Successive approximation type with 8 channels i.e. it can directly access 8 single-ended analog signals. The difference between ADC0804 and ADC0808 is the number of analog input signals. I mean, In ADC0804 we can give only one analog input. But in ADC0808 we can give 8 analog inputs. So if you want to interface more analog sensors, please select ADC0808.

ADC0808 is an 8 bit analog to digital converter with eight input analog channels, i.e., it can take eight different analog inputs. The input which is to be converted to digital form can be selected by using three address lines. The voltage reference can be set using the Vref+ and Vref- pins. The step size is decided based on the set reference value. Step size is the change in analog input to cause a unit change in the output of ADC. The default step size is 19.53mV corresponding to 5V reference voltage. ADC0808 needs an external clock to operate, unlike ADC0804 which has an internal clock. The ADC needs some specific control signals for its operations like start conversion and brings data to output pins. When the conversion is complete the EOC pins go low to indicate the end of conversion and data ready to be picked up.

Features

  • Easy interface to all microprocessors
  • Operates ratio metrically or with 5 V DC or analog span adjusted voltage reference
  • No zero or full-scale adjust required
  • 8-channel multiplexer with address logic
  • 0V to 5V input range with single 5V power supply
  • Outputs meet TTL voltage level specifications
  • Standard hermetic or molded 28-pin DIP package
  • 28-pin molded chip carrier package

Pin Diagram

Pin Description

 Pin NoFunctionName
1Analog Input Pin 3IN3
2Analog Input Pin 4IN4
3Analog Input Pin 5IN5
4Analog Input Pin 6IN6
5Analog Input Pin 7IN7
6Start conversion; input pin; a low to high pulse is givenSTART
7End of conversion; output pin; goes low when the conversion is overEOC
8Digital output bitD3
9Input pin; a low to high pulse brings data to output pins from the internal registers at end of conversionOutput Enable
10Clock input; to provide external clockClock Input
11Supply voltage; 5VVcc
12Positive reference voltageVref+
13Ground (0v)GND
14Digital output bitD1
15Digital output bitD2
16Negative reference voltageVref-
17Digital output bitD0
18Digital output bitD4
19Digital output bitD5
20Digital output bitD6
21Digital output bitD7
22Address latch enable; Input pin; low to high pulse is required to latch in the addressALE
23Address line CAddress C
24Address line BAddress B
25Address line AAddress A
26Analog Input Pin 0IN0
27Analog Input Pin 1IN1
28Analog Input Pin 2IN2

Selection of Channel

We can select any input channel by using the Address lines ADD A, ADD B and ADD C). We can select the input line IN0 by keeping all three address lines (ADD A, ADD B, and ADD C) Low. If we want to select input channel IN4 then we need to keep ADD A, ADD B low and ADD C high. For selecting all the other input channels, have a look on the given table:

ADC Channel NameADD CADD BADD A
IN0LOW
LOW
LOW
IN1LOW
LOW
HIGH
IN2LOW
HIGHLOW
IN3LOW
HIGHHIGH
IN4HIGHLOW
LOW
IN5HIGHLOW
HIGH
IN6HIGHHIGHLOW
IN7HIGHHIGHHIGH

Calculating Step Size

ADC 0808 is an 8 bit ADC i.e. it divides the voltage applied at Vref+ & Vref- into 28 i.e. 256 steps.

Step Size = (Vref+ - Vref-)/256

Suppose Vref+ is connected to Vcc i.e. 5V & Vref- is connected to the Gnd then the step size will be

Step size= (5 - 0)/256= 19.53 mv

How to use the ADC0808?

  1. Start
  2. Select the channel.
  3. A Low – High transition on ALE to latch in the address.
  4. A Low – High transition on Start to reset the ADC’s SAR.
  5. A High – Low transition on ALE.
  6. A High – Low transition on start to start the conversion.
  7. Wait for the End of cycle (EOC) pin to become high.
  8. Make Output Enable pin High.
  9. Take Data from the ADC’s output
  10. Make Output Enable pin Low.
  11. Stop

ADC0808 interfacing with 8051

Circuit Diagram

In this tutorial, I’m going to connect the PotentioMeter (Variable Resistor) instead of the real sensor. You can connect the real sensor to Hardware.

LCD:

  • RS  – P1.0
  • RW  – GND
  • EN  – P1.1
  • LCD Data Lines – P1 LSB 4 bits

ADC:

  • Output Enable    –  P2.0
  • EOC                      –  P2.1
  • Start                      –  P2.2
  • Addr A                  –  P2.4
  • Addr B                  –  P2.5
  • Addr C                  –  P2.6
  • ALE                       –  P2.7
  • ADC Data lines   – Po

adc0808 interface with 8051

Code

You can download the entire project here.

#include<reg51.h>

#define adc_data P0
#define lcd    P1

unsigned char temp, gas;

sbit rs=P1^0;
sbit en=P1^1;

sbit OE     =P2^0;
sbit EOC    =P2^1;
sbit START  =P2^2;
sbit AA     =P2^4;
sbit BB     =P2^5;
sbit CC     =P2^6;
sbit ALE    =P2^7;

unsigned char adc_val;

void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay();

unsigned char adc(unsigned int ch);
void ch_sel(unsigned int sel);

void  main()
{
    lcd_init();
    show("TEMP: ");
    cmd(0xc0);
    show("GAS : ");
    while(1) {
        cmd(0x86);
        temp=adc(0);                 //Reading Value from ADC Channel 0
        dat((temp/100)%10 +0x30);
        dat((temp/10)%10 +0x30);
        dat(temp%10 +0x30);
        
        cmd(0xc6);
        gas=adc(1);                 //Reading Value from ADC Channel 1
        dat((gas/100)%10 +0x30);
        dat((gas/10)%10 +0x30);
        dat(gas%10 +0x30);
    }
}

void lcd_init()
{
    cmd(0x02);
    cmd(0x28);
    cmd(0x0e);
    cmd(0x06);
    cmd(0x80);
}

void cmd(unsigned char a)
{
    rs=0; 
    lcd&=0x0F;
    P1|=(a&0xf0);
    en=1;
    lcd_delay();
    en=0;
    lcd_delay();
    lcd&=0x0f;
    lcd|=(a<<4&0xf0);
    en=1;
    lcd_delay();
    en=0;
    lcd_delay();
}

void dat(unsigned char b)
{
    rs=1; 
    lcd&=0x0F;
    lcd|=(b&0xf0);
    en=1;
    lcd_delay();
    en=0;
    lcd_delay();
    lcd&=0x0f;
    lcd|=(b<<4&0xf0);
    en=1;
    lcd_delay();
    en=0;
    lcd_delay();
}

void show(unsigned char *s)
{
    while(*s) {
        dat(*s++);
    }
}

void lcd_delay()
{
    unsigned int lcd_delay;
    for(lcd_delay=0;lcd_delay<=1000;lcd_delay++);
}

unsigned char adc(unsigned int ch)
{
    adc_data=0xff;

    ALE=START=OE=AA=BB=CC=0;
    EOC=1;

    ch_sel(ch);

    ALE=1;
    START=1;
    ALE=0;
    START=0;
    while(EOC==1);
    while(EOC==0);
    OE=1;
    adc_val=adc_data;
    OE=0;
    return adc_val;
}

void ch_sel(unsigned int sel)
{
    switch(sel) {
        case 0: CC=0;BB=0;AA=0; break;          //000
        case 1: CC=0;BB=0;AA=1; break;          //001
        case 2: CC=0;BB=1;AA=0; break;          //010
        case 3: CC=0;BB=1;AA=1; break;          //011
        case 4: CC=1;BB=0;AA=0; break;          //100
        case 5: CC=1;BB=0;AA=1; break;          //101
        case 6: CC=1;BB=1;AA=0; break;          //110
        case 7: CC=1;BB=1;AA=1; break;          //111
    }
}

Output – ADC0808 interfacing with 8051

ADC0808 interfacing with 8051[ Please find the output image Here ]

 

In our next tutorial, we will see an Ultrasonic sensor interfacing with the 8051.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials - STM32Zephyr RTOS Tutorials - ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Table of Contents