I'd always set TRIS before I do any Port I/O... so in Bruces example I'd initialise my PIC...
TRISB = 0 ' all outputs
PORTB = %11110000 ' output logic at power-up
in that sequence.
I'd always set TRIS before I do any Port I/O... so in Bruces example I'd initialise my PIC...
TRISB = 0 ' all outputs
PORTB = %11110000 ' output logic at power-up
in that sequence.
Hi Melanie,
I used to do it that way as well until reading the 16F mid-range ref
manual.
9.11 Initialization
It is recommended that when initializing the port, the data latch
(PORT register) should be initialized first, and then the data direction
(TRIS register). This will eliminate a possible pin glitch, since the PORT
data latch values power up in a random state.
Hi Bruce.
Yeah... I read that too and disregarded it... didn't seem logical to start any I/O operation before you decided what the pin is going to be first. I normally follow the TRIS immediately with my pin initial state value... the school of thought being that the 1uS or so that a pin 'might' be in the wrong state at initialisation isn't going to do anything drastic. The most dangerous peripherals most folks could have are Relays, Contactors or SSR's - and they're just not going to react that fast. Further, there will be a number of clock cycles between physical Power-On and when the PIC actually wakes up and starts executing (kinda like me in the morning between the time the alarm clock goes off and my first cup of coffee!) and executes your first I/O Instruction and TRIS... now that is an indeterminate time anyway which is beyond our control during which the I/O pin will be high impedance - whatever you've got connected to that pin, and depending on the circuit, could float either way anyhow, so what's another uS between friends?
Bookmarks