Announcement

Collapse
No announcement yet.

toggle command used on a Varable Bit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • longpole001
    replied
    nope it inverts only the bits selected in this case bit 0 ,, so if i wanted bit 3 inverted my_array[3]= my_array[3] ^ 8

    Leave a comment:


  • longpole001
    replied
    it compiles but it seems like it would change the enitre byte , not the bit 0 only i need to toggle ???

    Leave a comment:


  • longpole001
    replied
    bit wise Xor it seems

    Leave a comment:


  • longpole001
    replied
    not seen that before whats it fuction

    Leave a comment:


  • richard
    replied

    my_array[3]= my_array[3] ^ 1

    Leave a comment:


  • longpole001
    replied
    having some syntax errors when doing a replacement for the toggle command that was used incorrectly in old code , but its bit wise not (~) or ( ! ) wont compile and i prefer if possible not to use the long method of " If then else " to get the result of toggle



    Code:
    my_array var byte[10]
    
    toggle my_array[3] &  $01  ' toggle bit 0 of the array byte 3     - compiles but that not  good as we know
    ~  ( my_array[3] & $01 )     ' bit wise not - wont compile - s\yntax error
    ! ( my_array[3] & $01 )     '  syntax error
    
    if my_array[3] &  $01 =1 then    ' yes it works but not great when you have a lot of bits in various arrays to toggle
       my_array[3] &  $01 =0
    else
      my_array[3] &  $01 =1
    endif

    Leave a comment:


  • longpole001
    replied
    cheers charles , a reminder for those that use the toggle command

    Leave a comment:


  • Charles Leo
    replied
    As Richard points out, TOGGLE, HIGH and LOW will attempt to clear the TRIS bit so that the PORT bit is set to an output. When you use the commands on something other than a PORT bit, they will clear another bit in memory that isn't a TRIS bit. This can lead to some entertaining behavior, depending on the function of the bit that got cleared by mistake.

    To toggle bits other than ports, use the bitwise inversion operator (~):

    my_var.0 = ~my_var.0

    Leave a comment:


  • longpole001
    replied
    yep richard i agree , old code used and redouing the chip it (* 7 years back )had not reviewed that prior )

    Leave a comment:


  • richard
    replied
    not a good idea , toggle clears bit in var x [banksel var] +1,var x, should lead to very hard to bugs .it can only be user on "port" regs

    Leave a comment:


  • longpole001
    started a topic toggle command used on a Varable Bit

    toggle command used on a Varable Bit

    was going though some code i need to reuse , and remember notes from darral on how this command can be a problematic when used on a variable bit

    and looked up link shown

    charles can you advise if this is still a possible problem for the current PBP versions , as this info was some time back

    cheers

    sheldon
    I recently (ok, today) discovered that the PBP TOGGLE command can toggle a variable, as well as output pins (which I used regularly). I just tried a bit var, yep works. Goes 0-1-0-1. Mode var bit Mode_Butn var PortB.1 If mode_Butn = 0 then Toggle Mode LCDout $FE,$C8,"Mode",DEC1 mode
Working...
X