dip switchs & inputs


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2005
    Location
    down south
    Posts
    90

    Default dip switchs & inputs

    I have a little project were I need to use dip switchs as inputs.currect me if I'm wrong
    but if these switch are left on. would this not be constant current flow and extra drain on the battery?
    if so would this work or do you have a better way.
    if I set these pins as inputs,pull up resistors on @ power up read there state and put it in a Var and then make them an out put and set to 0.
    THANK YOU

    example:
    dip switch on gpio.2 and gpio.4

    @ DEVICE pic12F629
    @ DEVICE pic12F629, INTRC_OSC_NOCLKOUT
    @ DEVICE pic12F629, WDT_ON
    @ DEVICE pic12F629, MCLR_OFF
    @ DEVICE pic12F629, CPD_OFF
    @ DEVICE pic12F629, BOD_OFF
    @ DEVICE pic12F629, PWRT_ON
    @ DEVICE pic12F629, PROTECT_OFF
    DEFINE OSC 4
    Pause 5000 'Allow pic to Stabilize

    TRISIO = %00011100 'MAKE GPIO.2,.4 INPUTS (GPIO.3 IS ALWAY A INPUT)
    OPTION_REG =%00000000 'WEAK PULLS ENABLED
    WPU = %00010100 'GPIO.2,.4 WEAK PULL UPS (GPIO.3 HAS EXTERN.RESISTOR)
    CMCON = 7


    SYMBOL RED = GPIO.0 'RED LED
    SYMBOL NA1 = GPIO.1 'N/A
    SYMBOL DIP1 = GPIO.2 'DIP SWITCH 1 MODE,IF MADE PIN IS LOW
    SYMBOL NA2 =GPIO.3 'N/A
    SYMBOL DIP2 = GPIO.4 'DIP SWITCH 2 PC, IF MADE PIN IS LOW
    SYMBOL GREEN = GPIO.5 'GREEN LED
    RED=0
    GREEN=0
    MODE VAR BYTE
    MODE =0

    PC VAR BYTE
    PC=0

    IF DIP1 =0 Then GoTo LONG
    GoTo CHECKIT
    LONG:
    MODE= MODE +2

    CHECKIT
    IF DIP2 =0 Then GoTo SHORT
    GoTo CHANGE
    SHORT:
    PC=PC+2

    CHANGE:
    TRISIO = %00001000 'MAKE ALL OUTPUTS EXCEPT GPIO.3
    'RESISTORS ARE AUTO.OFF WHEN MADE OUTPUTS
    DIP1=0
    DIP2=0

    MAIN:
    ' (SOME CODE HERE DOING WHAT EVER)
    IF MODE=>1 Then RED=1

    IF PC=>1 Then GREEN =1

    GoTo MAIN

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    How about using external resistors and driving them from a spare output pin when you want to read the switches. That way there is only ever power supplied to the resistors just before you read them. After you have read the switches, turn the output pin off again.
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    The extra i/o to supply external pull-up will work and it's very common.

    You could also disable internal pull-up if you decide to use them. But it will leave the i/o floating... Maybe set them as output when you don't need to read from them. Just make sure of the I/O and the switch level to avoid 'short circuit'
    Steve

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

  4. #4
    Join Date
    Aug 2005
    Location
    down south
    Posts
    90


    Did you find this post helpful? Yes | No

    Default

    thank you both but Iam not sure I'm following what your saying. I'm still a newbee at this . In this little project it will start from a interupt and depending on how the switchs are set it will decide what to do then go back to sleep til next interupt.
    But Please for give me and please expain in a little more detail for this simple mind of mine
    thanks

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    grounded, Attached is a portion of a circuit I have used in the past to preset the port for a product. All you need to do is replace the switch SW9 pin 1 or 3 with an appropriate port pin from the micro and when you want to read the 8 position dip switch just place a high level on it then read the port then place it back low.

    Dave Purola,
    N8NTA
    Attached Images Attached Images

  6. #6
    Join Date
    Aug 2005
    Location
    down south
    Posts
    90


    Did you find this post helpful? Yes | No

    Default

    well that was headed right over my head. it just did'nt catch what yall were saying untill I looked at dave's attachment then it clicked.
    thank again.

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Erratic analog inputs .
    By timseven in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th October 2009, 22:34
  3. Unable to get 2 inputs to work
    By rangerdoc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st June 2008, 03:16
  4. inputs on 12F675 (or for that matter any PIC)
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2007, 19:43
  5. Using portb as inputs PIC goes crazy
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th November 2005, 14:15

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