PIC16F877A adc help


Closed Thread
Results 1 to 4 of 4
  1. #1
    CuE0079's Avatar
    CuE0079 Guest

    Default PIC16F877A adc help

    hello i am new to the pic chip and i want to read the value of a potentiometer using an adc. i use the picbasic compiler and a detailed explanation of the circuit or schematics would be very helpful. i tried the pot command but it never worked for me. i follwed this schemtatic for it http://www.microengineeringlabs.com/...mages/pot.gif. i never was sure where the third leg of the pot went. anyway i would really appreciate it if someone helped me read values from the pot using the adc or pot command. thx.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Connect your Pot (say 10K as a reasonable value) between Vss (0v) for the bottom end of the Pot, and Vdd (5v) for the top end of the Pot. The wiper of the Pot connects directly to your chosen PIC pin (in my example below it's RA0/AN0). See ADCIN command in PBP manual for further information also reference with the PIC's Datasheet. LCD defines not shown - add appropriately.

    MyVar var Byte
    CMCON=%00000111
    ' see Datasheet 12.1
    ADCON0=%11000001
    ' see Datasheet 11.1
    ADCON1=%00001110
    ' see Datasheet 11.2
    TRISA=%00000001 ' Set RA0/AN0 to Input
    Pause 1000 ' Wait for LCD to Initialise
    LCDOut $FE,1 ' Clear Screen
    Loop:
    ADCIN 0,MyVar ' Get Value
    LCDOut $FE,$80,DEC3 MyVar ' Overwrite with New Value
    Pause 100
    Goto Loop

    Note, my example ONLY defines RA0/AN0 pin as ADC Analogue. If you want to add further pins, change TRISA and ADCON1 appropriately.

    Melanie

  3. #3
    CuE0079's Avatar
    CuE0079 Guest


    Did you find this post helpful? Yes | No

    Default

    sorry i dont hav PBP just the regular pic basic compiler. i'll try to see if i can convert it but it would be very helpful if someone could show me the syntax in picbasic.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There's a perfect example with detailed comments provided for you...

    http://www.melabs.com/resources/samples/x1/pbc/adcx.bas

    ...it reads an ADC and sends the result to a Serial port.

    Work through it... compare the setting of each register against the PIC's Datasheet... if you have any questions then come back and we'll all see what we can do to help.

    Melanie

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 1

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