This note only applies to PIC chips with LATx registers.
What I mean by "toggle" is... if the Pin is ON , then Turn it off
and if the Pin is OFF, the Turn it on.
GCB has no Toggle command to quickly toggle the state of an output pin. There is a high level bitwise function called "FnNotBIT" that could be used, but is it rather slow.
This will toggle the Pin ON/OFF at about 620Khz with a system clock of 32Mhz
However to nearly double the speed it can be done as follows using in line ASM with "XORWF"
DIRPORTC.0OUTDoMOVLWb'00000001'XORWFLATC,FLoop
This will toggle PORTC.0 pin on/off at 1 MHz with a 32Mhz System Clock and is probably the fastest possible method on 8- bit PIC Chips with LAT registers. If you know of a faster method I would like to see it.
The Value after MOVLW is a "bit mask" so with bit0 set to "1"
we are telling it to XOR BIT 0 which is PORTC.0.
This method can also be used to quickly toggle multiple pins on the same Port.
TRISC=0'All PortC Pins are outputsDoMOVLWb'00101001'TogglePORTC.0,C.3andC.5XORWFLATC,FLoop
Enjoy
Bill
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This note only applies to PIC chips with LATx registers.
What I mean by "toggle" is... if the Pin is ON , then Turn it off
and if the Pin is OFF, the Turn it on.
GCB has no Toggle command to quickly toggle the state of an output pin. There is a high level bitwise function called "FnNotBIT" that could be used, but is it rather slow.
This will toggle PORTC.0 at about 210Khz with a 32Mhs System clock
A straight forward and faster method can be done as follows:
This will toggle the Pin ON/OFF at about 620Khz with a system clock of 32Mhz
However to nearly double the speed it can be done as follows using in line ASM with "XORWF"
This will toggle PORTC.0 pin on/off at 1 MHz with a 32Mhz System Clock and is probably the fastest possible method on 8- bit PIC Chips with LAT registers. If you know of a faster method I would like to see it.
The Value after MOVLW is a "bit mask" so with bit0 set to "1"
we are telling it to XOR BIT 0 which is PORTC.0.
This method can also be used to quickly toggle multiple pins on the same Port.
Enjoy
Bill