16F877a PORTA ADC and digital help


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default 16F877a PORTA ADC and digital help

    Hi,

    I was wondering if it would be possible to use PortA as analog but
    use 1 pin as digital output ?

    So:
    RA0-RA3 analog 10bit
    RA4 digital output
    RA5 analog input 10bit

    Can anyone help me with the ADCON settings ?

    Further RE0-RE2 will be digital output

    thanks

    Learning everyday

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi RF,

    Since RA4 is not an analog pin you get it as digital at default.

    Then, the rest is as you needed. See the table below.
    -----------------------------

    <img src="http://img4.picsplace.to/img4/26/adc.GIF" alt="Image Hosting by PicsPlace.to" >

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

    RE0-RE2 meaning that AN5, AN6 and AN7 are needed as digital in your case.

    Thus, you endup with
    ADCON1.0=0
    ADCON1.1=1
    ADCON1.2=0
    ADCON1.3=0

    ADCON1.4=0
    'ignore
    ADCON1.5=0 'ignore

    Then, assuming you want to use RC OSC,
    ADCON1.6=0 '(here you should use DEFINE)

    Then, you need 10-bit res.,

    ADCON1.7=1 'right justified is needed with 10-bit. Left justified is needed with 8-bit.


    You are set.

    -------------------------------
    Edit: Don't forget to set your TRIS registers for input/output thingie.
    Last edited by sayzer; - 22nd October 2006 at 00:04.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Sayzer,

    It is working, thanks I start to understand the ADCON setting

    Can you point me how Tris and internal pull-up works on a 877 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Sure.

    TRISA = %00100000

    Sets PORTA.5 as an input pin and all others in PORTA as output pin.

    There is something here to pay attention for.
    Although PORTA is 6-bit (RA0 to RA5), TRIS register uses 8-bit (0 to 7).
    In this case, only right bits are considered. Thus, Bit7 and Bit6 in TRISA register are ignored ; whether they are 1 or 0 it won't matter.


    TRISE = %00000000

    Sets PORTE.0, PORTE.1 and PORTE.2 as output pins.

    Also here, PORTE is only 3-bit (RE0 to RE2). So that, all other bits in TRISE register will be ignored.


    You can also set an individual bit by,

    TRISE.0=0

    Sets RE0 as an output pin.

    or

    TRISE.0=1 sets RE0 as an input pin.


    If you set a pin as analog, it must be an input pin.


    For Internal Weak Pull-ups, there is a bit in OPTION_REG register.
    Bit7.

    OPTION_REG.7 is PORTB Pull-up Enable bit

    OPTION_REG.7 = 1
    PORTB pull-ups are disabled.

    OPTION_REG.7 = 0
    PORTB pull-ups are enabled by individual port latch values.

    Once you set this bit as 0 then you can have weak pull ups on PORTB pins that were set to be input pins beforehand.

    -----------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Ok fine,

    Understood, so PORTB has only the weak pull-up feature ?

    another question concerning HSERIN

    I'm using a 16f877 with max 232 at 4mhz

    I'm having problems reading multiple variables in 1 serin string
    It works, but after some times it hangs so I think there is a buffer overflow
    What worries me is that when i measure with an osciloscope, there are pulses on portc.7 the UART RX even with no max232 chip connected ???

    Here is a part of the code:

    DEFINE HSER_RCSTA 90h ' enable serial port,
    ' enable continuous receive
    '
    define HSER_TXSTA 24h ' enable transmit,
    ' BRGH=1
    '
    define HSER_SPBRG 103 ' set baudrate to 2400
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error

    TRISB = %00000000
    'OPTION_REG.7 = 0 ' Enable PORTB pullups
    TRISC = %10000000
    TRISD = %00001111
    TRISE = %000

    loop:
    Hserin 500,LCD,[wait ("TAR"),dec3 var1,wait ("ANT"),DEC3 var2,wait ("AUX"),DEC3 var3,wait ("EXT"),DEC3 var4]


    LCD:
    pause 10
    Lcdout $fe, 1 ' Clear screen

    Lcdout "VAR1: ",#VAR1," VAR2: ",#var2

    Lcdout $fe, $c0, "VAR3: ",#VAR3," VAR4:",#VAR4

    Goto loop

    Any Idea ?

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi RF,

    I do not have much experience in serin/serout commands.

    I may mislead you with some incorrect or never tried advices.

    But, at first look, I am not sure whether you can use more then one "WAIT" in one serin command or not.

    I believe another member with valuable and reliable Serin/Serout experiences will respond.

    ----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Red face

    Hi,
    I just found this thread as I was looking at how to set up 4 of the 13 availiable A2D converter pins on my 18F4620. Can someone clarrify for me......

    If I want to set up AN0, AN1, AN4 & AN12 (8 bit resolution only) and leave every other pin on PORTA & B as digital input/ouputs.....

    is this code correct?


    ADCON1.0=0
    ADCON1.1=0
    ADCON1.4=0
    ADCON1.12=0

    'tristates will already be defined above
    Padawan-78

Similar Threads

  1. Replies: 5
    Last Post: - 16th October 2009, 18:29
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. 16F877A problem: "coupled" digital values
    By Lupo83 in forum General
    Replies: 16
    Last Post: - 4th December 2007, 12:46
  4. Replies: 4
    Last Post: - 24th January 2007, 22:20
  5. Problem with ADC
    By savnik in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 25th November 2006, 07:37

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