PDA

View Full Version : PIC 16F74 and PORTE



Len
- 3rd September 2004, 17:36
Hi folks!

I'm trying to use a PIC16F74 and need to use all three port E pins as standard digital inputs. I really think I've got everything set right, and PORTE.0 and PORTE.2 and working fine, but PORTE.1 refuses to see an input!!! The pin is really toggleing from 0 to 5V and I've tried multiple PIC's, so I must be doing something wrong...

Can anyone see anything wrong with this?



'Set PortA for digital operation
ADCON1=7

'Turn on Port B pullups
OPTION_REG.7 = 0

'Set direction of I/O pins
TRISA=%000000
TRISB=%11111111
TRISC=%00000001
TRISE=%00000111

start:

if porte.0=1 then
high porta.0
else
low porta.0
endif

if porte.1=1 then
high porta.0
else
low porta.0
endif

if porte.2=1 then
high porta.0
else
low porta.0
endif

goto start

Melanie
- 3rd September 2004, 18:16
Well if PortE.2 isn't High, then it'll set PortA.0 Low and you'll never know if PortE.1 had set it high beforehand unless you've got a fast scope as it'll only be High for a uS or so...

Try this as an alternative....



Start:
If PortE.0=1 then
High PortA.0
else
If PortE.1=1 then
High PortA.0
else
If PortE.2=1 then
High PortA.0
else
Low PortA.0
endif
endif
endif
goto Start


or how about...



start:
MyVar=PORTE & $07
If MyVar<>0 then
High PortA.0
else
Low PortA.0
endif
goto Start


where MyVar is a byte variable.

If you've got an LED on A.0 then any change on any of those three E pins should give the desired indication with either example.

Melanie

Len
- 3rd September 2004, 18:30
I'm smashing the button and watching on the scope, so I'm seeing things happen... not the nicest code, I admit, but it's showing me that E.0 and E.2 are being recognized, BUT NOT E.1!!

I can't understand it. I'm sitting here looking at 40 stuffed pcb's and am about to jumper that pin to another unused input, but hate to if I'm missing something dumb.

I was counting on you, Melanie, to give me the answer!! ;-)

Len

Melanie
- 3rd September 2004, 20:08
So just strip your code down to the very basics...

start:

if porte.1=1 then
high porta.0
else
low porta.0
endif

goto start

and tell me what happens after DOUBLE CHECKING that PortE.1 is actually switching between +5v and 0v. measure actually ON THE PIC pin itself... I've seen many a hairline PCB crack in my time.

Len
- 3rd September 2004, 21:52
I did it exactly.

No workie. I'm looking at E.1 on the cpu pin (44-pin plcc) with a scope probe, and it's going high and low, but no output on A.0.

I've also tried multiple cpu's. I'm going to have to jumper to an unused pin, and cob up the code a little since I can read the entire port at one time, but gotta move ahead.

I'll keep checking here for awhile, or feel free to email me directly:

[email protected]

if you think of something!

Tks!!
Len

Len
- 3rd September 2004, 22:42
I did it exactly.

No workie. I'm looking at E.1 on the cpu pin (44-pin plcc) with a scope probe, and it's going high and low, but no output on A.0.

I've also tried multiple cpu's. I'm going to have to jumper to an unused pin, and cob up the code a little since I can read the entire port at one time, but gotta move ahead.

I'll keep checking here for awhile, or feel free to email me directly:

[email protected]

if you think of something!

Tks!!
Len

Melanie
- 4th September 2004, 09:09
Is there any pin you can assign to a DEBUG output?

Read-in the WHOLE of PortE (as a BYTE) and output it to DEBUG as a continuous loop. Check each pin pulling it individually High and Low.

I don't have an F74, otherwise I'd pull one and try it myself.

Len
- 7th September 2004, 16:45
Well.....

It's working... and what I did doesn't make ANY sense to me, but here it is.....

Since PORTE is the source of my problems, and I've stared at this since Friday, I thought maybe I programmed the TRIS register backwards (it doesn't make sense, I know, since my MSB-LSB works on the other registers, but, hey, I'm out of ideas, ok!!) so I purposely programmed the TRISE register BACKWARDS with

TRISE=%11100000

Well, it started to work! All 3 input pins on port E now function as they should! Then I checked all the default config stuff in my programmer to see if something could be amis there... everything looked okay.

I went back to the code, and changed the TRISE register back to

TRISE=%00000111

AND EVERYTHING STILL WORKS!! I'm completely at a loss, but thought I needed to pass along what I did. I changed NOTHING in the programmer.

Thanks for consternating with me....

Len

Melanie
- 7th September 2004, 17:42
Well, if it's any consolation, I've had instances on a couple of occasions where things have not gone as expected, I've double-checked my findings, just about to post a warning about it here, changed something unrelated and everything suddenly works... and just like you, I've changed it back and frustratingly it STILL works. All that happens is that you loose half a day out of your life for no productive benefit.

C'est la vie.

PherricOxide
- 28th May 2012, 13:45
I know this is years too late, but I just spent 2 hours banging my head against the wall with what I believe may be the same issue (or at least, this is the only forum post I found regarding it, so I leave this for people of the future to find).

The ADC is enabled by default, and the PORTE pins RE0/AN5, RE1/AN6, and RE2/AN7 are set to analog mode. If you try to read from them, you always get 0.

To get it working for normal input IO,

// Disable the ADC
ADON = 0;

// Set the pins back to digital mode
ANS5 = 0;
ANS6 = 0;
ANS7 = 0;