Hi Andy, I'm sorry for the confusion. The tip I learned from you many years ago was referring to the #define directive for I/O, not the DQ line assumption in the code snippet. My apologies. I modified his code to show him a different way of doings things with the code. The detailed points you made are excellent, as you pointed out the hardware ramifications of both methods. Regards, Ken Pergola -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Andrew Warren Sent: Thursday, August 14, 2003 12:28 AM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: Re: a better "if .. then .. else" in assembly? Ken Pergola wrote: > Andy Warren taught me this many years ago (thanks Andy!) > > BCF CLK ; Bring CLK low > BSF DQ ; Assume DQ line will be a '1' > BTFSS ReadCmd,0 ; If it IS a '1', skip ahead. > BCF DQ ; Otherwise, force DQ line to 0 > BSF CLK ; Bring CLK high to tell temp. sensor Hmm... I hope he also pointed out that that method is ONLY acceptable in cases where a brief pulse on the DQ pin before every "0" bit won't cause problems. He should also have mumbled something about possible read-modify-write issues with such fast consecutive writes to the same port, and he should CERTAINLY have reminded you to check the setup-time specs for the device to which you're talking, to see whether a NOP or two is needed between BCF DQ and BSF CLK. By the way... The original method Sabachka showed, BTFSC SomeBit BSF Pin BTFSS SomeBit BCF Pin eliminates the little glitch before "0" bits (at the expense of one more instruction and one more cycle), but it has a subtle failure mode: If "SomeBit" can change between the BTFSC and the BTFSS (e.g., if SomeBit is an I/O pin, or a bit in a timer register or something, rather than a general-purpose register bit), then BOTH or NEITHER of the branches will be taken. Often, this isn't a problem, but it's something to keep in mind. -Andy P.S. My personal syntax preference for register-oriented instructions that place their result back in the register is neither ",1" nor ",F"; I simply omit the suffix entirely. Makes the code much more readable, in my opinion: DECF REG ;Decrement REG. DECF REG,W ;W = (REG) - 1, REG unchanged. P.P.S. Oh, one more: Andrew Kieran wrote: > I prefer to replace each argument (in this case, PORTx > and BITx) with separate equivalents [rather than] using > one word (e.g. CLK) to represent two items > > When I'm debugging, this helps me to check each part > of the instruction for accuracy. Yes, but if you use one symbol to represent the whole quantity, you don't HAVE to check each part of the instruction for accuracy. === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- 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