Variable to ports


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    Default Variable to ports

    I am sort of new using pic basic pro. I am learning it in school and i am working on a final project.

    I am trying to take a variable and send it to several different parts simultaneously, i do not know if this is possible but my example is


    would it work to:

    Code:
    'Initialize Variables
    
    
    LED1 var byte
    led1.0=porta.1
    led1.1=portb.3
    led1.2=portd.1

    And then later in my code just write LED1=1 to turn on all 3 ports and LED1=0 to turn them off. would this work

    thanks,

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    LED=%11111111 to turn all on
    LED=%00000000 to turn all off (0 would work also)

    Robert
    Last edited by Demon; - 4th April 2013 at 16:47.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    Hi,
    No, you can't really do it like that.
    You can't create an alias to individal pins "spanning" several ports like that - not that I know anyway.

    And, another point:
    When you say LED.1 = PortB.3 you assign the value of PortB.3 to LED.1 - that's definitely not what you want to do. To create aliases you use the VAR statement, just like you do when creating variables.
    Code:
    LED VAR PortB       ' LED is now an alias of PortB
    Pretty useless example but anyway....

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    Just a thought. Haven't tried it:

    LED1 var byte
    CLEAR
    LET LED1 = (YOUR VARIABLE #)
    GOTO READPORT

    READPORT:
    IF LED1.BIT0 = 1 THEN HIGH PORTA.1
    IF LED1.BIT1 = 1 THEN HIGH PORTB.3
    IF LED1.BIT2 = 1 THEN HIGH PORTD.1

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    Actually, there was a way posted a while ago. I just can't remember what to use as search string to find it.

    Robert


    EDIT: Here, read this:

    http://www.picbasic.co.uk/forum/showthread.php?t=3753
    Last edited by Demon; - 4th April 2013 at 20:34.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    Hi,
    Yes of course but then you are actually executing code which writes each bit to the individual port pins.
    Each output is written sequentially, they are not all written simultaneously which the OP asked about.

    But there's no way around that as far as I know.

    /Henrik.

Similar Threads

  1. Adding Ports status to a variable
    By lilimike in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th March 2013, 22:05
  2. Need two SDA SCL ports
    By lerameur in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th November 2010, 16:43
  3. activating i/o ports according to variable value
    By Picman in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th July 2010, 13:55
  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. One variable made up of another variable
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st September 2007, 00:18

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