variable as a bit position of a variable in SX/B
I'm trying to change one bit of a byte in a subroutine, however the bit place may change. It doesn't seem like I can refer to the bit position with a variable.
Simple example below.
all variables declared as BYTES. (Though I tried changing temp6 to a bit, because that's all it is, and it still gets the same results).
I get the error
'EXPECTED A VALUE BETWEEN 0 AND 7 "temp5"
I can't specify a hard value because I want to pass the bit postion as a variable so I can reuse this routine.
Any ideas?
Simple example below.
sub rtc_bit_change
' PARAM1 = Takes Byte address to change
' PARAM2 = bit position (0-7)
' PARAM3 = desired state
temp4 = __PARAM1
temp5 = __PARAM2
temp6 = __PARAM3
temp7 = rtc_read_byte temp4
temp7.temp5 = temp6
rtc_write_byte temp4 temp7
endsub
all variables declared as BYTES. (Though I tried changing temp6 to a bit, because that's all it is, and it still gets the same results).
I get the error
'EXPECTED A VALUE BETWEEN 0 AND 7 "temp5"
I can't specify a hard value because I want to pass the bit postion as a variable so I can reuse this routine.
Any ideas?

Comments
' Use: value = BITVAL someVal, position ' -- "someVal" can be a byte or word FUNC BITVAL IF __PARAMCNT = 2 THEN ' byte passed? tmpW1 = __PARAM1 ' get byte value tmpB1 = __PARAM2 ' get bit position ELSE ' word passed tmpW1 = __WPARAM12 ' word was passed tmpB1 = __PARAM3 ' get bit position ENDIF tmpB2 = 0 ' assume cleared IF tmpB1 >= 0 THEN ' position value legal? IF tmpB1 <= 15 THEN tmpW2 = 1 << tmpB1 ' create bit mask tmpW2 = tmpW2 & tmpW1 ' clear other bits IF tmpW2 > 0 THEN ' if not zero tmpB2 = 1 ' bit was 1 ENDIF ENDIF ENDIF RETURN tmpB2 ENDFUNCYou use it like this:
BITVAL FUNC 1, 2, 3 'Thanks to JonnyMac for these cool functions! 'It saved me alot of coding.CheckDataSin: For I = 0 to 15 [b]value = BITVAL data1, I[/b] IF value = 1 THEN HIGH SIN_1 ELSE LOW SIN_1 ENDIF value = BITVAL data2, I IF value = 1 THEN HIGH SIN_2 ELSE LOW SIN_2 ENDIF value = BITVAL data3, I IF value = 1 THEN HIGH SIN_3 ELSE LOW SIN_3 ENDIF HIGH CLOCK LOW CLOCK NEXTAlso keep an eye out when SX/B 2.0 is released for something to help you on this also.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Smykowski: Well-well look. I already told you: I deal with the customers so the engineers don't have to. I have people skills; I am good at dealing with people. Can't you understand that? What is wrong with you people?
' Use: result = SET_BIT value, position, new_bit FUNC SET_BIT tmpB1 = __PARAM1 tmpB2 = __PARAM2 tmpB3 = __PARAM3 tmpB4 = 1 << tmpB2 IF tmpB3.0 = 1 THEN tmpB1 = tmpB1 | tmpB4 ELSE tmpB4 = ~tmpB4 tmpB1 = tmpB1 & tmpB4 ENDIF RETURN tmpB1 ENDFUNC