Read-Modify-Write - Something that every PIC programmer should be aware of. Whenever you write a bit on any register, including port registers, the CPU= =20 actually reads the whole register, modifies the bit you want to set/clear a= nd=20 then writes the whole register back. When you write a port pin it sets a la= tch=20 on that port but when you read it, it is the actual voltage on the port pin= =20 that is read.=20 This would all be fine in an ideal world. However, it can take some time fo= r=20 the actual voltage on a port pin to rise from a 0 to a 1 (or vice versa). T= his=20 is depending on the capacitive and resistive load on that pin. Before the port pin output voltage have reach the threashold value for a=20 digital 1 on the input circuitry for that pin it will be read as a 0. So ev= en=20 if you have set the port pin latch to a 1, it can take some time before the= =20 port register bit for that pin will be read back as a 1. Now, if you set two bits on the same port right after each other, the secon= d=20 write can reset the first because the output pin for the first bit has not= =20 settled to a high level yet (as read by the input circuitry). There are a couple of ways to solve this. On newer pics, each port actually has two registers, the port pin register= =20 itself that sees the voltage on the port pin and also the latch register th= at=20 holds the value last written to the port. The latch register is always a 1 = when=20 it has been set to a 1 even if the voltage on the port pin hasn't reached i= ts=20 final voltage yet (and ofcourse vice versa for a 0). Therefor you should us= e=20 the latch register when writing individual bits to a port since a read on t= hat=20 register always reflects what was last written. Older pics can't read the latch register so there you have to solve the pro= blem=20 by not writing individual bits to a port register one at a time but instead= =20 always write all bits at once. You do this by using a shadow register (whic= h=20 works the same way as the latch register). Set and clear individual bits to= the=20 shadow register and then copy this whole register to the actual port regist= er.=20 This way, writing an individual bit to an outport, never involves a read on= =20 that port. /Ruben =20 > not sure i fully understand your suggestion. could you provide a a few li= nes > of code for me to view? >=20 > thank you >=20 >=20 > >> On a PIC16F88, I would use: > >> #define LED1 PORTAbits.RA0 >=20 > > In most cases this will put you at the mercy of the Read-Modify-Write=20 > > problem. Better define a bit in a porta-shadow register, chacge that=20 > > bit, and copy it to PORTA after each change of any bit. >=20 > > --=20 >=20 > > Wouter van Ooijen >=20 > > -- ------------------------------------------- > > Van Ooijen Technische Informatica: www.voti.nl > > consultancy, development, PICmicro products > > docent Hogeschool van Utrecht: www.voti.nl/hvu > > C++ on uC blog: http://www.voti.nl/erblog >=20 >=20 >=20 >=20 > --=20 > Bill > Key fingerprint =3D DB4D 251B FE8A BDCD 2BE4 E889 13F1 78D0 A386 B32B >=20 > --=20 > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124 200 39 Malm=F6 Sweden www.liros.se Tel +46 40142078 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .