Same code in different Pins


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1

    Default Same code in different Pins

    Hi!, i am currently developing an application with one wire devices, i have for convenience connected several DS1993 devices to different I/O pins (even from different ports), Is there a way of executing the same code on different pins?.

    Can i make this code reusable (something like a funtion gosub) for different pins?

    PIN var Portb.0
    owout PIN, 1, ["data here"]

    how can i change the I/O pin or the var PIN?

    Thanks in advance!

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas View Post
    Hi!, i am currently developing an application with one wire devices, i have for convenience connected several DS1993 devices to different I/O pins (even from different ports), Is there a way of executing the same code on different pins?.

    Can i make this code reusable (something like a funtion gosub) for different pins?

    PIN var Portb.0
    owout PIN, 1, ["data here"]

    how can i change the I/O pin or the var PIN?

    Thanks in advance!
    It's not what you want, but:

    pin var byte
    pin1 var portb.0
    pin2 var portb.1
    pin3 var portb.2...etc.etc.etc...

    pin = 2
    gosub outputstuff

    outputstuff:
    select case pin
    case 1
    owout pin1,1,["data here"]
    case 2
    owout pin2,1,["data here"]
    case 3
    owout pin3,1,["data here"]
    end select
    return

  3. #3


    Did you find this post helpful? Yes | No

    Default Sure its not what i want ;)

    That is a simple choice, but the code i posted is just an example, my real code could use up to 800 words, an maybe the code space isnīt enough.

    Come on there must be some way, I just donīt understand it, it seems to be in ASM. I really dont know.


    SAME QUESTION

    How can you change the definition of a variable in the middle of the execution???

    PIN var PORTB.0


    and later

    PIN var PORTB.1


    Thanks

  4. #4
    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

  5. #5
    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

  6. #6
    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

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