Jason Hsu wrote: > I have found that the LED sometimes won't light even with TRIS4=0. > Fortunately, (after much frustration) I have been able to resolve this > problem by setting RA4=0. If you're setting RA4=0 at the start of the program, and your program uses the other PORTA pins, then you're probably seeing the effects of Read-Modify-Write (RMW). Basically, when you do a BSF or BCF, the PIC reads the current state of PORTA, changes the bit, then writes it back. The problem is, reading from PORTx (any of the PORT registers) reads the state of the pins, not the state of the output latches. What this means is that if RA4 is above the '1' threshold, you'll read a '1'. This gets written back into the register... The typical workaround is to use a shadow register -- store the state of the latches in RAM, change that, then copy the new value to the PORTx registers after changing it. > Why is setting RA4=0 necessary for turning on the LED? I see on the > datasheet that the RA4 pin also doubles as the T0CKI pin and can be a > Schmitt Trigger input as well as an open drain output. I think this > has something to do with what I have observed, but I'm not sure what. If RA4 is != 0, then the driver FET isn't going to be pulling the pin low -- it'll float high (RA4 is an open-drain output pin and can't drive high). Thanks, -- Phil. piclist@philpem.me.uk http://www.philpem.me.uk/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist