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

AD converter....

Discussion in 'Microcontrollers' started by just angel, May 24, 2003.

  1. just angel

    just angel New Member

    Joined:
    Apr 26, 2003
    Messages:
    7
    Likes:
    0
    Location:
    -----------------
    Hello every body... Hope you all are in good health...

    I have these codes and I need an explanation of it...(line by line)....

    can any ony anwer my question?

    This is the program, it is for converting A/D for 8-bits:

    --------------------------------------------------------------------------------------

    ' PicBasic Pro program to display result of
    ' 8-bit A/D conversion on LCD
    '
    ' Connect analog input to channel-0 (RA0)

    ' Define LCD registers and bits
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1

    adval VAR BYTE ' Create adval to store result


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000010 ' Set PORTA analog and LEFT justify result
    ADCON0 = %11000001 ' Configure and turn on A/D Module
    Pause 500 ' Wait .5 second


    loop: ADCON0.2 = 1 ' Start Conversion

    notdone: Pause 5
    IF ADCON0.2 = 1 Then notdone ' Wait for low on bit-2 of ADCON0, conversion finished

    adval = ADRESH ' Move high byte of result to adval

    LCDOut $fe, 1 ' Clear screen
    LCDOut "Value: ", DEC adval ' Display the decimal value

    Pause 100 ' Wait .1 second

    GoTo loop ' Do it forever
    End
     

Share This Page