To set multiple bits in a port: movlw (1<<4)|(1<<3) iorwf PORTC,F To clear multiple bits in a port: movlw ~((1<<4)|(1<<3)) andwf PORTC,F To complement (toggle) multiple bits in a port: movlw (1<<4)|(1<<3) xorwf PORTC,F Bob Ammerman RAm Systems ----- Original Message ----- From: "Olin Lathrop" To: Sent: Wednesday, August 18, 2004 10:41 AM Subject: Re: [PIC:] simple code question > > Hi to every one of you every where > > A Very concrete question: If in the following code I want to clear > > bit 4 and bit 3 and then call the delay and then set both bit 3 and 4 > > Basically, instead of one pin at the time I want to make two pins > > high or low How can I do this? Would simply bcf PORTC, 4,3 work? > > No. BSF and BCF operate on only one bit at a time. To change multiple bits > simultaneously, you have to write a new value to the whole port. To just > set bits 4 and 3, read the port, OR with the appropriate mask, then write > the result back to the port: > > dbankif portc ;make sure banks are set for access to PORTC > movf portc, w ;read the old PORTC value > iorlw b'00011000' ;make sure bits 4 and 3 are 1 > movwf portc ;write modified value back to port > > To clear bits, AND with the appropriate mask: > > dbankif portc ;make sure banks are set for access to PORTC > movf portc, w ;read the old PORTC value > andlw b'11100111' ;make sure bits 4 and 3 are 0 > movwf portc ;write modified value back to port > > Beware of the read-modify-write behaviour of I/O ports. On a read of the > port register, you get what the pin voltage is, NOT what the output latch is > set to. These can differ if the pin is an input, or the external circuit is > forcing the pin level. There is a bit more to this but it's been discussed > many times here before and is also well documented in the manual. Make sure > you understand the issue. > > > ***************************************************************** > Embed Inc, embedded system specialists in Littleton Massachusetts > (978) 742-9014, http://www.embedinc.com > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu