One of those days... config question


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    35

    Red face One of those days... config question

    Hi,

    I'm trying to use a PIC18F2420 and configure all pins on PortB to be digital I/O's. I usually follow the datasheet quite literally, so have configured port b as follows:

    @ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L ;LV PROGRAMMER OFF

    ASM

    ;PORT B
    CLRF PORTB
    MOVLW 11111111b ;ALL PORTB PINS DIGITAL
    MOVWF ADCON1 ;A/D'S OFF
    MOVLW 11000000b ;PIN DIRECTION PORT B
    MOVWF TRISB

    ENDASM

    After doing this, I'm trying to toggle PORTB.5 with just a short loop:
    START:
    HIGH PORTB.5
    PAUSE 100
    LOW PORTB.5
    PAUSE 100
    GOTO START

    It absolutely doesn't budge.
    Would someone please tell me what I missed? It's been one of those days.
    Thanks much!
    Last edited by LGabrielson; - 15th May 2012 at 04:24.

  2. #2
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: One of those days... config question

    Referring to the PIC18F2420 datasheet (page 108), the sequece that can be used to initialize portb is as below:
    CLRF PORTB
    CLRF LATB
    MOVLW 0Fh
    MOVWF ADCON1

  3. #3
    Join Date
    Jul 2011
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: One of those days... config question

    Hi,

    If I'm not mistaken, 'CLRF LATB' is just an alternate way of doing 'CLRF PORTB'. Then in the next command, I'm simply substituting binary for hex, and since I want all 8 pins to be digital I/O's, it is 11111111b instead of '0Fh' that they are using in their illustration. I don't think I'm doing anything wrong there.

    Thanks though.
    Len

  4. #4
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: One of those days... config question

    Hi Len,

    ADCON1.5 = 1 will set AN2 as VREF- input and ADCON1.4 = 1 will set AN3 as VREF+ input. Also, bits 6 and 7 of ADCON1 are unimplemented so setting them to either one or zero will not matter.
    To set complete PORTB to digital IO, set ADCON1 to 00001111b (0Fh).
    Please refer datasheet page 224 for more details.
    Also you can set CMCON register to 00000111b to turn off the comparator module if you are not using it.

  5. #5
    Join Date
    Jul 2011
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: One of those days... config question

    Well, I'll be d*****! Thank you so much!

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