For the life of me I cannot get the GCB operator NOT (!) to fuction properly in GCB. Here's an example of what I'm trying to do...
DIM dir_bit AS BIT
dir_bit = 0
CounterValue = 0
Main:
CounterValue++
IF CounterValue = 100 THEN
dir_bit = !dir_bit 'here's the NOT statement
CounterValue = 0
END IF
GOTO Main
On the first iteration of dir_bit = !dir_bit, dir_bit does indeed toggle from 0 to a value of 1 but on all subsequent iterations, dir_bit remains at a value of 1. Can anyone suggest what I am doing wrong? And does anyone know another way to toggle a bit in GCB? A Toggle command would be a valuable addition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunatley, there is no bitwise NOT operator in Creat Cow Basic. You should have seen a compiler error when you used ! preceding the bit variable.
If you have read in the Help or elsewhere where GCB supports the "C" Bitwise NOT operator (!), I would like to know where you read it. .
Solution:
Help > Command Reference> Bitwise show the function FnNotBit as a way to toggle a bit with GCB.
The following code works well on 16F1825
DIM dir_bit AS BIT
dir_bit = 0
CounterValue = 0
Main:
CounterValue++
IF CounterValue = 100 THEN
dir_bit = FnNotBit(dir_bit) ' // Here's the NOT statement
CounterValue = 0
End if
Goto Main
======================================
You can also toggle a bit using "if then"
Code:
if bitval <> 1 then
bitval = 1
else bitval = 0
end if
Last edit: William Roth 2016-05-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all
Try dir_bit = 1 - dir_bit
--
Inviato da Libero Mail per Android lunedì, 02 maggio 2016, 06:43AM +02:00 da "William Roth" < williamroth@users.sf.net> :
Unfortunatley, there is no bitwise NOT operator in Creat Cow Basic. You should have seen a compiler error when you used ! preceding the bit variable.
Help > Command Reference> Bitwise show the function FnNotBit as a way to toggle a bit with GCB.
The following code works well on 16F1825
DIM dir_bit AS BIT
dir_bit = 0
CounterValue = 0
Main:
CounterValue++
IF CounterValue = 100 THEN
dir_bit = FnNotBit(dir_bit) ' // Here's the NOT statement
CounterValue = 0
End if
Goto Main
======================================
You can also toggle a bit using "if then"
Code:
if bitval <> 1 then
bitval = 1
else bitval = 0
end if
For now, using the "if then" as William recommends is the best option - it will do what you want while producing the most efficient code for the microcontroller.
New versions of the compiler will support the Not operator on bits, I implemented this just the other day. If you'd like to try out software that hasn't yet been tested properly and that might make your microcontroller catch fire, I've temporarily uploaded the newest compiler exe to http://gcbasic.sourceforge.net/newfiles/gcbasic.exe - if you use that, make sure to keep a copy of your existing gcbasic.exe file in case you need to go back. (It won't really set your microcontroller on fire, but using the if then is the easiest and safest option!)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(It won't really set your microcontroller on fire, but using the if then is the easiest and safest option!)
Its is still roumoured that the Early Motorola CPUs had a HCF instruction.
I never found it in the 6800 or 6809 and had left the electronics industrry when the 68000 came out.
For those not good with Acronymes HCF = Halt and catch Fire.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For the life of me I cannot get the GCB operator NOT (!) to fuction properly in GCB. Here's an example of what I'm trying to do...
On the first iteration of
dir_bit = !dir_bit
, dir_bit does indeed toggle from0
to a value of1
but on all subsequent iterations,dir_bit
remains at a value of1
. Can anyone suggest what I am doing wrong? And does anyone know another way to toggle a bit in GCB? AToggle
command would be a valuable addition.Unfortunatley, there is no bitwise NOT operator in Creat Cow Basic. You should have seen a compiler error when you used ! preceding the bit variable.
If you have read in the Help or elsewhere where GCB supports the "C" Bitwise NOT operator (!), I would like to know where you read it. .
Solution:
Help > Command Reference> Bitwise show the function FnNotBit as a way to toggle a bit with GCB.
The following code works well on 16F1825
======================================
You can also toggle a bit using "if then"
Code:
Last edit: William Roth 2016-05-02
Hi all
Try dir_bit = 1 - dir_bit
--
Inviato da Libero Mail per Android lunedì, 02 maggio 2016, 06:43AM +02:00 da "William Roth" < williamroth@users.sf.net> :
This is an issue that we're working on.
For now, using the "if then" as William recommends is the best option - it will do what you want while producing the most efficient code for the microcontroller.
New versions of the compiler will support the Not operator on bits, I implemented this just the other day. If you'd like to try out software that hasn't yet been tested properly and that might make your microcontroller catch fire, I've temporarily uploaded the newest compiler exe to http://gcbasic.sourceforge.net/newfiles/gcbasic.exe - if you use that, make sure to keep a copy of your existing gcbasic.exe file in case you need to go back. (It won't really set your microcontroller on fire, but using the if then is the easiest and safest option!)
Its is still roumoured that the Early Motorola CPUs had a HCF instruction.
I never found it in the 6800 or 6809 and had left the electronics industrry when the 68000 came out.
For those not good with Acronymes HCF = Halt and catch Fire.
http://research.omicsgroup.org/index.php/Halt_and_Catch_Fire
Last edit: Dave B 2016-05-09
Thanks very much for the help !