8-pin Flash PIC® Microcontroller Tips ‘n Tricks
TIP #18 Swap File Register with W Ejemplo 18-1 SWAPWF
MACRO XORWF XORWF XORWF ENDM
REG REG,F REG,W REG,F
El siguiente macro intercambia los contenidos de W y REG sin usar un segundo registro. Necesita: 0 TEMP registers 3 Instructions 3 TCY Una manera efficiente de intercambiar los contenidos de un registro con el “working register” es usando tres instrucciones XORWF. No requiere de registros temporarios. Aquí se presenta un ejemplo:
W
REG
Instruction
10101100
01011100
XORWF REG,F
10101100
11110000
XORWF REG,W
01011100
11110000
XORWF REG,F
01011100
10101100
Result
Page 1-14
TIP #19 Bit Shifting Using Carry Bit Rotar un byte por medio del “carry” sin usar RAM RAM variable para el loop: • Adaptado fácilmente para rutinas de transmisiones de interface en serie. • El “carry” bit se limpia (excepto en el ultimo ciclo) y ciclo se repite hasta el “zero bit” esté seteado indicando el final.
Ejemplo 19-1 LIST P=PIC12f629 INCLUDE P12f629.INC equ 0x20 buffer bsf rlf bcf btfsc bsf bcf rlf movf btfss goto
STATUS,C buffer,f GPIO,Dout STATUS,C GPIO,Dout STATUS,C buffer,f buffer,f STATUS,Z Send_Loop
;Set 'end of loop' flag ;Place first bit into C ;precondition output ;Check data 0 or 1 ? ;Clear data in C ;Place next bit into C ;Force Z bit ;Exit?
© 2008 Microchip Technology Inc.