Setbit after AND/OR

johndo

Member
Hi All,

I want to use this particular line in a project:

"if b2 bit 0 set and b2 bit 1 clear and w14=1000 and pinC.4=0 then gosub dim"

Yes i realize my code is convoluted but this is the extent of my programming skills 🤣

I have been using whole bytes for 1's and 0's which is probably a waste of bytes when I've used most of them already.

Is there a way to rewrite the code to make it work as PE does not like using "setbit" after AND/OR in an "if" statement...No problem with the line if using whole bytes.

Cheers,
Kurt
 
Last edited:

inglewoodpete

Senior Member
You are using b2, whose bits are individually addressable, so try the following:
Code:
if bit24 = 0 and bit25 = 1 and w14=1000 and pinC.4=0 then gosub dim
 

Jack Burns

New Member
if bit24 = 0 and bit25 = 1 and w14=1000 and pinC.4=0 then gosub dim
It looks like inglewoodpete has accidentally quoted the wrong bit numbers, as bit24 and bit25 belong to variable b3. For variable b2 you need to use bit16 and bit17.
Code:
if bit16 = 0 and bit17 = 1 and w14=1000 and pinC.4=0 then gosub dim
 

johndo

Member
Thank you for the solution @inglewoodpete and @Jack Burns.

I wasn't aware that you could address bits directly like that, so you learn something new everyday. For a "new member" your on top of it Jack (y)

This will free up half a dozen word variables at least!

Thank you again!

Cheers,
Kurt
 

inglewoodpete

Senior Member
It looks like inglewoodpete has accidentally quoted the wrong bit numbers, as bit24 and bit25 belong to variable b3. For variable b2 you need to use bit16 and bit17.
Code:
if bit16 = 0 and bit17 = 1 and w14=1000 and pinC.4=0 then gosub dim
Yes, I should have taken my shoes and socks off and counted properly, rather than trying to calculate in my head!
 

inglewoodpete

Senior Member
I have just discovered that you can only individually address bits up to bit31 (b3)...Is that correct?
Yes, true.

Depending on the project, I reserve (up to 4) byte registers (b0, b1, b2, b3) for use for flags. I then allocate byte registers b4 upwards and word registers w27 (X2s) or w13 (M2s) downwards. I also always give every variable I use a symbol name.

Code:
' **** Variables - t prefix: bit variable; b: byte; w: word; r: other RAM; s: scratchpad; e: EEPROM
'
'ymbol bCommsStatus  = b1     'w0
Symbol tStCommsGood  = bit8   'b1,w0 v0.14   'Wireless comms status
Symbol tStLocked     = bit9   'b1,w0 v0.14   'All Doors are locked
Symbol tStPrevLocked = bit10  'b1,w0 v0.16   'Previous state of all locks bit

Symbol bEEPROMPtr    = b8     'w4   v0.16
Symbol bSoundPtr     = b9     'w4   v0.16
Symbol bPWMPeriod    = b10    'w5   v0.16
 
Top