> Hi. > > I think the actual case here was to set the PORT reg to > some values (using BCF/BSF) *before* the port pins was > switched to outputs by setting the TRIS bits. > > In that case the BCF/BSF could read just about anything from > pins depending on how they was connected. > > The solution here is, as have been said, to use a shadow reg > (that could be set by BCF/BSF commands if that simplifies > the program logic), and then transfer the whole shadow reg > using one MOVWF operation when all bits are ready. I'm not worried about getting the right value written to the PORT register but instead about that value being overwritten by the PIC because the pin of interest is still set to input. Read below for more detail... > > And, if I remember right, the issue was to not have a race > condition on power on so there would not be any > glitch on the output pin(s). That is, setting the PORT reg > before switching the pin(s) to an output using the TRIS reg. This is what I am not sure about though. Let me give an example to explain where I am not clear. Say for simplicity we are concerned with RD0: So when the reference is off (initial condition) we have: TRISD = xxxxxxx1 (x = don't know/care) PORTD = xxxxxxxx But RD0 as an input will sample the low voltage from the unpowered IC input and put PORTD,0 to 0 so we have: TRISD = xxxxxxx1 PORTD = xxxxxxx0 Now it's time to power up the IC - there are two options: (1) Set PORT register before TRIS register: Set PORT register: TRISD = xxxxxxx1 PORTD = xxxxxxx1 Right here is where my question arises. Since there is a low voltage connected to the pin which is configured as an input, then won't the PIC just sample the pin low and overwrite the change I just made? So if I set TRISD = xxxxxxx0 PORTD might already be overwritten to = xxxxxxx0 and the IC gets actively pulled low (which is the case we are trying to avoid). (2) Set TRIS register before PORT register Assuming pin has been input for awhile and is sampled low: TRISD = xxxxxxx1 PORTD = xxxxxxx0 As soon as I set TRISD = xxxxxxx0 then the 0 in PORTD,0 causes the PIC to pull the pin low until the next instruction where I set PORTD = xxxxxxx1 It seems that case 1 is what most people are recommending but what keeps the pin from getting sampled low and overwriting the change to the PORT register while the pin is still an input? Thanks, Nick > > Of course, you could BSF/BCF one PORT reg bit at a time and > modify the same pin at a time in the TRIS, *if* the external > curcuit is such as no pin could be hard driven to the > "wrong" level... > > Jan-Erik. > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu