Analog to Digital converter (ADC) interfacing with Microcontrollers tutorial: Programming 8051 for ADC0804 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
ADC interfacing with Microcontrollers: Programming for ADC0804


►Programming 8051 Microcontroller

►8051 Assembly Programming for ADC0804

CODE:
        rd equ P1.0           ;Read signal P1.0
        wr equ P1.1           ;Write signal P1.1
        cs equ P1.2           ;Chip Select P1.2
        intr equ P1.3         ;INTR signal P1.3

        adc_port equ P2       ;ADC data pins P2
        adc_val equ 30H       ;ADC read value stored here

        org 0H
start:                    ;Start of Program
        acall conv            ;Start ADC conversion
        acall read            ;Read converted value
        mov P3,adc_val        ;Move the value to Port 3
        sjmp start            ;Do it again

conv:                     ;Start of Conversion
        clr cs                ;Make CS low
        clr wr                ;Make WR Low
        nop
        setb wr               ;Make WR High
        setb cs               ;Make CS high
wait:
        jb intr,wait          ;Wait for INTR signal
        ret                   ;Conversion done

read:                     ;Read ADC value
        clr cs                ;Make CS Low
        clr rd                ;Make RD Low
        mov a,adc_port        ;Read the converted value
        mov adc_val,a         ;Store it in local variable
        setb rd               ;Make RD High
        setb cs               ;Make CS High
        ret                   ;Reading done
 




►Programming 8051 in C for ADC0804

CODE:
#include <REGX51.H>#define adc_port P2              //ADC Port
#define rd P1_0                  //Read signal P1.0
#define wr P1_1                  //Write signal P1.1
#define cs P1_2                  //Chip Select P1.2
#define intr P1_3                //INTR signal P1.3

void conv();                     //Start of conversion function
void read();                     //Read ADC function

unsigned char adc_val;

void main(){
        while(1){                    //Forever loop
                conv();                  //Start conversion
                read();                  //Read ADC
                P3 = adc_val;            //Send the read value to P3
        }
}

void conv(){
        cs = 0;                      //Make CS low
        wr = 0;                      //Make WR low
        wr = 1;                      //Make WR high
        cs = 1;                      //Make CS high
        while(intr);                 //Wait for INTR to go low
}

void read(){
        cs = 0;                      //Make CS low
        rd = 0;                      //Make RD low
        adc_val = adc_port;          //Read ADC port
        rd = 1;                      //Make RD high
        cs = 1;                      //Make CS high
}
 



The next section of the tutorial will cover the programming of 8051 for ADC0804.


◄ Previous Page  |  Next Page ►

Back to Index


ADC Interfacing Tutorial Index
Introduction to ADC
AVR Programming for ADC0804
ADC0804 Interfacing
8051 Programming for ADC0804


Google Search for Microcontrollers!

Google
 

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems