Modifying bits with variables, not constants

Status
Not open for further replies.

gramo

New Member
Just trying to figure out the equivilent for Proton+ picbasic,

PICBASIC Pro bit setting/clearing with a variable:

porta.0[Variable] = 1 'sets bit(variable) of porta
porta.0[Variable] = 0 'clears bit(variable) of porta

Proton+ :

doesn’t work.. it can only modify register bits with addressing of constants in that manner.

If someone knows how to over come this - please let me know
 
I'm not familiar with that version of basic.
A generic way to do this would be,

PORTA = PORTA OR (1 << Variable)
To set the bit

and

PORTA = PORTA AND (255 - (1 << Variable))
To clear the bit.

The << operation is shift left. Variable would contain 0 to 7.

Mike.
 
someone on sparky hit the nail on the head for the proton+ equivilent:

Dim INDEX As Byte

For INDEX = 0 to 7
If GetBit PORTA,INDEX = 1 Then
' do something interesting
EndIf
Next

and to clear bits indexed via variables:

CLEARBIT Variable , Index
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…