Menu

NOT is not working for me...

Help
2016-05-01
2016-05-09
  • Blaise Barton

    Blaise Barton - 2016-05-01

    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.

     
  • William Roth

    William Roth - 2016-05-02

    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
    • Max

      Max - 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> :

      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


      NOT is not working for me...

      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gcbasic/discussion/579126/
      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
  • Hugh Considine

    Hugh Considine - 2016-05-02

    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!)

     
    • Chris Roper

      Chris Roper - 2016-05-08

      (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.

       
  • Blaise Barton

    Blaise Barton - 2016-05-07

    Thanks very much for the help !

     

Log in to post a comment.