PORTB.3 Input not working as expected.


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default PORTB.3 Input not working as expected.

    Hi,

    I am having a problem with using port B as inputs. The inputs are inverted. Here is the code.

    Code:
    #config
     __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BOREN_ON & _CP_ON
    #ENDCONFIG
    define OSC 20
    TRISC = 0
    TRISD = 0
    TRISB = 255
    
    led1 var portd.7
    led2 var portd.6
    led3 var portd.5
    led4 var portd.4
    led5 var portd.5
    led6 var portc.7
    switch  var portb.3
    
    high led5
    high led6
    
    start:
    if switch = 0 then
    high led1
    high led2
    high led3
    high led4
    pause 3000
    endif
    portd = 0
    while switch = 0
    wend
    goto start
    end
    I have tried the same code on both 871, and 877A with the same results.
    If I move the switch to any other port B pin then the program works as expected, the LEDs light for 3 seconds, and will only light again after releasing, and pressing the switch again.

    With the switch on port B3 pressing the switch turns on the LEDs as expected, but if I let go of the switch all outputs switch off instantly, not after 3 seconds. Then pressing the switch again will light up all of the outputs again, the first 4 for 3 seconds if I keep the switch pressed. Letting the switch go after that will turn off all outputs.

    It seems that taking B3 low is ok but then if it goes high again then the outputs all go off, and the program will not function.

    Anyone have any ideas please?

    Regards
    Bob.

  2. #2
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PORTB.3 Input not working as expected.

    Hi,

    As usual after trawling the net, and data sheets for many hours, I have found the answer only 10 mins after posting.
    When programming disable low voltage programming mode, and something called CPD also off.

    I have never understood why things default to a state which makes pins unusable as GPIO, AD converter, CMCON.7. Surely it would make sense to turn features on if you want to use them, rather than having to turn off anything you don't want.

    Regards
    Bob.

Similar Threads

  1. I2CRead & I2CWrite not working as expected
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 30
    Last Post: - 27th October 2021, 18:36
  2. Replies: 6
    Last Post: - 12th March 2011, 13:11
  3. portb input problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th February 2011, 15:18
  4. code needs much longer then expected
    By mischl in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd March 2006, 02:03
  5. Input not working with PIC12F675
    By Henque19 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2006, 11:27

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