> Van: > Aan: PICLIST@MITVMA.MIT.EDU > Onderwerp: Serial Blues Continued > Datum: vrijdag 19 juni 1998 1:01 > [Cut] > I found a reference in a book I have by Mike Predko that talks about the > problem using BSF and BCF that a read takes place and if the line is > pulled high via another device, it will be set high after the read takes place. > I believe that exactly what one of my problems may be. I am not sure what > the simpliest way is to solve this problem because I use the BSF/BCF > instruction throughout the PIC serout routine which is timing sensitive. > > Am I to understand using the MOVLW AND MOVWF PORT,B or the AND > (other) command will not inadvertently alter the pin states? All instructions that change data with regards to allready existing data are prone to this effect. Those instructions have to read, modify and than write the data back to the origin. And Yes, BCF does a _Byte_ read, OR the byte with the appropriate bit-mask (2^Bit-Number) and writes the Byte back. So does allmost every instruction (exept instructions like CLRxxx, BTFSx, MOVF, etc.) But, now the good part, you only have to think about it when using _I/O_. > Should I rewrite all my routines to eliminate BSF/BCF instructions? No. Those you could replace with something like : MOVLW 0x01 << BitNumber IORWF PORTx and thus emulating a BSF instruction, but alas, the IORWF has got the same problem. The only way to get rid of this effect is to use the 'shadow-register' method. Take a register, modify that and than copy it to your I/O-Port. Example : BSF SHADOWB,5 MOVF SHADOWB,W MOVWF PORTB > What is the most efficient way to alter a single output line? For example > if I want to set portb,5 high what instructions can do this efficiently without > altering the other pin states? Maybe the AND command? Could someone > provide an example? Normally, when you define your in & outputs and do not change them anymore (the directions I mean :-) you won't have a problem. Only when you change a Input-pin to Output this will happen. Example: BSF STATUS,RP0 MOVLW B'00001111' ; Low 4 are Input, High 4 are Output MOVWF TRISB ;/ BCF STATUS,RP0 CLRF PORTB ; Output the code B'0000xxxx' ; No input is suplied at the low 4 pins. They are all 1 (High) BCF PORTB,6 ;Change Output to B'0100xxxx' This will work fine, until you change one of the Input-pins to Output. Why ? Ok Follow me... BCF is a Read-Modify-Write instruction, right ? Ok. Read PORTB. Result is ........ Yes, Its 00001111. (try it out !) Now Set bit 6 : 01001111. And write it back. The Output-buffer for the Low 4 pins has changed from 0000 to 1111 because if the state the inputs were in. If you now change pin 0 to Output it will be High, and not Low. > By the way I am not sure what the term "bit banging" means. I think it > means bit manipulation using instructions such as RRF,RLF, AND, OR > etc. and not MOV or SWAP etc. Am I correct? My definition of the term is that only BCF and BSF instructions are used for "bit banging" (changing I/O pin levels), because AND & OR are Byte-instructions (although they can change a single bit, but so can a INC or MOV instruction). But, as said, thats _my_ definition. > Thanks Your welcome. Greetz, Rudy Wieser