PDA

View Full Version : One of those days... config question



LGabrielson
- 15th May 2012, 03:10
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!

shahidali55
- 15th May 2012, 04:18
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

LGabrielson
- 15th May 2012, 05:23
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

shahidali55
- 15th May 2012, 10:38
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.

LGabrielson
- 15th May 2012, 15:29
Well, I'll be d*****! Thank you so much! :cupcake: