Christopher4187, I for one would set the output ports used for relays and lights to an off default state before I set the direction registers. Also make sure that the interface you use (what ever it may be) also has a default state before power is applied, Ie pulldown resistors on transistor bases and fet gates. This takes care of the undefined state of the outputs during the poweron time when the port pins of the micro are defaulted as inputs. Also make sure you are setting the initial states of variables used in computations for the outputs. I always use the CLEAR directive and then set the initial states of the variables. If you do these things you will not have the random output states you are talking of.

Dave Purola,
N8NTA