"The simple fix is to setup all output port latches & TRIS registers in
the initialization/startup section of your code."
Bruce - are you saying to use TRIS to set the pins as outputs when the program starts?
Eric
"The simple fix is to setup all output port latches & TRIS registers in
the initialization/startup section of your code."
Bruce - are you saying to use TRIS to set the pins as outputs when the program starts?
Eric
Absolutely.
Example:
DEFINE OSC 20
MyVar VAR BYTE ' Define all variables, etc,,
PORTB = %11110000 ' output logic at power-up
TRISB = 0 ' all outputs
Main: ' Main code starts here.
The very first instructions that execute will be port latch setup (value
to place on any output pin at power-up), followed by TRIS settings.
Thanks Bruce et all for your help and insights into helping solve this issue. I've probably put a good 15 hours overall into wrestling with this issue.
Many thanks again!
Kind Regards,
Eric
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