-
Speed of commands
I used a PIC12F1501 to try a little experiment. I wanted to see how much faster LATx.y = z works than HIGH PORTx.y. So here's the premise; 4 MHz OSC, LOOOOONNNGG DO/LOOP, and an LED that tells me which version I'm looking at. Here is the short version:
DO
HIGH LED
FOR w0 = 1 to 10000
HIGH PORTA.2
LOW PORTA.2
HIGH PORTA.2
LOW PORTA.2
(about 32 times)
NEXT w0
LOW LED
FOR w0 = 1 to 10000.
LATA.2 = 1
LAT.2 = 0
(another 32 times)
NEXT w0
LOOP
I found commanding the LAT register to be about 3 times faster than using the HIGH/LOW commands. Just wanted to share.
-
Re: Speed of commands
HIGH and LOW commands first set the corresponding pin(s) to be output; then change the state of the pin to 1 or 0.
Therefore, it produces a few more lines of code behind; and it takes longer time.
-
Re: Speed of commands
Yes you should be doing porta.2 = 1 once tris is setup once at the beginning.
That would hopefully translate to a single set bit instruction.