Don't read the port. Just set the "pin" in portbuf, then copy it out to the port. As long as you ALWAYS set the pin in portbuf FIRST, you will never loose anything by not reading the port. -- James. -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Martin Sent: Friday, January 25, 2008 11:35 To: Microcontroller discussion list - Public. Subject: [PIC] macros to get around read-modify-write Do you use macros in your assembly program to get around the fact that you shouldn't be using read-modify-write commands on a port? I wrote two macros that should accomplish this: setb macro port, pin movff port,portbuf bsf portbuf, pin movff portbuf, port endm clrb macro port, pin movff port,portbuf bcf portbuf, pin movff portbuf, port endm Simple, right? They don't work right. If I do this: setb PORTB,0 setb PORTB,1 nop clrb PORTB,0 clrb PORTB,1 Pin 0 is set then goes low while pin 1 goes high, then pin 1 goes low - so it looks like the second "setb" doesn't occur until pin 0 is cleared. The pulses don't overlap at all. Do you know what the problem is? - Martin -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist