PDA

View Full Version : bit position variable



dsicon
- 16th December 2012, 19:07
i have some code like this:
'***********
WriteByte var byte 'WriteByte holds the on off states for 8 LEDs
LED32 var byte 'LED32 holds the bit position for LED32 on the pcb in the WriteByte byte

LED32 = 3 ' bit3 in WriteByte, LED32 is connected to bit3 of a port expander chip, not a PIC pin

WriteByte.3 = 0 'this turns on LED32 but is not very readable
'*************

but the above code is not very readable, i would like to write:
WriteByte.LED32 = 0
but above statement throws a compile error

what is the best way to handle this ? sadly, i think i used to know, an array ?

SteveB
- 16th December 2012, 19:42
i have some code like this:
'***********

WriteByte var byte 'WriteByte holds the on off states for 8 LEDs
LED32 var byte 'LED32 holds the bit position for LED32 on the pcb in the WriteByte byte

LED32 = 3 ' bit3 in WriteByte, LED32 is connected to bit3 of a port expander chip, not a PIC pin

WriteByte.3 = 0 'this turns on LED32 but is not very readable
'*************

but the above code is not very readable, i would like to write:
WriteByte.LED32 = 0
but above statement throws a compile error

what is the best way to handle this ? sadly, i think i used to know, an array ?

I think this is what you are getting at.


WriteByte VAR BYTE
LED32 VAR WriteByte.3

LED32 = 0

But, lets say that this LED is actually attached to pin 3 of PORTB. In this case, you could use this:

LED32 VAR PORTB.3
Or this:

WriteByte VAR PORTB
LED32 VAR WriteByte.3
HTH

dsicon
- 16th December 2012, 21:41
you seem to be suggesting that this is simpler than i am making it
:)
you might be correct, let me play with this and get back to you and thanks for your response