Variables and port pins


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Default Variables and port pins

    Hi,
    Having assigned a variable name to a port pin, eg:

    MyPin VAR PORTB.1

    I would like then to be able to use another variable to refer to that pin, eg:

    x = MyPin
    High x

    Is there any way to do this as I have tried many ways but nothing seems to work.

    --------------------

    Alternatively, if this would work, I could do what I want this way:

    If a = 1 then
    p VAR PORTB.1
    ELSE
    p VAR PORTB.2
    ENDIF

    But, when this is compiled, it reports that the variable p in the ELSE section is already an alias implying it is assiging the variable at compile time rather than when the IF statement runs.

    -----------------------

    Many thanks for any help or suggestions.

    Peter

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    VAR is a COMPILE TIME directive... ie it is acted upon by the compiler when your program is compiled and assembled - it is NOT an instruction or COMMAND that is acted upon during execution (RUN TIME).

    Using your own example... if you say...

    x=MyPin

    ...you are transferring the state of MyPin into the variable x (assuming you have previously defined x as a variable).

    You can have multiple definitions for any given pin...

    x var PortB.1
    MyPin var PortB.1

    Thereafter you can use any one you want within your program. But once defined, your definitions can't be changed or reassigned 'on-the-run'.

  3. #3
    Join Date
    Sep 2009
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Thanks

    Many thanks, Melanie. All understood.

    Peter

Similar Threads

  1. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  2. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  3. port/ pin explanation 16F877
    By emmett brown in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th August 2006, 01:07
  4. 8 port Signal Loss Detector, possible to use a pic?
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th March 2006, 15:59
  5. Assign 2 variables for 1 port..
    By oldtoddler in forum General
    Replies: 4
    Last Post: - 1st March 2006, 09:20

Members who have read this thread : 1

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