Hi Bruce.
I am trying to use PortD.0 to PortD.3 as digital input.
“IF PortD.0 = 1 THEN…”
and it doesn’t work.
/ Petter
Hi Bruce.
I am trying to use PortD.0 to PortD.3 as digital input.
“IF PortD.0 = 1 THEN…”
and it doesn’t work.
/ Petter
Are you holding the pin at ground with a pull-down resistor until a button isIF PortD.0 = 1 THEN
pressed taking the input high?
I don't have a 16F874A, but I do use the 16F876A with PORTD inputs, and
it works as expected.
It might help is you showed all your code & a schematic.
Hi again.
Yes, I am using pull-down resistor on all my inputs.
I will try to find some free time tomorrow to post my code & schematic.
/ Petter
Hi
This is my testcode & schematic:
'---------------------------------
Include "modedefs.bas"
@ DEVICE HS_OSC
DEFINE OSC 20
ADCON1 = 7
CMCON=7
TRISE.4=0
LED VAR PORTB.5
boot:
Pause 500
Low led
high porta.0
LOOP:
if portc.2 = 1 then high ut10
if portc.3 = 1 then high ut10
if portd.0 = 1 then high ut10
if portd.1 = 1 then high ut10
if portc.5 = 1 then high ut10
if portc.4 = 1 then high ut10
if portd.3 = 1 then high ut10
if portd.2 = 1 then high ut10
pause 1
low ut10
goto loop
'---------------------------------
link to my schematics:
http://www.mediespecialist.se/pic16f874a/874a.gif
and a picture:
http://www.mediespecialist.se/pic16f874a/IMG_2144.JPG
/ Petter
Hi Petter,
Where are your port settings for Port C & D in the initalization of your PIC?
TRISD = %00000000 'for outputs
TRISD = %11111111 'for inputs
PortD = 0' set port D to low
Same settings needed for portC.
Maybe that's why it's not working. You haven't told the PIC HOW you want to use the pins. This is a similar chip to the 877A. I had no problems using it with only setting the TRISD,C, & D and PORTB,C, & D to what I wanted them to do.
I did see you had tried TRISD = %11111111 in a previous posting but not on the current one.
Also how can you see UT10 change states when you only pause for 1us? Try at least PAUSE 1000 until to get some testing results then fine tune it.
Also since this is an "A" type device do you have .1uF caps across both Vcc & Vdd pins on both sides of the chip as close to the pins as possible? The A series micros are supposedly more sensitive to noise. I couldn't see any because of the crystal being in the way.
Hope some of this helps!
BobK
another thing...
is invalid. look at the faq there's a whole thread about config fuses setting.Code:@ DEVICE HS_OSC
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi again, and thanks a million for all the help.
Nothing worked!
So I gave up and tried from scratch with a new .bas file, and then…
EUREKA!
Here is my test code that worked:
'-------------------------------------------------
'från början
@ DEVICE HS_OSC
DEFINE OSC 20
ADCON1 = 7
LED VAR PORTB.5
UT1 var PORTB.4
UT2 var PORTB.2
UT3 var PORTB.1
UT4 var PORTB.0
UT5 var PORTD.7
UT6 var PORTD.6
UT7 var PORTD.5
UT8 var PORTD.4
UT9 var PORTC.7
UT10 var PORTC.6
IN1 var PORTC.2
IN2 var PORTC.3
IN3 var PORTD.1
IN4 var PORTD.0
IN5 var PORTC.5
IN6 var PORTC.4
IN7 var PORTD.3
IN8 var PORTD.2
BOOT:
PAUSE 500
LOW led
LOOP:
IF IN1 = 1 THEN high UT1
IF IN2 = 1 THEN high UT2
IF IN3 = 1 THEN high UT3
IF IN4 = 1 THEN high UT4
IF IN5 = 1 THEN high UT5
IF IN6 = 1 THEN high UT6
IF IN7 = 1 THEN high UT7
IF IN8 = 1 THEN high UT8
pause 1
LOW UT1:LOW UT2:LOW UT3:LOW UT4:LOW UT5:LOW UT6:LOW UT7:LOW UT8:LOW UT9:LOW UT10
goto loop
'-------------------------------------------------
Sometimes the world is a bit strange, but for the moment I am happy :-)
Thanks again for all your help.
/ Petter
Bookmarks