Tomexx
- 26th November 2004, 15:04
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.
----------------------------------------------------------------------------------
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
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.
----------------------------------------------------------------------------------
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