How to set PortA's RA0, RA1 as output using PIC18F2455

Discussion in 'Embedded Systems and Microcontrollers' started by Digital_Mike, Mar 7, 2008.

  1. Digital_Mike

    Thread Starter New Member

    Mar 6, 2008

    I am using a PIC18F2455. I would like to run a program that sets PortA as an output, then set RA0 High and RA1 low. I am using Assembly. How can i do that?

    I thought that simply using the following code would do that, however when i simulate it in MPlab, PortA seems to remain unchanged.

    clrf TRISA

    BSF RA0, b'1'
    BCF RA1, b'0'

    Why does this not work? What am I missing?
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    RA0 and RA1 are multiplexed with analogue inputs. Check the data sheet on how to configure it as digital pins.
  3. atferrari

    AAC Fanatic!

    Jan 6, 2004
    Basically, you have two ways:

    Read the description of EVERY pin to see whit what else it is involved or read the whole manual, noting every pin affected by a peripheral.

    I always go the first way. It works 100%. Manuals are complete enough for that.

    Your register if I recall right should be somthing like ADCON... But check it yourself.
  4. 0xFF


    Feb 26, 2008
    Code ( (Unknown Language)):
    1. CLRF PORTA ; Initialize PORTA by clearing output data latches
    2. MOVLW 0Fh ; Configure A/D
    3. MOVWF ADCON1 ; for digital inputs
    4. MOVLW 07h ; Configure comparators
    5. MOVWF CMCON ; for digital input
    6. BSF PORTA, 0 ; set RA0 high
    Page 113 of the datasheet gives you a clear example of initializing PORTA.

    Page 256 is the A/D Control Register 1.

    Page 265 is the start of the Comparator Module (CMCON).
  5. nanovate

    Distinguished Member

    May 7, 2007
    There should also be a table in the datasheet that tells you what the default state of the registers are after reset, POR, etc... I always look for this.