PDA

View Full Version : Input problems



ALFRED
- 23rd July 2006, 03:53
Hello, I am having some trouble geting simple data into my PIC16F767. I have writen a program that goes somthing like this.

TRISB = %11111111
TRISA = %00000000
ADCON1 = %00001111

Start: IF PortB.0 = 1 THEN HIGH PortA.0
LOW PortA.0
PAUSE 1
GOTO Start

I wrote this to clarify some problems I was having in a much larger aplication where the PIC is monitoring sensor inputs on a mobile robot.
The hardware that I have built seems to work fine in that when I program the PIC to output data to motors LEDs ect it works fine but when I tell the PIC to read the status of an I/O line it does nothing. The above program produces the following output; When PortB.0 through PortB.5 goes high, PortA.0 through PortA.3 or so goes high for about 5 seconds. When PortB.6 or PortB.7 go high the I/O lines on the above PortA lines breifly go high but this only works twice. ???? this is completly bazar and I have no idea what I could be doing wrong as I have some previous experience with PICs.
Thanks for any ideas or sugestions!!

note: I tried the program on a PIC18F252 with the same problems.
I also looked at the oscillator signal with my oscope and it is fine.

Rob
- 23rd July 2006, 10:34
Have you got a 10k pullup resistor on MCLR and a pulldown resistor, such as 4k7, on PORTB.0?

savnik
- 23rd July 2006, 11:50
Hello, I am having some trouble geting simple data into my PIC16F767. I have writen a program that goes somthing like this.

TRISB = %11111111
TRISA = %00000000
ADCON1 = %00001111

Start: IF PortB.0 = 1 THEN HIGH PortA.0
LOW PortA.0
PAUSE 1
GOTO Start


ADCON1 = %00000111

Christopher4187
- 23rd July 2006, 14:00
Alfred,

I'm not one of the experts on the forum but it looks like if PortB.0=1 then you are going to put PortA.0 high for a very small amount of micro seconds. By the way the program looks, PortA.0 will always be low no matter what PortB.0 is. If that's the case, I would adjust the program to use an If/Then/else, like this:


Start:
IF PortB.0 = 1 THEN
HIGH PortA.0
Else
LOW PortA.0
PAUSE 1
GOTO Start

Chris

Bruce
- 23rd July 2006, 14:41
Chris is right on the money.

You could simplify this even more with PORTA.0 = PORTB.0 and drop the IF
statement altogether.

ALFRED
- 23rd July 2006, 20:41
Hey guys, thanks for the ideas. Although what Chris said seems to make sense, I was able to run this code on a PIC16F88 with no problems at all. I also wrote a similar program that uses portc.4 as the input and ran it in the dark. Without the light on I could see the LED I had on the output light dimly when I brought the input high and turn off when I disconected the input. I am sure the LED was flickering and that is why it looked dim. I am not sure if this would also work on other I/O lines if I looked at them it the dark. I am now going to try your ideas and see what I get.
Thanks again!!

ALFRED
- 23rd July 2006, 21:02
It worked!! thanks for the idea Chris. I am still not exactly clear on why it didn't work the first time but hey, it works now so no complaints. again thanks for all the help.