PDA

View Full Version : 18F14K50, PORT C as outputs



RuudNL
- 1st September 2014, 09:31
Maybe this is a stupid question, already answered before, but I could not find the answer...

I am trying to use PORTC of a PIC18F14K50 as outputs.
To do so, I use:

ANSEL = 0
ANSELH= 0
TRISC = 0
PORTC = 0

IMHO this should configure PORTC as digital and set the outputs of PORTC low.
But it seems I can still pull the pins easily to high, using a resistor.
This gives me the impression that the pins are still inputs!
What am I overlooking?

longpole001
- 1st September 2014, 12:24
port c has comparator outputs i would set them to 0 as well

longpole001
- 1st September 2014, 12:26
refer page 95-97 of data sheet , comparitor take priority over data i/o

RuudNL
- 1st September 2014, 12:45
Isn't that what I am doing with ANSEL and ANSELH ? Or am I still missing something?

pedja089
- 1st September 2014, 13:38
This is register values that I used to turn off all analog stuff.


REFCON0=0
REFCON1=0
ADCON1=0
ADCON2=0
ANSEL =0
ANSELH=0
CM1CON0=0
CM2CON0=0
SRCON0=0
SRCON1=0
WPUA=0
WPUB=0

RuudNL
- 1st September 2014, 14:21
Thanks! I will try that and report the results!

RuudNL
- 1st September 2014, 14:35
Mmm... I tried this but it still doesn't work!


REFCON0=0
REFCON1=0
ADCON1=0
ADCON2=0
ANSEL =0
ANSELH=0
CM1CON0=0
CM2CON0=0
SRCON0=0
SRCON1=0
WPUA=0
WPUB=0

TRISC = 0
PORTC = 0

ProgStart:
PORTC.2 = 1
pause 1000
PORTC.2 = 0
pause 1000
goto ProgStart

pedja089
- 1st September 2014, 14:39
Are you sure that problems are in portc?
Did you test other port? Maybe you didn't configure oscillator correct, or MCLR pin, etc...

RuudNL
- 1st September 2014, 14:41
Yes, when I use PORTB everything is fine!
(I can pull the C-outputs still high with a resistor. This gives me the impression that the pins are inputs.)

pedja089
- 1st September 2014, 14:50
What value are resistor?
Try to put LED on portc with 1K series resistor, then see what is happening...

RuudNL
- 1st September 2014, 14:57
The result is (as expected): nothing!

pedja089
- 1st September 2014, 15:06
PORTC is probably damaged...
You can try to use LAT registers, but...

RuudNL
- 1st September 2014, 15:08
PORTC is probably damaged...
I don't think so, because the result is the same with different (new!) 18F14K50's...

RuudNL
- 1st September 2014, 15:23
New test:



REFCON0=0
REFCON1=0
ADCON1=0
ADCON2=0
ANSEL =0
ANSELH=0
CM1CON0=0
CM2CON0=0
SRCON0=0
SRCON1=0
WPUA=0
WPUB=0

TRISC = 0
PORTC = 0

ProgStart:
PORTC = 0
pause 1000
PORTC = 255
pause 1000
goto ProgStart

PORTC.3, C.6 and C.7 work, PORTC.0, C.1, C.2. C4 and C.5 don't...
So... what's the common factor?

HenrikOlsson
- 1st September 2014, 16:07
Hi,
I've been looking thru the datasheet to figure out what might be going on but I honestly can't find it.
So, I'm going to sugest that you might have a hardware issue, is this on a breadboard by any chance? Faulty contacts?

Going thru the datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/41350E.pdf) I also noted the follwing regarding setting all those registers to 0 in your code:

REFCON0=0 (pg.247)
Defaults to 16 at POR which means that the FVR is set to 1.024V but disabled, setting it to 0 shouldn't be needed.
Instead, it specifically says not to use the value 0....

REFCON1=0 (pg.248)
Defaults to 0 at POR, DAC disabled, setting it to 0 shouldn't be needed.

ADCON1=0 (pg.216)
Defaults to 0 at POR, setting it to 0 shouldn't be needed.

ADCON2=0 (pg.217)
Defaults to 0 at POR, setting it to 0 shouldn't be needed.

ANSEL = 0 (pg.98)
Defaults to 248 at POR, setting it to 0 IS needed to enable the digital input buffers.

ANSELH = 0 (pg.99)
Defaults to 15 at POR, setting it to 0 IS needed to enable the digital input buffers.

CM1CON0=0 (pg.229)
Defaults to 0 at POR, comparator is disabled, setting it to 0 shouldn't be needed.

CM2CON0=0 (pg.230)
Defaults to 0 at POR, comparator is disabled, setting it to 0 shouldn't be needed.

SRCON0=0 (pg.242)
Defaults to 0 at POR, SR latch is disabled, setting it to 0 shouldn't be needed.

SRCON1=0 (pg.243)
Defaults to 0 at POR, SR latch is disabled, setting it to 0 shouldn't be needed.

WPUA=0 (pg.86)
Defaults to 56 at POR, PortA pulups enabled, setting it to 0 disables the pullups individually.
However, INTCON2.7 is the "master switch" PortA and PortB pullups and it defaults to 1 which means pullups are disabled.
So, if you're NOT clearing INTCON2.7 there shouldn't be any need to set WPUA=0

WPUB=0 (pg.91)
Defaults to 240 at POR, PortB pullups enabled, setting it to 0 disables the pullups individually.
However, INTCON2.7 is the "master switch" PortA and PortB pullups and defaults to 1 which means pullups are disabled.
So, if you're NOT clearing INTCON2.7 there shouldn't be any need to set WPUA=0

/Henrik.

RuudNL
- 1st September 2014, 16:27
Thank you Henrik for your time and effort.
I think you are right, setting states that are the same as after POR are not very useful...
I think I give up for today. Tomorrow there's an other day...

Demon
- 3rd September 2014, 02:28
Have you tried AllDigital?

http://www.picbasic.co.uk/forum/showthread.php?t=11100

Robert