
LPC Demo Board Lessons
3.2.7
Lesson 7: Reversible Variable Speed Rotate
Lesson 7 combines Lessons 5 and 6 using the button to reverse the direction of rotation
when the button is pressed and adjusting the potentiometer to control the speed of
rotation.
The program needs to keep track of rotation direction and new code needs to be added
to rotate in the other direction.
Lesson 5 rotates right and checks for a ‘ 1 ’ in the Carry bit to determine when to restart
the sequence. In Lesson 7, we’ll also need to rotate left and check for a ‘ 1 ’ in bit 4 of
the display. When the ‘ 1 ’ shows up in bit 4 of the display, re-insert it into the bit 0
position.
EXAMPLE 3-6:
REVERSIBLE VARIABLE SPEED ROTATE EXAMPLE
Original Version:
Rotate
RRF
Display,f
BTFSC
BSF
STATUS,C
Display,3
;Did the bit rotate into the carry?
;yes, put it into bit 3.
Bidirectional Version :
Rotate
BCF
BTFSS
GOTO
STATUS,C
Direction,0
RotateLeft
;ensure the carry bit is clear
RotateRight
RRF Display,f
BTFSC STATUS,C
BSF Display,3
GOTO MainLoop
RotateLeft
RLF Display,f
BTFSC Display,4
BSF Display,0
GOTO MainLoop
? 2005 Microchip Technology Inc.
;Did the bit rotate into the carry?
;yes, put it into bit 3.
;did it rotate out of the display
;yes, put it into bit 0
DS51556A-page 25