10 bit ADC display on LCD using 16f873


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Default 10 bit ADC display on LCD using 16f873

    I have written a code for ADC conversion from 0-5v, but seem not to work. Can someone help me where I am wrong. Here is the code attached is the circuit diagram Cheers

    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 3
    Define LCD_EREG PORTB
    Define LCD_EBIT 2
    Define LCD_EBITS 4
    Define LCD_LINES 2

    ' Initialise ADC
    ADCON1 = %10000100 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %01000001 ' Configure and turn on A/D Module channel o Fosc 8
    'Pause 500 ' wait .5 second
    'Declear variables
    val VAR WORD 'final calculated adc valuesWORD' final calculated adc values
    volt VAR WORD ' scaled value real part
    voltd1 VAR WORD ' scaled value first decimal place
    voltd2 VAR WORD ' scaled value second decimal place
    i var byte ' counter
    '************************************************* ******************
    ' Main program code
    Start:
    GoSub ADC
    pause 500
    GoTo Start
    '************************************************* *****************
    ADC
    Val = 0 ' Value returned is the average of 5 conversions
    For i = 0 TO 4
    ADCON0.2 = 1 ' Start convertion
    NoteDone:
    pause 1
    IF ADCON0.2 = 1 Then NoteDone
    val = val + ((ADRESH * 256)+(ADRESL))
    nEXT I
    VAL = VAL/5
    ' Calculate Volatage to 2 decimal places
    volt = val * 5/1024
    voltd1 = ( val * 5//1024) * 10/1024
    Voltd2 = ((val *5 //1024) * 10//1024) * 10/1024

    LCDOut $FE,$C0, # Val, "=", #volt, ".", # voltd1, # voltd2, "Vdc"
    Return
    Attached Images Attached Images  

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hi pr2don,

    Looks like a few typos and omissions

    Your defines:

    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 3
    Define LCD_EREG PORTB
    Define LCD_EBIT 2
    Define LCD_EBITS 4
    Define LCD_LINES 2

    Try changing your defines to these

    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 3
    Define LCD_EREG PORTB
    Define LCD_EBIT 2
    Define LCD_BITS 4
    Define LCD_LINES 2
    Define LCD_COMMANDUS 2000
    Define LCD_DATAUS 50

    Also on your subroutine "ADC" you need to add a colon after ADC:

    Hope this helps

  3. #3


    Did you find this post helpful? Yes | No

    Default

    pr2don

    Are you using pic basic pro or pic basic? No LCDout command in pic basic. If using pic basic pro, look up the "adcin" command

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    You might want to initialize the LCD too.

    Code:
    PAUSE 500 : LCDOUT $FE,1 : PAUSE 250 ; Initialize LCD (You may not need this,
                                         ;  but some displays are picky)

Similar Threads

  1. LCD Display
    By lambert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th January 2010, 22:18
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. assembly in Pic
    By lerameur in forum Off Topic
    Replies: 11
    Last Post: - 1st May 2008, 20:06
  4. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56
  5. Need help with 16f819 10 bit ADC
    By bannrikae in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th September 2005, 15:20

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts