PDA

View Full Version : Can't Toggle PORTC.4 on PIC18F13K22



prstein
- 12th January 2012, 16:34
I'm working my way around a new PIC, the 18F13K22 at a smokin' 64 MHz using the internal osc and PLL. Finally got that working but for the life of me, I can't get pin 7 (RC3) to toggle. The following code toggles pin 8 (RC4) but not pin 7:


#config CONFIG FOSC = IRC ;Internal RC oscillator
CONFIG PLLEN = ON ;Oscillator multiplied by 4
CONFIG IESO = OFF ;Oscillator Switchover mode disabled
CONFIG BOREN = OFF ;Brown-out Reset disabled in hardware and software
CONFIG WDTEN = OFF ;WDT is controlled by SWDTEN bit of the WDTCON register
CONFIG WDTPS = 32768 ;1:32768
CONFIG MCLRE = ON ;MCLR pin enabled, RA3 input pin disabled
CONFIG XINST = ON ;Instruction set extension and Indexed Addressing mode enabled
#ENDCONFIG

DEFINE OSC 64

ANSEL = 0
ANSELH = 0

LATC = %11000100
TRISC = %00000000
LATB = %01000000
TRISB = %00110000
LATA = %00000000
TRISA = %00000111

'Set internal osc to 16 MHz, PLL enabled
OSCCON.6 = 1
OSCCON.5 = 1
OSCCON.4 = 1
OSCTUNE.6 = %1

pause 500

Main:
LATC.4 = 1
LATC.3 = 1
pause 500
LATC.4 = 0
LATC.3 = 0
pause 500
goto Main


Am I missing something silly and obvious?

Best Regards,
Paul

Darrel Taylor
- 12th January 2012, 16:47
Try it with ...

CONFIG XINST = OFF
CONFIG LVP = OFF

prstein
- 12th January 2012, 16:54
Wow, thanks Darrel! How come that made it work?

Darrel Taylor
- 12th January 2012, 18:00
On that chip, RC3 is also the PGM pin for Low Voltage Programming (LVP).
When LVP is enabled, you can't use that pin for anything else.

And you should ALWAYS disable the Extended Instruction Set (XINST).
PBP will not function properly when XINST is enabled.

prstein
- 12th January 2012, 18:09
Thank you for taking the time to explain, it is much appreciated.

Best Regards,
Paul