Same code in different Pins


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Assuming you have them on PORTB as shown. Just use Pin Numbers.
    Code:
    PIN  VAR BYTE
    
    for PIN = 0 to 7
        owout PIN, 1, ["data here"]
    next PIN
    Numbers 0-7 are usually PORTB.0 thru PORTB.7, 8-15 can be PORTC, but it depends on the chip you are using.
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Assuming you have them on PORTB as shown. Just use Pin Numbers.
    Code:
    PIN  VAR BYTE
    
    for PIN = 0 to 7
        owout PIN, 1, ["data here"]
    next PIN
    Numbers 0-7 are usually PORTB.0 thru PORTB.7, 8-15 can be PORTC, but it depends on the chip you are using.
    I've got no idea how this came to me...magic I suppose...
    How about a variable that's 'locked' into a certain memory location (porta in this case), and it's set up as an array.
    Since the ports are usually in sequential order in the memory map, it seems to me like a person should be able to access those bits as bits of a variable, like you would any other ram variable.
    i.e.
    PIN var byte[4] $F80 system '5 bytes to handle porta, portb, portc, portd, porte, in the case of a PIC18F4620

    then you'd access the pins by pin.0[index]...

    Wouldn't that work?
    Last edited by skimask; - 27th March 2007 at 18:28. Reason: corrections made

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Nope, won't work Skimask.

    For instance, with this statement...

    owout pin.0[index], 1, ["data here"]

    PBP will do an Array Out from the indexed pin, then use that result as the "PIN number" which will be either a 0 or 1. So it will always use either PORTB.0 if the pin is low, or PORTB.1 if the Pin is high.
    <br>
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Nope, won't work.

    For instance, with this statement...

    owout pin.0[index], 1, ["data here"]

    PBP will do an Array Out from the indexed pin, then use that result as the "PIN number" which will be either a 0 or 1. So it will always use either PORTB.0 if the pin is low, or PORTB.1 if the Pin is high.
    <br>
    ---deleted---I don't follow you at the moment...

    I got what you saying... pin.0[index] is actually a bit variable...0 or 1 correspoonding to port B
    but if you say it's not going to work...then chances are good that it's not going to work...
    Last edited by skimask; - 27th March 2007 at 18:50. Reason: never mind

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    ... pin.0[index] is actually a bit variable...0 or 1 correspoonding to port B
    This is another one of those examples where arrays act differently depending on whether a Constant or a Variable is used as the index.

    Using the same statement...

    owout pin.0[index], 1, ["data here"]

    If index is a Constant, it does what you thought, and will use the index to select the Pin as an offset from PORTA.0. So 8 would be PORTB.0. But then, you can't change it at run-time.

    IF index is a variable, then it makes it an Array operation that will read the value of the indexed Pin (0 or 1), that value then becomes the "PIN Number".

    When a statement works 2 different ways like that it's hard to grasp sometimes.
    Not sure why meLabs did things that way.
    <br>
    DT

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    This is another one of those examples where arrays act differently depending on whether a Constant or a Variable is used as the index.
    Using the same statement...
    owout pin.0[index], 1, ["data here"]
    If index is a Constant, it does what you thought, and will use the index to select the Pin as an offset from PORTA.0. So 8 would be PORTB.0. But then, you can't change it at run-time.
    IF index is a variable, then it makes it an Array operation that will read the value of the indexed Pin (0 or 1), that value then becomes the "PIN Number".
    When a statement works 2 different ways like that it's hard to grasp sometimes.
    Not sure why meLabs did things that way.
    <br>
    Might be the difference between a $250 compiler and a $2,500 compiler.
    But I got what you were getting at.

    I think the original post'ers only option is to do the SELECT CASE thing, combine all OWOUT's into one place, use a generic "data here" string type array variable and go with it.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think the original post'ers only option is to do the SELECT CASE thing,
    Well, I think Josuetas' best option can be found in Post #4
    <br>
    DT

Similar Threads

  1. My code for TV remote and MIBAM for RGB control
    By idtat in forum Code Examples
    Replies: 4
    Last Post: - 12th January 2013, 20:52
  2. Nokia COLOR LCD PicBasicPro 2.50a example code
    By skimask in forum Code Examples
    Replies: 49
    Last Post: - 28th September 2011, 01:43
  3. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17: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