PIN state VS Variable read


Closed Thread
Results 1 to 4 of 4

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Well, several way to do it.
    1)You could use a Timer interrupt which will read your dipswitch all the time, so in your main code you just need to read the DipSwitch variable.

    2) Create a simple subroutine which will read the dipswitch when YOU decide

    Now what's the better solution to read them... i will prefer to read the whole port where my dipswitch are attach to and only keep the interesting bits . Let's say i have 4 dipswitch connected to PORTB<3:0> i'll use

    DipSwitch = PORTB & $0F

    the & $0F is and bitwise AND with 0F hex. this mask <7:4> bit, and keep only <3:0>.. where my dipswitch are connected.

    You could still use
    DipSwitch.3=PORTB.3
    DipSwitch.2=PORTB.2
    DipSwitch.1=PORTB.1
    DipSwitch.0=PORTB.0

    Both do the same job.. i prefer the first one. Which is the faster.. i didn't measure it yet. I feel the first is faster...

    HTH
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    cburtis, Its really up to the way your program is meant to work. If the information from the dip switches can change during the operation of the code then yes you will have to read them during the operation. However if they are some type of preset or an address that is used during the constant operation of the program then they only need to be read once. In the past I have used diodes to common source the switch's so I can also use the pins for other purposes during the operation. The diodes (anodes) are connected to a single pin of the processor so that during the initialization of the code I would place this pin high and read the switches. After reading them I place the line low and away we go.....

    Dave Purola,
    N8NTA

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

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