Bit variables... typo?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Tomexx's Avatar
    Tomexx Guest

    Default Bit variables... typo?

    This snippet below is taken from MElabs website:
    http://www.melabs.com/resources/articles/pinaccess.htm

    ----------------------------------------------------------------------------------
    Specifying bits with variables

    Sometimes it is desirable to specify the bit with a variable in your program. This allows you to write to different bits, based on some condition in your code.

    Let's write a code snippet which will count 0 to 7 and make the corresponding bit on PORTB high for each count. To do this, we will use a bit offset.
    ----------------------------------------------------------------------------------

    Code:
    i    var    byte    ' i will hold our count
    TRISB = %00000000    'set all PORTB pins as output
    
    For i = 0 To 7    'loop for 8 counts
    
        PORTB = %00000000    'make all pins low
    
        PORTB.0[i] = 1        'make pin number i high
    
        Pause 500            'pause for half a second
    
    Next i        'go to the next count
    Notice the PORTB.0[i] line is that a typo?
    If not why is the "[i]" located next to ".0"?
    Please explain how it works

    Thanks,
    Tom

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Notice the PORTB.0[i] line is that a typo?
    If not why is the "[i]" located next to ".0"?
    Please explain how it works
    one things is stupid frome MELABS, is not allowing to write...

    PORTA.i

    anyway, we can consider PORTB.0[i] as a kinda typo.



    Last edited by mister_e; - 29th November 2004 at 00:13.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Tomexx's Avatar
    Tomexx Guest


    Did you find this post helpful? Yes | No

    Default

    Too bad...I was hoping to use it in an array.

    Anyway, so if we can't use an array here then what's the point of the example?

    Thanks,
    Tom

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Depending of what you want to do with an array... what do you plan to do?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Tomexx's Avatar
    Tomexx Guest


    Did you find this post helpful? Yes | No

    Default

    Nothing particular in this case. Just that the example said that you can specify the bit with a variable in your program which I didn't see in the manual. I thought that would be usefull sometimes. But I didn't understand the syntax.
    Code:
    PORTB.0[i] = 1
    Going back to the example they probably meant this:
    Code:
    PORTB.[i] = 1
    ...so I guess you can use it in an array otherwise they wouldn't show it, right?

    Anyway, I'm pretty new to the PBP and try to pick up new things when I see them. Also PBP is very limited compared to PC languages so every little trick helps.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ok, i'm not sure what you know and what you don't so here's fulll explanation.

    PORTB.0=1

    high level state to PORTB bit 0 (RB0). This is doing the same thing as HIGH PORTB.0

    PORTB.0[i]=1

    high level state to PORTB bit specify by i variable

    So let's say i=4, this will place PORTB bit 4 (RB4) to high level.

    i don't see lots of appliance for this function since i always use specific name to access an PORT pin.

    hope this put some lights

    regards
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    It's all here if you search for it...

    http://www.picbasic.co.uk/forum/show...=&threadid=544

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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