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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.4Dir MyLED OutDo Toggle(MyLED) wait 100 msloopMacro Toggle(MyPIN) MyPIN =! MyPINEnd Macro
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
Chears
Chris
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.
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.
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:
Cheers
Chris
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