Sabananthan Paramananthan wrote: > > Hi, > > I've had lot more trouble with PORTA of PIC16C73A/JW. I used RA4:RA0 of > PORTA as test out puts and RA5 as a jumper pin which is pull-up to 5V via > resistor. When I set 1 of the bits or clear one of the bits (bsf, bcf) all > other bits which were set are now cleared! I couldn't figure out why. Then > I read through the part which says every write to i/o port is read modify > write operation. However, this will affect only if I use the pins as both > inputs and outputs but not when they are fixed as either input or output. Not true, the problem you have noticed is also if the port pin are all outputs and you don't change direction. You are correct to say that write to port is actually read/modify/write but the read part gets the value _directly_ form the output pins. So if your program drives bit 3 high but the corresponding pin is tied to ground the read operation gets a '0' for that bit. When the PIC writes back the modifyed value to the port the bit 3 is written as '0'. > The solution was to use a temporary variable to and set or clear bits in it > and write the whole register back to port and use the register as a copy of > port of outputs. Problem with with this method is instead of one > instruction, we need three instruction for every single bsf, bcf operation > on a port. > > bsf PORTA,3 > > becomes: > > bsf TEMPA,3 > movf TEMPA,W > movwf PORTA Yes, this is a solution if you have this kind of problem. Ciao Marco ---- Marco DI LEO email: m.dileo@sistinf.it Sistemi Informativi S.p.A. tel: +39 6 50292 300 V. Elio Vittorini, 129 fax: +39 6 5015991 I-00144 Roma Italy