Page 74 - Making PIC Microcontroller Instruments and Controllers
P. 74
6' CO TNOLl|ilG IHE OUTPUT AIID BEADING THE II{PUT
Servo Position Control tor an Fi/C servo trom PORTB butlons
(This program uses a servo on Jumpet J7) lcontinued)
CENTERPOS VAR IIORD : s- o por io /d- abl-
MAXPOS.VAR WORD : s6 o pos io d- abl-
MMPOS 1IAR WORD : s- o pos io d abl-
POSSTEP l/AR BYTE r servo position step variable
SERVOI vAR PORTC.I ; alias servo pln Use.l? for sedo
POS=o r set variables
CENaERPOS -1540 r set variables
MAXPOS =23{0 ; set varialrles
MTNPOS =740 ; set varialrles
POSSEEP =5 ; set varialrles
AICOIiI1 = %00000111 ; PoRTA and PoRTE Lo diqital
LOW PORIE.2 r LcD R/W Los = write
PAUSE 100 ; wait for LcD to startup
OPTIOII_REG = $01111111 ; enable PORTB pullups
I,oW SERVO1 ; servo output Lon
GOSUB CENTER ; center seno
LCDOI'I $FE, L j clears screen only
UAINIOOP ! ; nain progf,d toop
PORIB = 0 PoRTB lines low to read butrons
ERISB = 511111110 ; enable first low of buttons on kybd
IF POREB.4 = 0 IHEN GOSttB I,EFE; check if any button is pressed
IF POR'B.5 - 0 ltlEN GOSttB CENTER ; and make a nove
IF PORIB.6 = 0 IIIEN GOSttB RIGHT ; accordinqly
LDOUT $Fa. $80, 'POSIIION = \, DEC4 POg r \ \ ;
SERVO1 = 1 ; siart seflopulse
PAUSaUS POS
SERVO1 = 0 ; end selvopulse
PAUSE 15 ; selvo update rare about 60 Hz
GOIO llAtllt OOP ; do it all folever
LEFI: ; move selvo left
IF POS < llAXPOg rgEN POS = POS + POSSBEP ;
RET('RN
RIGSI: ; nove servo right
IF POS > IIINPOS EIIEN POS = POS - POSSIEP ;
BETT'RN
CENTERT ; cenler servo
POS = CEMfERPOS
RE![URN
END ; end ploqram
Now, let's nuke Progran 5. 1 I more sophisticated by using the tbr€e potentiometers on
the LAB-XI board to manipulate the three va.iables that control the center position, the
end positions, and the incremental move of the servo in the Program 5.11. We will use
just one variable to adjust both end positions because we have only three potentiometers.