Problem setting outputs on PIC18FJ53

Thread Starter

spinnaker

Joined Oct 29, 2009
7,837
I am having issues setting outputs on a PIC18f26J53. I have done this on other PICs before so I am not sure what is going on.

I wrote a little test program to test the problem:

Rich (BB code):
TRISA = 0;
TRISB = 0;
TRISC = 0;

while(1)
{  
    LATA=255;
    LATB=255;
    LATC=255;
    delay_ms(10);
    LATA=0;
    LATB = 0;
    LATC=0;
    delay_ms(10);
}
I can see all but the following Latch pins transitioning:

PortA
All pins seem to transition as expected.


PortB
RB7, RB6 (both expected since they are also PGC and PGD and my PICKit is still connected.

RB5 (always measures high, debugger shows as high)

PortC
RC4,RC5,RC7 (always measures low, debugger shows 2 & 7 as low and 7 as high)


This PIC is a bit strange that is has an Open Drain option. I have never used this before but I don't think it is on all of the effected pins and I think it is disabled.

Can someone please take a look?

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en548696

BTW I also have a 18F27J53 which is pretty much pin and feature compatible and I am getting the exact behavior of the 18F26J53. So it must be something in the setup of the chip.
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
ANCON1
ADCON1
UCON
UCFG

RC 4,5 are USB D+/D-
You need to change UCON and UCFG as well as ADCON0/1

CLRF PORTB ; Initialize PORTB by
; clearing output
; data latches
CLRF LATB ; Alternate method
; to clear output
; data latches
MOVLW 0x3F ; Configure as digital I/O
MOVFF WREG ADCON1 ; pins in this example
MOVLW 0CFh ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB<3:0> as inputs
; RB<5:4> as outputs
; RB<7:6> as inputs
EXAMPLE 10-4: INITIALIZING PORTC
Note: On a Power-on Reset, PORTC pins
(except RC2, RC4 and RC5) are configured
as digital inputs. RC2 will default as
an analog input (controlled by the
ANCON1 register). To use pins RC4 and
RC5 as digital inputs, the USB module
must be disabled (UCON<3> = 0) and the
on-chip USB transceiver must be disabled
(UCFG<3> = 1). The internal USB
transceiver has a POR value of enabled.


CLRF PORTC ; Initialize PORTC by
; clearing output
; data latches
CLRF LATC ; Alternate method
; to clear output
; data latches
MOVLW 0x3F ; Value used to
; initialize data
; direction
MOVWF TRISC ; Set RC<5:0> as inputs
; RC<7:6> as outputs
MOVLB 0x0F ; ANCON register is not in
Access Bank
BSF ANCON1,PCFG11
;Configure RC2/AN11 as digital input
 
Last edited:
Top