These commands are now included in the general distribution of GCB @ September 2015
GCBasic lacks the ability to compliment a BIT therfor operations such as:
PortB.3 = NOT PortB.3
fail with an obscure warning but comple producing bad code.
This macro is a work around which I hope will be of use to others:
Macro isNot(BitOut, BitIn) If BitIn then BitOut = 0 Else BitOut = 1 End If End Macro
BitIn is the BIT to be Complimented BitOut is the BIT to SET/CLEAR BitIn and BitOut may be the same
Examples:
' Flash an LED '#define LED PortB.3 Do isNot(LED, LED) ' LED != LED wait 500 ms Loop
' toggle LED according to a Button '#define LED PortB.3 '#define PB1 PortE.3 Do isNot(LED, PB1) 'LED = NOT PB1 Loop
It will work on any bit field so
Dim Flag as bit isNot(Flag, Flag)
is valid as it
dim test as byte isNot(Flag, test.1 ) LED = Flag
Cheers Chris
I added two additional Bitwise Operators that are sadly missing and present it here as a macro Library and an example program:
' Bitwise Macros.h ' BitOut != BitIn Macro isNot(BitOut, BitIn) If BitIn then BitOut = 0 Else BitOut = 1 End If End Macro ' BitsOut = BitsIn << NumBits Macro LSL(BitsOut, BitsIn, NumBits) BitsOut = BitsIn Repeat NumBits STATUS.C = 0 Rotate BitsOut Left End Repeat End Macro ' BitsOut = BitsIn >> NumBits Macro LSR(BitsOut, BitsIn, NumBits) BitsOut = BitsIn Repeat NumBits STATUS.C = 0 Rotate BitsOut Right End Repeat End Macro
Example Program for 28 Pin Demo Board - Reversable Chase lights
#Chip 18f25k50 ' Target Device Name #Config MCLR = Off #include "Bitwise Macros.h" Setup: Dir PortB Out Mainloop: Do wait 500 ms if Direction then LSL(PortB, PortB, 1) ' PortB = PortB << 1 if PortB.4 then PortB = 1 end if else LSR(PortB, PortB, 1) ' PortB = PortB >> 1 if PortB = 0 then PortB.3 = 1 end if end if isNot(SW1, PortE.3) ' SW1 = NOT PortE.3 if SW1 then Direction = NOT Direction Loop Subs: Exit: END
I Hope it is useful Cheers Chris
Forgive all the edits, I couldn't get the code highlighting and formating to work but slowly it is getting there,
Thank you Chris.
With your agreement I would like to move these into the general distrubtion of Great Cow Basic.
I will move into stdbasic.h which means that you do not need the include file for these three methods.
Anobium
By all means, I would be honoured to have made a contribution towards all your great work. Cheers Chris
Log in to post a comment.
These commands are now included in the general distribution of GCB @ September 2015
GCBasic lacks the ability to compliment a BIT therfor operations such as:
fail with an obscure warning but comple producing bad code.
This macro is a work around which I hope will be of use to others:
BitIn is the BIT to be Complimented
BitOut is the BIT to SET/CLEAR
BitIn and BitOut may be the same
Examples:
It will work on any bit field so
is valid as it
Cheers
Chris
Last edit: Anobium 2015-09-29
I added two additional Bitwise Operators that are sadly missing and present it here as a macro Library and an example program:
Example Program for 28 Pin Demo Board - Reversable Chase lights
I Hope it is useful
Cheers
Chris
Last edit: Chris Roper 2015-09-08
Forgive all the edits, I couldn't get the code highlighting and formating to work but slowly it is getting there,
Last edit: Chris Roper 2015-09-09
Thank you Chris.
With your agreement I would like to move these into the general distrubtion of Great Cow Basic.
I will move into stdbasic.h which means that you do not need the include file for these three methods.
Anobium
By all means, I would be honoured to have made a contribution towards all your great work.
Cheers
Chris