1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

interfacing ADC0808 with 89C51

Discussion in 'Microcontrollers' started by mnoman, Jun 29, 2006.

  1. SHAHIDATIQ

    SHAHIDATIQ New Member

    Joined:
    Apr 10, 2007
    Messages:
    1
    Likes:
    0
    code to interface 0808 with 89c51 and display result on LCD

    I used port 1 of 89c51 to read data from 0808 and port3 to display data at LCD.The assembly code is:

    ;;;;======================== LCD================================:
    ; :
    ;PORT 3 is used for 8bit data :
    ; p3.7 is used as busy flag :
    ; p2.0 for RS select to select command or DATA register :
    ; P2.1 for R/W :
    ; P2.2 E to Enable latch :
    ; :
    ;;;;============================================================:


    ;;;;========================= ADC ==============================:

    ; PORT 1 for 8bit data ;
    ; P 2.7 EOC intrupt to UC that conversion is complete ;
    ; P 2.6 SC to start conversion ;
    ; P 2.5 OE for read operation to get converted data for ADC toUC;
    ; p 2.4 for ALE ;
    ; p 0.0,p0.1,p0.2 for chanel selection ;
    ; ;
    ;===============================================================;

    org 0

    BEGIN:
    mov A,#38h ;initialie 2 line LCD
    ACALL command
    mov A,#0ch ;LCD on cursor off
    ACALL command
    mov A,#01h ;clear LCD
    ACALL command
    mov A,#06h ;Shift cursor right
    ACALL command
    mov A,#'V'
    ACALL DISPLY
    mov A,#'O'
    ACALL DISPLY
    mov A,#'L'
    ACALL DISPLY
    mov A,#'T'
    ACALL DISPLY
    mov A,#'A'
    ACALL DISPLY
    mov A,#'G'
    ACALL DISPLY
    mov A,#'E'
    ACALL DISPLY
    mov A,#'='
    ACALL DISPLY

    ACALL ADC

    ACALL BINTOASC



    ;;;;;;;;;;;;;;;;;;;;;DISPLAY ASCII NUMBERS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    mov A,#06h ;Shift cursor right
    ACALL command
    mov A,34h ;Disply MSb of ASCII
    ACALL DISPLY
    mov A,#06h ;Shift cursor right
    ACALL command
    mov A,33h ;Display middle ASCII
    ACALL DISPLY
    mov A,#06h ;Shift cursor right
    ACALL command
    mov A,32h ;DISPLAY LSb ASCII
    ACALL DISPLY
    mov A,#'m'
    ACALL DISPLY
    mov A,#'V'
    ACALL DISPLY
    jmp BEGIN ;Jump to the top repeat the whole process

    ;;;;;;;;;;;;;;;;;;;TO INIALIZE LCD BY;;;;;;;;;;;;;;;;;;;

    command:
    ACALL READY ;Is LCD ready
    mov p3,A ;Issu command
    clr p2.0 ;RS=0 for comand instruction
    clr p2.1 ;R/W=0 to write LCD
    setb p2.2 ;H->L for to latch information in at data lines
    clr p2.2
    ret

    ;;;;;;;;;;;;;;;;;;TO DISPLAY USER DATA;;;;;;;;;;;;;;;;;;;;;

    DISPLY:
    ACALL READY
    mov p3,A ;Issu data
    setb p2.0 ;RS=1 for data
    clr p2.1 ;R/W=0 to write LCD
    setb p2.2 ;H->L for to latch information in at data lines
    clr p2.2
    ret

    ;;;;;;;;;;;;;;;;;TO CHECH LCD READY TO RECIEVE DATA TO SHOW;;;;;;;;;;;;;;;;;;;;;;;;;

    READY:
    setb p3.7
    clr p2.0 ;RS=0 for command register
    setb p2.1 ;R/W=1 to read command register
    BACK:
    clr p2.2 ;H->L to latch the data
    setb p2.2
    jb p3.7,BACK ;Busy flag(P1.7)=1 indicates LCD is not ready to recieve data
    ret

    ;;;;;;;;;;;;;;;;;;;;;;;;;;READS ADC DATA;;;;;;;;;;;;;;;;;;;;;;


    ADC:
    mov p0,#0fFh
    clr p0.0 ;Address 000 to select chanel 0
    clr p0.1
    clr p0.2
    clr p2.4 ;L->H for ALE enable
    setb p2.4
    setb p2.6 ;SC=1->0
    clr p2.6 ;H->L to start conversion
    WAIT:
    JB p2.7,WAIT ;Wait for end of conversion EOC
    setb p2.5 ;OE 1->0 to enable output from ADC
    clr p2.5
    mov A,p1 ;Read data
    MOV 35H,A

    setb p2.5 ;To disable read to start next conversion
    setb p2.7
    ret

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BINARY TO ASCII CONVERSION;;;;;;;;;;;;;;;

    BINTOASC:

    mov A,35h ;Input from ADC
    mov B,#10 ;Divide by 10
    div AB
    mov r0,B ;Move remainder into R0
    mov B,#10
    div AB ;Divide quatient by 10
    mov r1,b ;Move remainder in R1
    mov r2,A ;Move quatient in R2
    mov A,r1 ;Move second BBCD in A
    swap A
    orl A,r0 ;OR 3rd & 2nd BCD to form compact BCD
    mov 30h,A ;Saves 2nd&3rd BCD at RAM location 30h
    mov 31h,r2 ;Saves 1st BCD at RAM location 31h

    ;;;;;;;;;;;;;;;;;;;;;;;;;;CONVERTION FROM BCD TO ASCII;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    mov A,30h ;Takes 2nd&3rd BCD from RAM location 30h
    ANL A,#0fh ;Mask the upper NIBBLE
    orl A,#30h ;Convert lower nibble in ASCII
    mov 32h,A ;Save MSb ASCII at RAM location 32H
    mov A,30h ;Move BCD into A from RAM location 30H
    anl A,#0f0h ;Mask lower NIBBLE of BCD
    swap A ;Interchange lower and higher NIBBLE
    orl A,#30h ;Convert it in ASCII
    mov 33h,A ;Save 2nd ASCII at RAM location 33H
    mov A,31h ;Takes 1st BCD from RAM location 31H
    anl A,#0fh ;Masks upper nibble
    orl A,#30h ;COnvert into ASCII
    mov 34h,A ;Saves MSb ASCII at RAM location 34H
    ret
    end
     
  2. predator

    predator New Member

    Joined:
    Mar 17, 2009
    Messages:
    2
    Likes:
    0
    Hey Shahidatiq
    Wil U Plzz PoSt D Ckt Diagram
     
    Last edited: Mar 17, 2009
  3. predator

    predator New Member

    Joined:
    Mar 17, 2009
    Messages:
    2
    Likes:
    0
    I TRIED TAT TESTING DIAGRAM OF ADC 0808.MY LED'S WERE CONTINUOSLY GLOWIN EVEN IF I CHANGEd D ANALOG INPUT
     

Share This Page