Can't set portb.0 low


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158

    Default Can't set portb.0 low

    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.
    Last edited by spcw1234; - 15th February 2012 at 17:42.
    Shawn

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    Shawn,
    Have you tried?

    LATB.0 = 0

  3. #3
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    I have never used that, but will try it this evening. When and why should LAT be used?
    Shawn

  4. #4
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    Quote Originally Posted by spcw1234 View Post
    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!!!
    Thanks and Regards;
    Gadelhas

  5. #5
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    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!
    Shawn

  6. #6
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    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.

    Code:
    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
    Shawn

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Can't set portb.0 low

    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.
    Last edited by Heckler; - 16th February 2012 at 14:47.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts