Input question from a newbe


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    20

    Default Input question from a newbe

    New to this so be gentle on me. I wanted to solve this on my own, but after lots of reading and experimenting I'm now banging my head on the wall.

    I have a prototype board (16F877A based) with 4 buttons that pull RB0-RB3 to ground respectively. I'm having problems reading the input and if it didn't come with a compiled program that worked I would say it needed a pull up resistor.

    Can anyone help me with a simple code snippet to say light LED on RD0 when RB0 is grounded.

    I starter with the following based on reading.

    CMCON = 7
    ADCON1 = 7
    TRISD = %00000000
    TRISB = %11111111

    and then was trying to use if portb.0 in a look but no luck.

    What an I doing wrong? I have the C source for the program that works but don't appear to be able to replicate the same in PBP.

    Thanks,
    Brian

  2. #2
    Join Date
    Jul 2011
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: Input question from a newbe

    Replying to my own question, it looks like pull-up resistors was the problem after all. Adding OPTION_REG = $7F and enabling the internal pull-up resistors appears to have solved my problem

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


    Did you find this post helpful? Yes | No

    Default Re: Input question from a newbe

    Barely an hour between complete confusion and WOW! it works!!

    Good job, I bet that feels good. I know it does for me when I figure something out... especially after "banging my head on the wall".

    congrats!
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Input question from a newbe

    We all know what you mean, that's for sure. If your walls are located too far away... here's a portable solution...




    Should also grab one of these





    ------==== ====------

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jul 2011
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: Input question from a newbe

    Thanks for the head banging kit, I have a feeling I will got a lot of use out of it while trying to get up to speed.

    If you guys don't mind I have another probably very fundamental question, but my basic knowledge of electronics and programming is probably dangerous

    For my first Pic project I want to sense the current state of an existing piece of electronics and then be able to control it based on the current state and other inputs that are not part of the existing circuit.

    Below is the basics of the existing circuit.



    I've measured the current (flowing between 3 and 4) when the switch is closed and it is only a few mA so I think I can happily pull point 4 to ground to emulate the switch being pressed.

    For the sensing of the existing circuit and whether the LED is lit, can I just attach point 2 to an input and read a low (using internal pull up resistors)? I didn't know if that would interfere with the existing circuit. For the switch side of things I know I could use a relay or something to completely isolate the two circuits (mine from the existing), but wasn't sure about reading the state of the LED.

    The existing hardware isn't cheap, so I don't want to experiment too much.

    Any help or advice appreciated.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Input question from a newbe

    Hi,
    Since the external circuit operates on 12V the voltage at (2) will be 12V when the LED is off, if you connect that to an input of your PIC, which operates from 5V, current will flow from +12V, thru the resistor, LED and into the PIC's input pin, up thru the internal clamp diode and into the 5V supply line of the PIC and the LED will turn on (with less intensity since the total voltage is 7V instead of 12V).

    Use a high(ish) value resistor between point 4 and your PIC input (say 47k or something). That will limit the current into the PIC to safe level and stop the LED from glowing.


    Same thing with (4) really, if the voltage at (4) is 12V when the button is not pressed and you connect your PIC output (which toggles between 0 and 5V) to (4) it's likely that the external circuit will think the button is pressed no matter if the output is high or low. As you say, a relay or transistor switch should do the trick.

Members who have read this thread : 0

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