PDA

View Full Version : Can't set portb.0 low



spcw1234
- 15th February 2012, 17:38
I know this seems really trivial, but I am using an 18F2620 and I set portb.0 high in the beginning of the program with no problems. Later I try to set it low, and it won't go low. The program is quite large, and I can't figure out what could possibly prevent setting the pin low. I have one of my programs from a week earlier, before adding a bunch of stuff, and it works fine proving it is not hardware related.

I am turning off the AD and comparators for that pin with
ADCON1 = (%)00001010 (without the brackets)
CMCON = 7
TRISB.0=0 'set to output
PORTB.0=1 'sets the pin high, which works fine

I have tried:
LOW portb.0
PORTB.0=0
putting a pause before and after setting it low.
Nothing works. I am sure it is something stupid in my code, but maybe if you can bounce some ideas I will be able to find it. I am using the CCP1 module for measuring pulses on portc.2, as I was on the older program that works fine.

mark_s
- 15th February 2012, 19:00
Shawn,
Have you tried?

LATB.0 = 0

spcw1234
- 15th February 2012, 20:59
I have never used that, but will try it this evening. When and why should LAT be used?

gadelhas
- 15th February 2012, 21:25
I have never used that, but will try it this evening. When and why should LAT be used?

When you use 18F series. Because of the RMW issue!!!

spcw1234
- 15th February 2012, 22:19
Using LAT did not work. I don't think it is RMW as I am not reading the port, I already know it's state is high, I just want to make it low.

Thanks for the help!

spcw1234
- 15th February 2012, 22:44
OK, I got it working, after I commented out the line below it worked. Took me a while to understand why, then I saw it... :) The gosub wait1 is to wait for the ACK from the LCD display. If no ACK, it reboots the display. Well I jump to a routine that waits for the ACK, then return and wait again without sending another command to the display. Stupid little mistake trying to shrink the program to save some flash space.



shutdown:
serout2 tx, baud, ["s", 0, 2, 2, white1, white2, "- GOOD BYE -", $00] : gosub wait1
; gosub ln3blank : gosub wait1 ;PORTB.0 CAN GO LOW WITH THIS LINE COMMENTED OUT??????
serout2 tx, baud, [$59, $03, $00] : gosub wait1
pause 500
PORTB.0=0 'shutdown main power relay NOT GOING LOW??????????
pause 5000 'wait for relay to drop out
goto start 'if processor is still running, then reboot

ln3blank:
serout2 tx, baud, ["s", 0, 3, 2, white1, white2, " ", $00] : gosub wait1
return

wait1: 'WAIT FOR ACK FROM DISPLAY
serin2 rx, baud, 500, initdisp, [a] 'wait 500ms for serin, else goto wait2
if a<>6 then waitfail '???? 'check for ACK, if not then reinitialize display
return

Heckler
- 16th February 2012, 14:44
One thing I often do to "see" if my program gets to a certain point is to insert a "blink LED" routine at the point in question.
(assuming you have another free I/O pin). That way you can blink the LED to see if your program ever gets to that point.

Or you could do a GOSUB BLINKY routine and use it at several points in your program with a variable loaded with a blink count just before the gosub.

It's times like these that you have to drop back to basic troubleshooting techniques. One thing you could have done is to set aside your original program and just did a very simple LED blinky test to check the PortB.0 pin... then once you are convinced it is not the pin or your configs... you know it must be in software somewhere..

glad you found the problem.