Pins, ports and variables


Results 1 to 8 of 8

Threaded View

  1. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Pins, ports and variables

    They are trying to solve the problem thinking and coding in C.

    So the problem appears to be addressing bits as an array as you would when making a Knightrider LED bar scanner,
    except that in application you don’t want to change the state of the bits other than you’re interested in.

    To address a bit is easy, just multiply the step value by 2 each time (or shift it once) instead of incrementing it 0-7,
    We couldn't begin at zero and begin multiplying, but fortunately address the first bit with a 1
    Code:
    index var byte
    trisb = 0
    
    index = 1
    WHILE index > 0
    portb = index
    index = index << 1
    WEND
    Unless I’m mistaken the port bits were cycled real fast with no delays, repeats etc.
    But the problem is still that if port.3 happened to be initially set by something, it would now be cleared.

    Code:
    trisb = 0
    index var byte
    portbshadow var byte
    
    index = 1
    WHILE index > 0
    portbshadow = portb
    portbshadow = portbshadow^index
    portb = portbshadow
    index = index << 1
    WEND
    This should set port bits in sequence, leaving the previous bit set as it runs, and leaving all port bits set at the end,
    but that’s because the loop has no conditionals in it. It’s not a bad idea to shadow the port with a RAM byte anyway if you have the time.
    AFAIK when the pic sets any single port bit, it does a read of the whole port, then sets the bit in RAM, and writes the whole port byte back anyway.
    C isn’t real good for bit manipulation and this sort of thing always has to be done.
    Last edited by Art; - 4th April 2015 at 16:03.

Similar Threads

  1. Replies: 2
    Last Post: - 12th November 2014, 07:57
  2. Multiple Variables - Pins
    By GatorGuy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st February 2010, 01:08
  3. Variables and port pins
    By PeterReed in forum mel PIC BASIC
    Replies: 2
    Last Post: - 22nd September 2009, 14:01
  4. accessing ports pins using an index variable
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th March 2008, 20:36
  5. PIC - 8 Pins - 6 Output Pins ?
    By DanPBP in forum Off Topic
    Replies: 0
    Last Post: - 22nd October 2007, 00:23

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