cemments below... Olin Lathrop wrote: > Bob Barr wrote: > >>On the 16-series devices, so does avoiding the use of bit set/clear >>operations on ports by rolling your own read-modify-write operation. >>Reading the whole port in, modifying W as you need to, and then >>writing the whole thing back works well in situations like this. > > > That just creates your own manual version of the read-modify-write problem. > > The problem is that when reading the port bits, you get what the voltage is, > not what the you are trying to set it to. The BSF and BCF instructions do a > read, alter the indicated bit, then write the result back to the whole port > register. This is exactly what you are doing the hard way. > > The problem can be avoided by keeping a shadow copy of the port register > desired value. To change a bit, you first change it in the shadow register, > then write the whole shadow register value to the port. > > In practise the read/modify/right issue isn't as big a deal as the endless > discussions about it might lead you to believe. I have used shadow > registers on isolated occasions, but most of the time it's easy to get > around the issue as long as you're aware of it and understand it. If your > external circuit holds the PIC pin in the opposite state the PIC is driving > it for more than a few cycles, then there is likely something else wrong > anyway. Well-stated on all points, Olin. One unexpected advantage of shadow registers is that you now have a reliable expected value, which allows you to check for external faults, such as solder or trace shorts, or defective peripherals. Just read back what you wrote; if it doesn't match, something is hanging up the pin. Then pass the info onto the tech via on a diagnostic pin (manchester mark code, RES232 serial, etc). Makes the production line troubleshooter's job MUCH easier. --Bob -- -------------- Bob Axtell PIC Hardware & Firmware Dev http://beam.to/baxtell 1-520-219-2363 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu