Page 207 - Making PIC Microcontroller Instruments and Controllers
P. 207
OTES Olt US TG SEVEN-SEGII|ENI DISPLAYS 203
iili6jiladt1fa0l: Finished pulse counting prcglam (continuectl
Q=Q+1 ; counler ro take jiEter ouL of display
IF Q<15 THEAI , don'! do anything
ELSE
PULSIN PoRTA.4. 1. PUI,SE LEN ; read the pulse length on rise
Q=0 ; reser councer
E\IDIF
VAUTE=48500/PULSE_IJEIiI ; converts pulse tength to count
IF VALUE>1000 THENI DrGrTl=2000 + VrrUE/1000 ; separate
IF VAIUE>100 THEiI DIGIE2=2000 + (valuE//1000)/100 ; out the
IF vaI-uE>lo TIIEiI DIGtt3=2000 + {{valuE//1000)//100)/10 ; four
IF varuE>o TIrlriI DrGrT4=2000 + ({vAlUE//1000)//100)//10 ; dlSits
GOSUB DISPLAY , show value on the 4 seven seg displalrs
GOTO !4aIN ; do iL over
DISPLAI: , reads each digi! and lhen
READ DIGITI, VALI'E ; displays iT
PORTA=%o0000001
GOSI'B SHOVT
PORTA=%o0000010
RE]A.D DIGIT2I \IAIJI'E
GOSUB SHOW
POR|!A=%o0001000
REA.D DIGIT3, VAIJVE
GOSUB SIIOW
PORTA=%o0100000
REA.D DIGIT4, VAIJUE
GOSIIB SIIOW
RE!fURN
sHow: ; shows each seqnenL one at a tine
2=%11111110 ; selects one selrnent at a time
FoR x=1 To a j do the 8 segnents, includes dec poidt
Y=VAL['E ; get Yalue !o shot
Y.2=L ; inhibits the decinal poinL
PoRTB=vaIruE I Z , nakes value and z select one segnent
z=(z<<L)+l ; qo to next segnent
PAUSEUS P ; pause tO Shor segnenL
NEXT x ; next se€F(ent
POREA=o ; cLear PORTA
PORITB=o ; clear PORTB to prevent ghostinq
PAUSEUS P ; Pause Lo show clear
RIIURN ; end of subroutine
EIID ; end at1 proqrans uith end
If we want 10 lum somelhing on or off at a certain lvith our controllet all we have
rym
to do is add the condilion in thc loop. For example, if we wanled 10 have an LED come
on at I 750 rpm and go off at 1800 lpm. the code for adding that condition would be as
iollows. we will use the LED at PORTD.0.