Page 244 - Making PIC Microcontroller Instruments and Controllers
P. 244
2trt UI{DERSIANDII{G tHE COUt{tEn$ COUI|II O ITAFBLES
ll?iiiiian*l{li** Program to counl marbles wlth an escapement (confirued)
COUIfEER VAA AYrE ; counter variable
coufrER=o , sets counler
r r - ' '
; l e r l e p - o g r a - r ^ _ 6 ' e L o 9 0 o n d l r p -
oN TNTERRUP' Gctro INT-Roua;NE ; set inlerrupt targe!
- L - i n i q a c 6 s q -
; s e t : d - i c o . o i - ' o r ^ d s d e - a m j n e d
PC/!0=160 ; cLose top gate
pOTl=100 ; close botLon gate
- ' n
w d i . - L l ^ e p . o s s
WAITI,oOP: ; this is lhe loop for wailing Lo sLart
IF PORTB.4-l IltgN ; switch is connected to
GoTo 9fAIELooP ; line 84
EI/SE
ENDIF
RETURII
Since we wilL be readins the pholo-Lransistor on port B0 we
have to set PORTB
so that B0 is an input.
We are goinq to use lhe interrupb fearure of B0 in laLer
progrms so we want !o keep the sensor on 80.
i,ie could have use any line
TRrsB -?11111111 , r. r.ut. t" reassign lhis here tor
; B0 input
LOoP: ; main loop
PORfD.3=PORIB. O ; so you can see the siSrnal on D3
PCfr0=120 ; open top gate
r,cDouE $FE. $80, DEC3 POE2." \,zPntSS REgEtz
r,cDom $FE, sco, DEc3 couMlER, "
rF PoRIB.O=0 TIrE!{ l,ooP ; if no marble then go back to loop
.ADCIN O, POI2 ; r:ead POT0 for servo wait pause
POT0-158 ; open top erafe
pOTl=150 ; close botton gate
c,osuB FAUSER ; Pause beLween moves
PO4r0=125 ; close top gate
Pdrl-120 ; open botton gate
GosttB PAI'SER ; pause be.ween moves
cot NTER=cottNTER + 1 ; count Lhematbte
GoIo I.ooP ; go back to top
(ContinueO