PDA

View Full Version : Strange Behavour of PortC.5



BobP
- 15th July 2007, 00:07
Hi,

I know this is something I will kick myself for..

Simple circuit with PortC 4,5,6 and 7 set as inputs. But PortC. 5 will not trigger the test LED as shown in program below. Have changed PIC (18F2525) and checked circuit.

Any help will save whats left of my sanity!
Bob

**********************************************
DEFINE OSC 20 ' PIC18F2525

INTCON2.7 = 0 ' Enable weak pull-ups
ADCON0 = $00 ' Disable Analog
ADCON1 = $0F ' PORTB ALL DIGITAL
CMCON = $07 ' Compartors off
TRISB = %11110000 ' 0,1,2 & 3 set to OP
TRISC = %11110100 ' 0,1 & 3 set to OP.
PORTB=$0F
PORTC=$08

T4 VAR BYTE ' temp byte store
LedG VAR PORTB.0
LedY VAR PORTB.1
LedR VAR PORTB.3
BUZ VAR PORTC.3

start:
BUZ=1 ' buzzer off
LedR = 0 ' led off
LedG = 0 ' led off
LedY = 0 ' led off

PAUSE 500
t4=portc/16 ' Read the high 4 IPs. move to low byte
if (t4 & 0010)=0 then
ledY=1
pause 500
endif
if (t4 & 0100)=0 then
ledY=1
pause 500
endif
if (t4 & 1000)=0 then
ledG=1
pause 500
endif
if (t4 & 0001)=0 then
ledG=1
pause 500
endif
GOTO start
end
****************************************

mister_e
- 15th July 2007, 00:40
i'm about to sleep, but can you post your config fuses setting or your compiled HEX ?

Make sure you have selected HS OSC and the supply line is noise-free.

Is there any pull-up on PORTC?

but... let's see if the remaining brain cell may think of something else...



if PORTC.5=0 then
ledY=1
pause 500
endif

if PORTC.6=0 then
ledY=1
pause 500
endif

if PORTC.7=0 then
ledG=1
pause 500
endif

if PORTC.4=0 then
ledG=1
pause 500
endif

GOTO start
end

not tested yet...

But... erm..


PAUSE 500
t4=portc/16 ' Read the high 4 IPs. move to low byte
if (t4 & %0010)=0 then
ledY=1
pause 500
endif
if (t4 & %0100)=0 then
ledY=1
pause 500
endif
if (t4 & %1000)=0 then
ledG=1
pause 500
endif
if (t4 & %0001)=0 then
ledG=1
pause 500
endif
GOTO start
end
seems you forgot some %??? or it's a copy/paste error?

Archangel
- 15th July 2007, 00:57
Hello BobP, Mister_e,
Do you think SSPCON1 register may have effect on PortC? I was thinking,
SSPCON1= %00000101 ' to turn off SDO on PortC.5

mister_e
- 15th July 2007, 01:57
POR value of SSPCON1=0, so it's already disable... but yes never trust it :D

BobP
- 15th July 2007, 10:26
First many thanks for all the quick replies.

Second... I am now kicking myself around the room.

mister_e got it in one, I had forgotten to use the binary '%' symbol. The way 3 of the 4 inputs worked threw me completly and I thought it was periphal settings....

Thanks to all again,
Bob