I had the exact same problem when I was trying to drive a mosfet directly from a port pin. Turns out is *was* the read-write-modify problem. I was using a BCF on one pin immediately followed by a BSF on another pin. The first pin wouldn't get pulled low. If I connected a high speed digital scope I could just see a tiny glitch on the pin. Adding a NOP between the instructions cured the problem. I was only running at 4MHz, so I put the problem down to gate capacitance on the mosfet. These days I generaly don't do bit clears and sets directly on ports. I perform bit operations on a shadow register and then copy the shadow register to the port. You *can't* get bitten by this quirk if you do that, although it does take a few more instructions. Regards Mike Rigby-Jones mrjones@nortelnetworks.com > ---------- > From: Dave Johnson[SMTP:djohnson@SIRIUS.COM] > Sent: 04 January 1999 02:12 > To: PICLIST@MITVMA.MIT.EDU > Subject: porta troubles > > I discovered a problem with either my circuit or my PIC code, and I'm > stumped. Not sure anyone can help "remotely", but on the off chance the > symptoms ring any bells for anyone, I thought I'd write it up. > > One of my porta pins (this is a 16f84) is used to turn on and off power > to an external device. porta has some input pins and some output pins, > but none of them change from one to the other, so I don't think it's a > "read-modify-write" problem. > > The pin is directly connected to the input of one gate of a 74HC14 (hex > schmitt inverter), and the inverter in turn drives the gate of an > n-channel MOSFET: so when the porta pin is high, the inverter output is > low, turning the FET "on". And vice versa. > > I'm using bsf and bcf to toggle the pin. The problem is that the pin, > once it's been brought high, doesn't seem to want to go back low. I > assume it's a software problem, but I've been over the code many, many > times and can't find it. And in fact the simulator tells me it's working > fine: under simulation, the pin goes low when it should. But in the > circuit, once it's on it stays on. Weird. I'm stumped. > > I can't for the life of me think of any electrical reason the pin should > get stuck "on", can anyone else? I've tried several different PICs, and > the symptoms are the same, so I don't think I blew up that pin. Besides, > when I reset, it goes low, as it should at startup. > > Any ideas or debugging techniques that might be helpful will be greatly > appreciated. > > Dave Johnson >