Page 225 - Making PIC Microcontroller Instruments and Controllers
P. 225
IIIIERVALSWITH TlilEBS: tHE METRONOI{ES
222 CREATING AGCUnATE
lltlililiili.iliill6l{lll Prosram to use the tachometer board as a melronome
(Continuedl
9IRITE 2000, %00000110 , the nli]rer 0
WRITE 2001, %10111110 ; the numltrer 1
IIRITE 2002, %01001100 ; Lhe nun$er 2
wRItE 2003. %00011100 ; Lhe nu!$er 3 will depend on
WRITE 2004, %10110100 ; the mmber 4 how your par!icular
wRrTE 2005, %00010101 ; the nunber 5
vrRIfE 2005, %00000101 ; ihe nurnber 6
9IRITE 2007, %10011110 ; the nurnber 7
lrRlTE 2008, %00000100 ; the nlrnlrer I
l,lRITE 2009, %00010100 ; the nunber 9
DEFTNE aDC BITS 8 ; set nunbei of bits in resuLt
DEFINE a.DC_CIJOCR 3 ; set clock source (3=rc)
DEFTTIE ADc SAMPLEUS 50 ; set sanpling line in us
tRIsA=%o0000000
TRISB-%00000000
TRISC=%11111001
TRISE=%00000100
P VAR WORD ; pause vaiiabte
X 1IlR BYTE ; counler wariable
NUII VAR WORD ; number read fron Pot
LEDPOS VAR WORD ; position in display
VAI,UE VAI IdORD ; value of metronone counts
DIGIT VAR BYTE ; each diqit in dispLay
; pause in nicroseconds
ADCONl=?00000000 , this selects f,rst line in the table
tlitTCON.5=1 ; sets us the inlerrupt enab}e
' '1dg _-
INTCON.2=0 te npf so - aJ oe
oPTroriI_REG-%00000011 ; sels Lhe prescalar to 16
HIGH DORTC.2
ON INIERRUPT GoTo rNT ROUTINE 6lc p oqrd rl-r- o oo o.
; interrupt
MAIN. ; nain Loop of progrran
ADCIN 7. liuu ; read channeL 0 pot vaLue
!EDPos=208- ( ( (20a-40 ) *NuM) /255 ) ; the potentiometer
; position value
VAIIIE-IJEDPOS ; remenber value we are
; working dlLh
IF X>=16*15*30/LEDPOS THEN ; this is where we add lhe
; nulriply by 16
tOGGtE PORI[C.2 ; toggLe the speaker
x=0 j reser x
ELSE
ENDIF