PDA

View Full Version : differences using high- low or 0 1



volcane
- 18th August 2010, 23:26
Hi!

what are the differences between this code has the same function but in the first instance the code is longer than 4bytes?

SYMBOL led =PORTA.4
HIGH led
PAUSE 1000
LOW led

SYMBOL led =PORTA.4
led=1
PAUSE 1000
led=0

mackrackit
- 18th August 2010, 23:55
It is my understanding that HIGH/LOW sets the TRIS

0/1 needs to have the TRIS set before hand.

tenaja
- 19th August 2010, 00:14
Dave is correct. The High/Low commands perform a PortX.y = 1/0, and also set the TrisX =

They are for...
a) BS2 code compatibility,
b) idiot-proofing the compiler--which is a subset of a), really, as a helpful tool for newbies,
c) when you are regularly toggling back & forth between input & output,
d) you have extra code space you are trying to fill up, and


Unless you are alternating input/output, or you only set the pin once, they take twice the code space as a direct pin setting. For output pins often accessed, I prefer to toggle the sfr's directly, because...

a) you can set multiple bits at a time. i.e. TrisA = COMMUNICATE, (or for more symbol-happy people, PortA_IO_Directions = COMMUNICATE) for when your device is plugged into the pc.
b) you can set the output state to a helpful symbol--which also comes in handy when you are developing the h/w, and aren't sure if you'll be wiring things active high or active low. For instance, LED1 = LED_ON is more helpful in code reading than Low LED1.
c) it's shorter.
d) I've learned to distrust compilers for stuff this simple. (Case in point: ALL compilers [including PBP] screwed up the a/d port selection bits on the 16f88x pics when they first came out.)
e) if you are the one always setting the Tris fsr manually, you'll never be surprised when it changes.

Acetronics2
- 19th August 2010, 09:32
Hi, Tenaja

you forgot it is a very good way to mask the " RMW issues " of the 10/12/16F series ... ;)

Alain