16F819 config for A/D


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Location
    Lancashire
    Posts
    50

    Default 16F819 config for A/D

    Hi All
    Not used this PIC before, trying to read a voltage on AN0 pin17 but get the same result on my serial out for any input, 5235. I suspect I`ve either miss configured a register or missed one altogether. My test code is as follows, anything obvious?. Running 8mHz, a LED flashes OK at correct intervals as far as I can tell.
    Cheers Pete

    CODE:

    #CONFIG
    __config _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _WRT_ENABLE_1536 & _DEBUG_OFF & _CP_ALL

    #ENDCONFIG

    'Set PIC register defaults

    OPTION_REG.7=0 ' enable pull-ups on port B

    OSCCON = %01110000 ' Internal 8 MHz osc

    TRISA = %00000011 'set RA0/1 to inputs, all others to outputs

    TRISB = %00001111 'out,out,out,out,in,in,in,in

    ADCON1 = %11001110 'Use RA0 for Analogue input Right Justified

    DEFINE OSC 8


    'Define ADCIN Parameters
    Define ADC_BITS 10
    Define ADC_CLOCK 1
    Define ADC_SAMPLEUS 50

    'PortA.2 is serial debug
    extdataOut var porta.2


    'Define variables
    InputVoltage var word




    test:
    ADCIN 0,InputVoltage 'Get value

    serout2 extdataOut,16468,["Debug ",dec4 InputVoltage,13]

    pause 1000

    goto test

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 16F819 config for A/D

    Hi. I've used this routine many times without a problem Try it.

    OSCCON = $70 '8mhz
    adcon1 = 7 'set inputs to all digital - adcin command will convert individual input to analog
    @ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
    'declare bit, byte, word variables here
    TRISA = %00000011 'set RA0/1 to inputs, all others to outputs
    TRISB = %00001111 'out,out,out,out,in,in,in,in
    Clear 'RESET ALL VARIABLES UPON POWERUP
    Pause 100 'SETTLE DOWN
    'ADCON1.7 = 1 'RIGHT JUSTIFY RESULT on word variables - not needed for bytes

    start:
    ADCIN 0,(your variable)

  3. #3
    Join Date
    Jul 2003
    Location
    Lancashire
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: 16F819 config for A/D

    Thanks! That's got it up and running, Cheers Pete

Similar Threads

  1. 16f819
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th January 2011, 05:33
  2. 16F819 Help
    By jpeakall in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 29th December 2006, 12:19
  3. Osc 16f819
    By chip15 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th February 2006, 08:22
  4. 16F819 serin
    By markedwards in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd June 2005, 04:33
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 16:25

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