Menu

Need hel on XOR & #

Help
Paul Haug
2017-05-22
2017-05-22
  • Paul Haug

    Paul Haug - 2017-05-22

    I am trying to xor two bytes together with the results in one of the two bytes.
    I have spent consertable time looking at GCB documentation and see it is mentioned but cannot find an example.
    Also is there a way to flip a port bit with one instruction ?
    Many thanks to all on this forum for previous help also

    Paul

     
  • Chris Roper

    Chris Roper - 2017-05-22

    You can't do it in one instruction on the PIC12/16/18 devices like you can on the PIC32 as they do not have a toggle register.

    But it can be done in one line of GCBASIC code
    The following example should help:

    MyPORT = MyPORT XOR MyMask

    Where MyPORT is the Port you ar interested in, eg. PortB
    and MyMASK is the Port pin or Pins eg. 7

    Working example Flashes PortB.7

    #chip 16F877a
    
    Do
      PortB = PortB XOR b'10000000'
      wait 100 ms
    Loop
    

    Chears
    Chris

     
  • Paul Haug

    Paul Haug - 2017-05-22

    Thanks Chris,
    Both of those example are good for my task and I tested to see them work.
    I have this thing about the need to understand code in detail, so I will lookup the FnLSL function to clarify to myself how your code works. It's beautiful.

     
    • Chris Roper

      Chris Roper - 2017-05-22

      FnLSL is designed to emulate the C function <<
      So where in C or C++ code you see
      MyVal = 1<<4

      You can replace it in GCBASIC with
      MyVal = FnLSL(1, 4)

      Hope that helps.

       
  • Chris Roper

    Chris Roper - 2017-05-22

    Actually GCBASIC has got a Toggle instruction, as '=!' returns the logical inverse.
    So we can create a Macro that gives you the toggle command you need:

    '
    ' Flash an LED connected to PortB.4
    '
    #Chip 16F877A
    
    #define MyLED PortB.4
    
    Dir MyLED Out
    
    Do
      Toggle(MyLED)
      wait 100 ms
    loop
    
    Macro Toggle(MyPIN)
      MyPIN =! MyPIN
    End Macro
    

    Cheers
    Chris

     
  • Paul Haug

    Paul Haug - 2017-05-22

    Even better. Thanks.
    .
    will use like this, no need for the macro now to keep it simple.
    portb.3 =! portb.3 ; The toggle cmnd is =!

     

    Last edit: Paul Haug 2017-05-22

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.