Analog to Digital converter (ADC) interfacing with Microcontrollers tutorial: Programming AVR for ADC0804 free 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 AVR Microcontroller

►AVR Assembly Programming for ADC0804

CODE:
.include "8515def.inc"

.equ rd = PORTB0           ;Read signal PortB.0
.equ wr = PORTB1           ;Write Signal PortB.1
.equ cs = PORTB2           ;Chip Select PortB.2
.equ intr = PORTB3         ;INTR signal PortB.3
.equ adc_port = PINA       ;ADC data pins PortA
.def adc_val = r16         ;To store ADC value
.def temp = r17            ;Temporary register

.org 0x00
start:
        ldi temp,low(RAMEND)   ;Load stack with
        out SPL,temp           ;RAMEND - highest value
        ldi temp,high(RAMEND)  ;of internal SRAM
        out SPH,temp

        sbi DDRB,rd            ;Make RD as o/p
        sbi DDRB,wr            ;Make WR as o/p
        sbi DDRB,cs            ;Make CS as o/p
again:
        rcall conv             ;Start ADC Conversion
        rcall read             ;Read ADC conversion
        ldi temp,0xFF
        out DDRC,temp          ;Make PORTC as o/p Port
        out PORTC,adc_val      ;Move the read value to PORT C
        rjmp again             ;Do it again

conv:                      ;Start conversion
        cbi PORTB,cs           ;Make CS low
        cbi PORTB,wr           ;Make WR low
        nop
        sbi PORTB,wr           ;Make WR high
        sbi PORTB,cs           ;Make CS high
wait:
        sbic PINB,intr         ;Wait for INTR signal
        rjmp wait

        ret                    ;Conversion done
       
read:                      ;Read ADC
        cbi PORTB,cs           ;Make CS low
        cbi PORTB,rd           ;Make RD low

        in adc_val,adc_port    ;Read ADC data

        sbi PORTB,rd           ;Make RD high
        sbi PORTB,cs           ;Make CS high
        ret                    ;Reading done
 




►Programming AVR in C for ADC0804

CODE:
#include <avr/io.h>#define adc_port PINA                    //ADC data pins PORTA
#define rd PB0                           //Read signal PORTB0
#define wr PB1                           //Write signal PORTB1
#define cs PB2                           //Chip Select PORTB2
#define intr PB3                         //INTR signal PORTB3

void conv();                             //Start Conversion
void read();                             //Read ADC value

unsigned char adc_val;

int main(){
        DDRB = (1<<rd)|(1<<wr)|(1<<cs);      //RD, WR, CS as output
        DDRC = 0xFF;                         //PORTC as output
        PORTC = 0xFF;
        while(1){                            //Forever loop
                conv();                          //Start of conversion
                read();                          //Read converted ADC
                PORTC = adc_val;                 //Move it to PORTC
        }
        return 0;
}


void conv(){
        PORTB = PORTB & (~((1<<cs)|(1<<wr))); //Make CS and WR low
        PORTB = PORTB | ((1<<cs)|(1<<wr));    //Make CS and WR high
        while(PINB&(1<<intr));                //Wait for INTR signal
}

void read(){
        PORTB = PORTB & ( ~((1<<cs)|(1<<rd))); //Make RD and CS low
        adc_val = adc_port;                    //Read ADC port
        PORTB = PORTB | ((1<<cs)|(1<<rd));     //Make RD and CS high
}
       



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


◄ Previous Page  |  Next Page ►

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