Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top