You are on page 1of 207

?e o +.

o6 gAT
7q,o cn?ter

{.-"$ e6rycq:.r'l :
o
Gd**39olS1oBeT Q.O6T
o?3'q8:oc:ogJ:qtdAdnr$t"ary {.onry
oq16sa&-* -d-.i8$"q. $.onry

-@$oorc{:gS{{, oaQ:$Eo1 Eqao: o$.cr18@r


-{Ee eo$oii$6eq:98 {Eeeoz5c[:odnqr"? ufr8
"ldqnE$:a1q1*o: 4.qE@"
-{ee6o?Ecll@glog8:e6pcr? o8egcAgcEooEego8 o7cr5eora 0d,r{Eeqp:s)3 4.qE@u
-Gdqae,Gdoo<lcr5oen:qpto: c7q$no@E coo5go8eqg$,@u

-{edccr5@d$6ecpr q8gaeorqE:croaeo:g8 ancp:goesQ:Q:eepr l

-d:ora:S$oo$op!:q:p!go8eq; r

-{Eoco2$ !."drQ oe$5gc'eso6@6eerTcmecpr


-$6e<rTc,rod $pd,Q oe$SgoeeoEf8pd eeoS8ffiolqrc8ecm {EeeofccEo6q8capleoc8ecyr

-Q"4ft.""f,4#65d se$aE:garecpcngpqp:cr?crei: ocr5qg$pof:ocr5esc8 -gln-.8.q,,:


-eqpcac'5E:ga:ecpoqE 6Q8ga$6eoTcrneq:r
-Qd"a8,Gdo9 ooro5ogcg8 saq8:ef:qp:8o56oTd E:ga:ec1:$$1:of:qrc8esa8 ar$eoc8eq:r
-{36eo:6E:go:ecpo6q6q:4 r$"3.{Efe6:o:oc$ f8eeoa\E of8:q8:ar:Sd"A4.r\ cocr5oc'5qeE$eq:r

oRn"q'f,'-dfloE(g)t1"

-caEft:cco:c8:ol So8eloEg€. saoq€.oa{q}E8 tn:eq:r


.ca{pgcdreoc8gor5rsE.,n.eq:94olfecqp1eaegae9Eqp:ro{pcra:eq:coc?cDoqP:eeqpcE<gc$eocE
o8$:c36:eoo8 eqpcf eq:r
-{tr:qE8oEel d j3o$oc'5@rBcq: r

.
o6ft:em:q: ae$!tr{E{Eeq:98. ogeqgl$E tn:eq:r
)?)v) + q)s)cD) r lu ?cDaElc8,i@,ic\, so):floo)cDd:qp:(?l

Prc Qn8"fiqa$oficuc
-erQpo8co8sqps

oQE:(q)

PIC M icrocontrol ler Projects

PART (3)

eee
oc3@moe3

looG EeE e$Eo'lf,co

* e$qo'l{or -i-
tooG Eg6

r
3?l€€a + o:dcno ntC Qde{cg$mfio:o saoi:qoo[o:e\,::j:r(i)

q=olervt

e
ocqlmfs
oceel:11efisa9ooa ilt

soo${c) Example Programs in PicBasic c


c-3 c
c-J c
c-J-3 Program-1 3
c-J-J Program-2 J
c-J-? Program-3 c
r-J-g Program-4 c
c-J-C Program-S G

?-J-G. Program;O G
c-J-? Program-7 2
3-J-o Program-8 e
c-J-e Program-9 o
c-J-ro Program-l0 e
c-J-cr Program-'11 co

-"$dl) Source Code6qfd:-J J?


J-c $"1$' c?
J-J MicrochipPlCl6FS4AMicrocontroller c?
J? Good Programming Techniques ca
J-g The Registers 3C
J -e '
Writing to the Ports' .
Jo
1-G Detay Loops
J3
J-?
Subroutines
J9
J-o Reading from the l/O Ports jG
J-e LogicalandArithmeticOperators
?J
J-co BIT Operations
?3
J-cc Data Tables
9o
J -cJ
lnterrupts
9c
J -c?
lnterrupts - Writing the Code
99
J-cg The Watchdog Timer
9e

looG qq6 e$9o1flco IV o3,.o.3o3:


@?@ + s)e)cn etC Qc'5a{ca$-{* san:q1oo6cu5,et r(t)

ee$:(q) Projects with PlCl 6F628 JE


o ac
('
a-a
E3IE: 3e
?-J Four Digit Counter with 7-Segment LED Display 3e
?-? Digital LED Clock Gc

?-9 Digital Tachometer (or) RPM Meter Gq

?-c LED Matrix Display Gc


q-G LED Calendar/Clock GG

?-?- Frequency Counter Gq


oce
?- 3 o@€3eql[:eoa:os)c\)C):
?- Go

? - ?-J 1
o8<rsa{1:saoa:ooEoc6: Gg

*$'(p) 5x7 Display Circuit- 2 ?3


o ae
9-r f3r+: ?3
9- TURN ON A LED
|
?J
9-? FLASH A LED
?J
9-9 SCAN UP
??
9-3 SCAN UP & DOWN
29
9-G SWITCH WITHOUT DEBOUNCE
?0
' g-2 SWITCH WITH DEBOUNCE
9G
9-o REACTION GAME
22
9-B ANIMATION-1
?o
9-co ANIMATION-2 oc
9-rc ANTMAT|ON-3 (WtpE-Up SUB-ROUTtNE) o9
9 -JJ ANTMATtON-3A (COMB I NATTON) oe
9-c? ANt MATTON-4 (Wt pE-Up & WlpE-DOWr{) oo
^--^
7"> Ar.rrMATiot,t-5 (SLASH SUB-ROUTiNE)
8J
--^-
>"J At'J[lA.TtON-6
'c$
g -cG PRESS BUTTON ''A" AND SPLASH
Go
9-c? STARTiSTOP SPLASH AN IMATION 303
9-ro BULL'S EYE rot
g-cg LED DICE WITH SOUND-1 306)
I -Jo LED DICE WITH SOUND-2 JJ?
g-Jc MAKING A TONE 3J?
9-JJ PRODUCING A BEEP 3f,O
9-J? BEEP AFTER BUTTON A, B AND C 3f,G
9- J9 HEE HAW SIREN 3J3
I -J3 CALLING HEE HAW ROUTINE CJJ
9_JG MAKING A NOTE 3J9
q- lc) CREATIhIG A. SCALE eJt
9-Jo CREATING A TUNE at6
'J-(

t..G .^A ^l-.il.q^- q is

r
:coco@:30 _rn _ co!1oS6o o$& oool

9(9c :oc'Jsoo JanroJau l_G_G


16c
:ecr)coo JalJlrusueJl c_ G_G
[6c
lallorluoc aloLuau JU G-G
fg"
lelai4 a6ueg ctuoseJlln 5-G
eJCc
JelloJluoC alnleladuel uoou c-b
cdc
igAoiaoo rolo!\l :eddalg c- l-G
cdc
roilorluo3 .ro1o141 leddalg f'-G
cdc
clc c-G
g - .6-_reg;eg '$p$
sltnsr!J Ola! (G);$eee

); :.:l-\ ; eo-..p c S, U..^ cr'; !lcc$Pu: b c .,t


1
U J o J o
L ^.,,
viu
ccoaccl) -r. cecJe:
saeS:(c) Example Programs in PicBasic Ptc Qo6a{%$-{* aa1:q1oo8co6,qp,(q)

oo$:(c)
Example Programs in PicBasic
c-lr $s1$:

etc QcEafiq$-fi- saaT:q1oo5co3:qp:saQ8:(c)oog6og8 PicBasic @E.eq.a:a:,5.o2i


c,$oq8qp:c,i {:{ecu.cua{3q$qegdqld@S. gloa$:o38 o$:cc6er:a o{oq3ca{6c,i eoTS
cr'1e2il

c-1rr LED Display Programs

P I c € da fi %$ -$ * san : q1<;oEco3 :qp:saQ 3 : (c)'aq6 *$,(E)qa3 eoTQ;.ccAi,.,fi o q3


qp:13. crl",sTQelEi oe@o8:oepqp:c,? oc6o6p:eco.c,rlq$@6,iop)'r ,:r3:oosp69Q(E-"r)
qEeoTScoe:o$oo6cu6:c,to:gjeoocr5$: gloa$:o3EeoT@oo:rr2) ofioq6qp:cr? G$-d
c eoe i e
0(j:f,Joicol a)agil
elc {oSafiq$-{.-t PlC16F84A) er\ output pin qp:c{ott$Gr LED Disptay ..'fioq6
qp:B?{ SoEq:$cogiooi8: o3og3@o e<rTogo5$3e<.,a:$n PicBasic Q8.ofioq6eq:ar:epq8
output pin -6ti q.er:$6./Ge. @Ee<rTeoq$ Low/Hish command ofcogj:ecno8:r poke
command ctfco2i:ec,:a8: oa2:Qfite@c3r a3$:@6@eoo36.e2ir
{ command qp:crf sae2:
Q1p:r LED Display <.,fi oq6qp:eq:rrc:Q4 oc6ocfe,rT[<iepin

c-J-cr Program-l

Port B efi pin qp:q3 coSaoSo::eo.: LED qp:cf RBO(LSB) 9 RBZ(MSB) od


o:3q:q13: -otdo^1 ON/OFF @Seoe6 High/Low comrnand oe,0[?.,? g]ofioq6o33
eq.@3$Sciogjrr oN/oFF @G3.{$.,? eQcS:o)c$<.im Pause command 9 mittisecond
CO O fi e \ Oe.1 e
cDf t:o? 6[goc:cD6o:{col f,)e]il

I Progl
. bas
rl,ED display, LSB to MSB
' PICl 6F8 4A
'Initialize variable
SymJcol TRISB:134 iAssign TRISB for port B to decimal val-ue of, 134
Sym.rcol PortB:6 rAssign the variable portB to decimaf r.alue of 6
'Initial-ize port (s)
Poke TRISB,0 'Set ALL port B pins to output
Loop:
il ign 0 'Turn on LED connected to RBO
!'ause 500 rDelay for 0.5 second
Low 0 'Turn off LED connected to RBO
cee$:(c) Example Programs in PicBasic PIC qo8a{%i-{* oa?'ejoo5o6,qp'(e)

Pause -c00 'Delav for 0.5 second


High 1 'Ti:rn on LtrD conrlected to RB1
Pause 500 'Lrelay f o:: 0 .5 second
Low 1 "Iurn off LED connected to RB1
Pause 500 'Delay for 0.5 second
High 2 t : c
-r'i-n-ta
Pause 500 'as above
Low 2 t...

Pause 500 I

High 3
Pause 500
Low3.
Pause 500
High 4
Pause 500
Low 4
Pause 500
High 5
Pause 500
Low 5
Pause 500
High 6
Pause 500
Low 6
Pause 500
High 7'
Pause' 500
Low, 7
Pause 500
Goto Loop 'Go back to loop and bfink LEDs forever
'End

c-J-Jil Program-2

e@c6o'l o{oe16g8. oQ$oo9$ra:@8. eorta er\ pin qps%E o6o8oa:e3ra LED


qp:c,f nsz(MSB) 9 RBO(LSB) sao8 oEoT:q1E: ooydqt oN/oFF @Eeoq$ High/Low
command o.i rGtQ 4 gt]c,fi o e.t6 oSE 6%.Ge{ E o1 cogi n

' Prog2 . bas


'LED display, MSB to LSB
'PIC16F84A
'InitiaLize variabl-e
Symbol TRISB:134 rAssign TRISB for port B to decimal val-ue of 134
Symbol PortB:6 rAssign the variable portB to decimal val-ue of 6
'Initialize Port (s)
Poke TRISB,0 rSet ALL port B pins to output
Loop:
High 7 'Turn on LED connected to RB7
Pause 500 'Delay for 0.5 second
Low 7 'Turn off LED connected to RB7
:aa$:(c) Example Programs in PicBasic etC Q
c6afi ca$-{- san:q1oo6co6'W'(t)

Pause 500 'Delay for 0.lr second


Hrgh 6 'Turn on LtrD ronnected to RB6
Pause 5OO 'Delay for 0. 1 second
Low 6 'Turn off LED :onnected to RB6
Pause 5OO 'Delay for 0. 5 second
Hrgh 5 'as above
Pause 500 'as above
Low 5
Pause 500 ' ...
High 4
Pause 500
Low 4
Pause 500
High 3
Pause 500
Low 3
Pause 500
High 2
Pause 500
Low 2
Pause 500
Hrgh 1
Pause 500
Low 1
Pause 500
' High 0
Pause 500
Low O
Pause 500
Goto Loop 'Go back to loop and blink LEDs forever
rEnd

c-J-?[ Program-3

s"codol ofioq6g8qc{ec-'l3:o3c$er5qg3 PoriB er\ pin qp:o33 o:8ao3coo:eoc LED


qp:c{ nso(LSB) 9 RBZ(MSB) sad o:Eg:q3: oogEic,?J 3a?ga:3?@$ ooqo:or6: oN/oFF @3
eqeoe<-,c86.c2lrr glofioq6o38 oqc:sa$$ on@n@r8'ng6pqp:g 16oeiO.6.3,'3"ron'q$
pause ooccDo? 5009 1000 ci.,eQc8:olmo:e@t: arc3@1o1rr

' Proq3 . bas


'LED cii-splay, LSB to MSB and then l.jSR to LSB
' PICl 6FB 4A
'Tnitiaf ize r,ariabf e
Symbol TRISB=134 'Assiqn TRfSE for por:t B to decimat value of 134
Symbcl Por:tB:6 'Assign the variable portB to decimal vafue of 6
'Initial j_ze Port (s)
Poke TRISB,O 'Set ALL port. B pins to output
Loop:
lligh 0 'Tui:n on LEl connectetl to RBO
ause 5CC 'Delay for 0.5 secord

a
J

r
ea$;(c) Example Programs in PicBasic etc Qc8a{q$-{* on:q'o5cu6tep,(t)
Losr 0 'Tu!n off LED connected l-o RBO
Pause 500 'De1ay for 0.5 second
High 1 'Turn on LED connected to RB1
Pause 500 tDel-ay for 0,5 second
Low 1 tTurn off LED connected to RB1
Pause 500 'Delay for 0.5 second
High, 2 'as above
Pause 500 'as abowe
Low 2 t.. -
Pause 500 '-..
High 3
Pause 500
Low 3
Pause 500
High 4
Pause 500
l,ow 4
Pause 500
High 5
Pause 500
Low 5
Pause 500
High 6
Pause 500
l,ow 6
Pause 500 ::
High 7
Pause 500
LOW 7
Pause 1000 'Delay for L second
'Change directj-on
Hiqh 7 'Turn on LED connected to RB7
Pause 500 'Dela1' for 0.5 second
Low 7 "Turn off LED connected to RB7
Pause 50'0 rDelay for 0.5 second
High 6 tTurn on LED connected to RB6
Pause 500 rDelay for 0.5 seeond
Low 6- 'Turn off LED connected to RB6
Pause 500 lDelay for 0.5 seeond
High 5 nas above '.:

Pause. 50,0 'as abowe,


Low 5 t,..
Pause 500 r...
High 4
Pause 50,0
Low 4
Pause 5O0
Hish 3
Pause 50,0
T,ow 3
Pause 500
High 2
Pause 500
Low 2
Pause 500
caa$:(c) Example Programs in PicBasic PIC QoEo{%1-{- ean:q1oo6co6,Qp,(e)

Hrgh 1
Pause 500
Low 1
Pause 500
High 0
Pause 500
Low 0
Pause 1000 'Delay for 1 second
Goto T-oop 'Go back to loop and bfink LEDs forever
'End

c-J-g[ Program-4

ococBol o{oq6qp:cr?cqrra:6pql8 nigntow command ooa: Poke command o?


oe:@tqilE QQcr16o6a36ogi:e@o3: eq.$E$Eeoo$rr Program-1 crt Poke command @E
oq'qilE 6sroEoloo?E:cleoeE)rr (glo{oq6ooei Plc Qcfiofiq$coficua oa7:q1ooEoo6:qp:
oQ8:(c)oaq6er\ oo$:(9)9 Prosram +-z oof8:@Ecc2in)

' Prog4 . bls


rLED dj-splay, LSB to MSB (By using Poke comniand)'
. I PIC16F84A

' Initi-alize variabl-e


Symbol TRISB:134 'Assign TRISB for port B to decimal- value of 134
.' SymboJ- PortB=6 'Assign the variable portB to decj-mal- value of 6
'Initial-ize port (s)
rSet AT,L port B pins to output
Poke TRISB,O
Loop:
B0 : 1 'Set variable to 1 to start blinking at 1,SB
81 : 0 'Set vari-able to 0
Poke PortB, B0 rPlace B0 value at port to light LEDs
Pause 250 'De1ay for 0.25 second
For82=0to6
81 : B0 * 2 rCal-cul-ate next binary ascendj-ng number
B0 : 81 'Set B0 to new value
Poke PortBrB0 'Pl-ace new value at port to light LEDs
Pause 250
Next 82 rNext loop value
Goto Loop

c-J-gr Program-S
cf
eote command @8. eel:ep eoocr5olooiS:eleocplrr Variable eO ca$Q:
Prograrn-2
ocec gaoo:
c?arcogo:cpq3c u 12s up ooEgoEQ %"S:ql#g3. eEacr5o:8ao3, o$$:oo8gc8
qdoa3 (.) gt (4c€aS:go?.c,f go:co2ieoo8eco.c'rcirr

'Proo5.bas
'LED display. MSB to LSB (By using Poke command)
' PICl 6FB 4A
'Initiaiize variable
' SynJ,rol TF.ISB:134 'lissign TRISB for: port B to decirnal value of 134
c""$r(c) Example Programs in PicBasic rl c $eEa$c6$*{ * seri :qjodcu3,qp,(t)

Synbc PortB:6 'Assicin ih.g r-r3aiab,le p-o:rLB .r-c ieciiir.ri vliue'- of 6

'Ini tiali ze Port (s)


Poke TRISB,O 'Set ALL port R p.ins to orltput
Loop:
BO : 728 'Set variable to I28 Lo start blinking at MSB
Bi : 0 'Set variabfe to 0
Poke PortB, B0 'Place B0 value at port to light LEDs
Pause 250 'Delay for 0.25 second
ForF_2:Oto6
BL = BO / 2 'Ca]cuf a-Le next binar:y descendi ng nr-imber
B0 : B1 'Set B0 to new value
Poke PortB,BO 'Place new value at port to light LtrDs
Pause 250
I.lext B2 'Next loop value
Goto Loop

c-J-Gil Progrann-6
LED qprd LSB to MSB or8ogrelS: =old"e c.'3:/8c'l c?,:trt,?'f:d arcri{oE
o:3rry:eoc$q13 es-arc6<-,lsr{3:nry""leucalrr (glc.'floq8og) PIC ,!dafic6$c"fi.r>c sac2:q1
.ro8co6:qc, saQE :(c )toR6er\ cao$:(9)9 Prog ram a-28 :r,fi3z@6 o$ rr)

'Prog6.bas' ' :
I LED display, LSB to MSB in ascending order
'PIC16F84A
'Initialize variable
Symbol TRISB:134 'Assigrn TRISB for port B to decima.I value of 134
Symbol PortB:6 'Assign the variabte portB Lo decimal value of 6

'Initialize Port (s)


Poke TRISB,O 'Set ALL port B plns to output
Loop:
B0 : 1 'Set variabte to 1 to start blinkinq at LSB
81 : 0 'Set variable to 0
83:1
Poke PortB, B0 'Pface B0 value at port to liqht LEDs
pause 250 'Delay for 0.25 second
For82:0to6
B,1 : B0 * 2 'Calculate next bj-nary ascending number
_ B0 : B'1 'Set B0 to new val-ue
B3 : B3 + 81 'New holding variable
Polce PortB,B3 'Place new value at port to llght LEDs
Pause 250
Next 82 'Next loop val-ue
Poke PortB, 0 'Reset to 0
Pause 250
Goto Loop

G
oa$:(c) Example Programs in PicBasic PIC Qc,5afi oai-{ * saaT:q1ooEo5,qpr(t)

c-J-?r Program-7
ooc6<ll Program-6 9 LED qprd MSB to LSB o:6og:q13t soE{cf e@cE:Q$
c o c c a oc c
cDc:38o:cocYqilc GsocDo r sro?c :c$qcoee]il

' Prog7 . bas


'LED display, MSB to LSB 1n descending order
' PIC1 6F8 4A
rfnitialize variabl-e
Symbol TRISB=134 rAssign TRISB for port B to decimal- value of 134
Symbol PortB:6 'Assign the variable portB to decimal val-ue of 6
'fnitialize Port (s)
Poke TRISB,O rSet ALL port B pins to output
l,oop:
B0 = 128 'Set variabl-e to 1 to start blinking at LSB
81 : 0 'Set variab]e to 0
83 -- 1,28
Poke PortB, B0 'Pl-ace B0 value at port to light LEDs
Pause 250 'Delay for 0.25 second
For82:0to6
BI : B0 / 2 tCafculate next binary descending number
B0 = 81 rSet B0 to new value
83 : 83 + 81 "'New holding variable
Poke PortB,B3 'Pl-ace new val-ue at port to light LEDs
Pause 250
Next 82 rNelt loop val-ue
Poke PortB, 0 rReset to 0
Pause 250
Goto Loop

c-J-o[ Program-8
oooS<-ri Program-6 13. Program-7, €.9"EqE LED qp:ogl LSB to MSB
"?."i
ocr5 oi cr5cu8 :@ : eEoc6 M s B to l-S B aoc8 oi c,5 $$ o: E : cooe g)
rr

' ProgS . bas


'LED dlsplay, LSB to MSB in ascendlng order and t-hen MSB to LSB in
'decending order
' PICl 5F84A
'Initial-ize variable
Symbol TRISB:134 'Assign TRTSB for port B to decimaf value of 134
Symbol PortB:5 'Assign the var:iable portB to decimaf val-ue of 6
' Initial-ize Port (s )
Poke TRISB,O 'Set ALL port B pins to output
Loop:
B0 : 1 'Set variable to 1 to start blinking at LSB
81 : 0 'Set r,'ariable to 0
D2 - 1

Poke PortB, B0 'Pl-ace BO val-ue at port 1-o light r,EDs


Fause 250 'Delay for 0.25 second
For 82 : 0 to 6

e'
' tooG oa6 e8so'|8c,'t -9----e-s-
saa$r(.) Exemple Prograrns in FicBasic nlc $da$ca$ co{c:a sae;:q3odo--6,,q,"r(f )

ts1 : BO * 2 'Ca-icul;iLe rie>lt binal;' ascendinE nur.:.}:er


B0 : 81 'Set ll0 to nel -ralue
83 - 83 + 81 'New hr--,idirrg vari-able
Poke PortB,B3 'PLace new val-ue at port to liqr-- LEDs
Pause 250
Next 82 'Next loop value
Poke PortB, 0 'Reset to 0
Pause 1000 'Delav for 1 second
'Change the direc'uion
B0:128 'Set variable to 1 to starr blinking at LSB
81 : 0 'Set variable to 0
83 : 128
Poke PortB, B0 'Pl-ace B0 vafue at port to light LEDs
Pause 250 'Delar/ for 0.25 second
ForB2:0t.o5
BI : B0 / 2 'Calcutate next binary descending number
B0 : 81 'Set B0 to new value
83 : 83 + 81 'New hofding variable
Poke PortB, 83 'l: lace reh' vaf ue a r por-- -.-o L j1r, c LtrDs
Pause 250
Next 82 'i'iexc Locp val-ue
Poke PortB, 0 'Reset to 0
Pause 1000 'DeJ-ay for 1 second
Goto Loop

c-J-gr Program-9
Poke command @8. PortB er\cgiopi pin logic high @6eoi8noan@8.
"r?.{
88co8:eoc$ogi LED qp'4 8o6@c'5€S:qos$Se>airr gl<-'fioe16q€ oco<rS96q: ?oo?E
oc8 : S : eo : gB o cr5cQ$og c'5 cocto -..r.S"q.$$ o3 ap: Q
c{ ooTQ coo: o$ rr

' Prog9 . bas


'LEDs display Out in
I Prc16F84A
' Ini-ti-alize variabl-es
Symbol TRISB:134 'Assign TRfSB for port B to decimal- value of 134
Slnnbol PortB:5 'Assign the variable portB to decj-mal- value of 6
'Initial-ize Port (s)
Poke TRISB,0 'Set ALt port B pins to output
Loop:
Poke PortB,0 'Reset to 0
Pause 500
Poke PortB,24 'RB3 & RB4 ON
Pause 500
Poke PortB,50 'RB2,RB3,RB4, & RB5 ON
Pause 500
Poke PortB,I26 'RB1,RB2,RB3,RB4/RB5 & RB6 ON
Pause 500
Poke PortB,255 'A1l ON
Pause 500

o
caa$:(c) Example Programs in PicBasic etC Q cAa{ ca$-{ * san:qpoEcr:6:Cp,(e)

Poke PortB,255
Pause 500
Poke PortB,126
Pause 500
Poke PortB,60
Pause 500
Poke PortB,24
Pause 500
Goto Loop

c-J-co[ Program-10
Poke command @3. PortB efie;g)og) pin {""fl tosic high @6"oi8eooe@o3.
88co8:eoc$co2) leo qptd 8o5@[d6S:q<rs$Earairr oo$ For...Next loopins @E co8:cogi
sa@6crfooo8g-$80$-$rr glo{oq8oa8 Poke command 93. For...Next oa7tQ1
"?.Q.d
-otQd eoTQoa:<iccE!rr sao:q:co3:-ra::q:$oE SE@6r eg.eor:c'9:oE:-ofl:c6eco:q:co8:
g6@6oqc'5 I qga,-'fi o e16 eq. Soo:..,1 r, g)
rr

Poke command gt. For...Next


"?."a8 -$Qt-{f.{1,e@r3r.c,r@Er@8.
lro qp: pattern
oft, {p @ E. coE :{ e @ Q c,? oc6 c.:cf eco.*@d @.o c$ co 2i
<r'1 rr

'Prog10.bas
'LEDs display ln predetermined orders and repeating
' PIC]- 6F84A
'Initialize variabfe
Symbol TRISB:1-34 'Assign TRISB. for port B t.o decimal- value of 134
Symbo1 PortB:6 'Assign the variable portB to deci-mal- val-ue of 6
'Initialize Port (s) rSet ALL port B pi-ns to output
Poke TRISB,O

Loop:
For 81 : 0 to 1 'Two times looping
Poke portB,255 'A1I LEDs ON
Pause 1500 'Delav 1.5s
Poke PortB,O rAll- LEDs OFF
Pause 1500 'Delay 1.5s
Next 81 'Repeat again
Pause 1500 rDe1ay 1.5s

Eor82:0to1
Poke PortBt24} 'First four MSBs ON
Pause 1500 'Delay 1.5s
Poke PortB,15 'Last four LSBs ON
Pause 1500 'Delay 1.5s
Next 82 'Repeat. again
Goto Loop
*$d") Example Pr-ograms in PicBasic elc Q dafl cA$*6* =acg'qoCorS,qn'(q)
n-----*
i"i ii:i! djii i- 4*
ii
J-j-;jJii

gl'Jfioq8,re3 Gosub comniand $3. prograi-n qpr{"E*qdr.{ ail$""ctoi1::3lr Gcsub


c{oi:Q1ccdoul return 93. Qcc6eri!0t6ic@"3: a:dQ1'cQ,ierE)rr QcAafica$o$cw:"'\
program memory co.t55Q3ono:oc6 ,.ifioe13saeq=nca.6crf {oDQ$3eo.cg)rr esarcr5ca3 ofioqS
(0)t {oEQQ 4 +ffi"-@3.e,rTp.or:c''1 rrp)'r

'Prog11.bas
'Gosub procedure
'Prc16F84A
'Initialize variabl-e
Symbol TRISB:134 'Assign TRISB for port B to decimal val-ue of 134
Symbol PortB:6 'Assign the variable portB to decimal value of 6
'Initialize Port (s)
PoKe TRISB, O 'Set ALL port B pins to output
Main:
gosub loop1
gosub loop3
gosub loop5
gosub 1oop2
gosub loop4
gosub loop6
goto main
'Pattern 1
J-oopl :
Poke PortB, 0
forb0=0to1
hiqh 3
high 4
pause 500
high 2
hi-qh 5
pause 500
hiqh 1
hish 5
pause 500
hish 0
hish 7
pause 1000
1ow 0
l-ow 7
pause 500
Iow 1
Iow 5
pause 500
Iow 2
low 5
pause 500
low 3
Iow 4
pause 1000
o"$:(c) Example Prog,ams in PicBasic erc QcAo{q$-{- on:q1oo6co6,qp(q)

next b0
return
rPattern 2
Ioop2:
forbl:0to1
poke portb,0
pause 500
poke Port.b,255
pause 500
poke portb,0
pause 500
poke portb,240
pause 500
poke portb,0
pause 500
poke portb,15
pause 500
poke portb, O
pause 1000
next b1
return
'Pattern 3
1oop3:
for b3:0 to 1
Poke TRTSB, 0
B0:1
81 :0
Poke PortB, B0
Pause 250
For82:0to6
B1:B0*2
BO: 81
Dnr-_a DnrlD
!L LD
Dn
JV
I

Pause 250
\l^.,t
!\CAL Da
DZ
Poke PortB,0
pause 1000
next b3
return
'Patt.ern 4
loop4:
forb4:0t.o1
Poke TRISB, 0
BO : 128
81 :0
Poke PortB, B0
Pause 250
l-cr82-0io6
87 -_ B0 /2
F,L]: E1
c Poke PcrtB, BO
Ir.ruse 2 5 0

-t
Example Frograms in PicBasic erc Qcfofiq$*fi* sa.q,q1t o8o6'qp'(q)
=1i(")
i,trext 82
Poke PortB,0
pause 1000
next'b4
returir
'Pattern 5
1oop5:
for b5: 0 to L
Poke TRISB. 0
B0:1
81 :0
83:1
Poke PortB, B0
Pause 250
For82:0to6
81:B0*2
B0 = Bl-
83 = B3+B1
Poke PortB. 83
Pause 250
Next 82
Poke PortB,0
Pause 1000
next b5
return
rPattern 6
loop6:
for b6:0 to 1
B0 : 128
81 =0
83 : 128
Poke PortB, B0
Pause 250
ForB2:0to6
B]-=80 / 2
B0:81
83 : 83+81
Poke PortB,83
Pause 250
Next B2
Poke PortB,0
Pause 1000
next b6
return
Main program qE gosub oSooicrf gosub roop1, gosub 1oop2 r gosub
Ioop3,gosub loop4,gosub loop5,gosub loop6, . ..orr2)@3. combination -fttftt
e@o8: olery erc, @ E : @ 3. patte rn
fti t og oEeoTc\rafi E eo eor.o p)
r r

cJ
-$rf) Source Code eq4p]:-1 etC QcAafi q$-6* oc9:qooEco6:qp'(l)

*l'(l)
Source Code eqr?dr-.J

.1-cr fe1{:
Microchip Co.-9grcEg6oa:ea:o PIC microcontrollerdl:g,$gqp:ogc6 ptC16 Series
9-q_9--S Q O O c
icna{q}oi*qp'{ a
o{oqbeq:q3:epq8 oc1:@1qar2) instructions o{5ooo: (qC)dL,+8.
ntc {c6o{ o5co6:
Source Co :qp:{
o o n. c
84 i-nf *u[95d on8eoT
33 saS:ear PtC16 Series
.go:$ sacg:@1$Eeoc86p2irr

.1-.11 Microchip PIC 16F84 Microcontroller


Microchip co^. 9"?o5g6oo:e-oo prc16F84
{oEafi%$co{coo {EBo\ goE (pin) qp:
esa:c6<iq (1-r) o38uoT$coo:<,'iodil
1dryaf
c'i
eoT@<-,iepirr
4to5qpr-d1q18,rf o?A"6,rp *n@ot,

+t ++RAl
7
*%q
q+RA$
ft
bt w
cEe[
ql-ffitffiLffif,,I
4 ffi
G* ----+ffi
fl
*--VoD
tr <---F RB7
7
@ € FRBS
I 4-+-RB:l
@!+,REt4

Q(:-") Ptc't6F84erl gos (pin)qo;oc39o5Q


.aa$,(1) Source Code eq:qgj:-; PiC $da{q$-1ic.t sa:q:a;oo8o:6,qj",(?)

I'(AU o^.4
t'r*n'j PAo t PAt t QAZ t MA, p,Aq
=An-'-.--
,+ I r z 3
RA op) o?3c$:g3+!o26eao:3$3ea:: bidirectional porl $SoElrr oE,c{ input
output aa@6 EoE@ldardqdd san:S1$to1og)rr RA e'\eqoc69eq:oo:ea:oiolloE
"Q."u?"E
qp: (0toa) og) uit ,i<.io8qp:@E@ogirr {e@c8. RA og) S-bitdirectional portcoEq@6p,
.r8:q3<-'lo8earo bit or61q18:c{ input {.""td output 8o5@tc8DoEgo8!) sanrQp$3
""GE
ciloEirr

RBO To RB7

RB ccAicogl: q6c$:18{;q6eoc3{Eear bit (o)q<r'1oEco2$ bidirectional port


eqoc'5or61@6o2ll oc8:c{ input c$.oc:2o5 output oG8 8o5@toEoo8go8$oa7'$li8oioglrr
or8:q8 RBo, RB1, RB2,...,RBz occg!@8. 8-bits c.iloSoglrr

VSS And VDD

" VSS ccgi oqoE.r'1o1co6oc$E: ( 0V or cND) eoEGE$: VDD ccgl gaeciS:<-'1o1

o6c,c$E:qo5 @SoEirr saqp:ag:eo:{Eeoo ao6oc$3:Q.sa:ogi 6V GEE: oggl:ag:og) 2v


@Eco2irr

OSCI lCLKIN And OSCACLKOUT

<.uE:9o5qp:op) QcrSa{q$coficooocac'S timing GEug clock -Ac'SG


"?qE.f$
eo:q8 :qcca$ eqepqp:@6ogl u

MCLR
ococoeoee
icbo{q}o{cm oqd:$9obap*nqepep: (memory locations)
(o{oq6c'| $$co2)oca8c$o3joo'1) o8:gdc,f _eND
oe c
Gfqf%c e e o 'te e oc c\?c:sc,
oJc:QOc? 3a6orc:aoooo?c8
oc c

lNir
e c e o c o oc eoc c e e e rrc e ec e c co
oc:tocJe o?3eoa)o?@f:qlotcaoeg 3eoctoa)o?l9oa)e9il @cDo$orcstoq]c?.
oo:@E.e<.,:oo:p: ofioq6c'? S$o@E:r qc.rofioq6c'fq3rr$E' o$:cQo6og) o$g8o6q1c,i
eScE :o5 Q1q6eo@ E : ( nte rru pt) r- d4..,? G1o9 6i 3 o1 o $
I rr

TOCKl

Main clock g3.c,o8oc'5$t:e$d Q.'5ofioAq-ficm saqS:QE:$ timer c{caog6q6{E'


i E-d clock oo3 q o3o6 1 @Eogl rr o:3 :q6" jftt.,? qp' gosaaT :S1e.o.e$ cr'l eqp

ca
o"$:(1) Source Code eq:g2i:-1 et c Q
o5a{ q$-{* san:q<.roEco6,qp,(t)

J-?il Good Programming Techniques


oec
cr{oq8oe1.ar::qg): oecc,86c{ e euTSB oEtoqC)6q:f,r:6pcec on:Q1eo.fiog)
e3 ecrroS : o ep sa1 c'5sao: c'5 -{1"fl oE @ci e pj rr

Semicolon t;) o{oq6o61 er\ cg)er2)eq"poa3r{ cryf,r:coa:od{qf E o:3 :eil


-6td
eqo.r5og3olcoo6tr sae@o8:oepqptd compiler - qlS"ltSrloo:.,icc$r' ofioq6g3.
"i.GEd
ooEcccr5S: aBcc3.a3{cr5oEi sae@o8:oepoqcfootoS (comment) qp:.r? (;) eqcc6q8eq.oc:
eo:.fi<-,1o2)rr {cQpq.a:o:oc:$E:sn:@8. <-'fioq6er\g6eo8qldqprd -{$eeg:@$ordr3fi$3
e<-reo:o.cc2) rr qg,-S qopi ofi o q6ar6 I c,E @6oo comment qpt 4 -d * E :eq:oo: oc E.eocc g) rr

occoc oocc a)
Q
cDoJseqm3a6f fc. cp{:ca) (constant) register
co co o c
e,.l:68:G6ccpSrr 4{.--gd.p%E @e8 (I)$63rae€egq[: c? 68 :qor6cD,
coUNT {erg)c8$:eo{1:c{{c$oE)rr G6[:oo:6pq]3cog): oao?:o@: (capital letter) GE.eq:
eco.$a:2jrr

cno3creaql,r5sanft8. ; (semicolon) qp:c{oc9:$1$: ealE:8:


@Eopirr eoocrS,.,1g
*************)k*********************************************************
Author
Date:
Version:
Titl-e:
Description:

. * ** * * * * * J< * * * *** * ** rr *** t(* * * *)k * * * * ** *** ** * * ** * * * * ** * * * * *** * *** *** * * * ** * * *

egoc'SqtoqlcBsaeEg8. 88eq:cqara)o{o6l6c,? eg:p:gooo 9cr5er-,Toe8q"T@d"1', 4{.


e"1:r:aroE)saol ofioq8dgoei:Q (Flgrryjhart) qp:r <-r{oq6caao8.o8.q6eo8qlc8 (Agorithm
gc:c,pcogl: opo8ocQ o.qt$lulr ,

sao.,Ee,sT@<-,11saqcfqp:co2i r>8.ooec6 o{oe16ecr:o8:o6q qfieoe2) :aeoooSsaqqp:


oE$6e<.,ogirr

J-gil The Registers

Register o$gar2i Plc sao33:$$n- write c$.et2oE read q6iScca) Gfepor6?


@6o$rr oaql.z5gao:Ee"b.ti eeo-rasaqcr5ecoc6no:nf eqte:o:$3/$+codoo:$68og) egep{1:
oE@6oglrr

Plci6F84 saqS:fi Resister files qc:ogJfiega{ e<rTSoo:og)


"r-.'5"'lQ(1-L)-d
Q@EDgi,,

r0
./

sr"$tf) Scui'ce Code eq:oa;:-.1 PIC,ioEafi og4*$* srcq:q1oc6c.:8:,ip,(l)

t;!a _dr{.rrbE€ File Address


00h !ndirect addr(rj 8eh

01h Er{ h

02h a2h
64L
UJT I uJl I

04h 84h
0?h 85h

0Eh 86h
07h 87h
08h Beh
0sh 89h
.tAlr oiL
ffirl

lJc]r I 8Bh
oGh BCh

36/6E
(21 General 4P1 G)
2Fh
30h Pl
- -Purpose-
registers
- BOhP)
(sRAM)

(21 (2)
4p6 6p6
566 (z) DOh el

7Fh FFh
Hdnltu
Bank
O Bank t
EEI Unimptemented data memory location: read as'0'.

Note 1: Not a physical register.


2'. The address depends on the device used.
Devices with 36 bytes end at 2Fh, devices with
68 bytes end at 4Fh,

Ql -L) Plc16F84 oca8:fi Resister files qp;orgfieqQ

cG
saa$:(1) Source Code eqqpi:-..1 etc Qc6a{ q6-6* ocq:q1oc8co6'qp:(l)

4Q"aS Bank 0(Pase 0) 93. Bank 1(Page 1)"?S) eqrsEtd&:oo,e@c3:eo3.qe<-,og!rr

PIC er\
eoe"- Port A er\

od-d bit qp;o$ input bit qp:a:gj output e@ot :c,f oo59o5ec,:o g) rr

goeroot@8. Port R er\ oit {."qo8


pin o:6qo33 logic high :go Bank 1 c$.ap:S: logic high @BeocQoai
Port A efi bit {."u?d pin .l| output -G3 ero5go8eo:c$c,5qog)rr Bank o
"Qq"d
{.0$*[9'r oc'5{3ep oit c$pr.4o5 pin a8o$. losic 1 c'i c'iQ.eo:qoE)rr
Bank 1 qe8 on:oqp:ag: register files qp:9c STATUS, TRISA gE. fntse 4.G6
@o3)r STATUS resister ccgl Bank19 Banko{. Gi*":g8.@1op)rr TRISAo$ eortn 9
od-d pin input c$.coqo5 output o@Eoo59o5e<-,:S:r TRISB ccp! eort A g elg)a:g)
{
4
pin input cQ.cu7o5 output sa@6cco89o5eo:o:2lrr
Bank 0 ca8eg:q1cr5oa7:S1oo:eoo od-d
register {ff,"[..fl Bank 1 c$. q:e@o8:
ep:$ 3 r:$ rr ooo5o'l register (f \"f.-"68:c'f
co 66$gaeo:8E eco.coo@f :Q.rr

sfAfus oa}t

Bank 0 9 Bank t cQ. q:eQc8:cQqflE


STATUS register of caaT:$1q<iog)rr 4.i.
0lo?6q$oogc6 srRrus register er\ oit s c{ 1 q
ooigo5eo:qcio$rr omoS$ Bank 1 9
Bank 0 G$-dq:e@c8:cQq18 oE: bit 5 cr| 0 t,l7 o:o59oEeo:q<.,1copir STATUS resister
{.
ccgi address 03h qE opifi<ioplrr ('n' o$
Hexadecimal number c{eoT@<ioE)rr)
ooc6<iQ(3-L)oaE @d'1,

IRISA and TRISB 6,gL


, Aell

<r3:oi.og) 93. address eOrr {.oe3 "ac3:c3:og)ficriog)rr Pin o:31qc{


address 85h
output {..rtoE input ca@E oo59o5c$qg8 oc6{Esp register qpr${. o cQ.eqo5 1 clt
Q.ecl:qolopjrr {ai.Q.eso8epqaE binary c{eoEcug):ecno8: hex c{eer5co$:ecrraS: 8E
g6oc'5a:c$ 3rtri306Eo1oglrr Binav cl|on:@1q913 port raeqsaoa:crf co8o85pl5rr: EEnqa"
$Eoplrr Port A qAE pin (g)tfi-Ge. bit (5hc$sa6r:girr 4 p'n (g)t=fd oin oElqc{ input
sa@6 oe7r@L{qilS ,rE:So$. t c,iQ.eo:e1cca)rr samoS$ pin ,-6??4 output oGE
. fa O C e O O OO e
3a3? 3tglo?qllc q)c:6of?. ^
u c??.6o:q3re il

pin qp:eisaeqooo:srot3:@3a:2)rr Bit 0 o2) RAO @3og)rr


Bit qp:erlsaeEsaoo:og)
Bit l ergj nnt @Eo2irr Bit2r:g) nnz oo2j@3"... sae3:c3:@3@a:gjrr gocnor:@E. PortA
er\ RAo, RA393. RA44.c{ output @6eo$: nnlgi RA2"?.",? input @Eeo"Qqg3 TRtsAS{.
00110 (ootr) oiQ.eo;qrE)rr Bit 0 og) p9c"ct5q3fie@c3:oo3Srcr'1rr esa:.rS.ieqta:::q1cr5cri
@$cil

3c)a
saa$:(1) Source Code eq:qg):-..y P:C {oAa{q$-.fi * ocg:ero.3co6r"p,(q)

Port- A Pin RA4 R.A3 R.A2 RA1 RAO

Bit Number 4 3Z 10
Binary ,
001 10
ea a oe r-c e
Port B ocacfcogj: s;@ cD o r
Te]:3?o? c : [9 o 3J e9 il

PORTA and PORTB

Port A register {pu?"E Port B register eil output pin o6q1o38 logic high @Eeo
o e e oe
{"ad od{dcp output pin Sef. t c,f Q.eo:qS: losic low @Eeoc$qpl8 e>c'S{Eq3 output
pin a8eQ. 0 c{ Q.eo:qod,' 4{.0to?6"poS8 rRlsA gE. rnlsa q6131:og6
"?."aE@f"?6er$
cn$ (format) ooi8:@Eoglrr Port o:6q1er\ pin a:El logic high {."qd logic low GSrd
r- o o o c e o c . c c e o(
3?6e3ecEc?c:o?q1c cu8:oi.saqci set q<.rcoo;og omagiep bit er2j 1 ei.cc'2o5 0 GB
e@:S:cri o6eo:e1eoe$rr

e rre e e e
ctpl oeogeogal:$Eear generalpurpose register @o?t9o3re9il
W register orc:cceg
e eo
cag{omo5finfn- eooaTeccc
physical register o61eqo5eq1rr W register qlc eeloglcDforomcreg
n co e e c
o$Q o o8go8i E cc2i rr W resister qE o$ Q :oE1
: c,i c,f coo8g d$,nq"d @[9o:oEt:cDo?fc.orP:
.tC Oe C O e fr c oc e
6()r c:tca)?9r a?.€u?o ct6pc8.cl9Dc:tca)e9il oEocS co66oc
i:qgd: (overwritten) qa:

An Example Code
e C 'FFr (
saociqd eo $n.cog) oqlcEoocc'5qp:c'f oe@5$:
I o{oe16nqrf drf ?gr-6t 4 n.T$ul
t;gJrr

A of
set up g6egi4"lf8 e51:f:gc Bank 0 9 Bank 1a?. eSc8:qeEirr
Port
43Q.6QaE:qiooec6 BSF instruction c{on:$1p: address 03h q8fieer STATUS register o\
bit 5 c'? 1 @6eo8 set q8qegirr o8:c{ecoc'5<ioof8:eq:ey.,1tl2lrr

BSF 03h,5
BSFccgJ 'Bit Set F' crf{c$og)r F q8fiear bit .{ o$Q:oo59o5 (set) og6<io2
{cQo3)rr r -d oa7:@;.eg) memory location -6? .i.."?d register -61@Eog!rr
BSF erlegocr5o38eel:oo:ea:a 03h a:2) STATUS register er\ address GSgt 5 -d bit

4,ioE@Scodrr {e@o8. BSF 03h, 5 er\oEg'l<r59a address 03ho38fieoa STATUS register erl
\

Source Code eq:qg):-.1 etC Qc6o$q1-6- san:q.'cEco3,qp,(?)


"r"$,(j)
bit 5 c{ 1 @6eo8 set g3<iq{cQog)rr {{.0f.?A{c'5ea:ae@o3. cal$Soi.c;p) Bank 1

,.t.".pd6.8":cog)rr
b'00110'
MOVLW
Binary o$Q: b'00110'c{ W registerarQ"-d"9eoco@c8. MOVLW instruction .4
saa?:@G: ooc6olooi8:eq:ar:e1o$rr ocn<.rS$ hex o:$<!:@E.eq:el${qg8 eeocAcr'l ooiS:
c
6T6l6eil

MOVLW O6h

MOVLW ccgl 'Move LiteralValue into W' 4{"Q-2)rr MOVLW instruction a\egac,Eoet
nuT@ootet o -$Q, (Literal Value) crf W register %Eog)<tqoEglosqoeirr
"Q"+od
cu E: oQ Q
: c{ TRI SA reg ister
{.8.4- Ge. egacfol ooi 3 : eq: o g! l

MOVWF 85h

g1l
MOVWF instruction erioSglcSga "Move the Contents of W into the Register
Address that Follows" . w register q8fiegeoo
-iQ,qp,{ eqoc6oS8eoT$coa:cc$ address
eqf%8fi-2) resister afp@o8:eo:"1r?4"q-drr 85h r:2j rntsne.r\ address @6o2!rr

o1oa1 TRISA qa8


-$Q, 001 1 0 qfi qp:eoprr esnc6ci oEooieo?e:@6cc2irr

Port A Pin RA4 RA3 RA2 RA1 RAO

Binary00110
Input-,/Out-putOOIIO
{c$. eort A er\ pin qp:{ ,inpuVoutput ooEgo8S:eqcc6 eank O .i.Gi*E: c3crreJ":
Bank o egpc'S<.:'l instruction crfcacg:Slqeoog)rr
"? "?3qa"Sqe<.reoro.ca)rr "$.G$*q$
BCF 03h,5

gl
instructioncc2) BSF5E. o$.cApocr5@3og)rr BCFe\o8g1oS9a'Bit Ctear F' c{{
c$og)rr Address 03h ca8$ea:a STATUS register er\ bit 5 c{ 0 @6era:E crear og6cicq{c$
r: gi r { cQ.$1q6@:ara;oa'l Ban k 0 dcooar 3) rr

"Q"G$ "ep

saco cf ol i nstructio n (g
) t 4 go gl: ee1: a:a; c$ cr5eo8 era:c8 <-r1 ooi 3: epr 3j rr

BSF 03h,5 ;Go to Bank 1


MOVLW 06h ;Put 00110 into W
MOVWF 85h ;Move 00110 ont.o TRISA
BCF 03h,5 ,'Come back to Bank 0

ce
v

C C O C O . c a / \
-r^
"" Y"'"il"ci

^-q :^^+-..^+:^-
gll
/^\^^^^\--r -(-1.:- -Q
ilrluuuuuil \y/e3d!ic)Ji-Y;uLY(r/ -. c SCS --^-S
l}](ao:(./)f-lcigs)6:idru -^- ^-^-^^-.:l .. srJJLDa;[:/rJu!
bL\JL\.rrr-Ltr;uilr -f-- S
---..S
o c e o c o c c o e e a oc 1 c o l- ar-c e
Q63' o]c:o?"3)eg otoftoolo?q os)c6efrJ3j3?olc?c3 olocofr6oi6r,63)fclgpc.lJof,)Ptl

J-3il WnitEng to the Ponts

sacoc,Eq8 PIC $fieoo i/O port pin qp:oi input or ouiput ca@Stco5giQ a:o39c3.1gj:
qprc{eoTpnS:@6o2ll mc'5cocA$ port q1ll{. esorqp;Q.eo:g (writing to the port) sae@o3:
c,in,sTQ,.,1el 2i'r
2
c'a:e@E LED or8o7:c,i oulo rr GiqS-d c'{ oqSo$q c'ieepQol ca) rr

eg:f:gc LED c{ oN @6eoq$ or3:c{m6o8cEi Port A efi bit -Beqd output


sa@ Ecco8g o5,.il eE! rr B it 2 {@ o'l
Q.rr erraoEt l ooi3 : ec1"<-,1 c3) rr

mo..'lr,v 02h ;Write 02h r-o the lrl reqisLer. In binary thrs is 000-1 0, r,-:,i ch
;puts a '1' on brt2 (pr:. iS)whrLe keepinq the othe:r pins ic'{l'
movwf 05h ;Now move the contents of [^J (02h) onto the PorL A, whose
,'address is 05h

LED c'? orr @Eeoq$ eooE<io{E:eq"qo1e$rr


"fleq,r"E

movlw 00h ;Write 00h to the W register. Thj-s puts a'0' on all- pins.
movr^rf O5h ;Now move the contents of W (0h1 onto the Port A, whose
,'address is 05h
LED ergi oN/oFF oaoc'5c$o5Qq6eoq$o"ad{q8 ofioq5c{ofgi:c,:5 Gdedn
Q1o76qeoe2jn START {-d label c{ <;$oq6e'\ooq8oa:S: goto START4-d instruction
qoe.aeoceeocc..|,toce.c
cpma?:q]ccoScoo3o?mqiJc Qc:oso6[63re9 olol6oo)f,)9lcrzocooa)o\?: c6locEo: run 6E
ec-,o36.tl g) r ofl o q6o$2iog c{ emc6c'1 ooiS' eq.@ Ei eooE) E n

bsf 03h,5
movl-w 00h
movwf 85h
bcf 03h,5
Start movlw 02h
movwf 05h
movlw 00h
movwf 05h
goto Start
sacocrS,-,lofioq8qt comment qp;ol og)ee1:elcor:cD instruction 13. number qprd
orGq:f,:a:coo:er':e@c8. eqocr5QS:q8 uflnq3c4 G$cod0GEt6:6 (debus) cQogisaolcaS
add ress qp: nu mber qp: gt. eepeog :p: r 8o1 : o'3 De: g qp; @6eoTooEeo:.$eoccal rr

Jo
:aa$'(.,1) Source Code eq:qg):-.1 e t C Q c6a{ ca$-{- sacq:q1oc8co5,qp'(l)

{c$.e @8eoq$oqanE
'equ'{cca) instruction 4 -.itGL$Eolopjrr (o3o3 'equ
e
instruction Assembler 6<-t1c: o)oq
Assembler register address location
aae 60r programming terms
-Etd constant o$q$3.@Eeo saoa:{ree1:or:$3e<,t
cca) l eocf crl g ocrcrf @gi,i r

STATUS equ 03h ;this assigns the word STATUS to the value of 03h,
;which j-s the address of the STATUS register.
TRISA equ 85h ;This assigns the word TRISA to the value of 85h,
;which is the address of the Tri-State register for
; PortA
PORTA equ 05h ;This assigns the word PORTA to 05h which is the
;address of Port A.

oocfoloof8: constant value qp,{ set up og6$:eqocr5 o{o6l6cf$qeq:ea:E


emocrSci oot8 : eq.qeoc2) rr

STATUS equ 03h


TRISA equ 85h
PORTA equ 05h
bsf STATUS,5
movLw 00h
movwf TRISA
bcf STATUS,5

Start movlw 02}:


movwf PORTA
movlw 00h
movwf PORTA
goto Start

gl{."t-:@E'@3. ofioel8crfooSerp)caa1 comment qprd c"g)q3, ecjT[ercoo'


ea:Ecu2): ofi o e16e\og 6c$ : o j c,f Q Q a: errae,i cf qg.:S qo:e@3, cqJ.q6oe el il

1-Grr Delay Loops

eoTp;.og) LED oSog:cri oN/oFF @1og3eo:cg) o{oq8q3 oo:1gl:q1c'5


sacoo5caS
qp:fiegcieo:o:3)rr lnstruction o:61s"og6q66l$3acgcr5 clock cycle ar61 {."u?o3 machine
cycle (9) 1c$sa6crloglrr sam..:S$ 4MHz crystal cri orT,Sirld{q8 lnstruction
":Sqsaq8
.t6q$@{$-d gx1l4M{z, ollptS) @6a:$rr lnstruction (f) ed LED
C " O OC
moca:o?3?qjf bps srq3, ON/OFF E1"?O"g."S3.ogirr gl-{$- t G3.
-.E'Cl ""rt" c"..
LED og) coaoc6ca;l:cu3:Ee@:E: cq"Q8a.iqa<;c33'.cElrr {c@:3. o}J c'3iaa{$9t. oFF
a:g) sa{$se@'oa8 @$@ri$ (detay time) mE)eo:qaoc83.eglrr

Delay time eoTqo5Qgc- cr3$:oco,$:o$Q:oEq1c,f odgo5crro o$$:o161ett:c,f


"
n.gp.qj[9-, te{.nepdDd;d aelqc,5qog)@{$.,i *"Ss-'u'1'rE),'' i,B;-;
Eoevr couNT 4-d .8$tn.r.ri
eelqc,E@3: counter o@E c8$:eeror31c{ coo8goSelcia:glrr
oo59o5coo:opi{<i{.rr { couilr c{ 'equ' instruciion @8. general purpose register
-6??
(gu- oerr)og8 assign o?5cqc'5oeis?a1 oqp:ag: eqosd$33oai 255 ai.elt4o6
':$Q:.r$
FFh @6eoeoo.ocd"
-ftd:o::$8. oocag: <,io1oca8g3.4d-d -{$5 coUNT qE zss
o>$Q:$qeoc86pE)rr sam<.S$ 255 oqo5eoo o{Q:oE1 (Eu*lc 8sh ) .rf
coUNT equ B5h oooS@o8.{eaf Bsh o2) Tri-State "f"i{elS
register
"? "?dfi.,6oo59o5$esleqp
for Port A ORISA) sfi address location @6eqeere@E$Eccg)rr

egjci.c.T6qcdfd:4ce:.5 movlw instruction 4*"i'0G: 88oo59"S"Q-d-$Q,"?


w register q8p,gocogiollr movwf instruction c'i"aq:@1pt<r:3t Bsh .4 couNT
"fl"{,r"E
f3.43od Fregister(08h)ri. eQ:3:m2ic1,-,1og)rr esncf<i o6sooic,iecocm.ilii
movl-w 85h ;First put the vafue of 85h in the W register
movwf 08h ;Now move it to our 08h register.
"fl{.&"t8$:ar2$oo'}
coUNT equ 08h goo59o85.eare@a8. coUNT cat -iQt
85h qfi qp:eoeo:o.co2!r1

_ COUNT ? oi$:o6E1&c'f 6qilo.ql.P%Eoa?€1qeai instructiorr gae*,cSoloof8:


@6cogirr

DECFSZ COUNT, l

g1l instruction
DECFSZ ogi "Decrement the register F(in this case COUNT).|f we
reach zero, jump two places forward" q{{-d'r o8g1c.59o Register (<.u1 g<.rero38 couNT )
9 1 {n.fpnul rr omcrS$ r er\o$Q:e7gc$.eepcr5qp:Al8 instruction gEqq$c2:c-,l
"?{"q
cc
2) rr eocBol coT$qc'5c{@g).-,1 rr

COUNTequ 08h
Loop decfsz COUNT,1
goto Loop
Carry on here.
:

COUNT qE $era8 ococc$3:$8. set up q6c$c6ogirr qo8'oi8:q8 Loop


255
u?6f,:a label o6gcodgo5$: decfsz COUNT,I crfleq:coo:earan@E. COUNT 9 1 .4
eqp"qlc$c6rc2lrr g1o5p:qo3c'i CouNr ca3@$c36:a:2)rr oo8occ$3:ca8 soto Loop
instruction EE. eqadoE@8co6eqgp.q1eoQ$oca)rr CoUNT ca8
-$Q''?eGEq3o:r:g)
aaalgaro "Carry on here" o?661:oa:'.d"f"p{"e$qo,Et instruction saoft:
"Q"fep%S$og)
oc'5q6rp:oglrr g1hd'G3. delay loop c'i o$o8:S: @$@{$ detay time crt eoTqo8iS
saa$:(y) Source Code eq:E2i: _1
etC Qo8a{q$-{* san:q1ooEco6'qp:(t)

o<.rocg)rr @$@e{i @aE- c$sa6q18 delay loop qp'{ ofuS:o6q{o8ooSd 3a{:01€S


co3Ja)il

ococ8o3SeoT$."od LED flashing (oN/OFF) o$oq6oe8 detay toops qp:og)q3:S:


Gryf,ro:@o:Qc{ eszx,Eq8eoT@oa:cflo$rr o6:cc6<.'o3oS,Q4 Q(L-e)
"fioq3Q$cod@dg;
ca3 @g)cil r

.**t<**set up the constants****


STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
COUNT1 equ 08h ; Fj-rst counter for out delay toops
COUNT2 equ 09h ;Second counter for our deJ_ay loops
- ****Set uP the Port****
bsf STATUS,5 ;Switch to Bank 1
movfw 00h ; Set the Port A pins
movwf TRISA ;to output-
bcf STATUS,5 ;Switch back to Bank 0

. ****Turn the LED on****

Start movlw 02hl ;Turn the LED on by first putting


movwf PORTA ; it into the w register and then
; on t.he port

' ****Start of the delaY looP 1****


Loopl decfsz COUNT1,1 ;Subtract I from 255
goto Loopl ;If COUNT is zero, carry on.
decfsz COUNT2.1 ;Subtract 1 from 255
goto Loopl ;Go back to the start of our loop.
;Tris delay count.s down from
. i255 to zero( 255 times
,'
****Delay finished, now turn the LED off****
r
movlw -PORTA
00h ;Turn the LED off by first putting
movwf . ; it into the w register bnd then on
'.- l
_ . ; the port -" :
";r'

- ****Add another delay*r.**


i
Loop2 decfsz COUNT1,1 ;This second loop keeps the
goto Loop2 ;LED turned off long: enough for
decfsz COUNT2,1 ,'us to see it turned off
goto Loop2

,'****Now go back to the start of the program


soto start start and turn r,ED
: ?:
on :l:l^to
agarn

J?
*n$/U) Scurce Code eqri$:-".1 Pl C 1oEafl %$co{eo CI{;qprc3or6:qpr(t)

r'
!+ !r'?,-.C of thc prJul:;tl.+++ *

end ;Needed by some compiler:s,


;and afso just in case we rr.lss
;rhe goto instruction.

Q|-e) PortA ar\ RAlqo5q8 LEDo8o8coo:Q

3-gn Subroutines
Subroutineofioq6er\ saE6oQ€:o6?G6olc;drr 88ocQ$ccpioaloi8: o8:c{
er2l
oEollooSo5 eeTqcq:$$E6oc:elil o$n8oE1c,i ca6@5e;m -.itQtq$"$.a6cc2ioo1 o8:c'i
o+t$1"-.fi<io2lr goen delay oEqc,io$o3:ccp)oo1d1:q8 o8:od*qa$*"t:o8,r'1ccg)rr
o{oq6qE -$q, (co)@6eQc8'tl$'aoc: Subroutine
Subroutine c{o4:@1@E:@3.
o3tca6@6odr- e@c8:q$c$o6ec,cc2lr .fl.-GE PIC er\ memory ca8 <.r{oq6e'\eqep.r?n

eoc6<-i subroutine o6qcrtecu.cm<.,11 l


ROUT]NE COUNT equ 255
LABEL decfsz COUNT, 1

J9
os$:(y) Source Code eq:ggl:-..1 etC $o5o{ ca$-fi sacq :q1oo8cu6rqp,(t)
-
Goto LABEL
. RETURN

p:gac,o<l subroutine er\saog)c,i ROUTINE q$ taOet coSao:coo:c:d,


"fleod Qg$
LED flashing 3e%d detay @8erp)rr subroutine ei
"fioq6.'fnq:a:c:rg)rr {ofioq8oa:
saag:q3 RETURN instruction @3.oag:ooEegrpll

ofioepo:Eqo38 elp)o$eqepgel{ subroutine c,? ori:GtcqelS CALL instruction efi


subroutine er\ label ofeq:ur:S: eaTqsaaT:Q1qa:2)rr Subroutine
"+.r"6"ae -6t4 *@6
elp)HJ.rE @6<-,1 eo eaTuTsan:$fi Eogi rr

LED flashing ofioq6ooec6 oetay toop cf subroutine o@6ocatGlooorQd eg'cfoeE


ocdTQoa:c.i1o$rr

' *****Set uP the Constants****


STATUS equ 03h ;Address of the STATUS register
TRrsA equ 85h ;Address of the tristate regi-ster for port A
PORTA equ 05h Address of Port A
COUNT1 equ 08h First counter for our delay loops
COUNT2 equ 09h Second counter for our delay loops
'****SeL uP the Portx**x
bsf STATUS,5 Switch to Bank 1
movlw 00h Set the Port A pins
movwf TRISA to output.
bcf STATUS,S ;Switch back to Bank 0

; ****Turn the LED on****


Start movlw 02h ;Turn the LED on by first putting it
movwf PORTA ; into the w reglster and then on the port
***r(Add a delay
caii Del ar;
"-i' *Deiay finishei, no,r: tu::n --ite LED of f*tr**

mowlw OCh ;Turn -uhe LED off by firsi putting it.


movwf poRTA ; into the w regj-ster anci then on the port
****Add another delay****
cal-I Delay
****Now go back to the start of the program
goto Start ;go back to Start and turn LED on again
****rre-e is our Subroutine

Delay
Loopl decfsz COUNT1,1 ,.Thls second }oop keeps the LED
goto Loopl ;tr_ri:ned cff lonq enor-rgh fcr us to

--
j3
ea$:(J) Source coce eeyq2J:-j ptc
{daejca,S-{*
__---__--- sacl:qioo5co3,qp,(l)

rlecf s z COLINT2 T 1 ; see ii tur-ned of f


goto Loopl
return
-****End of the program****
end ;Needed by some compilers, and also
,' just in case we miss the qoto instructi-on.

Delay loop q3
subroutine trt 3"ri:G1cqc;83:G8. qoo<.rfioq6og] 120 bytes
9 103
bytes cQ. oiUryrn@E: eog.@Eiteooglrr

J-?il Reading from the l/O poris


Port A g pin
-Eed output pin ea@Ssacg:@1S: LED
4
CN/oFF eSfi36@ce: difi:
@6,r'1o$r ocr5cuc,5$ port or6Eer\ l/o pin -8td input pin e"@3"anrQ1Qc,i eoTp<,r'1elg)rr
l/O port -Et{ set up q6.d.?ql8 Bank 0 9 Bank 1 rQ. 8,e""&3:oiqe@c3, e<rTSiS:
@6 eocc g) r{c8g c,f errc6 <ri aroi3 : 3 t g"01.?6@ <i e g! rr

STATUS equ 03h ,'Address'of the STATUS register


TRfSA equ 85h ;Address of the tristate reqister for port A ;
PORTA equ 05h ;Address of Port A
bsf STATUS,5 ;switch to Bank 1
{"Vr"E Port A erl pin -6ed input sa@6oca:SLdqffS TrisA register q33 1 c'i
cco8go8eo:qo1o2!r
movlw 01h ,'Set the Port A pins
movwf TRISA ; to j-nput.
bcf STATUS,s ;Switch back to Bank 0
Port A efi uit 0 pin <rf input o@Eccd9d5$:e@c8: ooc,SciooQSq8eoTpoo:
<ioglrr { pin og8 Q.ra:: $6./@8. oeQoeqc'f oEeo'{"a8 BrFSc AE. errss 4-d
instruction fh{ oa7:S1qe<-,cr$r

BTFSC oEj
'Bit Test F, Skip if Clea/ {{{-drr o8g1<.S9a resister -Eefi
cco5goEoo:eoa bit
-6td o8eo:o'l'r { oit rod 0 GSeeF eqoc8 instruction 4
(skip) 1p:<i t1{c$ogj rr
"qf5

racoo:a;<.r8 BTFSS og) 'Bit Test F, Skip if Set' {{{-drr sa8g1<.S9o register
-6tfi oo8go5oa:ea:o bit -6td oEeeo:<.,'lrr { uit r"d 1 GSeqg1S egcc8 instruction of
eq,E {stio) q.::cil q{c$o$ rr

j0
oo$:(1) Source Code eq:qg):-.y etC Qc6afiq$-{- o1:qpo5o6,qp,(?)
lnput c{ gSol
o{oq6cQo3qnEe8. c{cfpieoel2i on$ong.rTq-d0' BrFSc
read
g3. BTFSS o?.cr? eg:qoSocgtQ1q,r1o2)" Ec,eno:@E - lnput qE t @6cog) oe@ongc,f
6or3@dcqqg8 eoocrS.i ooi8: BTFSS instruction 4
*.it$LQE<i oE) rr

Code here

BTFSS PortA,0
Goto start
on here
:"..o
PortA er\ bit 0 og! t
@Egarq18 ,:fioq6o2i 'Carry on here' 6fp"q. ecqlEqp:e,:cc$rr
eoc6<r'l BrFSc aE. BrFSS
"?.{-'i,GfE, @{$-'1$8. rco qoSo?oE€oEo?oE G6"f
og) oegooo:g ao7o54$6{;"lf8 ca{$g6o eg:qc:eoegl uo $o5qo5$"Eq"E ofioq8
o61 c{eq:@d@Q.rr uo?dd oed E :c$E:98. nno o?.o@o:%E o6ao8 oo:<i e2! rr

,'
*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS regj-ster
TRfSA equ 85h ;Address of the tristate register for port A
PORTA egu 05h ;Address of Port A
COUNT1 egu 08h ; Fi-rst counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops
.****set up the port****
.bsf STATUS|S ;Switch to Bank 1
movl-w' 01h ;Set the Port A pins:
movwf TRISA ;bit t to output, bit 0 to j-nput.
bcf STATUS,5 ; Switch back to Bank 0
-****Turn the LED on****
SLart movlw 02h ;Turn the LED on by first putting it
movwf PORTA ; into the w register and then on the port
' ****Check if the switch is closed

btfsc PORTA'O ;Get the vafue from PORT A


;blt 0. If it is a zere
call Delay ;a zero, carry on as normal-.
;If is is a 1, then add an
; extra delay routine
,.
* *,k 'kAdd
a delay
caff Delay
' ****Defay finished, now turn the LED off****
movlw 00h ;Turn the LED off by fi::st putting it
rnovwf pORTA ; into the rv registe:: and Lhen on the port

to
JI

(:
"-- ei
oa$:(.1) Source Coce c;i:+$:-.i rt c { c5afi cA$cofi rq1oC.*-6,qir,(q)

; ****Checl< if --he s.,..'rtch 1s still closed


btf sc PORTA, 0 ; Get the valr-re f ronL PCRT A
;bit 0. If it is a zerol
cafl Delay ;carry on as normal-.
;If is a 1, then add an
; extra defav routine

- ****Add another celay****


caf l- Delay
'****Now go back to the sLart of the program
goto StArt ; go back to Start and turn LED on again
't(***Here is our Subroutine
Delay
Loopl decfsz COU\TT1,1 ,'This second loop keeps L.he LED
goto Locpl ; turned off long enough for us to
ciecf sz COlliT2, 1 ; see it turned of f
gtoto Loopl ;
return
- **rr*End of the program****

end ;Needed by some compilers, and also


;just in case we'rniss the goto i-nstruction.
tr:?ea{$oE PIC l6FB4oqcr5 oo8go5coa:6aro instruction 35? *fd tOc{ oa7:S1
5S:@Ee@cE: 6cg.6tcoeal,r {c$.sacg'Qtfoa8 LED cn6q:c{ oN/oFF Q1o?6@E:r oo?o8
o:6q@8. oN/oFF @c{$,,? GEoS:oiiEEE'"?.4 S1q6a.o1og)r eq:@:i.ccg ..,fioq6qp:c'?
oq:o6@dcp oqlc'SrrcocBqptgad oa2:Q1oo:cc$3. c,fioq8og) g$o1c:qg$:p: memory
qE cfepq??9ocod: Qqprnqn@3:eq.qeooglrr "Q"@E. memory qE 6qcpo??fd:E:
ofi o q6 c,? q16coE cS 6o gj: gceq: er:$ t e gi g g): co6:o{6c,i ocfoc8arT@ o'l c
$ rr

XORF instruction o2) ofioq8c,f cr{geoccai instruction cn31@6a:g)rr cu8:oe@c3:


c,fecrT$<iegjrr
. LED coEo,7:c{ oN/oFF Gto?66EsofioqEqE o8m<.,'loEo3) oqlc6(9)nc69'c
eoc'5o1ooi8:@Eo3jrr

movfw O2h
movwf PORTA
movlw 00h
movl_w PORTA
p:goococ W register qt ozn c{cog)og3:cqcAcoeirr
{eqccA PortA register ei.QS;
LED c{co3:eor:3!rr LED 4Qq8c8q$ocgc,3 W resister q3 00h
4 cog)og3:cqc'S$tnqrd
PortA register:i.Q.eo:e1Q$o$rr o3:oi.o@ao33 oE:{$/$oE{$-"a"E detay subroutine c,t
cog)ec.':qo3lrr {o.7Sc$trj.? o$:oS@d"d"QqlS W register g3. eortn registerqp:cQ. oata
f3@68codeo:q$:' delay subroutine {-dr fS@Scodec.,:qog)rr tnstruction qp:g?{

Jo
oa$:l) Source Code ec1.q2!:-.1 etc Qo5o{o3$-{- on:qpc8coStCP,(e)

sacg:$p.qo2lr ai.n:r6 Exclusive OR (XOnl F instruction -d cccSgoEcoo:e::c register


f3, data qp:crf Exclusive oR function q66@3cqcr5r:$oa1 toggling procedure n@c8.
o{oq6og) cq;qa:ogrr
eg.eloc88 Exclusive oR
q8c$:oi{ -qirfl 0i-d..8:eg:@"'lp:Q"rr lnput (A
er\
and B) 961 $8, output(F) m31$o2)oa1 n 98. a cri Exclusive oR GL"?6AF r -d
eoocr5,-,1 ooiS : @6coo-29
"

A B F

0 0 0
0 1 1
1 0 1
1 1 0

oq116rr:@8. A+3. so?ep r -d o@EP:r cc?qilE t @Ecogil

omcS$ B .'|
qco(<r:o8) output o@Eoo5go8$: A .,? e@3:o}e<-,:qg8 o6G
: obap:c gicri ecu.cm@p)ea$ -
"drQ..&E
ND
AD F

00 0
00 0
10 1
11 0
10 1

om<-S$ A c,| 1 %3 qecooo:P: output gE. Exclusive on @1q6qg8 on@t g)


togs le @6 eE eo o$ r' { $ 3 q3 cfi esarcB,.r'l saoiS : eq.qeoc g)
rr

0 Current Output
EX-OR Wlrh 11 New Output
EX_OR WiIh 10 New OutpuL

g){.GEEe:e@€. output c{ 1 GE. Exclusive on Slq8AJE output ccgl from 0 to 1


to 0 oo3j@3. tosslins G66+e@re,eq3.qeocc$rr

XORF instruction .l| onr@1pr LED


"? oN/oFF S1qSaoq$eao3cr5 eeero3ol
instruction 9E{1:::a c$o5"@3:eo3.e1.oElrr
MCVLVJ O2h
XORr/iF PORTA, I
p:gc u/ register cA8 ozn {sdee:c$n5@rrpo5 PortA register c63$acccc8$rq1:r$3"
EXciR fuirciicr.i oyDa...:3o$J,;:C', C:i 1 o3) 1 G$qij8 0:>i. tcggle @Eqr:agirr O $5q13 1

=":Jo

(-
saa{:(3) Source Code ee1:qaS:-_t rtc oA$*{ acq:qooEco6=W;(?)
Qc6afi
-
r. toggle fiBqp:eei,r
13- v o W re-oister qE data cf o:S@6o:,2j:u epla-8:e,;:"$c$aE[$:
PortA register {-dr setup o96q$ec$eq1rr sa:ocr5e@o3.{car5 ,ilo1SE.c$oE-d+8.
qo:eoq8 PortA register $
1 @Eegeoae@ot.$3oE)r sam,rS$ qo:ooq8 o @EegoE)
{eo8cogi: EXoR function u@a8. togsle GEql2:$E@$rrdr
XORF instruction {*.i,GfE: I ococf c,'l <l{o616 g6qc'? S$cogieq:ar:regi{q918
ecac'S <i eoi E :eog$ E{ 3 eoo gl rr

Flashing LED
- *****set up the constants*r(*r(
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 egu 09h ;Second counter for our delay loops
r **rr*set up the
Port****
bs f STATUS, 5 " ; Switch ,to Bank 1
' movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0
movl-w 02h ;Set up orr. T register with O2h
' ****Turn the LED on and off****
Start xorwf PORTA, I ; Toggle the LED
. ****Add a delay

call Del-ay
' ****Now go back to the start of the program
goto Start ;go back to Start and turn LED on again
' ****Here is our Subroutine
' Delay
Loopl decfsz COUNT1,1 ;This second loop keeps the LED
g"oto Loopl ;turned off long enough for us to
decfsz COUNT2T1 ;see it turned off
goto Loopl ;

return
-****End of the program****
end
;Needed by some compilers, and also
;just in case we miss the goto instruction.

?o
*$t0) Source Codeeq:ggl:-.1 etC Qc6o{ca$-{- ocg:q1ooEcu6:qp'(q)

Flashing LED With Switch:


,.
*****set up the constants****
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tri-state register for port A
PORTA egu 05h ;Address of Port A
COUNT1 equ 08h ,'First counter for our delay loops
COUNT2 equ 09h ;Second counter for our deJ-ay loops
- *i<**set up the port**r.*

bsf STATUS,5 ;Switch to Bank 1


movlw 01h ;Set the Port A pins:
movwf TRISA ;bit 1to output, bit 0 to input.
bcf STATUS,S ;Switch back to Bank 0
movlw 02h ; Set up our W register with 02h
.****Turn the LED on and off****
Start xorwf PORTA, T ; Toggle the LED

' ****Check if the swi-tch is closed


BTFSC PORTA,O ; Get the value from PORT A
;BIT 0. If it is a zerol
call Delay ; carry on as normal.
;If is a 1, then add an
; extra delay routine
- ***:kAdd a delay

call- Delay l

,'****Check if the switch is stitl'closed :

BTFSC PORTA,0 ;Get the val-ue from PORT A


;BIT 0. If it is a zero,
call Delay ; carry on as normal.
;If is a t, . then add an
; extra delay routine
, ****Add another delay****
:'
' cal-I Delay
;****Now go back to the start of the program
' goto Start ;go back to Start and turn LED on again

,'
****Here is our Subroutine

ucrdy
Loopl Cecfsz COLINT1/1 ;This second loop keeps the LED
goto Loopl ; turned off long enough for: us to
decf sz COUliT2, 1 ,' see it turned of f

E JooG 196 u$+.li- -?c- o8:o<r5o3: t


sao$:(1) Source Code eo,;gEi:-.1 PIC Qda{ o;$-{* ocg :qodor6:,rp,(1)

go t-o Loopl ;
return
. x***End of the program***,k

end ,'Needed by some compj-1ers, and also


;jusL in case we miss the goto instruction.

XORF instruction of oa7:@1$E:e@cE. ofioq8sagoSrlpt"tQd esmcrS<.r'leo:o:q8


$ferr?$ eoTScoar<.,11 opl rr

Program Change Size (Bytes)


Flashing LED Original 120
Flashing LED Subroutine Added 103
Flashing LED XOR Function Used 91
LED With Srvitch Original 132
LED With Switch XOR Function Used 124.

J-gr Logical and Arithmetic Operators


Bit o61qE:caeggE. {:gE:earoc.:{p{Espooac6oqlcfqp:Gf"?6{+E. data tables
-.irQtQ4.{ "-.-@c,'lepirr oocBqEarTSS.-d EXOR function o:2! losical operator
oElo8@Er:glrr PIC cfoecoocfoqQleEo$ o@c:eoe logical operator qp:ocal:$eq63J:6p
oE :{.oe@E : c'i oc'5cuc6e<rT$ eEi <.r'1 rr

Loqical Operators

AND
AND function f6?c,?ftEtuyi$t "?AlE 1 qoSe<-r:p: cqqn8 0 goSeo:og)rr
-d bit

eo6or 1 AND 1 .QqE saa@ogjt @6@: 1 AND o {qg8 oe@ogl 0 @Ecog)rr word qp:
4*d, $t8:o?i$Er>E)rr AND function cog! Word q8<r'lo8og) bit o61q3:c'f $18:o7iog)r
eracrS o1 gcrenc{ @2) c.t1 rr

110 01011
AND 10110011
Equals 10000011

AND function crionrQlS: port qc:er\ec'co..116sae@onEc{ o6eo:{3oc2)rr gocr-Q3,-'


oo5c.:6:gt.aoc,Eq,:Scoo:eoo port o61o\ l/o pin qp:%3 .d-d pin og) nigh @66frlai
4 t34"at cu3: port of read ot6$tANDfunction G3. o6eo:$3o3)rr=aco.r5.r'lg<-recooiS:

looG 196 .ft.lfl- -?J -


cca
oc:@cDoc:
oo$,(..1) Source Code eq:qg:-j etC Qc6a$c6$-{- oa7:qpo8co3,Cp,(t)

Plc qE
AND function crf Q6f6{fG3. aaa:Gloic8$og)rr <^:E:oi.gc ANDLW q3.
ANDWF instruction oi.@6@Dgirr
ANDLW <number>
ANDWF <reglster>, d
ANDLW o2) Literal ,4eaTog) cco8go8coa:eurc8$: <number> oEqg8. W register
{.c,f nruo function Gto?663:GEo2)rr san@q W register qt .36'o2j:cca)rr
ANDWF a:E) W register tE. F register (gurlc PORTA ) 4.4 AND function 0to?6
@E:@6o$rr d=0 GEqE =rn@d w resister q3o33:og):@:r d=1 G6qlE on@d
rro5go8oc:earo F register oA3o36:oei:o2!rr eoocfe,rT@cigoercqp:cri eco.cuc,1lrr

MOVLW 11OO
ANDWF 05h,0
ANDLW 11OO

croegoenrr$ PORTA er\sae@oegc,i o8eo:@gi@3:@6o3ir lnput qpr.rd 1100


o2oEcqo5 on@d W resister %EG$d c36:o2):oo:oE)rr
'6eo'@E'@6cc2)rr
o3cu g <.reno2) W reg ister qE <.i of ea:oc8$ tqp: c{ o Eoo: @ E : @6 o2l
rr
1

OR

Plc qE oR function 4*d, Q6f6{fGE. o"tr@t.ilcffioogirr oE:oi.go


XOR(Exclusive OR) gE. IOR(lnclusive OR) instruction 4.GS@-dn XOR ca@o8:c,f
sacoc'5q8 eoTp;S:@Ecca)rr loR ooE) s6q1Eo,:Sdcoc'5og$:g69 OR function er\q6c$:oi
ooi8:@6ccg)rr eooc'S<-'') truth table qE ton functiqn efiog6c$:oi"? .qa.G8€Eogirr

ABO/P
000
011
101
111

Arithmetic Operators

-qp.?Eq, saqcr5saqlcr5qp:cri o76eo.:Eeo:a:p! Arithmetic operator qp:g3.$Eeoo


i nstruction qp:criecrT@,r1 opl rr

ann
_l
cB$:g61c,feo1E:e,.,,r:$rr e<.r'l3:cu5er2) e nits co.rSocqpqqt cnRnv flag c,al set @E
qa:r:g)rr CARRY flag clei STATUS register(O3h) bit 0 address q3 ficcajri PIC qE ADD
function c{ QOgS{1:@3. cne'Gloilo5fiarp)rr c-'3;oi.gc ADDLW gE" ADDWF instruction
o racr-- c
o?"tgo[gcragil
sao$:(.1) Source Code eo:qpl:-.; PtC,i cio 1iq$*{* saaT:qoo8o>E,r?p'(?)

ADDLi^l <n'.rrnk)er)
ADDI^IF <reqister), d

ADDLWccA) Literal qeoTe>gi rc8go8cor:eorc8$: <number> o:31g3. W register


q8o:lo3ec:ac8$:{.oi ec,13:a:glrr e"l8tco5c,i W regisier cg8 cS8:aopSroplrr
ADDWF -rd W register 93. a:o59o5crr)zcrn F register {.c{e"13to$rr d=0 GBqlS

SUB
d$t+EE4+1o5eo:ccE)rr ADD ci.cS,o8 sus og8coEi: SUBLW gE. SUBWF <.l?6r>:
instruction fE{1,fi-drr ADD gE. sue {.ogl q3c$:oloerro oroco3eo?o?c,8@Ea:glrr
eo1 3:@3:gE. g1o5@3:oo ca,c$:oglrr

INCREMEhIT
PICoe8 c'3$:or31cri 1 {:cqel8 sacorfqSoo'ili.ee:c ADD function c{sa3l;Qb!3
erg)rr W resister .,i t oi:cQqgl8 ADDLW 1 command @3. @:8:i8eo6cug):
""$,noo
register qp:oq c3{q18 esrocr5.:l saoi8 : gB ao8.Qlq 6eq ep: gJ rr

movlw 01
addwf 0c,1

6. g)ooa: I NC F i nstruction oton :


$L"af E Q €
qAd q ap:eoc86p$ rr
"Q.Q.$f"?
INCF (register), d
o=0 GBql3 e<r'|3:co3c,f w register q3e33:aogl:S:r d=1 GEqE e<iE:co5c't
oco59o5oo:ea:a F register qEc36:o2l:c.>$rr

INCFSZ oplcupi: increment command a$q@Eogirr

oo59o5oo:eoo register oEqof 1 of:eo:cQcBee:osaol register .rd 0 @Eqga:Alt

(lzt ol 1 e<.r'18:eo:c$c6a:pioa1{1:q8) eqoc'S instruction ecqpqga:eooglrr esDc8ol


",?
Eoenc{@g)cr'1r

Loop incfsz 0C
Goto. Loop

Rest of program.
I
0C register c,t ot:e<-r:c$c6o2lr 0C oE) 127 o@3cq3: goto loop @8. 1 ot:oo:
ega:glrr 122 c$.espo8$: eg:c'5o6 1 oi:cQcfea:orao1 Oc 0 @6qp:oa:ae@8. goto qE
loop of cap:ear"cd Rest of program .8oQ.""?FW:S: aocrSogSep:ogll

ccc
looG 996 "$q.'lf,- -?9- oc:@cDoc:
ea$:(j) Source Code eq:Eg):-,r etC Qc6o{ca$-$- on:q1:oEco8,qp'(e)

DECREMENT

D EC FSz sae@c8 : sa- cr5o38 erTGi.Gt G 3 $ co 66 el ecrTQecr:o.cr'l rr

COMPLIMENT

COMF <regj-ster), d
oo6goEcoo:6f,, register o:6qo33 cr'lo3ea:ccB$,qptg bitqp:c{ c@oS:0$oi$oo:ccg)'

o=o GBqflE
1:5.'? W resister o38e36:ogj:@:r o=1 G6qlE qo'Sd oo59o3oo:
ea:a F register og8 c36:o2!:cog)r eooc6,:1g,-,mcri @Eiolrr

0C:11001100
coMF 0C,1
0c:00110011

P:n o8qer\^^pin^qp:4 output ? input cQ.cog):ecrro8:r input 9 output {"


^
cugl:ecrro8: oql8o@$ e@E:olonr$L{qlS gacocr5<-,'L corrlr instruction
c,iog)r'
d -.?,G1.-.$

J-cor BIT Operations


r8$:oE1ai.e^opo8 register o:6qq8cr'lo8eero bit caElql8:c{ egepeg$E:r r c$.ero2o5
o @Eeo$E: oog)@E. c$sa6oc$ 86fiEog)l

BCF

Bit Clear F: Register F ca3cilo8eo: bit -6t4 O(ctear) @8eoog)rr


BCF <register>, <bj_t>

u) 3?.
o
registe(03h)g bit
E:q8eoTS5.o2)rr
3:r
Fd- q3c36:oc:ea:c
clear og6eo"9qge errcBol saoft: eq:qrcplrr
BCF 0C,03
BSF

Bit Set F: Register F q3<,io3oera bit 1(ser) @Seooglrr


-h4
(register>, <bit>
. "tt

r JooG Eg6 e$1olflcu -?C- o8:cocrJod, .


*${-il Source Code eEgp!;-3 eC {o5a{c6{*fl * sac} ;q1oo5cc6,qp,{g)

Dlnrufl/ar^^,.en)r:
v\vr ysve el
uGrrj\ e=nk,!(nrnrr.r--.1 t \^9.F-F.-[.qr..,,-A
j 1. -ar, SfattJSreaister(0-?h)c+
\"- /'i' tiii
Y "",
5 4 1 SSeo*-3ir {o3gc'}eamtgcBe$ BSF c'fec1;$$ge@c8; eg.Q3:q8eoT$;".:gi,r
--_-:----
P
g)E e C
:6f]e reg Ister €tP: 33cB cDcrJPi l-aOq
sft)3: o?s,of" : 19[6 c aJeg ll
C

ETFSC

BitTest Register F, and Sl<ip if it is Ctear: Register F qSoloEea:c bit -Bcr3) 1(set) ei"oc2i
o(cear) $6 rGA r6eao:$3r@3r:plrr sam,rS$ 0(ciear) G3ql3 eqroS instruciion trt ecqF
c
qr:a)e9il
BTFSC <register>,<bit>

STATUS register(O3h)9 bit 0 of carry flag 3?@33rr59.8e@c3:


saoc'5e38 eoTS;"St
@3=rg)rr BTFSC instruction of carry flag ci.c$.ea:o flag or8qcr? r6eaor-.$ogioa'ld1,q3
saq:Q1oo"$ol5ir 3oen n8$'+6e{ e"'13:p'nEcc6 carry flas trt 1(set) G8e@6$cqo2)ea1
eacS ci caoi 3 :eq: a:o: qn<rar $ n
BTFSC O3h, O
lolI -'- t i-.
Y lil Lrl ti s:l- tc I

or here if set to 0

sac,:o:qc.r8 carry flag a:gj . 0(clear) $3$: Loop -6??


e a oe o'l s "AdoQ-deaa'l{1:ca8
csnff) o I eo?c : 661. cor.sl o I f,) a9 I I

Loop :

:
BTFSC 03, O
Goto Loop
Carry on here if set to 0

BTFSS

BitTest Register F, and Skip if it is Set: Register F ca3<io8ea:o bit o:6og) 1(set) {".q"8
o(dear) @6 r3eao,Q3:@6o2lrr om<-S$ 1(set) @Eq13 nq"n8 instruction .,| e.t?fS
e "GB
aaB3ragil
BTFSS (register>,<bi-t>
BTFSC instruction 4 sa,t?tDLQ gE. oq8 ar gga$qol 3rei il

CI-RF

Cler Register F: Register F q8cilo8ea:a bit @?:o?:4 O(clear) @Eeoop)rr

CLRE (register>

!
3oS qlE -qG- o3:ocno8:
"$q.14-
a!
Source Code eq:g3j:-.1
?'$,(L) to
CLRW
_€d"fi "a4-{y -{:qoobo6:9p:(9)

crear Register w: Register w q8<ioSeoc


bit rao:og:c{
$6eoccai'
CLRW '(crear)
RLF And RRF
Rotate Left F Register through carry and
Rotate Right F Register through carry
RLF <register>, d and RRF <register>, d
resister F or6qoe8olo8ea:a bit o61c{
,:ilI1o _T'-d
i;ffi'.#,H'# A["#/
*g1 o:c6d<ucD (RLF)
cDcQj"oc,)
):l8ri eryl ooononir
;l,F,L3x
-i,Pe..* ::!i3H:"9-""T*gi:bJ
,d{.Gi"[1J:"?.p-ep ; "-n"'","; -b
carry^flag @dqa:$ai,r nlr' .6 :r'Ti ;lffi}T*H, [i: $
oc9 : [91d.91d qq-*"%e
-r?,$ta.q2;e ocoo g3E S$ecrTcoo"r g),, n.no.6-u1 -ds)
e ocrad ecu.coo<_,1', o"uTngr.$E:ogj 8 bits
register gE. carry flag .?.d n"Tg$,u1-.reiu

c 16543270
0 00000001
RLF 0 00000010
RLF 0 00000100
RLF 0 00001q00
RLF o oooroobo
RLF o oorooobo
RLF 0 01000000
RLF 0 10000000
RLF 1 00000000
RLF 0 00000001
R RF c{ or2' Gt"a E oo c8<i 6 q6 er\ e@cE j
@ :
0$ G6 @
BecrTeo o g) rr
" ",?
Example proqram
saoc6%EeoTSi.ea:o
tt^o,:':9.^ +mo.ofi1ri-drd
6(9 ilScr'lo3jr portA gE" eo.t - 3':1"':l^
LED .*:T^l',Gf:
qo:oE-36,u1,. portB o,io grlle.lS;[,
"?""ad . ;J,tI
:rx:1,:::P+ :i x{"
*,'=:* o6:a:Eoq5cu3:Qq8-' run
cco:a:g) P' - s ; fi GA ""* ; ; reT'ff ;;' o33eoTQ !
@g)u1,
;Example.asm
;Turning on LEDs forward & backward connected
;Use R:330K,C=22pF for external RC osciLl_ator at portA & portB;
l-ist p=pic16F84a circuit
include p16Fg4a.inc
_config hr3ff3'; _config _rc_osc c _wdt_off &
errorlevel -302 _pwrte_on & _cp off
TTME EQU 9FH ; Variable _for the delay loop.
PORTB EQU O6H ; Port B address.
TRISB EQU 86H ; port B Tri_state address-
PORTA EQU O5H ; Port A address.
TR]SA EQU 85H ; port A Tristate address-
STATUS EQU O3H ' page
COUNT1 EQU OCH
i select register.
; Loop reqister.

ecc
oc:coanoc:
ea.E:{;) sor:rcecaceery+3!:--1 plc fe8afic3$*{* :arr:alcolcos;,1:,(r)
COUI.IT2 FQt-t r-lng .
, T .rnr,
-'"'E -^-i -+ ^ .

SETUF BSF' STATUS,5 ; Go to page 1


MOVLi"i COH ; anrl :;et up
MOV,T{F' TRISB ; both Ports r1 and B
MOVT,W OOIJ ; to output,
MOVWF TR]SA ; then return to
BCF STATUS,5 ; page 0"
MOVLW OOH ; Clear Port A.
MOVWF PORTA

; Start of m.tin progra:ll


RUN MOVLW O1H ; Set the first bit
MOVWF PORTB ; on Port B.
CALL DtrLAY ; Wait a while
CALL DELAY

; Move the blt on Port B 1eft, then pause.


RLF PORTB, l
CALL DELAY
CA],I DELAY
RLF PORTB, l
CAIL DELAY
CAT,L DE],AY
RLF PORTB,1
CALL DEI,AY
CALL DELAY
RLF PORTB, l
CALL DELAY
CALL DELAY
RLF PORTB, l
CALL DELAY
CALL DELAY
RLF PORTB, l
CA],L DELAY
CALL DELAY
RLF PORTB,1
CA],L DELAY
CAII DELAY
RLF PORTB, l ; This moves the bit into the carry flag
; Now move onto Port A, and move the b:-t Ieft.
RtF PORTA, l ; This moves the bi-t from the zero flag into PortA
CALL DELAY
CALL DELAY
RLF PORTA, l
CALL DELAY
CALL DELAY
RLF PORTA, l
CALL DELAY
CALL DELAY
RLF PORTA,1
CALL DELAY
CALL DELAY

-?o- ecc
looG 196 oc:@cDoc:
"fu.')fl-
saa$:(1) Source Code eepg2l:-.1 PIC €cBo$c3$-fi o1 :q<-,o3co8,qp'(f )
-
; Move the bit back on Port A

RRF PORTA,1
CALL DELAY
CALL DELAY
RRF PORTA/ 1
CALL DELAY
CALL DELAY
RRF PORTA,1
CALL DELAY
CALL DELAY
RRF PORTA| 1 ; This moves the bit into the zero f)-ag
; Now move the bj-t back on Port B

RRF PORTB, l
CALL DELAY
CALL DELAY
RRF PORTB, l
CALL DELAY
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL DELAY
RRF PORTB,1
CALL DELAY
CALL DE],AY
RRF PORTB, l
CALL DELAY
CALL DELAY
RRF PORTB,1
CAIL DELAY
CALL DELAY
RRF PORTB. l
CALL DELAY
CALL DELAY Norv i,.re ar:e back where vre started,
COTO RUN 'I
el ts cc -ro: i n

; Subroutine to qive a delay between bit movements.


DELAY MOVLVJ T]I'4E ; Cet the del ay time,
MOV'.IF COUNT1 ; and put it into a variabl-e.
LOOPl DEC!'SZ COUNTl / 1 ; Decrernent 1 from the delay time until it
GOTO LOOP1 ; reaches zero.
MOVWtr COUNT2 ; Get l-he cielay time again,
; and repeat the count. down.
LOOP2 DECFSZ COUNT2,1
GOTO LOOP2

RtrTLTR.}.] ; EnC oi subroutine.


I I\it)

looG f.i-'$ *$+d1Q* -?G- oSrocr5o€:


o4r0) Scurce Code eq:opl:-.y Pic $c6a{e64-$* ocq:q1oc3o3rqp.(q)

RA2\-/ RA1
RA3 RAO

RA4/RTCC OSC,l
/IVIULN UDUZ
VSS VDD
RBO/INT RB7

Q(l -E) LED qa: oo3.:: -o@$co8:eqog) o6:cc6ooEcu6:Q

J-ccn Data Tables


Table oEqca8<-,lo8earo Gsot) (data) qpzfi'aq:Gl€Ecod instruction oe@o8:ofl
ocfcuc8 eoTQcile2irr Table oEqq8 @1o8@EoEcoo:eoo oo8:oqlc6sacocr5qp: <io8
,iccglr eooo- Gso, (data) qp:r cE$:ecc(constant) qp:r c8$:oco$: (numbers or literals) qp:
oogioi.@E@olcc2irr -fi,u-
Qc8afiq$co{cooqp:cc2i esooqp:crfl ccoEgo5oa:eo:a RAM,
ROM -6??? instruction oEqcagi:@8. file o6qai.-dqB8r oa7:@1$E@e.r
"toEqpr
ccplr PlCl 6F8a ocac8gcm: Table *.Qt@pf$ instruction (qhc$o8eoccplrr
"fl
Memory er\oo QE
: qE taote c'i o2ieoc'Sqoi o2i r e,rd -
"Q
Tabl-e1 ADDWF 02,1
instruction c{opi38:qec,o$rr Main routine %E W register of 'Jump" vatue gerao?
MOVe(load) g6eoc2! instruction cQo8eoogirr { 'Jump" value argl table
9 data $op$
eoTg$:r:2ioD$E:G6E: oqp'o:@8.-Et4 file ca8qg W resister cfl. move q6ec,'
"fp"fl
$E:o8@Ecogirr {eqccA 4 -.f r@tqnc'ccglrr
CALL Tablel instruction

Tablelo38 ADDWF 02,1 ocp! jump value { erogram Counter (o2h) qE co2)3t:p:
ofioe16cri Table 6\€aoc;8E:a?. 1$ot:a3o:eo<-,lo$rr Table o38<-ilo8eoa data byte {E:cc2)
RETLW(Return with Literal W instruction $t.-o? ogj{eqqeoepjl {.q- €d"{
in
oe$o$c,D3rei Table eoocrSoc8c$.o3:qa:oi3: data byte qp:{ o?d.?- W register
q8o2i@:egcd ?- routine c{p.q. G$"-ierd@6eor:g)r

..1ooG Eg6 e$q"lfl- -9o- ot:cooEoS:


:aa$:(1) SourceCodeeq:ggg:-j etC Qc6ofiq1-{- sa1'q1,-,oEco5,qp,(f)

c.lc/..-c.l
c3:acDo I
e
o€oo8c[(]?ego I il

StartUP

GOTO Maln

Tabfel ADDWF 02.1


RETLW AA
RETLW BB

Main

MOVF 0C,0
CALL Tab1e1

GOTO Main

Main routine q3E MOVF 0C, 0 instruction saq 0C fite crf W c$. move
e36E:6@cE.
0C q8fiaa:cc8$:qp:c,i eQcS:oicno table o33fie* Ovt qp,{ q"i$3e<.,o3)rr eooc- 0C
og) o @6ee>saa1 table q8$ef,f,c o@€ byte 4 q"i{S$t 0c a:pi t @Eeoosaol tabre
q3$eoo Qd- byte 4 qq$3-d ooE)@8. tabte o61g:q8$ea:o byte qp:of o6q
S:o:61 e1q$Ee<.,o2irr

j *"?*$!1 Eritefrupts

lnterrupt.Q-dS. QoEaficS$co{cu:
sa8.nq6aaor8q1c6(Main routine) c'i eag.IS-q.
eop:eqccr5 @2,G.6e6aaco3q1c6o:E?c{Elo?66ocog) c96c$:oi (process)
{.ru?d oA.,60
(signal) o:61 c{eaT,iarpjrr

Plc ca8 interrupt source, (g)e$11-drr oE:oi.c,i ecu"coo$3,-'1og)rr


ocooqEqq8 ptc "?6t0)td&:$
c$. @3cr9"u:6tsd interrupt source (L)1u'1"3@r q"3-"?St-AEqS pa
er\ saqS:Q3:9 og6eaoc3q-d interrupt process (J)qulo3"1are)rr

G3ogec,:oogi interrupt source (;)qcae@cStcri p:goecr'$oleleSr Timers e3. data


qr:i$:c33:63r3ec@c3:4.c{ ea1[c-rg]=anl Plc er\seo33:Q3:gogEeeorSerg) interrupt
process qr;sae@c8rc,i eoe"@€qer.rC8.o2irr
"aEg

. JocG a66 e$qctiSro) -9c -


ccc
Plc16F84 er\ pin qp'eoi$qlc;Q'? pin 6 e{ RB0ill'lr r-'1e
G$@gqE
:

eq.@3e1a<.,c86..21,r {"q,r;'ql"S-d o1 e"n o.{


bito(RBo) t^:l *Gi='t'
-
I

'interrupt-coggnu"$Ent
Gdu", o ptn-o@6."21: oe:Q63eo:e@o3, .oT@-o'@3:@Eo2)'r
o8oEat@3. Port B er\ bits 4 to 7 (P

:e1eoel$rr

ptc saq8:i address OBh oe8 INTCON o?-eaTea:o register ftif-d" ^t


resister cg8 a iits= fig, o:E: uit oiir3 enable(1) ('Q) disable(0) 0f"?SEe'GE.
egrc'5c'l

oe$ oeq qpt @


Ee.rTo:oe,: cc $ rr

INTCoN et\ BitT c{ GIE( Global lnterrupt Enable) "tttT{:'}l GIE c'? enable (1)
Plc c{oc3ec"$E'@Eeoc$rr
eScQoSGE:a:$ interrupt 4 -.i'0pd@Eo@c3:
INTCON er\ Bit4 c{ tNTE(tNTerrupt Enable) g2eoTg'loeirr^
INTE r:i_ enable_(i)
o?ScQdSS:a:ei RBo/INT clf interrupt pin o@SsatitQf"d@St@o3t
Plc c{sac3e"t@3'
@3e,-,el$rr
RBIE(RB Port Change lnterruPt Enable) u7eaTo1o2)rr RBIE
c{
lN
enable(1) Port .B er\ bits 4 to 7 tn interrupt pin qpt-@Eoa2:Q1e2i
GS@ces E' @Euuo2i"
ooi interruPt @EeoTgcc2i saqoEQ

@Ee<rTcoglrr ccdQlcl$saqn8p OPTION register r>[


E e''' rr
s"et ecti o n[1"? SE t gcce b it ietti n s Gfo? S q" dG $ rr

: - {f. interrupt oE @t"?E$e-EqqP:@Lo?68'uq"c6 interrupt <.,f

oc?:Stcqdea:osaa1 oq1 3n
INTF(intenupt Flag) qeaTo2i INTCON register er\ bit
1 og)
enable(1 oc$oeqpcB disable e@E$Eoqrr
4 ri"s "oei enable @-Sg''*'f
re'q6q$oo3ci ofioq6q8cogiq8:ee1:a:a:qar$rr
"Q"@E
qc8crsaq1c69o Program
edTg$:.,.,,rr$rr Plc .,t <.l101

Program Counter a:g) address


Program Counter cc$
address 0004h 6Eep
Gf,,,,,$oe13q3 interrupt c,fcaq:Q1oo;5.q13
interrupt routi ne of o.73eo8 eoq<-,1 c2l rr

-gJ- o3:coc3o3:
^
Jooe ?+o
c
cqforqco
c 1e
,rn$t(1) SourceCodeeq:gg):-.1 - Plc €a6o{%$co{cwr sai:q1oc8co6:qp:(q)

ofioe13crfeq.f,ra:cf,raoal oRG command cl|on:Q1$: ORG 0000h , oRG O00ah op$


address nEcpqp:{ oo5goEq<r'1eg)rr ORG OO00h command Etnq"d cOTo instruction GE.
main program crfqlD:{E:c,1rrg),' ORG O0O4h command @8. lnterrupt routine.fqr"?
"Q"q"d
nuTEEt interrupt routine .lt {dfid66l:a:o:$ear8o:p):ecrro3:r GoTo instruction
interrupt routine c{q6eao2€ooc,log)rr lnterrupt
@3.ea:Eco3i:ocr:ot:r 96ocAoc$eq:a:o:p:
routine of RETFIE(Return from lnterrupt routine) instruction @8. oag:oo8qcr'1og)rr PIC r:gj
RETFIE crt @Eeoo ol Program Counter o$ interrupt routine eloi88mfiS.eer address
eoTg$:eo:,-i o2)rr
"f 'p"?
ern.r5 <i E oenc{ eo.coo,i
"

ORG 0000h ;PIC starts here on power up and reset


GOTO start ;Goto our main program
ORG 0004h ,'The PfC wil-l come here on an interrupt
: iThis 1s our interrupt routine that we
. ;want the PIC to do when it receives
2 ian interrupt
RETFIE ,'End of the interrupt routine
start ;This j-s the start of our maln program.

I nte rru pt c{oe :


$1a, don'l o o3coo: c$ crSqaele 2ioqc6( j ) EJdfi o'l oc ai rr,-,co el oqlcf 9a
register o6lop!:c{ main program gE. interrupt routine
"?.qae Ete"?-er[91@a:a.qilc
interrupt n@c8. register o38<.r'lo8ea:oc8$:qp:e@:E:obqp:o$"{ oo8@1qnc>el2!rr gc,enoo:@8.
mainprograr%E Wregistercri eortn c$. dataqpt.{ 8.{E:od4o1Q.rr lnterruptroutine o3E
W resister {-dr data qp:crt -Enf epg o$c:o6ng"p{. Q.iE,coo:$$cc2l.Qql8 interrupt 9
@$"gdcooearccaa'l W register o3t,.:'loceera data qp:er$ interrupt routine 9cr'lcmea:a data
qp:elo@6$: interrupt routine ooi38 Port A {. kt"q"- fiq- data qp:ct.:2oEeo:a.eqrr
{cQ.e@Eeoq$-"gdt3):gr interrupt routine coi8S'W register"3E<-,'1o3n.:agco ciata qp,{
o,-6 ng epca E ea ga3 6:oo: e$c$sa3e,oa: 3l rr

qo3cur:o3coa:qc2)oqc59c interrupt caSqg8.o:Et@c, {E:6.{q (delay time) fiq$


cQsa6@3,<r8 @6<iogirr saooSe@o8."fleoE PIC ocac6 interrupt address
"+f{..gatqQ3:r
flas cr? set g6q$E:r interrupt routine gG$"8dqEE: or:g!{."r%nE o{$c$o6arae@c8.
@E,,r'lar2jrr {{E:e.{$opi Q9$sao:@8. 3 to 4 instruction cycles o$. fio8.eorr2jrr PIC
sa%c'S intenuptc{ S8..,,:o8co3:9 trisserq6o2isa"l{Lroa8 g)3aXcr5c,?a>o3@1qe<.rcEjrr

Port B 9 bits 4 to z oi.c{


on:Qlcopioa'l oo8cocc$cifiq"d
intenupt ca@8
saqc6qptcugJ:$<.,1eo:og)uo3:{.9 bit o31q13:c{ c3:ar$."grq1,:S$ inierrupt c8g
s:n:e@1$3nq;rr o:ooSe@ct.{ec$ o8:oi.g bit o$11of enable o?8cqoEep bit qc:
"e1$
aiglcog), enable @33c:@ea:cn@c8.@3ec,oplrr eoe" bit a gE. bit 5 o?"cl| enable
o?ScqdcglS bits 6 and z oi"ocE)cup!: enable @3qc:@eooE)r, {oi. uit (p)EG3. interrupt

cec
looG 193 .$Eo181co -cc- ocicocrloc:
s'a$:(J) Source Code
:-::--+------_-
eq:+aS:-..; ntC {c6a$q4-6* cr?:qoC.r:5,qp,(?)
---__

c c c o ' -oe e o t *-,'\-S e c


mq%c cPJ3).3?f,J:l(JLica)+al:a?€3-}] '-...-*;.!J pln y-.
"S w(,i-twwJ.uwrvu)LUi:oid1cr3c
^.4^-,.q-.----^..i.-
e

{3,(t)t-+cB or6q1 rrign @Sej8 plc og) qlcAqlS:q$.G$t G1fl3"<;c€3pEil


EocnoEgeaqg8 nousealarm cro8coS:o:3?4@d.1rr or8:ca8 PortB e'-i bits 4toT
sensor (E)t -6-3mo:og!@3sb.rr {aaolrd-d sensor or6119e{ ptC cr? trisger
"fl."a8
T6Et alarm .l| @gjeocilc$rr Alarm @gieoca) sounding routine ccgl interrupt routine
@6<iogirr gl.Q.-e,GL$SES:a:d Pic "anf$3. port qp'{ o:S{qc.?; eo'l8@g)oSeao:
____s e a
3Do?oo)o ? 3\)cD3)af,a?:f,) ric s c o o o e e c oeoc
Gf q$eg
[gc. cnjf s?o?oqp:c? coco66pct66pcD cy oc?c{ c 6()60.r.
cJegil

lnterrupt .,? ,d.?..,t3q.Se@g8:{Ee@a3: Eocn,-rfioe13orE1ee1ta:c:scrT$<r'1f :oglrr

J-c?n lnterrupts - Writing The Gode

lnterrupt can:@1-Qsae@c8: cacocr5caSecrTQi$:eqoc; ofioq6o33og):g3:ee1:rc:Qcri


3c,ccor61@3. aocAcuo5eoT@olep)rr .r:qn.Tp.3)g<-,oc<-,fioq6-d oogo5ofuc{flS-d ""@3
oeqsacac'S (o ? 0 oo8) .,? LED (9)g:Gg. {e+{Qa@8. geoT$arcg)$Ee<.,ccEjrr tnput
{..utoE interrupt of nao qE oogo5m@E @dcg8:e<.r,c,'leglrr
<.roeg8eaca8qegloqlc8ga interrupt G66oT{$ Program Counter(PC) meoTg$:cogi
address 6fp{. t$qpr.1$ Plc c'? oc3eo:qegloqlc6@Eogln
{oqlcEc{ eeoc6c'1sao}E:
6Ttca)eI
org 0xO0 ;This is where the PC points to on power up and reset
goto main ;Goto our main program
org 0x04 ;This is where our interrupt routj-ne will start
retfie ;This tell-s the PIC that t.he interrupt routi-ne has
; finished and the PC wil\ point back to the main
;program \
main ;This is the start of our main program
interrupt oc9:@lelEioe@E:g8. RBo pin o cn interrupt pin o@Esan:Q1ca)
"Q,"q,r"E
o,;@c8: Plc c,? eoc6o'1 ooi8:oc3eo:qe<.rc$rr

bsf INTCON,'7 ;cIE - G1obal interrupt enable (l:enable)


bsf INTCON,4 ; INTE - RBO interrupt enable (1:enable)

8oEq1e1erao3 interruptflag 4 eg:p:ga clear og6cootq<-,1el2lrr

bcf INTCON,T ; INTF - Cl-ear flag bit just in case

SooG q96
"fu.lfl- -gg- o6:cocAoS:

?
san$,(1) SourceCodeeeyEg):-.1 etc QcAofica$-{* ocq:q1,:oEo:3,qp:(t)

Ports qp:crf set up qEqcr'leglrr


"Q.e,r"E
bsf STATUS,5 Swi-tch to Bank 1

movlw 0x01
movwf TRISB Set RBO as input
movlw 0x10
movwf TRISA Set the first 4 plns on PortA as output
bcf STATUS,5 Come back to Bank 0

aqo8$6og)o@6oeqoqc'5 c36:o2!:q$oqc8 COUNT.pn"T-d variable crfocg:Q<.iepin

Ioop
movf COUNT,O ;Move the contents of COUNT into W

movwf PORTA ,'Now mowe it to Port A

goto loop ;KeeP on doing this


end ;End of our Program
ea8m main program eqtaro:S,Gg?d epla:2ica{$o38 interrupt G6ed4roeic{ Plc
c,f
gar: gac3e,::qeoe2lrr glgcrecq8 interrupt ogi aogo8$Sarg)-{$@Eo$n aqo8o6qoE$6
4Et PIC m coUNT "3e -Eq'-61ot:eo<ie2!rr CoUNr go"$Q:qP:c,? PoRTA {."Q.8 w
register ca8$eqea:ao$Q:qp:c'f TEMP t:7oel$eo:oa:o$ address Ggcpq E ooc€a963@a:q
c-
6o6eil
movwf TEMP ; Store W register in a temporary l-ocation
couNrcAE @qQ:o81oi:eo,iog)rr qafc{ cou\ q8@$c36:cr'ie2irr

incfCOUNT,l ;fncrement COUNT by 1, and pu-r the result back


; into COUNT

couNr q8$eoco{Qi-d (e) oc,EecqEsg$'3a,$8,$no$c{ o6eao'q,ieg)rr 4.q.


"Q"E""E
01"?S.1$o"e.r5 courur .{ ('o)e fpE@dfiEciog)rr

movlw 0x0A iMove the val-ue 10 into W

subwf COUNT,0 ; Subtract W from COUNT, and put the result in W

c<.l5eoac8$:9 @:et:ocB$r4+L"EqlS Carry flag o$ set @6q3cte:eis>%c,5 Carry flag c{


ce
oo6e:q6of,)agil

btfss STATUS,0 ;Check the Carry f1ag. It irj-lf be set if


;COUNT is equal to, or is g'reater than VJ,and
;r^rifl be set as a result cf the sub-wf
,'i nstruction

, ---.-
.1coG 15,$ "F+"l.i- -gJ- "3:ooEo8:
s>a$:(3) Source Code eei:o$:-j etC { cfi ofi o9$*6* saai:qlooEo:6,qp'(e)

nnl llriT ...\


*r: /o)*^,1(#,"^.,S ^-^.-R fi-!..'?F.rti.,.-1,, lol*.i,-,iRr^.-r^-,'S rnpin
--,,!-S
""..-*ij
o ra \u/*"/t!.-i"yJ' -^l=--t.uy.lJ1-"-.-f:,' \u/--'.--{jjj--*--*jii.t*
prcgi'am c?. %.:[g: PortA
{. accr!cu,$,f.eo:eqo'},-'3ir a:Grc;olcq:r.:r.'r;3cp:,f7 car"n::o}rr
goto carry on ; If COUl.iT is <10, then can carry cn
"';e
goto cl-ear ;If COUNT is >9, then we need +-o clear iL
UAI! V UII

bcf INTCON,OxOI ;We need to clear -rhis flag to enabler


;more interrupts
movfw TEMP ;Restore W to the value before the interrupt
retrae ;Come out of the interrupl routine
clear
r. rf .nTr..'rr . qa I ^nIl),T ba:k t: 0

bcf INTCON, i ;l^le neei tc clear tnis f laq to er-abr e


; more -inEerrupts

retfie ;Come out of the j-nterrupt routine

ococBo'lg8:co8:etrTlGql"Eqpd q"d,d o$oq&a$eioqc{ cscE<iooi8:Q$-dnqt =


oe c
a)ostccosJPlr

org 0x00 ; This is where we come on poster up and reset


. * * * * * * * * * )k * i.* * * * * * * SETUP CONSTANTS* * * * * * * * * ** * * * * * * *rr

INTCON EQU 0x0B ; lnterrupt Control Register


PORTB EQU 0x06 ; Port B reglster address
PORTA EQU 0x05 ;Port A register gddress
\
TRISA EQU 0x85 ;TrisA register address
TRISB EQU 0x86 ;TrisB register address
STATUS 0X03 EQU ;Status reqister address
COUNT EQU 0x0c ;This will be our counting variable
TEMP EQU 0x0d ; Temporary store for W register
goto main iJump over the interrupt address
- * * * * * * * * * r. * * rr :h * INTERRUPT ROUTINE * * * * * * tr * * * * * * * *

org OxO4 ;This is where PC points on an interrupt


movwf TEMP ; Store the vafue of W temporarily

lncf COUNT, I , fncrement COUNT by 1, and put the resuft

looG qg6 "$q"lfl- -9G- o3'oc,5o3'


*$t!) Source Code ee1.Eg):-.1 etC QcAa{q$-{- oc;:q1oo8co6,ep,(q)

;back into COUNT

movlw 0x0A ,'Move the val-ue 10 into W

subwf COIJI\IT, i ;Subt::act W from COUNT, anci pi-r'r- rhe


; result in W

btfss STATUS,0 ;Check the Carry flag. ft wrfl be set if


;COUNT is equal to, or is greater than W,

; and will- be set as a result of the subwf


; lnstructton
goto carry on ;If COUNT is <10, Lhen we can carry on
goto clear ;If COUNT is >9, then we need to cl-ear it
carry on

bcf INTCON,OxOI ;We need to cfear this flag to enable


,'mc,re interrupts
movfw TEMP ;Restore W to the vaLue befoi,e the interrupt
retfie ; Come out of the interrupt routine

clear
cl-rf COUNT ; Set COUNT back to 0

bcf INTCON.I ;We need to cfear this flag to enabfe


\\
;more irt,orr,rots
retf ie ; Ccrrre cut oI .he j ila- j:t up: routine

,.
****** **** * * * * * * * * *Mr i n program* * * ** i- * * * * * ** * * * * * ***

ma.l-n

. **)t****************set up The Interrupt Reg.isters****


bsf INTCON,T ;GIE - Gfobal interrupt enable (1-enabfe)
bsf INTCON, 4 ; INTtr - RBO fnterrupt trnable (l-enable)
bcf TNTCCN/ 1 ; INTF - Cfear FLag Bi t Just In Case
- * *** * *** * ** * * * *r- * *- *set up The Ports *** ** * x )k * * * * * * * * * *

bsf STATUS,5 ; Sh'itch to Bat:k 1

rlc.rlw 0xO 1

aec
looG 1i$ 6td.i- -92- oc;@r,"?oc: c
oa$:fu) Source Code e<gqpl:-.; P lC q o8a{r:;$cofl cto caq :q;<-'o8co6,qp,(e)
.Qa# DDfl l-*.-!
r.no-.2!^rf TP.ISB , u=L r\uv -^
dD IrtPuL

mov]w 0x10
movwf TRfSA ;Set R 0 to RA3 on PortA as or:tput
bcf STATUS, 5 ,'Come back to Bank 0

- ****** ** ** ******** *irlow senci The Vafue Of COUNT To Port A

loop
movf COUNTT 0 ;lvlove the contents of Count into tr{

movwf PORTA ;Now move it to Port A

goto loop ,'Keep on doing this


end ; End Of Program

ooc'Scio{oq6c{o6eao:q$ Qf -C)qa€noT$"oo:toEioo8or&.sooit: eoc6g<.:S"poe$l


or8:oo8co6:q8 RC oscillator c,o5o6:oqcf mo<.S8cno C1 crf ca6o8ecoa:e@o8:e%G8€e
o1er2)n oo8o$:q€ @6e.rTnqean @coreqg8moo8Eo8.'(stray capa'citance) cf timing
capacitor o@6 oa2:$[oarcicrpirr {gpj:o6aecp! .ccTpoecq6a}5cu2i: moc:S8oagperqcrg)
oo1fr:q8 timing oq3c6oeq:e@:cogi o6:cc6qlcfqprs%cE ooBOSoc? @a?:[9[f . noeca) a)e
ti
e
g$:o6:o8?-GE eoT@@E:oo$E<icc2irr oo5co6:arglesooEQcoTq-dd occDoqEc.
cno<rSEo:oo$Qt-d oeQc8:oo)fi{E<iogjrr I
\
uo?o8 51 o8o8oa:ogi pin 6 qE C2 hE. R2 soi de-bouncing oo8co8:crf
co2$qg8:oo:e@a8:c{cu$: eoe.@E{ E<.il ogi rr

ceQ
looG 196.$t"li- -9f)- oc:octtoc:
nqqd'-J erc Qo6a$oeQ-$* oq:qocficu3,qp,(e)
=: [
onQ,(
"o:t"9!go"

oscl
OSC2
VDD
R87
7 loo. oo^l 12 D1
R86
I l^^^ I tt
R85
e l^-^ R&r
I to

q!-g ) lnterrupt routineo6:cc6oo3cu5:Q

\\
J-cgl The Watchdog Timer "

llC er\saca3:Q8:$ Watchdog Timer aae@cE:cf e.rT@c,1oEirr Watchdog rimer erl


saSm_q6c$''ip prc saca€:*qi33,-"'..:o u{nq8opi cae@c5-E11"@d. ge$o.?3
6 6a i -9,
o q 6$ 3 oo,:"o gi aaal dL' g 3"@Leq.cooa:g)saa'1 reset o9 E eo-q e S,
=:e $
Watchdog Timer <;o5cu6:o2) PIC efi eaqAS:QE:oeE resistor/capacitor network
@3.
o:q)e^oct5coo:@3:@6fi: cr3:ccg) o3cqea:o clock ofld@qp:cr? ogo5eo:oXcAfi.jl-d';
c,"8:er\ clock oE) @3o9e,:3E:oo:ccg) dock o?,"-Jr6grflinql,,-
93.
c$cr5ao:oa1 counter o61og) oo 9 FF d 1
epcrSqo:eorsaal Plc d
WDT m PIC c,? r oi
:e1l%E wDr c{ oo .;
(periodically) S: reset o.76eo:eq@3 :oE @6<;11 r-'g) rr

looG qg6 $qo'l{co >\", ot:co,fo8, '


:i>a$:(1) SourceCctieeeyoEl:-".y FIC Qc6a{ca$o{ot: :aq,qod.o3tV*(l)

Watchdog Timer c{sae:Q$Eieaal esarcDci saq1.;(e)e"Ed arcSfijiqeoc35.eg)rr


- !\rDr { ieset .f8q| sa{$ogi916l3rqei;
- wDr reset qE$E:cBgc{ ,d{."dtQ$$ dearo?E6ioeiqei:
- Programmingsoftware@i wor "fl ,d.Q."dQ enableogS$3o+g):

oar$c'i.$3@<ierg)rr o3:oi.o:fuq13::a"@o8,crf QQEo,o$rrerrono1"Eeo"$ sac{1-:sae@ct:


.oer5 o 5 t: g| oe@o8 :sa epqp: c,f cr5
% 3 -g, qpt g &, d
eoT$c,'l o g) rr

"s^ro

WDT Times

qE WDT efi oo-caag:@o{$ (period) cf 18mS qeo:coa:c.ro5cr'l


PIC data sheet
::3irr ai.ao8 {o{l$-d .o3"cQ3t$.sm:r sag3,1$ ooglcaqcBsaar,sqp:ec-,Teorg)p: a$c3:oi
-dc,loeirr no:7.,q1saot@3. $iDT .ca)tams @.?3t reset o73ergit2 .,;{3"'lrrElrr
{sa{$oc8 q@c6rreQl?fi3-d g2j:o6:fi,iog)rr PIC saca3:$ Prescaler c,2naTa:2)
..ro8co6tor6i,-,11$,:logjrr o3:cogi WDT e$ RC clock c{ divide o?6Q8c,le>eir ofioe16ee1:
rrg)o"'1 prescaler 9 WDT efi RC clock tri e$g divide oq6e<.r:e1cd"? -"EgoEo<-t:c1ctlcca)rr
q6-d divide oeacoqlc:coreco WDT c{ reset q6q$@CcD6cD @6e<-to$rr
Prescaler ccgl addressBlh q8fieoo OPTION registerer\ oits0to 2cEep%E -d6
r-r1ccp)rr Prescaler e$ division rate c{ bit assignments @8. aoc6o6$: WDT sao3cf time out
9o5oo:c,1og)rr
o{$-d G
e) o@E9o5qq
eoT@r-,1c2jrr

Eunno:@8. wDT o2i Plc .,? haff second @"?Er reset og8eoc$opi@Esb.rr
{ru'l.c,rotq8eoTSqlc6caq half second gE. ofi:o6og:ca{$ogj 576mS, or 0.576 seconds
@8e.-ro2)rr 4@o1 oPTloN register q3 n'tot'ca$Q:cfi Q.e,r:qe,:el2)rr

q93 -3o- o3:"ocr5ot:


..1ooG
"$t.lf,-
oa$:(y) SourceCodeeq:gg):-.y etc {o5afiqi-{* oa2:qoo6co6,qp,(q)

Bit Rate WDT Time

2.1,0

0,0,0 1:1 18mS

0,0,1 1:2 36mS

0,1,0 1:4 72mS

0,1,1 18 144mS

1,0,0 1:16 288mS

1,0,1 1:32 576mS

1,1,0 1:64 l.lSeconds

1,1,1 1:128 2.35econds

movlw b' 101' ;This i-s 0x05 in Hex


movwf 81h ;This is the Option Regi-ster

_ ccu?o1sr:@8. qcoooq8 prescaler op) sa$,noc internat timer (TMR0) ca8


o.?r0[.1$ assisn oq6oo:@:@Eog!rr prescater c'i wor o%d oai:$pd{ele
e coc n "Q"@cS.
og8c$c8eyie2irr .fle,rd Bank 1 ai.e@c8:S: prescaler crt WDT
e
651:e:8o TMRO c'? reset o?oo?mqoleS
o e oc o
3eqJcrt assign o?6- c$o6ea:ao{$c{ set upQ\cr'ltlg)r
c
E'"aE Bank 0 {. G$"&8,
q<-,1el3!rr esactSc,l code eq:ggl:crfeco.cuocrlrr <rE:qE **x
-d c$o6ecro prescalertime cr|
qq$ assisn q6qod bit pattern @6,iccgirr
bcf STATUS/ 0 ;make sure we are in bank 0
clrf 01h ;address of the other timer: - TMRO
bsf STATUS,0 ; switch Lo bank -
c L rvrdt ,'reset the WDT and prescaler
movlw btxxx' ;Sel-ect the new prescaler value and assign
movwf OPTION ; it to WDT
bcf STATUS,0 ,'come back to bank 0

3 clnwor command o3) ptc c{ reset cq68 _yvdT .,t ctear


o?6- r ofioe16q8 WDT og) .d-deqrq8 time out c96og)4-d
.,fl % Plc cca) reset e@searto2noqpodcfepoof8Sq3 CLRWDT
command .l| co2)q3:oc:qolca)rr om<lS$ ofioq8o$ saqg$gagcgi:olm CLRWDT
corn ma n d c't or3
@6 c cn cog)e<-r: c'fl3e6e@o8 : cc o3QileooE)
61$ rr

oecltos3r{+ (default time) @Sea:c 18mS .{


oei:$1ca){o'lm ofioq6og3- 1u}is
-ii$@{E: CLRWDT command
"fl -d*E:oc:qec,cglrr

.1ooG qg6 e$9o1Qcu -cc - o3:ocrSo3:


srn$,fu) Source Cocje eel,qgj:-y P lC Q
cDo $ cp$-fi * ee7 :+.1ooEor6,ep,(E)

lnstruction Tiryllg

FIC ar3i $3o9cogiq3:eo;cor:argl external clock ofa @3'oa;@:egoo5 internal clock

{pu?oS instruction cycle sa@E san:Qy-,1r:g)rr samcS$ +n,lHz crystal c{


Plc ca8 o6o3
sacl:@1coo:cd4qge Plc e'lsacaS:Q8:q3 of,oAEB l MHz fi"- instruction cycle Ge.
oog6q6ege<.,cg)r sa{$ca:@E eoT$"lna;E 1l(4M1zl4) = 1pS @Sopjrr saft instruction
qpta>d saq6$rn$c361$ instruction cycle or61oa cQsa6p,' o{;.r3) g8qc$:a6o1o$rr
4Mlzcrystalnfl or?t$tq118 1 instruction cycle -%nE lps @o$:r 2 instruciion cycle saqtr5
2FS @olldi@Ee<-ro2)rr PIC efi Data sheet c3E instruction o3l instruction cycle
"d-d
egigopo6od"? .*TG-'<.i oplrr
.qg"Squitgdfd,?" instruction o:cQ:cQcQ"od cycle ofo6o2luo{oq6oq8:
1
ca6eqcpepcQ. cBa:{E:6cD instruction qpeqcr5cca 2 cycles c.fo6o1co2ll

movM command ar$ 1 cycie c'Qo8ogjrr o:ocSe@c8.


E,:cnqp:@E.e<rT$e1oo5
{"ri oSra:2) data c{ mBegqrg -6e"p{. ag.eo:qgoo cpEqet:cn@c8S6oglrr The
goto command og) 2 cycies .8o3o3)rr sa:o,-So@o8.{oarE oStrrg) Prograrn Counter
(Pc) crf c.,{oq6saq8: or8eqepepcQ. aga,i8:ea:oe@c3.@Eoglrr The RETURN command
a:2io2i: 2 cycles c$o3o2irr o:o,,;E@a8.eQeo8 u:E:er2) Program Counter (PC) .n
ofioq8og8: o8egspepg S$coa{E:ea:oe@o8.@EoEin cQ.eo8 DEcFSZ, lNcFSZ, BTFSc
gE. errss 4.-d 1 cycles ("?J 2 cycles cu8:oi.q8 q2Qco2iolcB
o8qlc8$craiu {-qld?" -.@oegoS1198.c,fc6 instruction c{ ecqI5cBD:$Et
(skip) @:r ec{o8glqg8r eqac8 instruction e{Et E@Etcgirr auon- DECFSZ

"orr"-nO
qE r r"gi"t"r 9 r {nqp.qegoo$rr e1co5o2i 0 eo2oEqg8, 6fac8 instruction
saot8:q6eo8eqr:g)rr g1loo3d I cycle a:ac$o6apirr ocncS$ qoEccgi o @Eqg18r
eqac6 instruction of ecqF€a:a:airr g[oo3cA 2 cyclei c$sa6og)rr oco,.Se@o8rQea:E
,r8:oEi Program Counter (Pc) .r| co$Q:eQc8:eoea:oe@c8.@6og)rr qcr: instruction oqtrE
1 cycle GSEt Pc a$c8:q$oo3c'5 eqac,5o6 1 cycle cQa6$E:@6ogin erac,5q8
eoT!"oa:earo Eqgo codeo%d cycle elglglcQo8o$c,i %d@d@olQ.il

movlw 02
movwf COUNT
Ioop decfsz COUNT
goto loop
end

o@el instruction ccg) 02 ,fl W register "4. egeo:cc$rr crc8: command cogi
-BnEfep{. qp:$E:elopo5ea:ae@c8. 1 cycle ooc$o8ogirr qo8cr instruction co2icoEi:
ocm:o2o8 W register 9 c8$:qp:cr? coUNT register cQ. eg.e":e1o@8. 1 cycle arc$o6
o:2)rr oo9cp instruction a:g) eg:f:go COUNT register ? 1 nq9p.q1e1o@8. 1 cycle
"?
c$o8ccpin qcoEog) O @Srel@Sc,foEeo:er$rr 0 e@6ecc:ea:o.@o3.r goto instruction crf
aoc'Sry:ocEirr ,rttsao3cr5 2 cycles c$oc2ir decfsz instruction rQ"G$""p"EEtegonE co_UNT
regist-r 9 1 .'i eq11c.qlQ$ar$r' o8:oqcf 1 cycle cQo3)" qo:Sogl o $6rc@6ofl
o6eo:S$cogJrr glo"S@S%3 elorScc$ O @Eeare@ct. soto instruction .,| ecqlEapr$:

gooG 19E -eJ- oErcocr5oS:


"$e.'l{-
oa$:(1) Source Code eq:qpl:-.y etC QcBofi q$-6* oc;:q1oo8or5'qp'(t)

ofioq8$,agrogi end ei.eepoSqa:ccp)rr o3:oqcr5 1 cycle c$cc2)rr coUNT


register crf o2)38:S: "Q.@3.(7 cycles)
"aE -$Qt oz 1 6qilD.qt63ro ococ'5<-,1@3q6sao3cr5 ggeci8:
c$o6o2)rr 4MHz crystal <rt S8ogcoSo€on:@1qg18 {o$oqSccal ggeo13: zps ca{$@c
ar2)rr [1/(aMHzt4) = 1pS per cycle, therefore 7 cycles takes 7 x 1pS = 7pS.]

DECFSZ ci.ci.ea:o instruction qp:oqc6 cycle sac9:@LQ"?"a"Eq"Ea:g)oo1 saq$:c<-,S


glo8e"g: gfi e@c8 : o o9Q1.8e,.,c86p gj rr

Proqrammer Software

PIC er\oo3E:QE:qE'Fuses' cpeaTeoa oepqp:$olopjrr <r:E:of.ccgi programmer


Ge. 'blown'g6i3ea:o electronic switches qp:@6@o1ord,, 'Fuses' qptd enable (c$.)
4
disableog6$E:oo'@8. ptC el\ q6c$:o0.€ 'Fuses'qp,qJ8 WDT c{ {
"ir@de<-':{E<-,1oE)rr
enable (cQ) disable o?6i8coei Fuse <-ilo8cogln 'Fuses' qprd enable (o$) disabte
4
.y6epoe8 E2i:o3:(1)1$ologirr ooeqEl:go <.r{oe16eq"oo:og)oo1 o{oq6ooQ3:q3
'Confis' 4-d directive command GE. cQsa6qldqp:c{ og)3g8:eoT@$E:@6o'1rrg)rr
qo8ocgEj:9c 'Programmer software'o3E manually set up og6eot$3:@6o$r qo8cuqgito2)
ooeggj:crf ovenvrite q6<i ogll
Sample Proqram

WDroc9:Q1Qc'imn@5eoa ofioqSoEloq:qai:cfeoT@olcail oE:qE WDT .'i


enable og6coa:S: PIC crt oo?6q6{E:o1eg)rr ooeo3t WDT c{ periodically clear q6p:
c'fioq6eg6"?6Q"? eo.c'ocie2)u {nqrd CLRWQT command .{EpEE' PIC o $om<rS
reset $E e@o8 : c'? eco.coo<-,1 eEl rr oa7 :$pEirbSo'6'} Q 0 - g)og8 noTGS.E:G6Dd LED qp:
-uS-a3a oQ$oca$eg$: co8:eEco$oo5co6:@E..iogjrr Plc reset GEcoTnc{ GEqsd
eoq$saogd nc o$Q:c{ ofl EB exHz qern8 e6:q1<.Soo:<-,1og)rr gcoofioq8o38cio8eoc
comment qp:6f ep%8 clock cycle saeqsaqc6g8. <,,fioq8oo[ ooq6oodg@{i (BKHz clock
@t.saq6q6nf '0 ) 4.4 co2)q8:eoTQcoa:o1 og) l
TTME equ 9FH Variable for the cielay loop.
PORTB equ 06H Port B address.
TRISB equ 86H Port B Trist.ate address.
PORTA equ 05H Port A address.
TRISA equ 85H Port A Tristate address.
STATUS equ 03H Page select regj-ster.
COUNTl equ OCH T,oop register.
COUNT2 equ ODH Loop register.
bsf STATUS,5 cyclen 0.5mS
movlw 00H cycle, 1 .OmS
movwf TRISB cyc.Le, 1 .5mS
movlw 00H cyc1e, 2. OmS
movwf TRISA cycle, 2"5mS
bcf STATUS,5 cyclet 3"OmS
mov]w 00H cycIe, 3.5mS
movwf POF.TA cyc1e, 4"OmS

jooG qq6 -0Q- o3roocrSo3,


"$t"14-
oa$:(1) Source Code eel:g2g:-..1 elC Qc6a{c3$-fi
- =oc1:q1oolco6:qp:(?)

; S'carL oi i-rLaii-t pi:ogi:aiii

RUN

movl-r^r O 1H ; 1 cycle, 4.5mS


movwf PORTB ,' 1 cycle, 5.OmS
call DELAY ; 2 cycLes, 486mS
cal-f DELAY ; 2 cycles, 957mS

; Move the bit on Port B left, then pause.


rlf PORTB, l ; l- cycle, 957.5mS
cal-l- DELAY ;2 cycJ-esr1.45S
calL' DELAY ; 2 cyc).es'1.93S
rlf PORTB,1 ; 1 cycle' 1.93S
'caIl DELAY ;:2 cycles;2.41-S' ,

cal-l .. DELAY ;2 cyclesi2.89S


rl-f PORTB,1 ; 1 cyc1e, 2.895
call DELAY ; 2 cycl es, 3.37S
cal- I DELAY ; 2 cyc:.es,3.85S
rl-f PORTB,1 ; 1 cycle' 3.855
caII DELAY ; 2 cycles, 4.34S
cafl DELAY ; 2 cycLes,4.82S
rl-f PORTB,1 ; 1 cycle, 4.825
call DELAY ; 2 cyclesr5.30S
cafl ' DELAY ;2 cycLesr5.78S
rlf PORTB,1 '; 1.:'Cycie;,- 5:7gS
cal-I DEIAY ;, 2, cycles,6.263
caf l- DELAY ; 2 eycJ-esr 6.74S
rl-f PORTB, 1 ; 1 cycle , 6.7 4s
call DELAY ; 2 cyc}esr7.22S
caII DELAY ; 2 eycLesr7.70S1
rl-f PORTB,1 ; 1 cycle, 7.705 \
Now move onto Port A, and move the bit left.
rIf PORTA,1 ; 1 cyc1e, 1.705
call- DELAY ; 2 cycl-es, 8.19S
call DELAY ; 2 cycLes,8.675
rl-f PORTA,1 ; 1 cycl-e, 8.67S
call DELAY ; 2 cycLesr9.15S
caII DELAY ; 2 cyclesr9.635
rl-f PORTA, l ,' 1 cycle, 9.635
call DELAY ; 2 cyeLes'10.11-S
caff DELAY ;2 cyc:--esr10.595
rl- f PORTAT l ; 1 cycle, 10.595
call- DELAY ; 2 cyclesr 11.07S
call- DELAY ; 2 cyc).es'11.55S
Move the bit back on Port A

rrf PORTA, l ; 1 cyc]e, 11.55S


cal-l DELAY ; 2 cycles, 12.04S
cal-1 DELAY ; 2 cycl-es,12.52S
rrf PORTA, l ; 1 cycle, 12.525
ca1 f DF]LAY ; 2 cycles' 12.99S

ccc
jooG qgE -c9- oc:@cDoc:
"ft.li-
oa$:(1) Source Code eq:gp):-..1 etc Qc6o$q$-6* on:q1oo6co6:qp".g)

calf DELAY 2 cycles, 13 . 48S


rrf PORTA, 1 1 cyc1e, 13.48S
calf DET,AY 2 cycles, 13.96S
caff DELAY 2 cycles t14.443
rrf PORTA, l 1 cycJ-e, L4 - 445
; Now move the bit back on Port B

rrf PORTB,1 1 cycle, 14.445


calf DELAY 2 cycJ-es ,I4 .925
cafl DELAY 2 cycles/ 15.40S
rrf PORTB, l 1 cyc1e, 15.40S
calL DELAY 2 cycles,15.895
call DELAY 2 cycles,16.37S
rrf PORTB,1 1 cyc1e, 15.37S
call DELAY 2 cycles, 16.84S
caf f DEI,AY 2 cycles.17.335
rrf PORTB,1 1 cycle, 17.33S
cafl DELAY 2 cycJ-es,17.81S
calL DELAY 2 cycles tL8.295
rrf PORTB,1 1 cycle, 18 -295
cal-l DELAY 2 cycles,18.77S
caf l- DELAY 2 cycles ,L9.255
rrf PORTB,l- 1- cyc1e, 19 . 2 55
cal-l- DELAY 2 cyc1es,19.73S
cal-l DELAY 2 cycles,20.22S
rrf PORTB. l 1 cycIe, 20.225
cal-I DELAY 2 cycles,20.'l 0S
cal-l- DELAY 2 cyc1es,21.18S I

goto RUN 2 cvc1es,21.18S\ \


; Subroutine to give a delay between bj_t movements.
;Total of 957 cycles, 480mS
DELAY
movfw TIMB ,' 1 cycle
movwf COUNTl ,' 1 cycle
LOOPl
decfsz COUNTl 9F;x l cycl-e + 1- cycle = 150 cycles
goto LOOP1 9Ex2clcles= 316 cycles
movwf COUNTl 1 cycle
LOOP2
decfsz COUNTl 9Fx1cycle+ I cycle = 160 cycJ_es
goto LOOP2 9Ex2clcles: 316 cycles
return 2 cycles
END

sacoo3qSe"T$qdoq BKHz clock c{ san:QloatoEi:aqcr5 LED a$og:g8.o:6oq:


m@+ co8:e1$@{$.rd 1 second$:,11:@6S: LED sa::q: s?go:$G$
-S,q$@{$-|i zr
seconds The delay routinu.rd 48OmS
"$@c"@E:eq"eleoeg)rr @co'1op)rr eort Sc$. Oit
4rQ.8 delay crf f6@S CALL gSoa:cico2)rr

jooG 195 ccc


-33- oc:aa ana)a:
"$to1{*
-"$tl) Source Code eq:qp|:-j etc q$-fl oal:qpdcu6'qp,(q)
Qc'Safi
-
oc6cucS@: WDT c{ periodically reset o?6Qsan@E:c,f e<sT$oltlpirr WDT c{ set
'1-1 second.
6iSoEicaqp,ag'o{$o2j 2.3 seconds @6$:r qo3oroqp:"i.*{i-d |QE
e@o3: saoc8q8e.T$.-d eo:a:o38eq.Gffeol:odrr WDT crf clear qE{E-pg q3):cub:
([11c,Sfic,1erplt ocoeEpl:go delay 9E@6p:of8: subroutine -Eed cafl q6$: WDT c'?
clear q6ccd+d,GS$:r qo8orqp):go delay loop oq8:$ cLRWDT c{og$q3:oepa:a:@_:
WDr c,? dear og6$E:g2l: oi$S@doSrr neodoa8 qoSorqa::c,? *i'GG' wDT c,?
clear og 6 Q c{ ococ6 c.,1 ofi o epq8 co2iq8 ;eq.a:a:S: o6a eoTpoot.i o2il

TIME equ 9FH ,' Variable f or the delay loop '


PORTB equ 06H ; Port B address.
TRISB equ 86H ; Port. B Tristate address
PORTA equ 05H ; Port A address
TRISA equ 85H i Port A Tristate address '
STATUS equ 03H ; Page select register.
COUNTl equ OCH ; LooP register.
COUNT2 equ ODH ; Loop register.
OPT equ 81h ; Option Register Lo control the WDT

-*************set up the ports, WDT and prescaler*****-**********r'*i(


cl-rf 01h ;Clear TMR0
bsf STATUS'5 ;Switch to.'bank 1
clrwdt ; reset the WDT and prescaler
movlw b'1101' ; Select the new prescaler value and assign
movwf OPT ;it to WDT
movlw 00H Now set up the pgrts
movwf TRISB l
I

movl-w 00H I
movwf TRISA
bcf STATUS' 5 ome back to bank 0
movlw 00H
movwf PORTA

.*************c+aft
t 9w Of main pf Ogf am* * * * * * * * * J' * * * * * * J< J< * Jr *** * * * * * Jr

RUN

movl-w 01H
movwf PORTB
-'caIJ- DELAY
call- DELAY

. *************Move the bit on Port B J_eft, then pause-**************


rl-f PORTB, 1
ca1 I DELAY
cal-f DELAY
rIf PORTB,1
call DELAY
call- DELAY

n C e aC ot:cocr5o3:
-qG-
sra$'(3) Source Code eqgEi:-.1 ptC
Qc6a{q$-6* ocq:q1oc3co3'qp,(?)

rff PORTB,1
cal f DELAY
caff DELAY
rlf PORTB. l
cal I DELAY
call- DELAY
rIf PORTB,1
caf l- DELAY
caf l- DELAY
rIf PORTB, 1
ca.If DELAY
caf I DELAY
rff PORTB, l
cafl DELAY
cal-l- DEIAY
rff PORTB,1

' *************Now move onto port A, and move t.he bit 1eft. ****r(******
rlf PORTA, l
calf DELAY
caff DELAY
rlf PORTA, l
call DELAY
calf DELAY
rlf PORTA| 1
call- DELAY
cal-f DEIAY
11f PORTA| 1
cal-l- DELAY
calf DELAY
)
,.
******rk******* Move the bit back on Port A************************
rrf PORTA, l
ca l1 DELAY
calf DETAY
rrf PORTA, l
caf 1 DELAY
cal I DELAY
rrf PORTA,1
call DELAY
call DELAY
rrf PORTA/ 1

-**rkr(********r.)k:k*** NOW mOVe the bj-t back on port B**rr*********_k"*****


rrf PORTB/ 1
cal- 1 DELAY
cal-1 DELAY
rrf PORTB,1
call DELAY
I l
^- DELAY
rrf PORTB,1
cal I DELAY

lcoG e .15 ."$qol(ic.) -J?- oc;@aDoc;


saa$:(_;) Source Code oepqg:-.1 PIC { da{ic6$co$cua saal :qJodoo:qp;r?/

call DELAY
rrf PORTB,1
cafl DELAY
call DELAY
rrf PORTB, l
call- DELAY
cafl DELAY
rrf PORTB, l
call- DELAY
cal-1 DELAY
rrf PORTB,1
cal-l- DELAY
cafl DELAY

goto RUN
. ********subroutine to ive a delay between bit movements.**'(*'r*
DELAY

movlw TIME
movwf COUNTl

IOOPl
decfsz COUNTl
goto LOOP1
movwf COUNTl

LOOP2
decfsz COUNTl
goto LOOP2

a, t a r a f a t, r r, t t a, t t r r r n f t t a a, t t r r, t r r, t, r r r 1, t r, t
I
trf trrtrrrrrrrrrtl,rlrrrrrrrrrtrtrrrf tt I
/
i; This part resets the WDT
; i Cornrnent out or remove this command to see the WDT
ii in action.It should reset the PIC ....:
t i r a, t a r r a t, t t r t i i i i r i t t r, t r r r r, t, f t r a t l, r r r r r, t r r, t r al r,,, t, f ,, t t r ' t
" '
i i ; ; ; i i ; ; i ; i i i ; ; i ; i i i i r, ; i i i i t ii, i i i ii ; ; i
clrwdt ;This simply resets the WDT.

. ** * * ***t<**** * * *Return from our originaf DELAY routine**)k* ** ** *******

return ;

END i

CLRWDT command crf ooc6olo{oq59 ooSqo5oa:q;E (comment out or remove)


PIC arg) LED c{ o8:g8peo:6cDo.Gqlrr WDT
Qd- PIC reset q6egeare@43.$6 m c{
cop)rr CLRWDT command c{@$cogla38:oa:c$c39ocqg8 ofioe16o2i Qg$ooflE: run eglc{
@Eeq.qeoel2lrr

cec
-0o- oc:@cDoc:
looG q96 "$+"lf,-
o"$'(q) Projects with PlC16F628 etC Qdafi cB$-{* :ai:q<-,o5co3,qp:(e)

oo$:(q)
Projects with PlCl 6F628
q-cn {e'l$:

glsaa$:q8 Microchip Co. 9ogo8o,76cc'r:ea:o PlC16F628 QcSofio3$-ficooc,isacA:S1


o,r:ccg) SoEoSoc:goSep san:q1<-roEco6:sa{6c,f eoT$oo:o1ccg)l {<.to5co6tqp:tr\
"ae@o3:
3eep sr6n:86 oqlcfococ6qp:c{sa8o.n+cB website: http://www.josepino.com
"aE@dSrL$3
,-,1og)l
c,o5oc6:oqp:goqcr5 source code (asm file) qp:oteoTSecoo:cd hex file qp:{u
e"TScoo:<.,')co2)rr { hex file qprd Sl-g6g3.oo7o1..roard co ecrTfi Chapter 3-HEX Files
folder odoe8e,iT0coo,c.,lcc$rr QoEo{q$-{cm{38o"a8t{. ofioq633:odonl oo5co6:
or318saqcr5 cccB{Eeoa hex file qprd yr"i@rerrn8 o:E: hex file of EPIC Programmer
software {.""fo8 aaS:earo programmer software oEqqefioq-d@E. Plc16F628
o c O c O e O e C C fe e C C C. O C Cf- eOC'l c
? cDo fl c8lcoQ cuoqJc os o qccoeg 38 c :E:
oo"cDes3Do?oo? o? o? oc:3) olg?gt c o a)e il I

q-.1r Four Digit Gounter with 7-Segment LED Display

Common Cathode sa{1:ooo: 7-Slgment LED Displav (p)t gt. etctoroze QcAafi
digital Counter c,oEco6:orEEcri e,rT$<-tlel pjrr Q(q-t)oSt
"a$-fi-"?.",tsaa2:Qloorea:o
ecryr3cr-rcc.,o5cu6:sao3cf Plc16F628 e"'\ pin qp:e''\ q3c$:oiqp:crie.rT$cootSr Q(e-l)"ae
co u n te r co 3) a-o cE Q,: c5 co 3 t cri ocrT@ cc'::'jl ., p)
"

JP62B1 - FOUR DIGITS COUNTER


f,LEAFiCOUHT 1'= orSPLAY 1

SA',/E CDUtIT 1D's


C CATHOEE,C A]'IIIDE 1r-r0's

lt{FUT SlGllfl- 1000's


l.'L-ca I\&k-
GH0
R OP
B G

c F

tl E
\,r/1;j'#..tL-tgEFltJill.coi..,l

Q(t -r) nc,:o3o-rloCcu6:=r.go6 Flcl 6F628 cfi pin qp:e,\ og6c$:oiqp:",sT@q


.
sea$:(q) Projecis with PlC16F028 -raI
i- \, tO cDa
C o C o C \'
cB+ co ra--l F3i :.ijo or cDo
{.1
\)
:
/
qP: \ ? I
\

- pin (c){ GF.iD;3"eodqy8 clear $6q:rS,' t/SS+3"acc8crrt8 countca3oq'opSl


- pin (L)d GNDg3.a:cAqg13 power oo:3g8.oeSceal :qP:,co,g:3 countoTSS:r VSSeS.acc8
qfl3 eod.?: countalepgoc'5cocf countqEog)'r
- pin (q)4 common cathode display "r%d cND gS.aocAqoSqp:, common anode display
sa%d vss gS.oo5qoSelcglrr
- pin (9)o3! oo8caqc8S o3eeprA"p3iegg@3o$rr
- pin (C)d aoSoc$3: cND 93. oc6q<.$o,ca)rr
- pin (G)(q)(oXeXooX"t)("3Xtq) {.c,i z-segment display '\ o:o5{3ep sesnent qP'f3.
ocr5qoSqeg)n
- pin (c9){ oSoc$E: VSS 93. aocr5q<.'Sqcg)r
- pin (ca)(cc)(caXr.)"?.{ eoo8reprao,:Sr1 c8$:qp:erT$oei 7-sesment display e'\
common anode/cathode g o5qp:g8pocr5e1elp)rr

Q6rar:@3. Common Cathode ca{1:saoo: 7-Segment LED DisplaY ep:cfsacgt@1oot


ea:a t,o5co8:o:6go-.g)na":cAgc'ieoT$<iergjr {c,dco8;q3 c,'lcilS3"c.?nEql3 0000 qSoo:3
n{[9 r a o7o8 c,i or8 qj d $6"? dolS : cou nt or3 1 of :cvre@S'.{."TQ e,rer g) rr o q i eg qrq 3
".TG
LDR, reed switch ood{.G3. ooo:{:cacat$1$E.io3lrr sa$ecp5 leo Display =r%.6 3v
o6oc$E:c'isa3i:G6S$: sa86:eep8 LED Display oq.'5 5v ao6oc$E:ofloa?:$68ar2lrr

. T+3v JP6281 . FOUR D]GITS


COUNTER
I
?

4
5
PINO.COM
B

7 Seg Common Cathode/Catodo comun

Q(e-L) Common cathode display counter oc3co8:cn2)eucr5Q

{c,o5co3:ocacf hex file 9o CD g Chapter 3-HEX Files folder fi leOZet.nex


@6,io$rr

Go
Proje' ls with PlC16F62B et C Qo5a{ ca$cofi c"r :;:9'q1,-,o6co3:gp:(?)
"rn$,(q)

?-?il Digital LED Clock

- mooSSo"ro(1)o.7:r flrg-(e).?;r 7-segment LED Display (g)t ae13oo:<.l5o61


Nomally open push button uofo3(:)t 93. PlC16F84 or PlC16F628 Qc'5ofioe$coficoo:51
oi.r':<-,1 o 3 ea:a D g ital LE D C lock c, o3.o3 : o16 1 or2)eoo.6Q.r? eoTp u1 3i,'
i

"
{.-'o5o6:oqc'5 QcAofic6$cofic,:cqp:e\ pin q6c$:riqp:c{ agarc8,.r'lQ(e-q)"A8
n.rTQcoot<i oglrr

JP6282 T JP841 . trIGITAL LED CLOCK PIN INFORMATION


1's Hours 10's Mins l's Hours
l0's Hours 1's Mins l0's Hours
C CATH/C AHODE C CATH/C ANODE
Hst connected !lii[ + noo r,'L=
ReEet/Etable !lii[ + noo r..rr.,'

GND vss36-d.5\,bhs GNB VSS3.6-55\{:hs


A OP DP
B G B G
c F c F
u E o E

Wv\\'V,IOSEPINO.COM

Q(t - e) Q
c'So{ q$ofi cucqp' e,\ pin q6c$:oiqp,n"T0Q

- pin (c)c{ 8E6 aooSooa$: display g3.aoc'SqoSqed'l


- pin (l)d EgE locn$: display g3.aoc'5q<.:Sqcplrr
- pin (t)d common cathode display @%d GND g8.oc63,r5q$,r common anode display
Q C C C
s>%@ rraavbb Tc.om?g(})q()a:il C

- pin (9)ogi Plc16Fo28-%d accr5qcSgcfidr etctoFB4saqc6 't0Kohm flogo-ror6E


5
$: ecSoc$E : sae<-,1 3 :oi t : 13" c:cBcr,-,S 1r1,r3) rr

- pin (f)d ao6oc$3: ci'iD 93. acc5cgoSqaE)rr


- pin (G)(qxoxgxco)(c")('1Xcq) "?..,? 7-sesment display er\ oc,5{36p sesment qp:g8.
aocr5qcSqog)rr
- pin (c9){ a"6oc$3: VSS (+3.6v to +5.5V)gi aoc'So8csqc$rr
- pin (ca)ge.(cG)4.c,? oscillator <ro5or6:sacac'5 oqgo:<-Sg8. m<.,<-SB "-ti.r| aoo5qr:SqeEirr
- pin (.9){ qo{ o<rSocur$; display gS.aocr5qc.Seltlglrr
- pin (co)of Vri tn*$: display g3.aoc,Eq,-Sqerp)rr
Plc16F628 c,focq:S1co::eocooEcuS:crt Q(E-g)"a8".T$coo:o'l::3)rr {oo8co8:Qq8
ao.-Socor$: 7-Segment LED Display q1r,4 eeocr5{:oSao8coc:e@c3: eroBQ1eoc'fl,r1arE)rr
s:mc'S$ 7-Segment LED Display @:oc:{1:c{ oqt$toQq;1l t+ncs+t or 4050 d.cQ.e::c
buffer 43 3q1::5 $ o:Eso8 qe.,o g) r { oo8co6:,{1,.,f Q(E -C)"a3"cTScoo: ci og) r

cE,qoE * r:{ q og3 u;n3":3 E ii cil :: 3) rr 74H Csa 1 c{ cocl'$p7 3 c-':3 ::+qoS
9
""9c, Q3 "o3
aoSoc$3:Q.eacfl 1 2V eo:6-ioqo'l rr
=rn$,(g) Projects
rvith FlCi6F62B rtc Q
c8afi og$-$- oal :a1odco6tqp,(i)

+ 3.8 " 5.5 Volts


JP6282 i JF841 . DIGITAL LED CLOCK

{(o
TL --{h
-rrl I
(D
JOSEP COi\4
(o
(\t
(D
IL
(D

* 1Uk Only i 6F94 / Solrr para 1 tsF84 7 Segment, Common Anodei Anodo comun

Q(e-l) Digital LED clock oo5or3:0

+ 7.5 - 12 VoEs
DIGITAL LED CLOCK
J ,onaso1 can be reptaced with
aruv cMos NonJnver-ting
ft
74HC5411 buffer

+ 7.5 - 12 Votts

Jose Pino.- Rev 1 .0- 11n7n4


Use only 22pf or 33pf Capacitors 7 Segment, ComrFn Anode/ Anodo comun

Q(e-C) Digital LED Clock with Jumbo LED Displays <.ro8oc6:Q

{oo5co3:ocaoEooi:Q16feai hex file qpr{ Qc'5afi%$coficm{ESocQcf eracSo38


i@c:eoTpoo'rlogJrr
Plc16F84 QoEofiql$@fiom:flE8saqcB hex file 9o CD 9 Chapter 3-HEX Files folder $
JP841-4.hex @5o1og)rr
PlC16F628 qdofi%$@{clr{38oqn5 hex file 9o CD 9 Chapter 3-HEX Files folder fi
JP6282-4.hex @3 <i o g) rr

G1
,ru$,(q) Projects with PIC16F628 etC QcDo{cai-{- snntq,,,o8co6tqp,(t)

q-9rr Digital Tachometer (or) RPM meter

PlC16F628 e{cacg:Q1oc:eoc co3)ooEgof3:cnoarg)ooEcoSr (Tachometer) -Btd


noT[oa:,.icc2)rr cog),-,o5gc,|ooqSog)ogg):o@6 optical sensor qpt@E@c:el photo
transistor, photo resistor oi.c{coE):ec,:o3:r Magnetic sensor qp:@S@a:e) Hall effect, Reed
switch {.c'fcogl:ec,:a8t on:Q$Eoioglrr gl<-,o5co3:@8. cog)c,o5gsaqp:a?: oi3:on$Eo2)
oc)6)f) 30,000 rpm @E<iog)rr eraoc'Sc-rlQ(e-G)"aE Plc16F62B er\ pin qp:caqc6 q6c$:oi
qprd noT$coo:ci a:gl rr

JP6283 . DIGITAL TACHOMETER RPM


'

WVWV.JOSEPINO.COM

q(e-e ) etctorozser\ pin qp:oqcf q6c$:opqp'nrT0Q

ootrS<r:1Qoq oin (q)o$ display type icommon anode / common cathode) c,fodgo5
eo:S: pi(E)-d saoEoqlc'S@o2)aeE:qioqc6$6<icoglr pin %Eog)?88:eo:qcrg)
"A
oo8oqcfS$.o:ocp! 5v ocfecqpqX8 cMos, TTL, op Amp or transistor oi@*SS:g
o$qE:ec.':q<.le2lrr

Oscillator crystal sa%.8 10MHz crystal c{on:Q1oa:S:r mo,rSEonepzsr,agc8 ZZpf


or 33pF cog)<-,o5g$:c,ioo5cc2$caa'1 7-segment displays oe8 cdl$coo:
"?."? -ri,0L€3cir:gjrr
o 3) o cnoc c'f oB ocr5 g8p@c6$:o o5g -$ Q tog$ c'f opoe gl r

Digital Tachometer <.,o5co6:caqcr5 hex file 9c CD 9 Chapter 3-HEX Files folder qEfi
6f,, JP6283-1.hex @6c.'1
ogjrr

o o5 o 6 : o: gj e o cB q c,i er,c cr5,.il


Q
( q -f ) qa 3 n.TG oa :.,,1 co
$ r,

G1
ea$:(q) Prcjects with PlCl€F628 nlC Qciafi ca$-{ * s?e,ai,ro8co3,op,(q)

JP62g3 . DIGITAL TACHOMETtrR T RPM

2
c

4
5
B

I Segment, Common Anode/ Anodo cornun

Q(f - q) Dig ital Tacfi ometer Digital Tachometer <.ro8cu6 :ogleocr5Q

q-gn LED Matrix Display

PlC16F628 4o"?t$t-o:eoa LED Matrix Display oo8cu6:o6t4 n"T$-:o1oog)l


LED Matrix Display arr4/ 4 5X2a @Eeoq$ SX8(common Anode) eol8:o6$
"i+E(e)td
o:Eieoc6oo:o1o$rr errrEcoqp:crf co8:eoe1$caqcr5 shifi register qp:crf oaT:Q1oo:,-il cc2)rr
T4HCXXX TTL c$.eo7o5 74FXXX TTL o{1:ooo:qp:c{ o1:Q1o8.o$rr -/+|-SXXX TTL
o{1:ooa:od o:l 01 si€qd +d'-d@%d en:cc8pou

ooSc'c6:o$eorfiqc{ erao8<tq(q-o)q8e"TScoe:,r1cc$rr {Q"aE shift register gE.


ocr5a<-r5Q saecc:E6oq;cr5ooccfqp:c{eoT$oe:c.iloog)rr SX8(common Anode) LED
"Q.*GE
anay qE6 oqS r
Q
E :o16* d Q 4-d: e,rT$coo: <-,1 cc$ rr

LED Matrix Display .-,o8cu6:oogc8 hex file 9o CD 9 Chapter 3-HEX Files folder fi leOZa+.nex
$3o1o2)rr

G9
ou$,(q) ProjectswithPlc'16F628 elc Qo5a{ca$-fi* on:q1oo6o6,cp:(r)

JP6284 - LED MATRIX DISPLAY (5r€4)

lsvon WWWJOSEPINO.COM
2fi
3Gt6
4 (\t ls
sfrr+
6(O13
rrt2
Ifi
I t0

SxE Morbh Display(3 Fcs) Lrp2s5scA

Shift Register Connection Detail

+ 5 Uolb
Fkt
SHIFT REGISTER GND
=

D0 Dt D2 D3 D4 0f U6 07 E5

Led Array tretail

Q(e-") LED Matrix Display oo5co6:coEleoo.:5Q

Gg
*.$t{e) Projecis r,viih FiC16F628 rlc 8dafi ca$o"{..:r ean ;qooScuSrqpr(q)

q-Gr LCD CaBendar/Glock

Plc16F62B qE r-'fioq6oo$o83;ma:$: LCD Display eoTca3 G"A8$+e. f"q"?."{"-TE


oo:*g)c,s5o:6 :coEloi e"TS o1 ca) u
o o5co 6 : cn g! e.o:crS Q
c{ .-rr.6 Q
(
1-e ) nrTG coc: t'1 o: pl rr

"'l "a3

ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
t23456780101t121314

+5! sfts

I - 1€

t 1?

j lrl

+ ffitr
.{
- (D 14
-_l- lr-
6 to13
z -1?
I l',l
I ll

__r_
JP6285 - LCt l Clock with Calendar
Re ( 'J LCD con calendario
=GND
Q(q - g) LCD Calendar/Clock oo5cu6:o2Jeo:cf Q

coe
orc:a?.qlc -
HH = Hours
MM = Minutes
SS = Seconds
x=AM/PM
mmm = Month (Jan, Feb, Mar)
dd = Day.
of$6@r,E)',
glo6:o8qln8oa8 1ox1 LcD Display c{saca:Q1coc:@E:@3. Qc6ofioA$o{*+3"
oc6qoSog)sao1 4-bits interface c{a:a -.?r$lqi"Qo6eoog)rr 16x1 LCD Display
"fl.-03
cogi character sadl:ooc:qp:gcc,pcogl: e<rTogo8e<.x{3o3)rr LCD Display saoo: 7-segment
display {-dr e$:E:oisan:QfiEooccgirr P|C16F62B erl l/O pin qpr@E@earo A2, A3, ,A4

gE. ns
"?.4 -.?tq.@a:6qll

GG
o$r(e) Projects with PlC16F62B

ex fite o:S occiSg3.aaopcicr>oog) CD d


Chapter 3-HEX Fites fotder fi jOOZAS.n"x@Bciogir, -
<_,o3cu6:ogjeaocc,b@: {,f q:cor:ccd"l"EQ",fl esDc;ol
t(q_.o)q8 ecA@3$daooplrr

Q
(
e-
"o) <.rc8co6:org) eaoocr5$:
{ c6 q : oo: od.l C i

q- gll FreqL"tency Counter


.aSorrgcf website

Go
:aaQ:(q) Projects vrith PlC16F628 etC Qcfi afi o3$*Q* ocq:qodco3,qp,(q)

? - ? -c u o@<lo€*3s@€asoo5ol6:

R\2 \-/ RA1

RA3 RAO

RA4/RTCC OSCz
".GF-l A4CLR OSC1
toont
I'no" RBO/INT R

RB1 R

I:I
tt
il5
@e

Display: 7-segment, Common Cathode.


1=9, 24, 3+8=cathode, zf=e, $=(, $=ip,
7=c, 9=b, 10-a
(
e-
ocoesa{1:ooo: frequency counterc>o8co6: ctt o: cn6 @:q8o$eaocioo:
Q
"t) Q

ococfci Q(e-.")qa8 ocoeo{n:ooa: frequency counter c,o8cu6:c{ oo:.nE@:


'
eoTca8 oEleoc'S-orQq e,rT$oa:.r1-du -Segment LED Display (Common Cathode)
(l)q nfl on:$1coo:ogirr
- '-ro5or6i-glnoo.r5$:eqccA
{ crSq: co::o d"l "EQ.,! eoc6d Q( q - c1)o38@$ "1 "

Q
(
e -
"
L ) ococsa{1:ooo:,.,o8co6 to gleaooc6f9t nqrnE { c6q:oo: od"l dQ

Go
glr$,(q) Projects with PIC'16F628 etC Qc,Sa{c6$-{* oe2:q1oc6o3:Cpr(l)
o c c o e ere s I s I q o oee c o e c e ^^
qoo)cD()!c?o)e96e)cDl9:cfDcD ?cDo$%f@QcDoQcoq3c o$o6[6?gc:qi uu g
Chapter 3-HEX Files folder fi counterl.hex cfocg:Qlqeoc2il

? - ? - J n 1 o9.lo{poo: oolc,>6:

qo3osadl:ooo:,ro5co6:9o q$oficmoo5cu6:Q8:g8. LED Display Qer{..,? o:.n8


So:oEq16o2i:eoTq8 o:6oE@E:e@p LED Display
qE:c'? es13c$c'5"aegooo:@3. cS'@c:
ogleeocrSoo:o2!rr q o3cuodl:ooo:r.,o5oc6:odeordQ c't e"^rrcrSci Q(q- c q)q8 eoTQcoa:
cr?9ll

na v c
(, (DtD
t\)r
TD
o
z
6# tI N)

--l !c)
( O)
-rl
nn v
T
TD
5 (,tur(D o)
7
ul
\l sRBt I N)
@

ddp c e f g

f
to cathodes digit 1...4

Component values for type-2 (as shown above): Rl ...R8 = 1k, R9=R10=10i<,
D1..D4=1N4148, Q1=8C547 or similar, C1=C2 about 22pF (select them to tune the crystal to
exactly 20 MHz), C3=100nF, X1=20 MHz, PIC: 16F628
.t c
(?(? - c?/\ Q
o o c c
o)or3zqll:32oo:os)cDc;cDelceoocD?
e.

{<ro5co6:.{orpleocc'5S'nyrd Qc8a{o3$cofiNo433%3 ofioq6.gE'q$ CD 9


Chapter 5-HEX Files folder fi counter2.hex cf sacg:Q1e1eoc2il

odco6:og)oaocf$:egacf {cr5q:-,r,.:d.i"EQ.? e=-rrnSc-,lQ(q-c9)g8. Q(e-"g)"?.


q3@g)o1rr

Gg
:3og)@:3o -oL- co!;os$o g$& gool

0 go 1,up.. r.oorb g$ 5:3$pc,$e :fl gcee$(,o :ecopo :coee:lpeemgo b


r
1Gc - d
I
6

b3o ;"p.. r.-rdup $ t5:


3|'6e :fl g.:cce$c.o;ocD.oo
r :coee:llbeecoco t (5 c - d ) b
on$r(E) 5x7 DisPlaY Circuits-2 e I C QoEo$ca$-{* ooq:q1ooEor3'qp,(t)

*l'(E)
5 x7 Display Circuit-2
9-crr {e1f:

website: http//www. talkingelectronics.com,au ca8 eoTSoo:eoo 5 x 7


"aSoroqcr5
Display Circuit o6:cc6q1cfc,o5co6:qp:cri oo6q:1?cToo:3.earo PIC €da{%$@{cr>o
ean:q1oo5o:6:qp: sa<i8:(1)oosp6ca8 oE{go6ocBGoTE}€:GEe,-'o2!r gfioo$:caE 4
website g o6:cc6q1cfoo5cu6:qp:cri eocAcucA$ eoT$oo:<-,lccplr
"11$6"fna):6f,)o
eorcr5qte"T@"d o6:oc6qcr5co6gq18:8ocacr5 e.rTQcoo:G3)o source file qp:crt Hex
fite .i. MPASMWIN er\ oqopi@E.eQc8:oJ@:eqrd EptcwlN ci.ai.ea:o programming
software o6Eqe'l oqo2j@8. Plc16FB4A qdafi%$.ofic.':ca8 o{oq6ogicg8:S: o6:er6
r- coq I q I c e o e o e or-r-ere e oo . o e
[!?P?tcora)e9il ogoqo6$Oosqlmqp:c?cDe: o?3rof,)o?lglgelg:cfzcD 66of,?:qjo?a)?9 32cf
sao:: d1: eepcr5erao8 o$ o3:$ t @eo cc2! rr

vdd
RB6

RB5

RB4
16F84
RA4 RB3
C,'la
I \ts,,,r
l-iL1I
a' fi'l . -- =i*\,
r LEIJ.J | 'r
RB1
RA1

RAO RBO

Jumper
needed
Vdd reset clock if no
4017 t.,^^
vis
eE transistor
fitted

Circuit fer Eryenlsnenfs 1-6

Q(E-") *Q3(p-L) g (E-") s?C o3,rJ3qoEry:saca"E =a:1'@1.eppioo5cuS:Q

.1ooG gg8 4q.1{- -?c- oE:ooJot;


P C q .:o -:; qi.:c8.--8: q,:: ( g)
"i" *$
i :
19
"o fi

g G TDispiay <.oo5co3:co8t"trd

-dn ,d Q( o3':-'3{3,-'1:reirr
E ..,m u:E:co"1$tgo-rrt\ sm5coetScno
93. Scn 6 qroa E Jum p er o'l en @1: o:6 "qp8
: o ct5 a3 c$ ao toot e1,.,1 o
E)
r I

".ro4..+

9-jn TURN ON A LED


C e e e O a " Q :-- e e
QoEafioB$o{coo 3)o?oc?oq+3.;q3or oElo6loGTf,r:$ 3aqSore?:fc.
3e?o?:63)r
r6;a:6q1cr5o6qcrf oo8eoT[o1"pirr LED display efi c,ooecn8c,5g ee-rrcfaprnfpfi LED 4

; Turns ON bottom left-hand LED


list p:pic15f84
include p16f84. inc
confiq h'3ff3'
errorlevel -3C2 ;ilininai: l;-.rj: riarning
Start ORG 0xO0
BSF 03,5 ;Go to pagel to set up the ports
MOVLW 00h ;Put 00 into W
MOWF 05h ;Make all RA lines outPut
MOVWF 06h ;Make all RB lines output
BCF 03,5 ;Go to PageO for programming
MOVLW 02h ;Put 02 into W to
MOVWF 05h ;Reset the 4017
LED ON MOVLW O1h
MOVWF 05h ;Turn on first LtrD
GOTO LED ON ;Loop the routine
END

g-?n FLASH A LED

LED display er\ <.,oelecz5o3g neodn?:G+ep6 LED c{ oflog88 2Hz @8. $"E"t"E
$"S"t"E Sp8eoeEi o6:o6q1c6$6cio2jr DELAY RoUTINE o"i'GLQd oo8arT$coE!
o 6:o 6qc3$6 o1 ccgi rr eracfo38 sou rce code qp:otooT@oo:o1 o2) rr

;Botton l-eft-hand LED ffashes aL 2Hz


list p:pic16f84
include p16f84. inc
_config h'3ff3'
errorleve]- -302 ;Eliminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for setting-up the ports
MOVLW 00h ;Put 00 into VJ

MOVWF 05h ;Make aI1 RA lines output


MOVWF 06h ;Make all RB lines outPut

c C 'le cqa
toot!^ aso G550locu oc:@cDoc3
,=
5x7 DisPla'r Circuits-2 etC Qc6o$oe$-{- ocg:qooEcoS,Wt(e)
-n$,(9)
BCF 03,5 Go to PageO for programming
MOVLW O2h Put 02 into W
MOVI^IF 05h to reset the 4017
Flash MOVLW 01 Put 1 lnto W
MOVWF O6h and output to turn on LED
CALL Delay Cal1 delay
MOVLW OO Put 0O into W
MOVWF O6h To turn off LED
CALL Delay Call delay
GOTO F1ash Repeat cycle
: Delay MovLW 03 Delay routine start
: MOVWF 1Ah
, De1aY1 DECFSZ 1Bh,1
: 3:::.;"i3il1,
GOTO De1ayl
DECFSZ 1Ah,1
GOTO Delayl
RETURN

END

r g-gr SCAN UP

o\
ooeecn8cug LED qp:cri oq%EB zHz @E ca6q:q1t:co3:ryr:eoeg)
LED display
o3:r:6q1c6@6o1o2irr RLF instruction LED qp:c{ o6q:q1t:cut:eo@3: G6r1
"?*"it@f@:
o$rr esrnc6o38 source code qp:crieoTScoo:ol co2) rr

;First cofumn of LEDs scan from bottom to top aL 2Hz.


Iist p:picI6fB4
' : ..-.:rJ- n l. rf Qt . i:
'_'-----*- l.-- -_

coniig h'3ff3'
'ln,,ar 1,1) .r'll- L-.Llr--G i,..,^ :,-,,- -,-,^r^^
, L - Jat_:- i.C, .i Lljq

Start ORG Ox00


BSF 03,5 ,'Go to pagel for setting-up the ports
MOVLW 00h ,'Put O0 lnto W
MOVVJF 05h ;Make aff RA lines output
MOVWF 05h ;Make alf RB Iines output
BCF 03,5 ;Go to PaqeO for programinin-o
MCVLbI 02h ;PuL 02 into W to
l.iOVhlF 05h ; Reset the 4017

Scan BCtr 03h,0 ; clear the carry flag


MOVLI,,'] O1h
MOVr,iF 0 5h
Scanl CALL Delay
F.LF 0 5h, i
GCTO Scanl

c(f,
looG 196 e$qol{or -??- oc:@0foc:
::a$r(9) 5x7 Disptay Circuiis-Z FIC $*ia$q,i*:f.c.;" :arg::1uC:;'l:y,(q)

Delav I.IOVLI"I C3
NIOVIiIF 1Ah
Delayl DECFSZ 1Blt,1
GOTO Delayl
DECFSZ 1Ch,1
GOTO Delayl
DECFSZ 1Ah,1
GOTO Delavl
RETUR}J

END

g-gn scAN UP & DOWN

LED display Efi o@cocD8org LED qp'{ o{qEB


cDooi:qlc: 2Hz Ge
CoC

snmc6g8.esaocr5 gaocSoao8:q8$: co3:eooP$ oStr:6q1cr5@6c,lop5ir err:c3o33 source code


qp: e,f n*T$oc: <-il op! rr

;LEDs scan up and down aL 2Hz.


Iist p:picl6f84
include p15f84.inc
config h' 3ff3'
errorlevel -302 ;Eliminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for settinq-up the"ports
MOVIW OOh ;Put 00 into W
MOWF O5h ;Make all RA l-ines outpuL
MOVWF 06h ;Make all RB lines outPut
BCF 03,5 ;Go to PageO for programming
MOVLW O2h ,'Put 02 into W to
MOVWF O5h ,'Reset the 4017
UpDown BCF 03h,0 ; clear the carry flag
MOVLW O1h ; Turn on the bottom LED
MOVWF O6h ; and output a HIGH
CALL Delay
UpDownl RLF 06h,1- ; Shift the HIGH up the column
CALL Delay
BTFSS 06h,6 ;Has it reached the top?
GOTO UPDownl ; NO.
UpDown2 RRF 06h,1 ;YES. Shift the HIGH down
CALL Delay
BTFSS 06h,0 ;Has it reached the bottom?
GOTO UpDown2 ; No.
GOTO UpDownl ;YES. Repeat the cycle
Delay MOVLW 03
MOVWF 1Ah
Delayl DECFSZ lBh,1
GOTO De1aY1
DECFSZ 1Ch,1
GOTO De1aY1

looG qg6 "h"1{- -2g- oE:coc'5o8:


saa$:(9) 5x7 Display Circuits-2 etC QcEe{ ce$-{- on:q1ooEco6,W:(t)

DECFSZ 1Ah,1
GOTO Delay1
RETURN

END

9-Gn SWrTCH WITHOUT DEBOUNCE

$6oqo8 n cl| oEqd$6";;8 LED disptay e'l ooeecrr5cugeocrSag: LED c,f o:E:eo
E,' eqoc6oEqlc6$6c$c6qilE oc8: LED c'| $oSeoe$ o6::o6q1c6@6<io2ln glo6:er6q1c6
q3 switch debounce oEoof,c{oE)eoa:cc@8. oeo8cr?$68: LED .,fl g,oosSc. oc c

@1q6oog)oo1 ecoqp9e;${Eeqn eocf caS source code qp:c{e<rT$oo:<i a:2)l

;Togg11ng a LED (no de-bounce)


list p:pic16f84
incl-ude p16f 84. inc
config h'3ff3'
errorlevel -302 ;Eliminate Bank warnj-ng
- Start ORG 0x00
BSF 03,5 ;Go to pagel for setting-up the ports
MOVLW 04h ;Load W with 04
MOVWF 05h ,'Make RA2input for button A
MOVLW 00h ;Put 00 into W
MOVWF 06h ;Make aff RB fines output
BCF 03,5 ;Go to Page0 for programming
MOVLW OO
MOWF 06 ;Zero the output port
MOVLW 02h ;Put 02 into W to
MOVWF 05h ;Reset the 4017
.:ri,'i.:cri BTFSS O5/ 2 ; Is sr,vi i-clr ;1 pressed?
GOTC Swl-oopl ; YtrS. Go t-o Swl-oopl
CALL Delay
Swloop2 BTFSC 05,2 ;Is switch A pressed?
GOTO Swloop2 rNO. Go to Swloop2
MOVLW 01 ;YES.
XORillF 06/1 ;ToggJ-e the LED
CALL Delay
GOTO Swl,oopl

Delay DECFSZ 18h,1


GOTO DeJ-ay
DECFSZ 1Ch,1
GOTO Delay
.
RETURN

END

u JooG 196 -oct- oS:cocfio3,


t
"$+"1i*
*"$-(g) 5x7 Displa-v Circuits-Z Pl C q o8ofi %E*.,i c,tr sarq:qoo5or6'qpr{e)

9-c1n sWrT€Fi WrTli DEBOUNCE


gJo6:r:3q1cfica3 switch de-bounce delay seosaoec?cogmoto)t p)r {e@c3. r.?o8
A c{ fl68: LED c{ eaEdogSfiog6og)saa1 eoqpq$e<-'ccElrr eeodoa8 source code qp:
c'|e<iilSor:<iccgir

;ToggIing a LtrD (vrith de-bounce)


Iier n-ni c.L 5f 8-1
inclucie p16fB4.inc
_config h'3ff3'
errorlevel -302 ,'Efiminate Bank warning
Start ORG 0x00
BSF 03,5 ;co t_o pagel for setti_ng_up the ports
MOVLW 04h ;Load W wi-th 04
MOVWF 05h ,'Make RA2 input for button A
NIOVLW 00h ,'Put 0O into Lr7

llO\rr,JF 0 6h ; Make aii ,EB lines outpll l:


BCF 03, 5 ; Go -.o PaEeO f cr prtgr:ainr - i -

MOVLW 02h ;Put- 02 into !V to


MOW,VF 05h ;Reset the 4017
MOVLW OO
MOWF 06h ;Zero the output port
GOTO Main

Switch BTFSS 05,2 ;Is switch A pushed?


GOTO Switch2 ;YES.
MOVF 1Dh,0 ;NO. Copy 1Dh into W
XORLW 00 ;XOR W with 0O
BTFSS 03,2 ; Is fife 1Dh:0?
GOTO Switchl ;NO.
RETURN ,. YES .
Sruitchl DECF 1Dh,1- ; Decrement the debounce fil-e
RETURN
Switch2 MOVF 1Dh,0 ;1Dh is the debounce file
XORLW OO ;
BTFSS 03,2 ,'Is f if e 1Dh:O?
RETURN ;NO.
MOVLW 01 ,'YES. T,ED is on lineO of port6
XORWF 06,1 ;Toggle the LED
MOVLW 80h ;Load tV with 80h loops
MOWF 1Dh ;Put 80h i-nto debounce fil-e
RETURN

l4ain NOP
CALL Swltch
NOP
NOP
GOTO Main

END

.1ooG 196 -2G- o3:cocr5ot:


"$q.1{-
saa$:(9) 5x7 Display Circuits-2
1lc q.'5.6 %$-{- on:q1<.ro8o:3,qp'(e)

9-on REACTION 64,l E

glo6:er6q1d-d game moo:qg),or6{rG6o1udn ecrrSco(c)ca3 ococr5/egarc6


n@,@: Qg$co8:ego2i leo qp,ofd ocooSor2)org) LED cr| uo?o8 A c'i $6@3:a::@8.
Spogqeld moo:qEi'@E<iog)l 4 LED eqepo33 ago8c'i$SSeF co3:og$o{$or6oc6
6c.?p.ce1qlD:eoo36.epl u emcr5q3 so u rce code qp: c{eoTQcoo: ccpl l <r'1

;REACTION GAME
list p:plct6f84
lnclude p16f84. -Lnc
conf ig h'3f f 3'
errorlevel --302 ;Efiminate Bank warning
Start ORG 0x00
BSF 03,5 ,'Go to pagel for setting-up the ports
MOVLW 04h ;Load W wrth C4
MOWF 05h ;Make RA2 input
MOVLW 00h ; Put OO into W
MOVWF 06h ;Make all RB l-ines output
BCF 03,5 ;Go to PageO for programming
MOVLW 02h ;PuL 02 into W to
MOVWF 05h ;Reset the 4017
BCF 03h/ 0 ; clear the carry flag

Game MOVLV{ 01h ,'Turn on the bot.tom .LED


MOVWF 06h ;and output a HIGH to LED
CALL Delay
CALL Del-ay ;
Gamel CF 1E/ 5 ; Reset the flag bit for button A
Game2 RLF 06h,7 ; Shift the HIGH up the column
CALL Delay
CALL Target
CALL Delay
BTFSS 06h, 5 ; lias .i
t ;:eacLreo the top?
Gaine2
GOTO ; I'lO "
Garne3 BCF 1E,5 ;Reset the fJ-ag bit for button A
RRF 06h/1 ;Shift the HIGH down
CALT, Delay
CALL Target
CALL Delay
BTFSS 06h,0 ,'Has it reached the bottom?
GOTO Game3 ;NO.
GOTO Gamel ; YES. Repeat the cycle
Target. MOVLW 80h
MOVWtr 1Ch
Targetl DECFSZ 18,1
GOTO Targei-1
BTFSS 05h,3 ;fs target LED l-lt?
GOTO Targei2 ; l.trO .
BTFSC 051i, i ; iq Lrut''*oi-r ;'i r.-'r-'esseci?
GOTO Tarqcl3 ; YES .

o JooG qg6 *$+.ilef- -g?- o3,ccdo8: A


roa$:(9) 5;<7 Dispiay Gircuits-2 rtc 8cr5a{..;.qlco13c.l oc1:i1odcu6:q::(g)

Target2 DECFSZ iCir, i ;iiO.


GOTO Targetl
RETURN

Target3 BTFSC 1Eh,5 ;Has but.ton A been pushed incorrectly?


GOTO Target2 ,'YES.
' GOTO Game

Delay MOVLW 01h


MO\/!VF 1Ah
Delayl DECFSZ 1Bh,1
GOTO De1ayl
BTFSC 05b,2 ,-fs button A pressed?
BSF 1Eh,5 ,.Yes. Set flag for button A
DECFSZ 1Ch,1
GOTO De1ay1
DECFSZ ].Ah,1
GOTO De1ay1
RETURN

END

g-gn ANITTIATION -I
g1]o6:o6q1o8-d on:QfiEo2i ccq8QeoTQg(animation) o6:cc6
-oa$rQndep%E
qd{F@Eareqn crDog$:QQe.poe8 cells o2eaTo$ frames e<-iE:qp:gcsaq:Qlqeocc2lr cells
O ene e e e e l-c e C C roC c e . e c
qP:c? cDcD[9cF$aorP:ccrrc: %f qllargc.6a)aore9:6crrc:€qccre9il oroq]f:?Gcrrc:oo?
q6 q$-"ad coEog$.qt cells e<i t : (c1)9 eoTq$cQo8eocogl rr

5x7 Display qt LED ecr'13:(qC)o?:cioEea>e@o8.<.t:E:qE pixels e<r'18:(qg)1$cc2irr


4.@E. n6qoEgcQ.eu?d cell co6loi pixels e<JE:(qg) @E.eoTSQEod', cell o61c{ 4
QeoTepq8 oEog,$.e'\ooSQ-6Q cQo6cc@8. oEog2$.ca8 cell eolt:(c")td QeoTfiEe<r
c86p 2i n C el I oEqo$o8t Q 4
eeoc6 <.,'i 2 <.,oocqp, @8. eoTQoa: <r'1 o gl r

40 fi) 4{l fl
H
E
10 20 20 I * I
x 't0 t0 t0 il s g
V I I I t
a
I 4 4 4 ln
u
e 2
I
2
1
2
I
llr n6
file Ho: ll 12 ,t3 1.1 15 11 {2 13 l{ {5 {1 12 13 1+ l5
A bIanK CELL Exarnplel Example2

Q(E-L) Cell co61saca,r5 nex value oo59o5g

.1ooG'qqE "$q.1Q- -?o- oE:cocr3ot:


sr"$'(9) 5x7 Display Circuits-2 etC Qo5a{q$-{- oc1:q1oo8cu3,qp,(t)

saocr5<r'1qq8 o@o cell ccE) vatue 91 coo5go8qeo;og) btankcetl


_
cr:31@6o$rr Hex value 93. file number
"ej-d hex
4. ooEgoEqlc'5c,f e<rT@$3r.r"G8;dil o@e
.c',Ecoca3 o%d (q)"edfilqr ,3;oi.cc$ dispray n"Tfi LED (q)"i'"fl c'iuSoc'Q1.'gj'
osarcr3ag:o"adgrd sae<-,T.c,5cQ.orc8a3c:q13 hex vatue otot 01,02,04, 08, io,20, a0qS:
oo3go8coo:og)rr c,oerecnEo3q3ecrTQoc:og) hex value qprod file number 11h er\ ooe
(2)qepg3..oc'5{Sergirr cu1o5:o6qnEoa3 eo g3.{Ee3re6pd sacg:@1eoo:eq1rr
?d*
ncnEcoog) file number 12h g3.oc3{3og)rr -"g*".o8-.rd rrte numner rsn g3.ocr5{3
rrg)r oo2gecn8cucog) file number 1ah g3.erc6{Eopirr ogeecrrEcoogJ fite number tsh
c e oc c
lc.Dm€?caraqil

cogiqS:e<rT@leEjrr Fite o:61er\-$Q'-d 00 to 7F G6$Sa>d;


4-$$,4qq$"adqlcfrS
p c"^-rf o oEG)nq
"Pq8 fi n.r" o$ Q :qperle<i 3 :co5 gE. oe.rToc3(q)q.pq8$ n.ro -$$,
qp: erlec,'1 E :co5 g oE):S : 00 to 7 F saq8 ; e1fi eraoS 6dfGE S :
"?."'? G6oE)
rr

Example 1 og8eoT@@o:q1cr5saq-
<.,ocecn8cog8.{teoofile 11n erlo$Q:gc 04+93=96 and 10 1C @6r:g)rr
"Q"@S.
qo8oecn8cogS.{Eearc file 12h er\o$Q:gc 02+941gg-O- and 20+40=60 4"@e. 6E
@6o$rr
oro3crecricog8.{Eeoo file 13h er\o:$Q:go 01+08=09and 10+20=30
4€"e. 39n @6ccgin
oo2gecrr5cog8.{Eea:o file 14h eilo:$Q:gc o+ @3rog)rr
ogcecnEcog8.{Eeer file 15h er\o$Q:gc 01+94=95 and 10+40=50
46@}€. 55h @6cogin
sacoo:o2 <.,8 Exa m p e 2 saqc8 r qp, n? qa c6@d q*f S era:crS ooi E : nq.$ E o $ u
I
-$ Q <-,1

File 11n er\o$$:gc 22h @Eogjrr


File l2herlo$Q:gc 1Eh @6r:pil
File 13h a\o{$:go o7h @6oglrr
File 14h er\cn$Q:go 71h @6arg)rr
Fiie 15her\o$$:gc 7Fh @6o$rr

. gaocrScigaoi8: file o:E1:aqcr5 QeoTc$eoc hex o>$Qtqprcr? a:o59o5$:egocB frarne


-.t.diq$@{${ o:o59o5e1eon,glr oqp:r,::@3" 4@{$.'| 0.5sec g:ro59o5.cu"
fi@::s!,r
eraocBqe8 Example 1 saqcB Qe<rT@eo:op) source code qp: c,fe*T$oo:<.icop)rr

;Display examplel for 1/2 sec;


list p:picl6f84
include p16f84. inc
_config ht 3ff3'
errorlevel -3A2 ;Etiminate Bank warninq
Start ORG 0x00
BStr 03,5 ,"Goto paqel for setting-up the pcrts
l,lOVLId 00h ;Put 00 into W

' JooG iq-5 a$gol{co -?e- "


oc:co.i!ra€, r
-n$,(g) 5x7 Display Circuits-2 rlc QcAo{q.$*{- oc7:qoo5cu6tep'(?)

MOVhJF05h ,.ro make porr 5 (po::c A) aJ-J- cutpur-


MOVW!'06h iand r.al:e port 6 (port B) all output
BCF 03,5 ;Go to pageO for proqramning
GOTO Main

Framel MOVLW 1Ch ;pface the 5 values into ihe 5


MOVWF 11h ; files to produce the pattern
MOVL'd 6Eh ; shown i n examplel above.
MOVviF 12h
MOVLI! 3 th
MOVWF 13h
MOVLW O4h
MOVWF 14h
MOVLW 55h
MOVWF 15h

BSF 05,1 ;Reset 4017


NOP
BCF C5,1
li:Via l1h, 0 ; Mo.;e f if e 11 rnto W
MC'VWF O 6h
CALL DCID
MOVF 12hl O ;Move file 12 into W
MOWF O5h
CALL DeID
.,,i,:=.l4gvF
'j 'i L3h,0 ;Move file 13 .into i w
MOVWp Oefr i I '

CALL Del-D
. MOVF 14h,0 ;Move file 14 into W
MOWF O6h
CALL DeID
MOVF 15h,0 ;Move file 15 into W
r4ovwF 06h
CAT.I Del-D
RETURN

Del-D DECFSZ 1Bh,1


GOTO DeID
MOVLW 00h ;Zero port B to prevent mirroring
MOVWF 06

Cl-k BSF 05,0 ;Clock the 40L7


NOP
BCF 05,0
RETURN

Main MOVLW 50h ;Each 10h represents 100mS (10 frames/sec)


MOWF OCh

Mainl CAI,L Framel ;Display framel for 1/2 see


DECFSZ OCh
GOTO Mainl
NOP

a€
o"$r(S) 5x7 Display Circuits-2 etC Qo5o{o3$co{,r.n ooq:q1<.,o5o:6:qp:(q)

Main2 NOP ;Do-nothing loop


GOTO Main2 ; Reset power to view screen agarn
END

goSqcfn rr oQ5(9-g)goo8$ epeEQ8:e<il$et$ o6:er61c$qp:of ecu.dooeol Plc


{cfefiq3fio{or oq:qoo5cu6:qp:o{E:fu)oaq6r oefdo)f Q(o-o)18. Q(o-l)"?.ua8
eril@o:ecn oo5cuE:q;c:of opleoc$$ o6:cc6d$to1 o$r

g-con ANI^,IATION -2
glo8:oc8qldoa8 cell (or) frame (g)1eri A6Q.{""T0c,'1el2in g1l+d,GE. cetl saeq
oqc'Sqp:c'f {'.il$, crroq$:q6Qqp: QeoT@{Ea.,? n"'o.6"1Q(E-t)qE q""f
"s$fiEeocc2lrr
G"d cett (g)1er\gc{ eoTpcoo:.ic;2lrr ccoE{Eep cell o6qql8:oq.r5 hex o$$:qp:r,?
oeecec
ofl oqeqlc @egc8c:6$3Jo:6'l6oce9 il

4tt 40 40
2E 20 20
.t0 t0 't0
t B I
rf 4 4
2 2 2
1 I 1

11 l2 '13 ,14 ,a5 'l'l {2 '13 l.l '15 't.t l2 {3 {+

4{l 40
. ,'o
.&
20 EF 20
r:.iO
{0 {0 @
h
1? \J'"

4 I
tEF

2 2
,| II 1
'lj@
,t':i@
11 12 {3 {4.15 1t 12 tt trt {5
A S-celt .e,FIlffiATlS$8

Q(g-e) Animation Qn.TEod celt (g)EerlQ

e"arc6q3 Animation-2 :a%d source code qp:c{ eoTQcoc:<icoplrr

,'5-ce11 animation
list p=pic16fB4
include p16f84. inc
_conf ig tr'3f f3'
sao$,(9) 5x7 Display Circuits-2 etc Qc6afi q$*$- ac1:q1ooEco6,qp,{t)

ei:ror-fevef -302 ; LIIIIITIId.IE bdIIJ( WdTIIJ-II9

Sta.rt CP.G 0x00


LSL: 03,5 ; Go to pagel for setting-up the ports
r4ovli^i 0 0h ;Put 00 into W
MOVI'F O5h ,'to make port 5 (port A) all output
l"lovrdF 0 6h ;and make port 6 (port B) all output
BCF 03,5 ;Go to pageO for programming
GOTO iriain
CelI1 MOVLW 01h iplace the 5 val-ues into the 5
MOW.iF 11h ; f iles to produce the first cel-l-
MOVLW O1h ; as shown above.
MOVIdF 12h
MOVLW O1h
MOVWF 13h
MOVLW 01h
MO\rvVF 14h
MOVLW O1h
tiovl,irF 15h
GCTC Scan

Cel-12 MOVLW 08h ;place the 5 values into the 5


MOVWF 11h ; files to produce the second cell
MOVLW O4h ;as shown above.
MOVWF 12h
MOVLW O4h
MOVWF 13h
MOVLW O2h
MOvwE 14h
MOVLW 01h
MOWF 15h
: GOTO Scan

Cell3 MOVLW 40h ;pface the 5 values into the 5


I MovwF 11h ; fi-l-es to produce the third cell
MOVLW 2Oh ; as shown above.
MOWF 12h
MOVT,W O8h
MOVWF 13h
. MOVLW O4h
' l4ovsrF l-4h
MOVLW O1h
MOVWF 15h
TGOTO Scan

CeIl-4 MOVLW 00h ;place the 5 values into the 5


.MOWF 11h ; fil-es to produce the fourth cell-
'MOVLW 00h ; as shown above.
MOVWF 12h
MOVLW 6Oh
MOVWF 13h
MOVLW 1Eh
: MOWF 14h
MOVLW Olh
MOVWF 15h

oJ
ou$,(E) 5x7 DisPlaY Circuits-2 PtC Qcfa{c?$-{- o1:qooEco6,qp,(q)

GOTO Scan

CelL5 MOVLW OOh tplace the 5 values into the 5


MOVWF 11h ; files to produce the fi-fth cell
MOVLW OOh ;as shown above.
MOWF 12h
MOVLW OOh
MOVWF 13h
MOVLW 00h
MOVWF l_4h
MOVLW 7Fh
MOVWF 15h
GOTO Scan

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,1
MOVF 11h,0 ;Move file 11 into W
MOVWF O6h
CALL De]-D
MOVF 12h,0 ;Move fil-e 1,2 into W
MOVWF 06h
CALL DelD
MOVF 13h,0 ;Move fife 13 into W
MOVWF 06h
CAIL DeID
MOVF 14h,0 ;Move fil-e 14 into W
MOVWF O6h
CALL DelD
MOVF 15h,0 ;Move fil-e 15'i-nto W
MOVWF O6h
CALL DelD
RETURN

DelD DECFSZ 1Bh,1


GOTO DeID
MOVLW OOh ; Zero port B to prevent mi-rro: ing
MOVWF 06
ctk BSF 05,0 ;Cfock the 4017
NOP
BCF 05,0
RETURN

Main MOVLW 5Oh ;Each 10h represents 100mS


MOVWF OCh
Mainl CALI Ce]11 ;Display Cel-l 1 for 1/2 sec
DECFSZ OChf 1
GOTO Mainl
MOVLW 40h ;Each 10h represents 100mS
MOVWF och
Main2 CAIL Ce112 ;Display Cel-I 2 for 400mS
DECFSZ och,1
GOTO Main2
MOVLW 3Oh ;Each 10h represents 10OmS

o?
*$,(g) 5x7 Display Circuits-2 PIC € o&a{oB$*$* eoi:q1-rcEco6:ntp,(q)

MOVWF OCh
Main3 CALI Cell-3 ;Display Cel-l 3 for 3COmS
DECFSZ 0Ch,1
GOTO Main3,
MOVLW 2Oh ,'Each 10h represents 10OmS
MOVWF OCh
Main4 CAIL CeII-4 ;Display CeIl- 4 for 200mS
DECFSZ OCh,1
GOTO Main4
MOVIW t-0h ;Each 10h represents 10OmS (10 frames,/sec)
MOVWF OCh
Main5 CAIT, Cel15 ;Di-splay CelI 5 for 100mS
DECFSZ OCh,1
GOTO Main5
GOTO Main

END

g-ccr ANIi ATION - 3 (WIPE-UP SUB-ROUTINE)

glo6:cc6q1d-d sub-routine o61@Eo1opfrr


16qo6loQdn"T@ "qrc8 eooc6aq:
row cf6p?oo8cno oec,Tocf row q;c:oo8 an6lqE: $o8qo:eoed -8*iSolccgln
g1l subroutine {
WIPE-UP qcoTol3}elr CALL WipeUp instrudbn c{oc?:@ffi:
,dod animation {f"a8o{ oc8:ofo$q8 *ii0f{Eeocr$n '.

;Sub-routine "WipeUp"
WipeUp MOVIW OFFh!
MOWF 11h +
MOVWF 12h
MOvwF 13h
MOVWF 14h
MOVWF 15h
MOVIIW 20h
MOvwF OCh
xx BcF 11h,0
Rr,F 11h,1
BCF 12h,0
RtF 12h,1
BCF 13h,0
RLF 13h,1
BCF 14h,0
RrF 14h,1
BCF 15h,0
RLF l_5h,1
BTFSS 15h,7
RETURN
YY DECFSZ 0ch,1
coTo zz
GOTO XX
ZZ CALL Scan
GOTO YY

09
oa$:(9) 5x7 Display Circuits-2 et C Q
cAa{ cal-{* oe7:q1,roEo6:qp:(?)

Scan

END

g-cJn ANLI ATTON - 34 (cOI BINATION)


gaocSrr'l WIPE-UP sub-routine c{ Animation-2 qE og)q3:on:S1oa:Qc{ e<rTp
oa:oloElrr

; Experiments (comb j-ned)


list p:pic16fB4
incl-ude p16f 84 . j-nc
_conf ig h' 3f f 3'
errorleveL -302 ;El-iminate Bank warning
Start ORG 0x00
BSF 03,5 ; to pagel for setting-up the ports
Go
MOVLW OOh ; Put 00 i-nto W
MOWF O5h ; to make port 5 (port A) aII output
MOVWF 06h .'and make port 6 (port B) all output
BCF 03f 5 ,'Go to pageO for programming
GOTO Main

Cel-f1 MOVLW 01h ;pface the 5 val-ues into tne S


MOVWF 11h ; fil-es to produce the first cell-
MOVIVI 01h ; as shown .above.
MOVWF 12h
MOVLW 01h
MOVI'iF l_3h
MOVLW O1h
MOWF 14h
MOVIW 01h
MO\,'IfF 15h
GOTO Scan
Cef12 MOVLW OBh .;p1ace the 5 values lnto the 5
MO\/WF 11h ; fil-es to produce the second cell-
MOVLW O4h ,' as shown above.
MOWF 12h
MOVIW 04h
MOVWE 13h
MOVT,W 02h
MOVWF 14h
MOVLW 01h
MO\'I{F 15h
GOTO Scan
Cell-3 MOVTW 40h ;pface the 5 values into the 5
MOVWF 11h ,'f i-les to produce the third cef f
MOVIW 20h ; as shown aborre.
MOVWF 12h
MOVLW 08h
MOVT.JF 13h
MOVLW O4h

*s
ea$:(9) 5x7 Display Circuits-2 P;C €r5c{e$-fl* oeTeqoo8cu6,Ep'(?)

MOVItF 14h
MOVLW Olh
MOW/SF15h
GOTO Scan
Cel- l4 MOVLW 00h ;p1ace the 5 values inL.o the 5
MOVWF 11h ; files to produce the fourth ceff
MOVLW OOh ;as shown above.
MOVWF 12h
MOVLW 6Oh
MOVWF 13h
MOVLI^I 1Eh
MOVWF 14h
MOVT,W O1h
MOVWF 15h
GOTO Scan
CeII5 MOVTW 00h ;p1ace the 5 values into the 5
MOWIF 11h ,- files to produce the f lfth cel-l
MOVLW OOh ; as shown above.
MOVWF 12h
MOVLW OOh
MOVWF 13h
MOVLW OOh
MOWF 1_4h
MOVLW 7Fh
MOWF 15h
GOTO Scan

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,1
MOVF 11h,0 ;Move file 11 into W
MOVWF O6h ;l4ove W to output port6
CALI, DelD
MOVF 12h,0 ;Move file 12 into W
MOWF O6h
CALL Del-D
MOVF 13h,0 ;Move fil-e 13 into W
MOWF O6h
CALL DelD
MOVF 14h,0 ,'Move file 14 into W
MOVWF O5h
CALL DeID
MOVF 15h,0 ,'Move file 15 into W
MOVWF O6h
CALL Del-D
RETURN
Del-D DECFSZ 1Bh,1
GOTO DeID
MOVLW OOh iZero port B to prevent mirroring
MOWF 06
cl_k BSF 05,0 ;C1ock the 4017
NOP
BCF 05,0
RETURN

oG
oa$:(9) 5x7 Display Circuits-2 etC Qc6o{ca$-{* on:qpoEco6:qp,( l)
Wj-peUp MOVLW OFFh
MOWF 11h
MOVIVF 12h
MOVWF 13h
MOWF 14h
MOWF 15h
MOVLW 8Oh
MOWF OCh
GOTO YY
XX RLF 11h,1
BCF 11h,0
RLF 12h,1
BCF 12h,0
RLF 13h,1
BCF 13h,0
RLF 14h,1
BCF 14h,0
RLF 15h,1
BCF 15h,0
BTFSS 15h.7
RETURN
YY DECFSZ OCh,1
GOTO ZZ
MOVLW 8Oh
MOWF OCh
GOTO XX
ZZ CALL Scan
GOTO YY

Main MOVT,W 50h ;Each 10h represents 100mS


MOV9IF OCh

Mainl CALL CeIl1 ;Display Cel-l I for I/2 sec


DECFSZ och,1
GOTO Mainl
MOVT,W 40h ;Each 10h represents 10OmS
MOVWF OCh

Main2 CALL CelI2 ;Display CeIl 2 for 400mS


DECFSZ OCh,1
GOTO Main2
MOVLW 3Oh ;Each 10h represents 10OmS
MOVWF OCh

Main3 CALL CeII3 ;Display CelI 3 for 300mS


DECFSZ 0Ch,1
GOTO Main3
MOVLW 2Oh .'Each 10h represents 10OmS
MOWF OCh

o?
s".$:(9) 5x7 Disptay Cii-cuits-2 r:C '$c'5e{q+:$"-_=:""J,rc.5"r3:'g-,:(?)
: - l:l:
=:::

Main4 CALL CeIl" 4 ; Daspf ay Ce-LI 4 for 200rnS


DECF'SZ OCh,1
GOTO liain4
MOVLW 80h
-::
;Each 10h represenLs 100mS
T'TOVTJF OCh

Main5 CALL Ce1I5 ;Display CeIl 5 for 800mS


DECFSZ Och,1
GOTO Main5
CALL WiPeUP
GOTO Main

END

g-c?r AMMATION - 4 (WIPE-UP & WrqE-DOWN)


Wipe-down sub-routine +6tnfl e<.ili:o6e*TQ
o?6o?6qe:eq Wipe-Up sub-routine oq6q6q98.
Up $8. wip+down sub-routin: opiq8:
+!t4

;5-ceII animation with WipeUp and WipeDown-


Iist p:pic16f84
incLude p16f84.inc
_config ln'3ff3'
errorl-eveI -302 ;El-iminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for setting-uP the ports
MOVLW 00h ; Put 00 into W
MO\/WF .05h ; to make port 5 (port A) all output
MOWF 06h ;and make port 6 (port B) all output
BCF 03.5 ;Go to page0 for programming
GOTO Main

CeIl1 MOVLW Olh ;place-the'5 'valueS into the 5


MOWF 11h ; files to produce the first.cell
MOVLW 01h ; as shown above.
MOVWF 12h
MOVLW O1h
MOWE 13h
MOVLW O1h
MOVWF 14h
MOVLW O1h
MOVWF 15h
GOTO Scan

CeIl-2 MOVLW OBh ;place the 5 values into the 5


MOVbIF 11h ; files to produce the second cell
MOVLW 04h ; as shown above'

te
oa$:(9) 5x7 Display Circuits-2 Plc QoE€ i"ai-{* ocg:q1ooEo6rCp,(e)

MOWF 12h
MOVLW O4h
MOVWF 13h
MOVLW O2h
MOVWF 14h
MOVLW 01h
MOWF 15h
GOTO Scan

Ceff3 MOVLW 4Oh iplace the 5 vafues into the 5


MOVWF11h ; fil-es to produce the third ce11
MOVLW20h ; as shown above.
MOVWF12h
MOVLW08h
MOVWF13h
MOVLW04h
MOWF 14h
MOVLW O1h
MOVWF 15h
GOTO Scan

Cel-f 4 MOVLW 00h ;p1ace the 5 values into the 5


MOVWF 11h ; files to produce the fourth cel-l-
MOVLW OOh ;as shown above.
MOWF 12h
MOVLW 6Oh
MOVWF 13h
MOVLW 1Eh
MOVWF 14h
MOVLW 01h
MO\/WF 15h
GOTO Scan

Cell-5 MOVLW 00h ;place the 5 values into the 5


MOVWF 11h ; files t.o produce the fifth ce1l
MOVLW OOh ; as shown above.
MOVWF 12h
MOVLW OOh
MOWF 13h
MOVLW OOh
MOvv[F 14h
MOVLVi 7Fh
MOWF 15h
GOTO Scan

Scan BSF 05,1 ; Reset. 4017


NOP
BCF 05,1
MOVF 11h,0 ,'Move f i-l-e 11 into VI
MOVyiF 06h

CALI, DelD
MOVF 12h,0 ,'Move file 12 into W
MOVWF O6h

o8
*.$,(q) 5x7 Display Circr:its-2 Ptc {c6a$ca$*fl* on,q1oo5or6,qpr(e)

CALI DeID
MOVF 13h,0 ;Move fil-e 13 into lal
MOVWF O6h

CALL DeID
MOVF 14h.0 ;i'love fi-le 14 into lJ
MOVWF 06h

CALL DelD
MOVF 15h,0 , ;Move fife 15 into W
MOVWF O6h

CALL DeID
RETURN

DelD DECFSZ lBh,1


GOTO Del-D
MOVLW OOh ;Zero port B to prevent mirroring
MOVWF 06

clk BSF 05,0 ;Clock the 4017


NOP
BCF 05,.0
RETURN

WipeUp OVLW OFFh


MOWF 11h
MOVWF 12h
MOVWF 13h
MOVWF 14h
MOVWF 15h
MOVLW 8Oh
MOWF OCh
GOTO YY

)o( RLF 11h,1


BCF 11h,0
RLF 12h,1
BCF 12h,0
Rt F 13h,1
BCF 13h,0
RLF 14h,1
BCF 14h,0
RLF 15h,1
BCF 15h,0
BTFSS 15h,7
RETURN

YY DECFSZ 0Ch,1
GOTO ZZ
MOVLW BOh
MOVWF-'och
GOTO XX'

go
r>u6,(g) 5x7 DisPlaY Circuits-2 PIC Q<160{%6-{* ocg:q<.,o8co6tqpt(q)

ZZ CALL Scan
GOTO YY

WDown MOVLW OFFh


MOWF 11h
MOWF 12h
MOVWF 13h
MOWF 14h
MOWF 15h
MOVLW 8Oh
MOVWF OCh
GOTO BB

/ AA RRF 11h,1
BCF 11h,7
RRF 12h,1
BCE 72}j',1
RRF 13h,1
BCF 13h,7
RRF 14h,1
BCF 14h,'l
RRF 15h,1
BCF 15h,7

BB DECFSZ OCh,1
GOTO CC
MOVLbI 80h
MOVWF OCh
BTFSS 15h,0
RETURN
GOTO AA

CC CALL Scan
GOTO BB

i,iain I.{C\ri,Iri 0FCh ;Each 10h represents 10OmS


MOVWF OCh

Mai-n1 CALL CeIf 7 ; Dj-sp1ay CefI 1 for 7/2 sec


DECFSZ OCh,1
GOTO Mai-n1

MOVLW 40h ;Each 10h represents 100mS


MOVI1]F OCh

Main2 CALL Ce112 ; Display Cel-l- 2 for 400mS


DECFSZ 0Ch,1
GOTO Mai n2

MOVI-W 30h ,'Each 10h represents 100mS


MOVWF OCh

tr{ain3 CALL Ce113 ; Drsplay Cel-l 3 for 300nS


-I
DECFSZ CCh,
GOTO Maj-n3

t:

B3
on$,(E) 5x7 Display Circuits-2 nt C'$o5o{o6$-{- ec1:qodo:6:qpr(q)

MOVLW 20h ;Each 10h represents 100mS


MOVWF och

Flain4 CALL Cell4 ;Display Cell 4 for 200mS


DECFSZ och,1
GOTO Main4

MOVLW 80h ;Each 10h represents 100mS


MOVWF och

Main5 CALL Ce115 ;Disp1ay Cell 5 for 800mS


DECFSZ OCh,1
GOTO Mains
CALL WipeUp
CALL WDown
GOTO Main

END

g-cgr ANLI ATION - 5 (sLAsH SUB-ROUTIN9


gio6:o6qc6c,? slash sub-routine o?6aTo'l3oeir q6qoEWa8-$.-iSo6egolp:g
@6eoTe"@E:oqo8 oa2:QfiE<icopirr eo.6,iQ(9-E)"aE cells (11) ?@%d slash sub-
routine on:Spa:Qc{ 6oTQ@a:o1 opin

aalaa aoalo i)ai}aa OOa+a O+OO+ iOi}OO


aotaa tooo!} toloi} oi)+oo oooat +ta+o
ttot+ +ftla allo+ aaato ++ai)a +i}lot
oloo+ toiloo
i)oooo aoooo ooe+t
l}+aoa o+oo+ o++oo
OOO+I oo+o+ o+Oo+ OO++O
+or+o lfooo ++)j) +o++o o+ooo llti}i}
ao+++ a+tao o+ooi} lo+++ oa+to toaol

oo++o |tooo ooat+ oaoaa oi}oal}


+a+++ aaaol oila+o l++t+ aloai}
otota ooaao oc+oo
a+oto ao+o+ oaao+
ooora ooata l)+oOO toaa+ otl}a+
Ol+O+ aoaoa +++la OOa++ +ilot+
ailoal oolol Oi}t++
ot+rr +OOiO
aoaot oatoa
'OOOi} +ooi}o
SLASH 1I-CELL ANI/l/lATION

Q(E-t) cells (11)saqc8 slash sub-routine ocg:Q[@o:Q

GJ
oe$:(9) 5x7 Display Circuits-2 etC Qcfa$cai-{- oe7:qpoEcu6rqp,(?)

; SLASH animation
1i-st p:pic76f84
incl-ude p16f 84. inc
_config h'3ff3'
errorl-evel- -302 ;Efiminate Bank warning

Start ORG 0x00


BSF 03,5 ;Go to pagel for setting-up the ports
MOVLW OOh ,'Put 00 into W
MOWF O5h ;to make port 5 (port A) all output
MOWF O6h ;and make port 6 (port e) all output
BCF 03,5 ;Go to pageO for programming
GOTO Main

Sfash BCF 03h,0 iClear the carry bir


MOVLW OOh
MOvwF 11h
MOWF 12h
MOWF 13h
MOVWF l_4h
MOVWF 15h
BSF 11h,0
CALI ShiftUp
BSF 12h,0
CALI ShiftUp
BSF 13h,0
CALL Shift.up
BSF 14h,0
CALL Shifrup
BSF 1-5h,0
CALL Shifrup
CALL Shifrup
CAIL ShiftUp
BCF 11h,7
CALL ShiftUp
BCE 72h1,'7
CALL ShlftUp
BCF 13h,7
CALL Shift.Up
BCF 14h,7
CAL], ShifTUP
RETURN

ShiftUp MOVLW 2Oh


MOVWF OCh
shifrl DECFSZ OCh,1
GOTO Shifr2
RLF 11h.1
RLF 12h,1
RLF 13h,1
RLF 14h,1
RLF 15h,1
RETURN

e?
*l'(E) 5x7 Display Circuits-2 PIC Qe'5a{qi-{- on:q1oo6cu6'qp,(l)

shi fr2 CALL Scan


GOTO Shi_frl-

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,1
MOVF 11h,0 ;lviove fiie 11 into
MOVWF O6h
.CATL DdlD
MOVF 12h,0 ;Move file 12 into W
MOVWF O6h
CALL DelD
MOVF 13h,0 iMove fil-e l-3 into W
MOVWF 06h
CALL DeLD
MOVF 14h,0 iMove file 1-4 into W
MOVWF O5h
CALI, Del-D
MOVF 15h,0 ;Move fife 15 into W

MOVWF O6h
CALL De]-D
RETURN

Del-D DECFSZ lBh,l_


GOTO DelD
MOVIW 00h ' izero port B to prevent mirrqring
MOWF 06

clk BSF 05,0 ,'Clock the 4017


NOP
BCF 05,0
RETURN

Main CALL Slash ,'Display Sf ash


GOTO Main

END

e9
o{,(E) 5x7 Display Circuits-2 ctC Qc'So{q$-{* on:qoolcu6,qpt(e)

t-cgu ANIfrTATION - 6

gfio5:o6qc'5.,fl splash sub-routine o2eaT<-,log)rr n69o61c'iQn"Tepoa8 ooc'Soc'i


egepgocotogcAecrTc'm$:ofc,r5 eo:<.,doo5cu2ic$. G$.-toAcr5e<.,Tc,oeocc2lrr eoc6.1Q(i-g)
qE cells (5) 1"aqcrS splash sub-routineon:Qpo:Qd n"TG-":do$rr

o++aooooo+ oatot aoaeo aaaoo


o++o+oo+o+ o++aa +o++o oo++il
o+r++
a++aoo+++o +o+++ oaaoo otoot
o+o++oa++o
aa+ao too+e ooo+o oo+o+
i|+ooo ooooo oao++
ooao+o+ooo aoot+ ootoo oa+oo
+++ato+ooo o+ooo +a+aa aoo++
SPLAsH 5-6ELL ANI/IIIATTON

(g-g) Splash sub-routine G@aE. cells (5) toaE t6QG6e<rTc,:oQ

; SPLASH Animati-on
list p=picL6f84
include p16f84. inc
_conf ig h'3f f 3'
errorlevel -302 ;Eliminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for setting-up the ports
MOVLW OOh ;PuL 00 into W
MOVWF 05h ;to make port 5 (port A) all output
MOVWF 06h ;and make port 6 (port B) all output
BCF 03, 5 ;Go to page0 for prograrnming
GOTO Main

Cel11 MOVLW OOh ;place the 5 values into the 5


MOWrF t_lh ,- files to produce the first cel1
MOVT,W 00h ; as shown above.
MOVWF 12h
MOVLW O8h
MOWF 13h
MOVLI^I 00h
MOVWF 14h
MOVLW 00h
MOVWF 15h
GOTO Scan

Ce1 12 MOVLW 00h ;p1ace the 5 values into the 5


MOVWF llh ;files to produce the second cell
}IOVLW 1Ch ; as strown above.
MOVWF 12h

Gfl
oa$:(9) 5x7 Display Circuits-2 etc Qc6sfi oe$*{* oa1:q:oEcuE,qp,(e)

MOVLW 14h
MOVWF 13h
": I4OVLW ICh'
. MOVWF.14h .

MOVLW OOh
MOVWF 15h''
GOTO Scan

CeIL3 MOVLV{ 3Eh ;place the 5 val-ues into the 5


MOVWF 11h ; files to produce the third cell
ytovLw 22h ;as shown above.
MOVWF L2h
T\4OVLW 22h
MOVWF 13h
MOV],W 22h
I'{OVWF 14h
MOVLW 3Eh
MOVWF 15h
GOTO Scan

Cel-I4 MOVTW 41h ;place the 5 values into the 5


MOVWF ].1h ;files.to produce the fourth cell-
MOVLW 41h ;as shown above.
MOVWF 12h
MOVLW 41h
MOVWF 13h
MOVLW 41h
MOWF 14h
MOVLV{ 41h
MOVWF 15h
GOTO Scan

Ce115 MOVLW 00h


MOVWF l1h ;The fifth cell is blank
MOVLW OOh
MOVWF 12h
MOVLW OOh
MOVWF 13h
MOVLW OOh
MOWF 14h
MOVLW 00h
MOVWF 15h
GOTO Scan

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,1
MOVF 11h,0 ;Move file 11 into W

MOVWF O 6h
CALL DelD
MOVF 12h,0 ;Move file 12 into W

MOWF O6h
CALL Del-D
MOVF 13h,0 ;Move fil-e 13 into W

gG
:F
i -"$,( g) Sxt DisPlaY Circuits-2 elC Qc6a$q$-{* oc9:noo6o;6:qp:(e)

I rovwF o6h
' CAIL DeII)
i yovF 14h,0 ;Move fil-e 14 into w
MOWF O6h
CALL DelD
MOVF 15h,0 ;Move file 15 into W
MOVWF O6h
CALL DelD
RETURN

Del-D DECFSZ 1Bh,1


GOTO Del-D
MOVLW 00h ;Zero port B to prevent mirroring
MOVWF 06
Cl-k BSF 05, 0 ; Clock Lhe 4017
NOP
BCF 05,0
RETURN

Main MOVLW 50h ,.Each 10h represent.s lOOmS


MOVWF OCh
Mainl CALL CeflT ;Disptay Cel-l 1 for I/2 sec
DECFSZ OCh
GOTO Mainl
MOVLW 10h ;Each 10h represents 100mS
MOVWF OCh
Main2 CALL CeIl2 ;Display Cel_I 2 for 100mS
DECFSZ OCh
GOTO Main2

MOVLW 10h ;Each 10h represents 1O0mS


MOVWF OCh
Main3 CALL CelL3 ;Display Cell 3 for IOOnS
DECFSZ OCh
GOTO iriain3

MOVLW 10h ;Each 10h represents 100mS


MOWF OCh
Main4 CALL Ce114 ;Dispj_ay CeIl 4 for 1O0mS
DECFSZ OCh
GOTO Main4

MOVLVJ 80h ;Each 10h represents 100mS


I'iOVWF OCh
Main5 CALL Cef f5 ;Display Cel-l 5 for 8O0n,S
DECtrSZ OCh
GOTO Main5
GOTO I'iain

nlln
DI! U

ao
-u$dE) 5x7 Display Circurits-2 etc $c6o{q$-6- oa7:q1oo5co3:qp'(q)

g-cGrr PRESS BUmOi{ "A" AND SPLASH

g]o6:o6q1doa8 no?d .A" (4 $ScQc,5er$oa1 animation o:61 splash @SocrTcmQ


.,? n"T@.rEi,' ogoEoqc6 de-bounce feature crfo2)g3:oa:eoae@o8. "e"8.{$58,
@g):ei8:ga q8t5.q.r5""t5cugl: animation o$@6ere<-,Togct5cmn@E:eogele,rc$rr
<rr8 : o 6 : o 6 qc6oq cr5 sou rce cod e crlecaoctS qE eoT$oa: c, $ rr

;Press button A for SPLASH! - with debounce


list p:picl6f84
include p16f84.inc
_config h' 3ff3'
errorlevel- -302 ;El-iminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for,setting-uP the ports
MOVLW 04h ; Put 04 into W
MOWF O5h ;to make RA2 input
MOVLW OOh ,'Put 00 into W
MOVWF O6h ;and make port 6 (port B) all outPut
BCF 03,5 ; Go to pageO f or Progtramniing
GOTO Main

Cel-I1 MOVLW 00h ;place the 5 values into the 5


MO\/WF l1h ; fil-es to produce the first cefl
MOVLW OOh ias shown above
MOWF 12h
MOVLW 08h
MOVWF 13h
MOVLW OOh
MOVWF ].4h
MOVLW 00h
MOVWF 15h
GOTO Scan

cd.L2 MOVLW 00h ;place the 5 values into the 5


MOVWF l-1h ; f il-es to produce the second cell-
MOVLW 1Ch ;as shown above.
MOVWF 12h
MOVLW 14h
MOVliF 13h
MOVLW ]-Ch
MOWF 14h
MOVLW OOh
MOVWF 15h
GOTO Scan

Cef13 MOVLW 3Eh ;place the 5 values into the 5


MOVVIF 11h ; fil-es to produce the third cel1
MOVLW 22h ;as shown above-
MOVWF 12h
MOVLW 22h
MOWF 13h
MOVLW 22h

go
oa$:(r) 5x7 Display Circuits-2 Plc EoBa$%$-6* on:qoo5co6,qpt(t)

MOVWF 14h
MOVLW 3Eh
MOVWF 15h
GOTO Scan

Cel-L4 MOVLW 41h ;pface the 5 val-ues into the 5


MOVWF 11h ; fifes to produce the fourth ce1l
, MOVLW 41h ;as shown above.
MOVWF 12h
MOVLW 41h
MOVWF 13h
MOVIW 41h
MOWF 14h
MOVWF 15h
GOTO Scan

Ce115 MOVLW 00h ;pface the 5 values into the 5


MOWF 11h ;files to produce the fifth cell-
MOVLW 00h ;as shown above.
MOWF 12h
MOVLW OOh
MOVWF 13h
MOVI,W OOh
MOWF 14h
MOVI,W OOh
MOVWF 15h
GOTO Scan

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,1
MOVF 11h,0 ;Move file 11 into W
MOVWF O6h
CALL Del-D
MOVF 12h,0 ;Move fi:.e 72 into W
l"IOvl'tF 0 6ir
Cz\LL i-relli
r.rArTF T ?rr n .l/^-,^ f if e 13 rn:C tl
MOVWE O6h
CALL DelD
MOVF 14h,0 ,'Move fil-e 14 into tr^J

MOVWF O6h
CALL DefD
MOVF 15h/ 0 ;Move fife 15 into !V

I"IOVWF O 6h
CALL DefD
RETURN

DelD DECFSZ 1Bh/ 1


GOTO DelD
MOVLI{ 00h ;Zero port. B to prevent mirrorlng
MOVWF 06
Clk BSF 05,0 ;Clock the 4C17
NOP
BCF 05/ 0

---.::_
r-"ll

-
oe$:(g) 5x7 Display Circuits-? PtC {cia$c5$*{- :acq;q.:o co6:o;r:(q)

RETURid

Splasl'r IIOVLW 50h rach iir represent-s 1OOmS


IV]OVWF OCh
Splashl CALL Cel-I1 Display CelI 1 f.ax t/2 sec
DECFSZ OCh
GOTO Splashl
MOVLI^7 10h E,ach 10h represents 10OmS
F1OVWF OCh
Splash2 CALL Ce112 Display Cel-l 2 for 1O0mS
DECFSZ OCh
GOTO Splash2
MOVLW 1Oh ,'Each 10h represents 1O OmS
MOWF OCh
Splash3 CALL Cel-l-3 ;Display Cel1 3 for 10OmS
DECFSZ OCh
GOTO Splash3
MOVLW 1Oh ,'Each 10h represents 10OmS
MOVWF OCh
Splash4 CALL Cell4 ;Disol,av CelI 4 r-'or 1COmS
DECFSZ OCh
GOTO Splash4
MOVLW O8h ,'Each 10h represents 10 OmS
MOVWF OCh
Sp1ash5 CALL Cel15 ; Display CefI 5 for 50mS
DECESZ OCh
GOTO Splash5
RETURN
Main MOVLW 40h
MOVWF 1Dh
Maj-n1 BTFSC 05,2 ;Test for button A. NOT pressed fine : LOW
GOTO Main2 ;Pressed
MOVF 1Dh,0 ;Not pressed
XORLW OO
BTFSC 03,2 ; Is fil-e 1D : 0?
GOTO Mainl ; YES
DECF 1Dh,1 ;No. Decrement Debounce file
GOTO Mainl
Main2 MOVF 1Dh,0 ;Move file 1D to W
XORLW OO
BTFSS 03,2 ; fs file 1D :. O? Is .the zero-flag SET?
GOTO Mainl ;No
CALL Splash
GOTO Main

END
*it(E) 5x7 Display Circuits-2 P lc q c'SoQqAE-{* on :qpo5co6:qp'(q)

g-cQn START/STOP SPLASH ANII ATION

glo6:o6q1d-d oocfc'llo6:cc6qc'5e'\ of::[<.,{oq6@6o1cc2in to?d "Au "'t


TOGGLE BUTTON oG6 START/STOP feature crfon:$1coa:oc2lrr uo?d "A' cr? o@e
ca6qc6$6cqc6og)oo1 splash animation $6e,.'Tc'o:p: qdcuar6qd$8cEc6eoaoa'l q6-$.
qp:ccg! rr oE :o5:cc6q1c6e%c6 source code c{ ernc6q8eoT@coa:cogjn

; Press button A to START/STOP Sp1ash animation


list p:pic16f84
include pl-6f 84 - inc
_conf ig h' 3f f 3'
errorlevel -302 ;Elimi-nate Bank warning

Start ORG 0x00


BSF 03,5 ;Go to pagel to set-up the ports
MOVLW 04h ;Put 04 into W
. MOVVIF 05h ;to make RA2 input
MOVLW 00h ;Put 00 into W
MOVIVF 06h ;and make port 6 (port B) all output
BCF 03,5 ;Go to page0 for programming
GOTO Main

Cel-I1 MOVLW 00h . ;place the 5 values into the 5 ' ..


MOVWF 11h ; fiLes to produce the first cell-
MOVIW 00h ;as shown above
MO\/I,1IF 12h - :t "'
. MOVIW 08h
MOVWF 13h
MOVT,W 00h
MOVWF 14h
MOVT,W00h
MOWF 15h
GOTO Scan

Cell-2 MOVLW 00h ;place the 5 values into the 5


MOVWF 11h ;fil-es to produce the second cell '

MOVLW 1Ch ;as shown above-


MOVWF 12h
-; MOVI,W 14h
- MOVWF 1,3h
MOVIW 1Ch
MOVWF 14h
MOVLW 00h
MOVWF 15h
GOTO Scan

Cet13 3Eh
I.IOVLI/J ;p1ace the 5 values into the 5
MOW{F 11h ; fiJ_es to produce the third cefl
MOVLW 22h ;as shown above.
MOVI{F i2h
I4OVLW 22h
MOVWF 13h

30c t
*$,(f) 5x7 Display Ciicuiis-2 rtC QcBa$cg$*{* sacg :q1oc8or6:qp,(t)

i{OVLIf 22ii
MOVIAIF 14h
I'{OVLI\I 3Eh
MOVhiF 15h
GOTO Scan

Ce114 r{ovI,!! 41h ;place the 5 val-ues i-nto the 5


MOVWF 11h ;files to produce the fourth cell-
MOVLW 41h ;as shown above-
MOVWF 12h
MOVLW 41h
MOVI{F 13h
MOVLI^I 41h
MOVWF 14h
MOVLW 41h
MOVWF 15h
GOTO Scan

Ce1l5 I"lOVLr.d 0 0h ;place the 5 values into the 5


I'lOvwF 11h ; files to produce the fifth cel-1
MOVLW OOh ; as shown above.
MOVWF 12h
MOVLW OOh
MOVWF 13h
MOVLW 00h
MOVWF 14h
MOVLW OOh
MOVWF 15h
GOTO Scan

Scan BSF 05,1 ;Reset 4017


NOP
BCF 05,l-
MOVF 1lh,0 ;Move fil-e 11 into
MOVWF O6h
CALI DelD
MOVF 12h,0 ;Move file 12 int.o
MOVWF O6h
CALL DelD
MOVF 13h,0 iMove file 13 into
MOWF O6h
CALL DeID
MOVE 14h,0 ;Move file 14 into
MOWF O6h
CALL DeID
MOVF 15h,0 ,'Move file 15 into
MOVWF O6h
CALL DelD
RETURN

Del-D BTFSC 05,2 ;A pushed? Pushed : HIGH


GOTO Dell
BCF 1E,4 ; Cl-ear the button-pushed flag
GOTO De12

JOJ
*$,(g) 5x7 Display Circuits-2 PIC QoEafi %$-6- oa7:qloo8o:6:qp,(t)

Defl BSF lE' 4 ; Set the button-pushed flag


Del,2 DECFSZ lBh,1
GOTO Def2
MOVLW 00h izero port B to prevent mirroring
MOVWF 06
Clk BSF 05,0 ;Clock the 4017
NOP
BCF 05,0
BTFSS 05,2 ;A pushed?
RETURN ;A not pushed
BTFSC 18,4 ;Has the button been released?
RETURN ;No.
BCF 1E,5 ;Yes. Donrt send Micro to SPLASH
RETURN

Splash MOVLW 50h ;Each 10h represents 100nS ., '

MOWF OCh
Splashl CALL CeIII ;Display Cell 1 for L/2 sec
DECFSZ OCh
GOTO Splashl
MOVLW 10h ;Each 10h represent.s 100mS
MOWF OCh
Splash2 CALL Cel-12 ;Display CeIl 2 for 100mS
DECFSZ OCh
GOTO Splash2

MOVLW 10h ;Each 10h represents 100mS l

MOVWF OCh
Splash3 CALL Cell3 . ';Display Cel-l 3 for 100mS :,r-.
DECFSZ OCh
GOTO SpJ-ash3

MOVLW 10h ;Each 10h represents 100nS


MOVWF OCh
Splash4 CALL CelI4 ;Display Cell- 4 for 100mS
DECFSZ OCh
GOTO Splash4

MOVLW 08h ;Each 10h represents 100mS


MOVWF OCh
Splash5
' CALL Cel-15 ;Display Cell- 5 for 50mS
DECFSZ OCh
GOTO Splash5
RETURN

Main BCF 1E,5 ;This flag sends micro to SPLASH


BCF 1E,4 ,This flag detects button NOT pressed
Mainl- BTFSS 05,2 ;Is button A pushed? Pushed = HIGH ,
GOTO Main2 ;Not pressed
BSF 1E,5 , Pressed. Set 1E,5 flag
CALL Splash
GOTO i.{ain1
Main2 BTFSS 1E,5
GOTO Mai-n1
eo$:(9) 5x7 Disptay Circuits-2 etC {cr5a{q$-fi * on:q1odct.6,qp,(?)

CALI Splash
GoTO Mainl
END

g-co[ BULL',s EYE


gflo6:o\p6cogi "Hit the LED" same ofioq6o6q@Eccpir LED qp:ogi screen
eoTq8 oq6:omcu8:q@ogin ocuoSor-rf$ LED ("Bull's Eye'tu8:coo{iqa8 no?o8 "B' cr?

$68AF piezo g siren sacccgc8e<-,1'cooeo"3g"


<r E : o 6 :c.: 8qcr5oog c,E sou rce cod e c{ eocr5oS8 eoTQoa:cr g) r

;Bul-lrs Eye
Iist p:pic16f84
include p16f84. inc
_conf ig h' 3f f3'
errorlevel -302 ;El-iminate Bank warning

Start ORG 0x00


BSF 03,5 ;Go to pagel for setting-up the ports
MOVLW 08h ;Put 08 i4to W
MOVI{F O5h ;to make RA3 input
MOVLT{ 00h ;Put 00 into W
MOVWF O6h ;and make port 6 (port B) all output
BCF 03,5 ;Go to page0 for programming
BCF 1E,7 ;Clear the flag bit
GOTO Main

DeIayl MOVLW 01
MOWF ]-Ah
DellA DECFSZ 1Bh,1
GOTO DeIIA
DECFSZ 1Ch,1
GOTO DeIIA
DECFSZ 1Ah,1
GOTO DeIl-A
RETURN

Delay2 MOVLW 02
MOVWF 1Ah
DeI2A ECFSZ lBh,1
GOTO Del2A
DECFSZ 1Ch,1
GOTO Del2A
DECFSZ lAh,1
GOTO DeI2A
RETURN

Delay3 MOVLW 03

oo9
"r"$r(9)
5x7 Display Circuits-2 PIC qc6a6%q-{ * ocg:q1,' r5co8'qp'(?)

MOWF 1Ah
Def3A DECFSZ 1Bh,1
GOTO De13A
DECFSZ 1Ch,1
GOTO Def3A
DtrCFSZ 1Ah,1
GOTO Del3A'
RETURN

Slren MOVIW O1h ;:1loop


MOVWF 1Ch ,' of Slren sound
SirnD MOVLW 1Oh ;No of on-off cycles
MOVWF OEh
MOWF lOh
MOVLW 3Oh ;No of steps
MOVWF OFh
MOVTW 50h ; Determ-ines f requency
MOVWF OCh
Repeat MOVF 0C,0
MOWF OD
On BSF 06,1
DECFSZ 0D,1
GOTO On
MOVh]F OD
off BCF 06,7
DECFSZ ODf 1
GOTO Off
DECFSZ 10h,1
GOTO Repeat
DECF 0C,1
rNcF 0E,1
MOVF 0E.0
DECFSZ 0F.1
GOTO Repeat
DECFSZ 1C,1 ,'1 cycle of Siren sound
GOTO SirnD
RETURN

Rowl BSF 05,1 ,'The row routine clocks the 4017 to the
NOP ,'required row
BCF 05,1
Return
Row2 BSF 05,1
NOP
BCF 05,1
NOP
BSF 05,0
NOP
BCF 05,0
Return
Row3 BSF 05,1
NCP
BCF 05, 1
N'Il,] D

303
ou$,(9) 5x7 Display circuits-2 etc QcBo{og$*{cm oe7:qooEco6tqpde)

llJt uJ, u
NOP
BCF 05,0
NOP
BSF 05,0
NOP
BCF 05,0
Return
Row4 BSF 05,1
NOP
BCF 05,1
NOP
BSF 05,0
NOP
BCF 05,0
NOP
BSF 05,0
NOP
BCE 05, 0
NOP
BSF 05,0
NOP
BCF 05,0
RETURN

Row5 BSF 05,1


NOP
BCF 05,1
NOP
BSF 05,0
NOP
BCF 05,0
NOP
BSF 05,0
NOP
BCF 05,0
NOP
BSF 05,0
NOP
BCF 05,0
NOP
BSF 05,0
NOP
BCF 05,0
RETURN

Main CALL Rowl


MOVLW 01
MOWF O6
CALL Delayl

CALL Row5
MOVLW OB
MOVWF 06

coG
oa$:(9) 5x7 Display Circuits-2 Plc Qo6e{%$-i* en:q1oo8o6:qp,(q)

CALL Delay2

CALL Row3
MOVLW 20
MOWF 06
CALL De1ay3

CAI,L Row4
MOVLW 10
MOVWF 06
CALL Delayl

CALL Rowl
MOVTW 0l_
MOWF 06
CAII De1ay1
CALL'Row3
MOVLW 20
MOWF 06
CALL Delayl

CALI, Rowl
MOVLW 02
MOVWF 06
CALI Delay1

CALL Row2
MOVI,W 04
MOV9{F 06
CALL Delayl

BTFSC 05,3 ;Button B pressed? This is the "BulI's Eye"


BSF 1E,7 ; section
CALL Row3
MOVLW 08
MOVWF 06
CALL Delayl
BTFSS 05,3
GOTO : x t":: '' '. : :

BTFsc.,_1Er:7 ,-,
GOTO x
CALL Siren

Cef,f, now5
MOVLW 02
MOWF 06
CALL De1ay1

CALL Row4
MOVLW 08
MOWF 06
CALL Delay3

CALL Row5

co?
on$df) 5x7 Display circuits-2 e t C Q
cf o fi qi-{ * eacl :q<-ro5or6r,r.pt(g)

MOVLW 04
MOVWF 06
CALL De1ay2

CALL Row5
MOVLW 20
MOVWF 06
CAT.T, Delay2

CALL Row2
MOVLW 10
MOVWF 06
CAIL De1ay2
CAIL Row3
MOVLW 40
MOVWF 05
CALI, Delay1

CALL Row3
MOVLW 20
MOVWF 06
CALT, Delay1

CALL Row2
MOVLW 40
MOVWF 06
CALL Delay3
BCF 1E,7
GOTO Main

END

g-cg[ LED DrCE WITH SOUND-I

QcAafiq$ofic.n oa7:q1oo8co6:qp:oQ8:(j)ooq6oe8eoTQ;.ccpi LED DlcE o6:cc6


e C . e c O S S l-e e o c C . e c c
q"b%e occo2)coo:r:g o6oiod,1[gdcogn o{oqdogd oe3gdpobocieoo Face6B
sub-routine o6qo66 co$q8:oa:<ioglrr "piezo-bit' qeeTcc2i file 1F efi Bit 7
"?a>d
cc2i ser $6a32:q18 piezo g ooogcfecrTcooeoc€8p2lrr
gfi o6:o 6q1cr5ooec,E sou rce code qp:c{ eocAq8 eoT$oo: o1 cog! rr

,'LED Dice with Sound-l


list p:pic16f84
incl-ude p16f 84. inc
config h'3ff3'
errorl-eveI -302 ;E1j-minate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for setting-up the ports
tOutw 04h ;Put 04 into w
,
.

coo
-
oa$:(9) 5x7 Display Circuits-2 etc Qc6a{ca$-6- ocg:q1oo6or3,ep'(t)

MOVWF O5h ; to make RA2 input for button A


MOVLW OOh ; Put O0 lnto W
MOVWF O6h ,'and make port 6 (port B) al-l output
BCF 03,5 ;Go to pageO for programming
MOVV'/F 1Ch
BCF 1F,7 ; Bit for tone
GOTO Marn

Tab1e1 ADDWF O2h,I ;Add W to Program Counter


RETLW O3h
RETLW O7h
RETLW O6h
RET],W O4h
RETLW O2h
RETLW O6h
RETLW O7h
RETLW O3h
RETLW O5h
RETLW O2h
RETLW O2h
RETIW O3h
RETLW O5h
RETLW O4h
RETLW O2h
RETLW O7h
RETLW O6h
RETLW O7h
RET].W O4h
RETLW O3h
RETLW O2h
RETLW O5h
RETLW O?h
RET],W O 5h

RETLW O3h
RETLW O2h
RETLW O2h
F.ETLI\r C3h
RETLI,{ O 4h
RETLW O5h
RETLW O4h
RETLW O3h
RETLW O7h
RETLW O4h
RETLW O6h
RETLW O7h
RETLW O2h
RETLI/I 03h
RETLW O4h
nrmi r.r n trL
I\LA!V! UJlI
RETLI^7 01h
Facel FIOVLIV O Oh ;place Lhe 5 values into the 5
IlrU\'W-E -L-Ln ; files to prociuce the first face
MOVLW O8h
l'1CVi,Jtr 12h

coa
oa$:(9) Sx7 Disptay Circuits-2 rtC Qc6ofiq$oo{o* sacq:q1oo5oE,qpt(q)

MOVLi^l 1Ch
MOV!{F i3h
IVIOVLW O8h
MOVWF 14h
MOVLW OOh
MOVWF 15h
GOTO Scan

Eace2 MOVLW 03h ;place the 5 values into the.5


MOVWF 11h ; files to Produce the second face
MOVLW O3h
MOVWF 12h
MOVLW 00h
MOVWF 13h
MOVLW 6Oh
MOVWF 14h
MOVLW 6Oh
MOVWF 15h
GOTO Scan
Face3 MOVLW 03h ;place the 5 values i-nto the 5
MOVWF 11h ; f iles to Produce the -rhlrd face
MOVLW OBh
MOVWF 12h
MOVLW 1Ch
MOVWF 13h
MOVI,W 68h
MOWF 14h
MOVLW 6Oh
MOVWF 15h
GOTO Scan
Face4 MOVLW 63h ;place the 5 values into the 5
MOWF 11h ; files to produce the fourth face
MOVLW 63h
MOVWF 12h
MOVLW OOh
MOWF 13h
MOVLW 63h
MOVWF 14h
MOVLW 63h
MOWF 15h I

GOTO Scan
Face5 MOVLW 63h ;place p.he 5 values into the 5
MOVWF 11h ; fil-es to produce the fifth face
MOVLW 5Bh
MOWF 12h
MOVLW 1Ch
MOVWF 13h
MOVLW 6Bh
MOWF 14h
MOVLW 53h
MOVWF 15h
GOTO Scan
Face6 BTFSS 1F,7
GOTO Face68
MOVLW OEBh ;place the 5 vafues into the 5

cco
-u$.(f) 5x7 Display Circuits-2 etC Qc6a{q$-fi * oa1:q1<-'o5co6,qp'(q)

MOVWF 11h ,'files to produce the sixth face


MOVLW 80h
MOVWF 13h
FaceSA MOVLW 6Bh
MOVWF 12h
MOVLW 6Bh
MOWF 14h
MOVLW 5Bh
MOVWF 15h
GOTO Scan
Face 68 MOVLW 68 ;This sub-routine only alfows the
MOVWF 11h ;tone to be produced
MOVI,W OO ;when the final face6 appears on
MOVWF 13h ;the screen.
GOTO Face6A
Scan BSF 05,1_ ;Reset 4017
NOP
BCF 05,1
MOVF 1l_h,0 ;Move file 11 into W
MOVWF O6h
CAI,L DelD
MOVWF O6h
CALL DelD
MOVF 13h,0 ;Move file 13 into W
MOVWF O6h
CAIL DelD
MOVF 14h,0 ;Move file 14 into W
MOVWF O6h
CALL DelD
MOVF 15h,0 ;Move fite 15 into W
MOWF. 06h
CALL DelD
RETURN
Del-D DECFSZ 1Bh,1 I

GOTO DefD
MOVLW 00h ; Zero port B to preven-u mirroring
MOVWF 06
clk BsE 05,0 ;Cfock the 4017
NOP
BCF 05,0
RETURN
XX MOVF l-Ch.0 ;Move 1C to W
CALL Table1
MOVWF 1Dh ;Move W to 1D for decrementing
DECFSZ 1Dh,1
GOTO XXi-
MOVLW OO ; Detects end of tabl-e
MOVWF 1Ch ; Zero 1C to start at top of table
GOTO XX
XX1 DECFSZ 1Dh,1
GOTO XX2
GOTO Facel
DECFSZ 1Dh,1
GOTO XX3
GOTO Face2

1a-1
Dispiay CircLrits-Z l-ic '--':i:X'o5c.:**";t,(q)
-*$:(9) 5>:7 Qr--5a$c3{*11.-,":

XX3 DtrCFSZ 1Dh,l


1/\'
U\J
^ ^m^I U AN '1
A

x)(4 DECtrSZ lDh,1


GOTO XX5
GOTO Face4
XX5 DECFSZ 1Dh.1
GOTO Face6
COTO Face5
Main MOVLW 30h ;Each 10h represents 100mS
MOVI\IF OCh
Mainl CALL XX
DECtrSZ OCh
GOTO Mainl
INCF 1C
MOVL!{ 4Oh ;Each 10h represenls 100mS
MOVUiF OCh
Main2 CALL XX ;Display Face for 40OmS
nFnraT nah
GOTO I"1arn2
I1.]'CF iC
NIOVLW 50h ;trach 10h represents i00mS
MOVI^IF OCh
Main3 CALL XX ;Display Fdce for 500mS
DECFSZ OCh
GOTO Main3
INCF 1C

MOVLW 6Oh ;Each 10h represents 100mS


MOVWF OCh
Main4 CALL XX ;Display Face for 600mS
DECF'S Z OCh
GOTO Marn4
INCF 1C
MOVLW ?Oh ;Each 10h represenl-s 100rnS
MOVWF OCh
Main5 CALL XX ;Display Face for 70OmS
DECFSZ OCh
GOTO Main5
INCF 1C
Main6 BSF 1F,7
CALL XX ,'Display .until button A pressed 's"-.
BTFSS 05,2 ;Test for button A
GOTO Main6
BCF 1F,7
GOTO Main

END

3ClJ
eai:(g) sxz D'spray ckcurts-2 Prc €o3a6.B1o$o orl, qoc3o6:qPdq)

9-1ou LED DICE WTTH SOUND-2


glo6:o3qc6og! s:cociciloS:a:3q1rBo5 qcio6:e,8qldor61o3@6o$rr o{oq6c63
oc5gS.ooEern5eoc tone oTcrgi sub-routine o:61<{ e@"3,O-2ic83:-","1cr$'
glo[,:o3qr6oc6c'5 source code q]rd ao:c6o3€arTQcoc:,-';lc-'2)r'

; LED Dice irith sound-2


fist p?ic16f 84
incfude pl6f84. inc
config h'3ff3'
errorlevel -302 ;Eliminate Bank warning
Start ORG 0x00
BSF 03,5 ;Go to pagel for setting up the pol!8
MOVIL 04h ; Put 04 into W
MOVI{F 05h ;to nake RA2 input for bulton A
MOVr9t 00h ; Put 00 into a
MOVWF 06h ;and nake port 6 (port B) alt output
BCF 03, 5 ;Go to page0 for progranning
l4ovwF lch
MOvItrF oFh ;zero the nun'ber of cycles for Tone
BCF lF.7 rBit for tone
CoTo Main
Tablel ADDI.TF 02h, I ;Add W to Progran Counler
RETl,t{ 03h
REAT,W 07h
RETLW O6h
RXTI,W 04h
RETT,W 02h
RETI,W O6h
RETr,Vt 07h
RETT,W 03h
RETLW Osh
RETI,!] O2h
RETtql 02ir
RETl,ri 03h
RETLW O5h
RETr-lt 04h
RETLW O2h
RETr-W 07h
RETLW O6h
RETLW O7h
RETLIi O4h
RETI,W O3h
RETLW O2h
RETI,W O5h
RETI,I'I O7h
RET],W O6h
RETLVI O3h
RET!I.i O2h
RETI,W O2h
RETII"T 03h
RETr,h' 04h
:.'.'.1 r./Fridv :, . \.2 .l: i ri t''r .:, : 1: ,'

RETlti C:h
Ra!Lii 04h
F.ET!'i 0lh
RETr,r.r 0 7lr
RETi!' C4h
P.ETI-\d0 6h
RETL',i O7h
F.ETLr.i 0 2il
F,ETIIi O3h
RETLi' O4h
RETLiI O5h
RETLI4 O6h
RETLIN O1h

Facel MOV].W 00h ;place rhe 5 values :-ito t,re 5


MOWVF 11h rliles to prc.tu.e the fi.st face
MOVtlt 08h
MO\,'i7F 12h
MOVI-W 1Ch
MOVWF L3h
MOVLW O8h
MOVWF 14h
MOVL!i 00h
MO!'IdF 15h
GOTO Scan
Face2 MOVLW 03h tPIace the 5 values inl:o the 5
MO!'!\iF 11b ; files to p.oduce the second face
MOVLI{ O3h
MOWF 12h
MOVLi{ 00h
MOvWt l3h
MOVLW 60h
MOVWF 14h
MOVLW 60h
MOWF 15h
GOTO Scan
Face3 MOVLW 03h ;place the 5 val-ues inlo the 5
MOV!nF 11h ;f:iles to procluce the third face
MOVLW OBh
MO!'i.]F 12h
MOVLW 1Ch
MOVWF 13h
MOVLW 68h
MOWE 14h
MOVLW 6Oh
MOWiF 15h
GOTO Scan
Face4 MOVLW 63h ;place the 5 values into the 5
MOVtnF l1h ;fiLes to produce the fourth face
MOVL!d 63h
MOV'{F 12h
MOVLW OOh
MOVtjF 13h
MOVLII 63h
MOVIVF 14h
@4d9) sxz Display circuits'2 ptc
E.5a{cA1@6M sooi,qooso6:qpd?)
MOVLW 63h
MO\,''!{F 15h
GOTO Scan
Eace5 Movlw 63h ;Place tbe 5 valu€s into the 5
MOVWE l1h ;files !o produce the fifth face
MOVLW 6Bh
MOVWE 12h
MOVLW 1Ch
MOVWE 13h
MOVI,W 6Bh
MO!'I.]F 14h
MOVT,W 63h
MOVWF 15h
GoTO Scan
Face6 BTFSC 1F,7
coTO Face6B
Face6A EOVLW 6Bh ;p1ace the 5 values into the 5
MO!'l{F l1h ;files to produce the sixlh face
MOVLW 6Bh
MOVI{F 12h
Irovlw 00h
MOWF 13h
MOVLW 6Bh
MO\,'t'iF 14h
MOVI,W 6Bh
MOVWF 15h
GOTO Scan
Face6B DECFSZ oFh,1 ; Decrenenl the tone cycfes
GoTO Face6C
INCF OFh,1
. GoTO Face6A
Face6C BSF 05,1 ;Reset 4 017
NOP
BCF 05,1
I4OVLW 6Bh
06h
MO1,'I{E
CAI,L Tone
MOVI,W 6Bh
MOVTiF 06h
CAil, Tone
MOVI,W OO
MO!'I]F 06h
CAI-L Tone
uovtw 6Bh
MO!'WF 06h
CALL Tone
MOVLW 6Bh
MO!'I{F O6h
CALL Tone
IIETURN
MOVIti oAh , The nuhber of cycles
MOVEE ODh
Tonel MOVI,W 60h ;the 0N and OFF tine
MOV|F oEh
MOVLW 80h ;Toqqle the piezo line

c.c
eoldg) 5x7 Display cirsits-2 Plc €do{ceq@6o:, e.i!$,cto3sJ':(r)

xoRr.lF 06h/ 1
Tone2 DECaSZ oih,1
cOIO Tone2
DECFSZ ODh,1
GOTO Tonel
GOTO Cl.k

9SF 05,1 ;Reset '101?


NOP
ECF 05,1
MOVE 11h,0 ;Move file 11 inlo W

tlov!1rE 06h
CALI, DelD
L1OVE 12h.0 ;Mowe fale 12 lnto w
MOl5iF O6h
CALL DelD
MOVF I3h,0 ;Move file 13 into I^1

iiCVI,iF C5h
C.'Ll,:)!:lil
iil\i Iln.0 ;l'lole Jif:'14 1nL:o i'l
rloVr/lt 0 6i1
CALL DeID
MOVF 15h,0 ;Move file 15 into W

MO!'I{F 06h
CAIL DelD
RETURN

DeID MOVI,ltO4h iA 2 file de]ay routine


IlovwF oDh ;to give sufficienl tine
DelE DECFSZ 0Eh,1 ,for lhe tone routine
GOTO DelE
DECFSZ 0Dh,1
GOTO DelE
l{O!'L!l 00h ;Zero Port B to prevent nirroring
MO!-WE 06
cfk BSF 05,0 rclock the 4017

BCF 05,0
RETURN

XX MO\rF 1Ch,0 iMove Ic to W

CALL Tabl e1
MOVWF 1Dh ;Move !{ to lD for decrementing
DECFSZ lDh,1
GOTO )O(1
MO\,' t 00 ;Detects end of tabfe
MO\/I,{F lch ;Zero 1c to start at top of table
GOTO )O(
xx1 DECFSZ lDh, L
coro xx2
GOTO Facel
xx2 DECFSZ 1Dh,1
GOTO XX3
GOTO Facez
XX3 DECFSZ lDh,1

33G
5x7 Display circuits-2 F'u 9.Don.?eoElo sa:q oooc:qp:l?l
'oi:(9)
GOTO XX4
GOTO Eace3
xx4 DECFSZ 1Dh,1
GOTO XX5
GOTO Face4
DECFSZ lDh, 1
GOTO FaceS
GOTO Face5

BSF 0Fh,5 ;set 32 cycles for lone


MOVI,W 05 ;5 faces before final face
MOlniF 1E
Mainl MOVT,W 10h
MOVWF OCh
I']a in 2 cAr-r- xx
DECFSZ och
GoTO Main2
INCF 1C,1
DECFSZ 1Eh,1
GOTO Mainl
BSF 1F,7 ;tone wil] only sound duri4g final display
Main3 CA].L XX ;DispLay untif button A pressed
BTFSS 05,2 ;Test for button A
GOTO Main3
BCF 1Fh, ?
GOTo Main

END

oa:g8po8ocAeoc o6:co8qrfqp:cE eo:crSca8aocBcoc6eoT[<ip:e$rr

9-1rn IAAKINO A ToNE

5x7 display c,cLrlt board 4-{,GLE, u{q36 sooH. a$.$eo: rone 3,rio,6ec8o56di
c\r,*,8 EsrSco:odo3,o6q1o5-61@3o r , j
.ol,ri'.61-".ca - sorce code cf e -::c6%Sc,ilpccn: !S r

;Creating a tone
Iast p=pic15f84
include p16f84. inc
_confiq h'3ff3,
errorlevel -302 ; Ellnirale Btrnk lrdrni trg

Starl oRG 0x00


BSE 03,5 ;GO 'Lo pa9c1 .or seLting u? '!he po.:s
Itovtll 00h ; Pul C0 into r,'
MOr,.riF 05h nLake ail P,A lii3s ol-L.ri:
MOWF 06h aLr Rl li..i out::t
BCF 03, 5 'i:kc
io Pnlie0 ioi .r..9::irnii.
@a4:(t) 5x7 Display ckcuits'2 Prc q.6o{.B$@$o' o1:qrodcDSrqP'(q)
:
Td.el BsF 06,7 ;Lhis is lhe Piezo line Turn it oN
C.arI,t DelaY ; Call Delay
BCF 06,? ;Turn oif rhe piezo
CAI,L Delay ; Call DelaY
GOTO Tonel ;RePea! the loutine
Delay DECESZ lAh'l ;Delay for tone
GOTO Delay
RETURN

END

9-1r PRoDUCING A BEEP

5x7 di ard ol BEEP

3?oo) gleo6 3'D99 cu6:ca€


piezo :6c, LdE; 3 n":e1

,'l1"d rr

- -3,"6,o5qp'5cacaci source code cfl esa:.6c63n"TS-o,arE!'r

;Creating a beeP beeP beeP


list p:pic16f84
incfude p16f84. in
confis h'3ff3f
errorlewel -302 ;Elininate Bank varninq
SLart ORG 0x00
BsF 03.5 ;Go to pagel for settinq-uP the Ports
MO\.r,r{ 00h ;Put 00 into w
MOVWF 05h , to make aII BA lines outPu!
litoln.lE 06h ;to nake aII RB fines oulput
BcF 03,5 ;Go to Pageo for proqran''ning
Beep MOVLW 40h
MO!'!'iF 1Bh
Beepl BsE 06,? ;This is the piezo fine Tuln it ON

cAl-L Delay ;caff Defay


BcF 06,7 ;Turn off the Piezo
cAl,L DeIaY
DECFSZ 1Bh,l. ;RePeat for 40h cycfes
GOTO BeePL
cAl,L longDe] ;call Long DelaY
GoTo BeeP ;Repeat the routine Delay
MOVLW 40h
MOWF 1Ah
Delayl DeCFSz IAh.I ;DFldY for BeeP
GoTo Delayl
RETURN

longDeL MovLw 04 ;Long delay betEeen beeps


MOVWF 1Ch
DeL2 DECESZ 1Ah,1
GoTO Del2
5x7 Dispray circuits-2 prc qd6{%io{M e+,etoo3o3:qpd?)
'ai:(9)
DECFSZ 1Bh,1
coTo DeI2
DECFSZ lch, 1
GOTO DEL2
RETURN

END

9-J?[ BEEP AFTER BUTTON A, B AND C

g1lo6:3r6qd%3 aqo5 A .{
$6q91€ BEEe @a>o:61cArf e oTcu:p:r ao2o6 e c{
$.5q91€ BEEP @ari6e"g.5e,,,Tco:cr:: oo2o8 c c{ $8elt BEEe @a1+:1 cgcieoTo,oeo:€
01o96co:cd sa8-,oio:61 @6-p!'r
o3,o6:ar6q1c6"rcaci source code rf eo:cicgteoT$coc:oEjrr

;Beep after Button A, B and C


fist p=pic15f84
incfude p16f84 . inc
config h'31f3,
errorlevel 302 ;Elininate Bank warninq
start ORG 0x00
BSF 03,5 ;co to pagel for setting-up the ports
Mo\,-ttt 00h ;Put 00 into: w
MOVtli 1c ;Put 0001 1100 into Id
Mow,rF 05h ;nake RA2, p,A3 and F-A4 rnput
MOvLI,i 00h
ljov-dF 06h ;nake all RE lines ourpui
BCF lil,5 ;co !o Paqe0 for prcqra:ri:rirq
CITO Maln

tiiA BTFSS 05,2 ; Is s\r:lch !, fLshed?


COIO SnA2 ; YES.
l!:OvF 11h,0 ;No. copy tth into'r'i
ONh
IoRLr-i ;xOR !i lrith 00
IT|SS 0:, 2 ; Is file 11h:0 ?
GOTO SnrAl ; NO.
FnTURl.l ; YES .

SFA1 tECF 11h, I ;Decremenir tne .ielrounce tjle


RE!-LTRI]
S 12 l.!ol.rF 11h.0 ;i1h is.he debounce iile
xoRl,ti 00h
ETISS 03.2 ; Is Iite L1h=0?
RETUil.i ; N'O.
CI-LL BeePl ; YES.
Iioflli 80h ;I,oad li irith 80h 1..p3
l":O!i',rF L1h ;Ijlt 80l] irto d.b.)ri.. aile
IETURT

.r3
ooidg) sx7 Disptay Circ'.rits-2 prc
Qc,ta{oa9co6cur oq:epo5c.,3:qD,(1)

BTFSS 05,3 ; Is siitch B p.;shed?


GOTO SwB2 ,YES-
lvrovF 12h,0 ;NO. copy 12h into w
xoRl,vr 00h ;XOR Ii with 00
BTFSS 03,2 ; Is file l.2h-0?
GOTO SwBl , NO.
RETURN
SrBl DECF 12h,1 ; Decrement the debounce fife
RETURN
SrB2 MOVP 12h.0 ;12h is the debounce file
xoRlw 00h
BTFSS 03,2 ;Is file 12h=0?
RETURN
'NO.r: -
CAI,L Beeb2
MOYIW 80h_ ,Load I,r with 8Oh loops
MowF 12h.- ;Put 80h into debounce file
RETURN

BTFSS 05,4 ; Is s'ji'rch C pushed?


GOTO SwC2 ;M.
MOVF 13h,0 ;NO. coly 13h into il
xoRrvr 00b ;XOR I.1 rith 00
BTFSS 03,2 ; Is -'ile 13h:0 ?
GOTO SwCl ; NO.
RETURN
SwCI DECE 13h,1 ; Decrement the debounce file
RETURN
MOVF 13h,0 ;13h is the debounce file
xoRrw 00h
BTESS 03,2 , fs file 1Dh=0?
RETURN ,NO.
CAI,L Beep3
MOVI,W 8Oh i load ld with 80h loops
MOVWF 13h ; Put 80h irito debounce file
RETI'RN

Beepl MOVT.W 40h


MO!'liF ].Bh
Beepx BSF 06,7 rThis is the piezo line. Turn it oN
cAl-r Delay ;Cafl Defay
BCF 06,7 ;Turn off the .piezo
CAiI- Delay
DECFSZ 1Bh,1 ;Repeat for 40h cycles
GOTO Beepx
RNTURN

Beep2 CAI-L Beepl


cAlL lrongDel
CALL Beepl
RETURN

Beep3 CALL Beepl


cALl ]JongDel
CALL Beepl
cAl-i, LongDel
@61d9) 5x7 Dispray circuits-2 Plc qd6{.e$o{o otri:qpo3o6,qpd?)

CALL Beepl
RETURN

Delay MoVLW 30h


MO\,'I,IE lAh
Delayl DECFSZ 1Ah,1 ;Defay for Beep
GOTo Delayl
RETURN

LongDef MOVLW 01
MO!'I{E 1Ch
DeI2 DECFSZ 1Ah,1
GOTO Def2
DECFSZ 18h,1
GOTO De12
DECFSZ 1Ch,1
GOTO Del2
RETURN

Main CALI- SwA


CAL]- St{B
CAI-I- SwC
GOTO Main

END

9-J9r HEE HAW 5IREN

gloS:ar6qlo5od Hee Haw caqcieo:E@ei eacrorSlcgo5eoTo:aes::3 Qpa6eo:c2i


o3,o6q1c6"'6q@6-p)rr e::rcgcicucop ococnc3<u9 LEDqp:$dara!: qo8o?o5$o5".3
co6:c':rec'cS3.o$ rr

o:3,r3'"r3q.ts-q.3 source code c{es::cf q3ecilQcoa:og!

;Hee liaw Siie! ith flashlng LEDS


list p:picl5f84
include p161 84 . inc
_conf iq h'3f i3'
crrorler€l -:!2 ;tlrminaic Bark Liar.rng
start oRG l!00
BsF 03.5 ;co to pagol io. seitirg up Lhc pofrs
IlOVL'rl 00jr ;:ui 00 :nto I,i
IiO.rriF 05n ; to nake afl R,\ fiLres cuiDut
}joti'rF 06iI ;-. r:ke all RB fi.es oL.DLi
BcI 03,5 iGc :o Paqe0 t.r prograa'nirg

;He€ - ihis is tne LOi.J irequercy


liee t{Oril,ti Cr'Fh
!lo!''rlLr 06 ;iLin ou slr I rlrs
l40vl it c,l

JIJ
sai,(9) 5x7 Display circuits-2 ptc
Q,r5o6,€g@6M $esJocANs,qp:(?)
MOV-!!E 1C
lleel MOVL'T 080h
MOVI'iE LB
Hee2 MOVLti 80h ;Toggte the piezo line.
xoRnF 06h,1
MOVLW OBOh
MOVWF 1Ah
CAI,L Delay ; Cal] Delay
DECFSZ 18,1
GO'[O Hee2 ;Repeat the routine as per file 18
DECFSZ lC,1
GOTO 8ee1

;fiaw - This is lhe Hlcll frequency


Haw MOVLW 00
MOl'liS 06 ;Turn OFF all LEDS
MOVLW 04
MOVi,rF 1C
Ilanl MOvLw 0D0h ;Create D0 loops
tvlcvr,rE 1B
Hav2 MOVL!! 80h ;ToggLe the piezo line.
xoRWF 06h,1
MOVI,W 80h
MOVWF 1Ah
CALL Delay ;Call De]ay
DECFSZ 18,1
GOTO Han2 ;Repeal tlie routine as per file 18
DECFSZ 1C,1
GOTO flaw1
GOTO Hee

Delay DECFSZ 1Ah,1 ;length of ON and OEF time for tone


GOTO Delay
RETURN

END

g-Jo" CALLIN6 HEE HAW ROUTTNE

glo5r":6qo5o$ Hee Haw routine o? cai{. oALL


oq.6 e of $6c$oEqie Hee Haw @3r (9)@6cgdco?$:6{ac'5 "?8qedd ""T[6€:86-dil
q3o'q.oe.*"d6.ce9n
o€:o6:o5q1c6oca.f source code c{eoccr5c68eoTQcoc:oplr

; CaII inq Eee Haw siren


list p:pic16f84
include p16f84 . inc
_config h'3ff3'
errorlevel -302 ;Elininate Bank Rarnjng
Start ORG 0x00
BSF 03,5 ;Go io pagel to set up the ports
MOVtll 08h ;Load W riEh 0000 1000
MO!'WF 05h ,to nake IIA3 input

cJJ
r
Prc q06.6,"io6M oJ?:qoc3os,qpd?)

MOVLti00h ;Put 00 into W


MOVWF 06h ;to make all RB fines oulpul
BcE 03,5 ;Go to Pageo for prcgraming
GOTO Mai.j

;Hee this is the I-OW f.equency


Hee MOVLW oFFh
MOVWF 01t ;Turn oN aff LEDS
MOV] ti 04
MOVWF 1C
Heel MOvLI4l 080h
MO\,'I{F 18
llee2 MovLll 80h ;Toggle the piezo line.
xoRltF 06h,1
MOVLIN OBOh
MO\.7t'tE 1Ah
cAlL Delay ; cafl Delay
DECFSZ 18, 1
GOTo Hee2 ;Repeat the routine as per fife 18
DECFSZ 1C, 1
GOTO Heel

;Haw This ls the ITIGH frequency


Haw MOVi,W 00
MOVWF 06 ;Turn OFF all LEDS
MOVLr'i 0 4
MOvItF 1C
Ha!r1 MOVLW 0D0h ;Create D0 noops
t4ovltF 18
Haa2 l.1OV1,lJ 80h ;Toggfe the piezo line.
loRI.lF 06h,1
I{OVLr' 80h
llovi{f lrth
ar!-,I- D: ;! ;::L1 iel:l
)..,aa1 a,
aiC.i- :::j,;r ;l\;.:ai ihe !.jL ,L. -:rj ;:r i!l: ii
i-CFiZ iC, a
GCIC Haul
RE!URI]

Delay DECESZ 14h,i ;Length of ON and oFF Lime for tone


GOTOLef..y
AETU.
Maia BTaSS 05,: ;is bDiion B pressed?
GOTO rlair ;li
MOVt14 05 ;Yes. Create .-c loo:,s lor ilee rraii
I.IQV I i D]l
l4ain1 CALL llee
DECFSZ 1Dh,1
GOTO Mainl
i'lain2 CALL Deiay
BTFsc 05.3 ;Is button B released?

.Ja
s+id9) 5x7 Display Circu,rs 2 Prc F.,5o$,E{o-qo, o:1:q<-ro5c.:3'cpdp)

GOTO iiain2 ,iio


GOTO Main ;Yes bulton B is leleased!
END

9-36rr A4AKIN6 A NOTE

g;lo5:o3q1c'5c>pi Note .,clo,6qd 6d3iFoTcqo5qed46"T@oE!


"6,":3q1.6
o:61@6oE!rr €oTcaa3.$dco, Note o:iof1ca3 o{cg36$"$oieaSec,o$rr
"SoX.o,
4{.6dlceo5qic-, Note qp:c{ eo13:o3$: .!oi (tune) qp:{ o$d:i86,.>crdr
Note saooragc{ ON tlme (ihe HIGH for the noie) o6q93. OFF time (the LOW for the
note) or3?o?G3.dpd!:coa:ol ereiu Delay loop qp,cAecrqpf"e.tqdS: c$sa8op) ttote:a:r
o)oi3eqlcD oqceco.? 6(,r o?o){coroe9r
eo,c'5c,1Q(9-g)cet Middte Note "c" c$€: cycte o:69Qc{ eoTQcoc:t,ilo2!r, {Qc63
ON time it. OFF time o?..{ 1929 micro sec. qcoql sub-routine "C' G€, 6oTc?o5coc:83:
G6r,d-

1929
L/\cro l.'r
ii 1929 nicro
seco.ds semnds

One Cycle of Noie "C"

Q(9-0) Middte Note "C' <{3: cyctecoEq{

<.,{oe13q€ Oetay ci I 'units of time" (ono unjt of time for each NOP and DECFSZ and
two units for GOTO) 3ro3sa"r11"peo€ 8Q€:q3coo:oilo:pirr File 14.A F0 (240) o$$: 6o:coa:
z+ox a = tszo microseconds ot delay of$6e"Teoe'glrr
'c@3.
I
"C" sub-routine o2! micro-seconds (CALL = 2 microseconds) and GOTO takes 2
microseconds) qeg:r ef.dn: delay cycle or?q g microseconds 3e{}o;eore@:3. gqeol8:
oN time oei 1929 microseconds $6opj'r "ao:"'q<,3 oFF time Delo)e9: 1929 micro-
seconos o8@6o2lrr o{:,o1 .{c6€3::$ [1/(2x1929 rnicrosec = zeo Hz] GSoeil )
o,€,-{,i,ard Nriddte Note "c":ocB.t 6oo59dcoo:eccco{c633@6oag 261.63Hz 93. -oai
fi:o6@:3:eqqe,-'o2)'
,:r3:o6'o3q1.6"aqci source code c{er:rricg8 noT@coo, o p! rr

;Making a Note r,1lddle "c"


list p=pic16f84
include p16f84 inc
_conf i9 h'lf f :'

looc q96 o{qo1{o - rJ9- o3:ocAo3:


5x7 Djspay cncuils-2 Prc q.,5o{%lo{M oal:qoo3o6,qP(1)
'o6:(9)
errorlevel -302 ;Eliminare Banl nrninq

start oRG 0x00


BSF 03,5 ;co ro pagel to scr up rhe ports
MoVLll 00h ;Put 00 lnto ti
MOVWF 05h ;Make all RA lines ouiput
06h
Mo\.!nF ;Make aIL RB libes ourplt
BCr 03f 5 ;Go to Pageo for proqrar ning

r Producing
C MoVLw 80h ;Toggle lhe piezo 1ine.
xoRliF 06h,1
MOVI,W OFOh
MO!'r'iE 1Ah
CAIL Delay tcafl Defay
GOTO C tRepeat the routine
Delay NOP ;Length of ON and OEF time for Note
NOP
NOF
NOP
NOP
DECFSZ 14h,1
GOTO Delay
RETURN

END

t-J? CREATINO A scALE

g]o6:e>6qldalei Middle "c" g lJpper "C" sed 8 notes <.io€ea:c octave dr6
saqc6 note scaie cn6?,f 6dcl.coTc?c36icdc'? .0T063,G6a>d'r
..T"?"6"?"3.-, Note o:5of 16s:qcA doX63r' oqc33866l$.$o8eoo2)l {.3.
eoTca"5q$eu Note qp:cri e,i3:o5[!: cSol (tune) qp:c'l oio3:{€eooplrr
glo6'a,5ql.6ce€ qdo{cgq-6"lro?%.,5 .aa7:Q-r,noc R-c osclllalor soi: 4 MHz
crystal oscillator c{ e@3:oi:oci:S1o3.@c3' o@Gtc$olodr cf.goc o3atrearr o{c636
qp,.fl 6i6{e"d@6cood' 4.-G€ qq@d.oeGtr sar:of@::cQq9l6 piezo.oor: speaker
eac,:5m: c{e@o€:c}o:8:oter3,o1op!rr
<u3,o6,.,6q.6o.6.6 source mde rrf carrf cate"TSco:'o2i'r

; Creatang a SCAI,E
lisr p:picl6f8a
include pl6f84 . inc
_config h'3ff3'
errorlevel -302 ;Elininate Bank warninq
Start ORG 0x00
Bsi C3,5 ,Go to pa9e1 i.o se! up the porrs

.J3
i., r. . ,i,: .... l,:,
' ,,.
I'l!!il,il lrlilr ;'fl: 00 1n[. -i]
fiovi-r! 05r ;iiake all FA frres ou.pLjr:
I'lCF.li 06i r:.lal.e ;.li lll .1i..: .tlpri
Bca 03,5 ;co Lo 1,aEe0 for prcgrarniii{.r
L.OTO l4arn

i.loie Movlll 80h ;Toggfe t:re piez. line-


xoRl.il 06h, 1
IIOVF ti\,0 ;copy file 1A into u
I.1ovi'rr lch ;l.rore i7 into file 1C
CALI, Defay ; CalI Delay
DECESZ 18h.1 ;Dec file 1B fcr length of note
GOIO Not€
RETUFN

Delay NO! ;i,enqth oi oN a.d oEi tine for Noire


NOP
NC?
uoP
ll0t
iEaasz lah,1
COTC D:i.iy
RETURN

Main MOVLIi 0F0h ; Frequency oi note C 261112


MO\4dF 1Ah
MOVI,I{ 80h ;Lenqth of note C
MOVllr'1Bh
CAU, Noie
Movl,in 0D:n ; Frequency of note D - 293;12
MOV!,IF 1Ah
l.lovll,'i 90h ;Lenqth of noie D
MOVWF lEh
CAI,L Note
Movllt oBDh rFrequency of note E 330H2
MOVWF 1AN
MOVL!i OACh ;length of note E
MOr/",nF LBh
CAll Note
0B2h
MOvLI.i ;Frequency of note F 349H2
MOv_r"lF 1Ah
MovLW 0B0h ;length of note F
MOVhIF lBh
CALI, Note
tlor/r,i'i 09ilh ;Frequency of note G 392H2
MOIWF lAh
I4Or.rLIn 0C0t: ;tengih ot note c
MOV'dF 18!
CAr,L Noie
uol/],fi 03Dn ;Frequency of noie A 41Nf.
MOVhF tAh
MCVi,'rr llD0l , Leng'Lh oi note A
l10t!li 1Li
cAlL r,o|c
MCi.rL !r-'l ,Frequency of nole B ttlL.

.:6
soldg) 5x7 Display circuits 2 Prc E.3.6 io6o o+:qoc6o6:qPd?)

MOV\,iF lAh
MOVLIT 0E0h ;Lengtb of note E
MO\,'I,[F lBh
CALL NOtE
MOVLIi 077h ;Frequency of note c' 52392
MOVWI'lAh
MovLW 0F0h ;Length of note c'
lBh
MO\,'I{E
CAI,L Note
GOTO Main

END

g-Jorr CREATIN6 A TUNE

glo6ro6q1.6ergl Note o:6q13:ecao5 sub-routine ci cE)c$.setup cAOq"ei.{


."rGE3,G6-P:'
o:€:o6:o6q1c6oqci source code npera:c6q€eoT$cor:ar2jrr

;Creating a TUNE
list p:pic16f84
inctude p16f84. inc
_conf iq h'3f f 3'
errorlevel 302 ;Elininate Bank warnins
Start ORG 0:00
BSF 03,5 ;co to pagel to sel up tne ports
MOVLh lOh ;Put 00 into 9,r

MOwlF 05h ;Make aff P.A fines outpui


MO!'''I 06h ;Make all RB ]ines outpur
BCF 03,5 ;Go to Pageo for programing
GOTO l{:in

c Novl,'/t 8 0h
l!ajtiif :-Bi!

toRilF 116.,1
140!'ttt 0luh
i'lo\r.rlF 1!-h
CALI- Delay ; CalI DeLay
DEC|SZ tBh.1 ;Dec file 1l ior lenoih of note
GOTO Noiec
RETUJ]N

D I']ovtnr 90h
110\rFF 1Bh
Nc'.cD llot],tl Elr ;ToqgLe .he plezo tjne.
loRi.i! !r6il, l
!,ioirl,ti 0u5h
t1o./tiF 1Ah
CAlt aelay ; Call Delay
DEaaSz lBn,l ;Dec Ij -- 1E foi 1--n9th of nor.
GO1O 1l'rl e D
sEdg) sx7 Display circ'ri!s'2 nu tosacSqoaM o1l:fl ocr,ax:qP:(?)
REl'URN

E MO\rr !t 0A0h
MOViNF lBh
NoleE MOvLli 80h ;ToqgLe the prezo tine.
xoRI{F 06h,1
MOVI,W OBDh
MO\ll{F lAlr
CALL Delay ;CaU Delay
DECFSZ 18h,1 iDec fife 1B for fenqth of note
GOTo NoteE
RETURN

F MO!.LW 0B0h
MOV9TF lBh
NoteF . MOVLW 80h ;Toggle the piezo tine.
xoRhF 06h,I
MOVLW OB2h
MO\,-!{F 1Ah
CALL Defay ; Calf De]ay
DECFSZ 1Bh,l ;Dec file 18 for lengrh of nore
GOTo NoteE
RETURN

C MOVLW OCOh
MO\,T{F 1Bh
Notec MOVLW 80h r Toggl'e the piezo 1ane.
xoRt{F 05h,1
MOVl,9t 9Fh
MO!'!{E lAh
cALr-Delay rcall Det.ay
DECFSZ 18h,1 ;Dec file 18 for fength of nore
GOTo NoteG
RETURN

A MOtaLW 0D0h
MO!'I{F lBh
NoteA MOVl,9t 80h ;Toggle the piezo ]ine.
xoRwF 05h,1
MOVI,W 8Dh
MO!'WF 1Ah
CAll, Delay ;Calf Delay
DECFSZ lBh,l ;Dec file LB for length of nore
GOTO NOTEA
RETURN

BB MOVI,W OEOh
MOVWF 1Bh
NoteB MOVL'T 80h ;Toggfe the piezo tine.
xoRhrE 06h,1
MOVLW 7Eb
MO!'IIE lAh
CALL Defay ; caff Delay
DECFSZ 18h,1 ;Dec file 1B for lengEh of note
GOTO NoteB
-oi:(9) 5x7 Display circuits 2 Prc €o3.{("$@{o o.i:{oo3d5!q}(e)
RETURN

cc Movlli 0F0h
MOVWF 1Bh
NoteCC MOVLW 80h ;Toggle the piezo line.
xoRWF 05h,1
MOVLB 77h
MOVWF 1Ah
CAl,]- Delay ; call Delay
DECFSZ 1Bh.1 ;Dec file 18 for length of note
GOTO NoteCC
TTXTURN

Defay NOP ;Lenglh of ON and OFF titne for Note


NOP
NOP
NOP
NOP
DECESZ 1Ah,1
GOTO De]ay
RETURN

Main CALL C
CALI E
CAI,L F

CAL], G
CA],T G
CAL], G
CA],I G
.CALI G
CA],L C
CALI E
CALL F

CAL], G
CAI,L G
CAL]- G
CAL]- G

CALI E
CALI- F

CALL C
CA],I G
CALL E
CALI E

CALI, C
CALI C
CALL E
CALL E

JJE
rait(9) s'7 Djrprr/ cfiu L--2 r,c e-:i-;-lu r+: alc a o:: tp:l ri l

c;T,L il
cALl, t)
cnLL t)
CILL D
CA.LI, O
C.],Ll, Delay
C-ILL aefry
cAt,L ;l
CAIL D

C-ALL C
CALL C
C4LL Delay
CALL C
CALL C

CALI. E
ci Li,

CAL]. G
CALL !.
CAL]- F
cAtt
CALI, F
CALI
CALL
F

CALL G
CA].L G
CALL
CAL!

CALI D
CALL D
CAI,L Deray
CALi D

CALL I)
CALL C
CALL C
CALI C
c-1Lt -.:tar,,
CALL C
GOIO Main
oaido) Plc circuils Gallery 2 Prc qda6(€4@{o, elQ:etocaos:qP(?)

*1dc)
PIC Circuits Gallery - 2

g-cr fslf:
ieSo.rSCrS website:http//www hobby-€lec org eoT@co:,eo: PIC Circuits Gallery
"63
oo5co6:qp:"ae@c8:r'i etc {c,5a{c6$o{cucocT:q1oo5co6:qp: .,Q€dJ)oca?8c6€ 0'16{;
0160.3 6,rTE50:G6ol.rp!r' glc".$'q3 a1${nqn r,".rru"5-6:e{gc{aocfc".A"oTSolepl'r
Experiment o6q1€:ocgci oo5co6:o:ple"-.f,q, Software Flow
"o8c'>6'-.93c,?6Qr
Chart g€. Source Code file of.c{ q:oD€oTlcDr:ollrreir Source Code file.'i Hex file 3?GB
e[n8:ciepca€ N,4PAsM-wIN.EXE (.?) t.lpLne tDEoi 3?oi:Gt{€ d] rr2!r q{c,:oecr: Hexfile
cl| EPlc prosrammer uoaro @t. oo5{€9 Plc {do6%1cofior4€6cf. co$q€'p:qco6
oo8coS'o"16o78Qofl eco-cm@2)gfi 3<.'1o2lrr

O-Jr Stepper Motor Controller


Stepper motor se{t: Gror:qprgc$<-'1o2! rr o3:oi.gc
- Unipolar type
- Bipolar type
- Single-phase type
- lirJlti-pahse type oo2l{$6@<-'1op!r'
-3,o1.3?td 2-phase unipolar PL4 type stepper motor oo3c3 etctora+n
€,r5a{,€ic"{orc,i aa:g:Q1S: Controlter <-'cEo:3'":61 o:2!e;o'.6E.{
"oTQolcpin

0-J-cn Stepper lvloto, -e&e6,i


PNI type siepper molor :a{i:saoc:c63
permanent magnet c'i rotor 3rG6 :ac?:Gt@:
ldiEner) coil qp:{ stator
""Tc63
<-'cEcoc,<-'llopj'
q6or3?3?G5 4-potes 6€rrc stepper motor
oo31 o:p!eeoc.'5qc{ Q(9-c)ce8 .olEcor:
cilar2jrr {ee5o'r:.acao5 one step cA3 90
aegrees <o$oo5opi@5eoo$n
+-poles fiopi:acaci =aop,c$c8ca€
\nccrr ncoru L?Gr--J r8lco)oqgE: Grrcoim
%3 ( '/coil, Tcoil ) c2eo: .At€-6,i86"ooeln
n.3o-,o.up!odg91$:coo:93. -d""5?J:ord
:D.nc? cot:6o:6.9r>%o 3acomorcBlcqP: c
9(9 c)4 ooles-stepper motor o169o2lea,,o5Q
o4(g) Plc Circ,rrts Gaiiery-2 prc
{cJ5o{%{co{oD o.q,xoo5<u6,op(c)

@d6:eocp! q*33:e@c3'.€ d$,eo:np<-'cgil


9c{cuc6oo2lopicrn:qpsaoit: cogicro6e os$o%ri c,i13qp:c{€,cd,,'ll ecu:q6o,e$
qp: eo:ept,c2l,r

XI[IYIY
0101
1001
1010
0110
{(S-t) q"{-.6;-dcc;$cw9ool3:<oploo5eEQ
qa{coc6acop!opico::p j8.{.a$ o$corr qe{€, cu$odeodoqo5 c{g8qp:.'?
eocBd ec,:"q6 aeQq:: er.lqeotr$n
Gounterclockwisg control
x, X, Yand T{.ofeor$dloEoolooiSrd$:eo:qeoc$r
1l = Q.o::QE.oe$rr o= $.or:{6.ec@)

l;Fl;FF,"*r',1
F-i,-l'*ii
trriilrl
lrio iir]
ll roii

3?J
@4dJ) Plc circuits Galery - 2 Prc q.ae{oaEcD{c\, o4:qodcDs:sd?)

X IX IY IY
0101
0110
010
100l

Q(9- q) f"{-.3ac"$o$corqpg€.$.crg3oo63?oi€:odoo56f {
.aco.r5"l q qp:=aq rotor c)e! stator poles
g6qo\ :aco,-'5eq9q3 o:p!p5eg@@: stator
pole o:6oc6ocAfi
Q.ocro.@.@':€rcgc,ai3 *c$o8aic6.-'@6erjlorcr:: rotor o3oleccc cf
cr:pl od9@3e<-rTeo::p! rr

Stepper motor olcg:@c:eo:=oq2!oqt:g: -.8$'saqdQer6$3?Gfqp:coTgc.re9$ o3q1


ec> 5"{ecoc3.co2!od9c{ S1o76eo"{3$E:o8@6tr d' {@Ge rolor.{ o5-X
":g!$6e$ca8
eor o5c$cie1c6or:oc5ecpcr5e<.':g@c3. ord$63"":oJd#i: (Slationary torquehDaqcoeq:
Q$@:<r:@e8: eo'4qeoo2lrr
'--
{6+€oT0co"rcr$-stepper ccEc.rrcas ne steps c,f "ac9:Spoc:o@€. step angle o$
7.5 degrees @6op!r gc{co.'5;co::epool3:co2ioo59"acac$ od$:eaqc,5@qp:eo:coc:Q.'f
eo:c6,.,1eoc:cg3 eco.cuc@pi ol rr

The case of the clockwise control is shown below


The combination of )(, X, Y and l.epeats four patterns

IXyySteparsle Xf;yyStepangle
0I 0I 00. 0 1 0 1 1800'
1001 '7.5" I 0 0 I 187.5.
l0t0 15.0. 1010 t95.0.
0 tl0 22.5. 01102025"
0i01 30.0. 0 I 0 I 2100"
I 00I 17 5" I 0 0 I 217 5"
I 010 4500 I010 225 0"
0r 10 52.5' 0110232.5"
0101 60.0' 0101 240.0"

.??
ooi3(r) Prc circlits Gallery- 2 Prc €.nai.Sro{o -4=p":."5,qp'(q)

I 001 67.5' I00 !

010 7i 0" 1010 t5i 0'


0 1r0 82 5' 0ll0 t6:.5'
0 l0r 90.0" 0l0l 2 t-0 a'
1 001 97.s' 1001 211.5"

I 0t0 105 0' l0l0 235 0"

0 110 tt2 5" 0110 292 5'


0 t0t 120 0" 010I 300 0'
I 001 127 5' l00l 307 5"

I 010 13i 0' 1010 315 0'


0 110 142.5' 0l l0
0 10i 0101 310 0'
I 001 157_5' l,iu l
I 0t0 165 0' 1010 3,15 0'
0 !10 1'.72.5' 0110 352 5"

STEPPEB I,iOTOF
(4?SPtl-24DCZA)
Dl
i0l FB TF2
IC2 | _." 117 r-3li

;rooI
t, D a-+ o.]-f
,-,
/// 3

RE5 RA?

RB7

882

lnI BBI OS[] lrll:PlCl$F84A


IC2:70LUF
rBt;2sct9t5
BE', !s!l TFz: ?SDl?rlsI
'+ | \u {\m {" TR3:2SDl1!3(
TB4: !s0120![
ILEFI !T!F IBIGNI I TRs: ?SDl ?08r,:
' .47 ,..7 /-7

Stepper N.loro' Conl o le' oc8't;:o)ei6.c'r.A+


Q(g-9)
o"{dd PIC crrcuits Galle.v- 2 Prc €.,5a{%1cofi <\r o:,i:qpdo5:{rdp)

,-'o5-6,c63 eacl:Q1co":arei stepper motor er\ naor:oqciocu.6qp:E,


"o:c6,i"r{3'
@6dlc,p!rr
2-phase unipolar PM type stepper motor with 48 poles
Step angle
7 5 degrees ( 360 degrees/48 )
Drive voltage : 5 to 6V
Coi cuffent :250mA(5V)/2 coils

(P,A,FB hod.)
(F€ Pu I I -@ oFF)
0110 ?

(sPD cont iiit itl)

set C|l dota(o1l0)


S€t cfl .hta(0101)

Set CU ddt.(1010)

[l](I I Ie(a l)

S€t Cl dita(1001)
Set C€l{ ddta{Io10)
set ccu dat.(o110)
Set C$ dald(0101

aet ddtd(0101)

Q
(5-g) stepoer votor Controller Flow chartE
-4'(9) Plc circllits Galrery-2 Plc q.Bo{,zi@{o -i-s<,c8co3,9.(q)

Stepper Moioi Cori,roller s:<6cr5 assembty lenguege S3.e<',::-=:cc::c3-E sor.lrc6 code


(asm file) cl? eorc,5ca€."T$cor: o1"rpi'r

Scepper lilotor contlol1er

; Autho! : Seiichi rnoue

List p:pic15f84a
include p16f84a. rnc
_config _hs_osc & wdt_off & _Pwrie_on & _cP off
errorlele1 -302 ;Eliminate bank warninq
T,abel Definition
cblock h'0c'
;operation mode
;0=sEop 1=riSht 2:left
count2 ; l'iail counter {for lmsec)

rb0 equ 0 ;RBo of PORTB


rb1 equ 1 ; RB1 of PoRTB
tb2 equ 2 ;RB2 of PORTB
.Eb5 equ 5 , Bqs of PoRTB
rb7 ;RB? of PORIB

orS 0 ;Reset vector


golo init
orS A ; Interrupt Vector
clrf intcon ,Clear Interruption reg
Process *********
init
bsf status. rpO , change !o Bankl
clrf trisa ;Set PORTA alf ouT
movtw bt001001111 ;R80,1,2.5=IN RBI=OUT
movrdf tr:isb ,.Set PORTB
movlw b'10000000' ,RBPU=I Pull up not use
mo!'rf option reg ;Set OPTION REG
bcf status, rPo ;Change to Banko
clrf node ;set rnode = stop
clrf countl ;Clear counter
clrf count2 ;C1ear counter
movlH br00O0O101l ; SeE PoRTA inirial value
movvrf porta ; Write PORTA
bsf portb, rb7 ;Set RB7 = 1
btfsc portb, rb5 ;RB5=0?
goto $-1 ; No. t'lait

3?6
@b$do) Plc circujts callery - 2 Prc EcEo{%i@fi M ori,qoo6o6:,iP(?)

bttsc portb,rbl ;itBl (stop ley) = ON ?


qoio checkl ; N. Next
cl.i node ;Ycii set srop node
goto drive ;No. Junp to nolor drive
btfsc portb,rb2 ;RB2(right key) = ON ?
goto check2 ;No. Nexl
movlE d'1' ;Yes. set righ! mocle
novwf node ,Saye mode
goio drive ;No Jump ro notor drlve
check2
btfsc portb, rbo ,RBo(feft key) = oN r
goto drive ;No. Jump ro notor drive
movlw d'2' ;Yes. ser lefr node
movdf rnode ; save node

movf node, w ;Read node


bz star! ;mode : stop
bsf portb, r:b7 ;SeE RB7 = 1
btfsc porlb,rbs ;RB5 = 0 ?
qolo $-1 ;No. Wait
noYlw d,5, ;Set foop count(smsec)
nowwf countl ;save loop count
loop caff timer ;fiait lnsec
decfsz countl,f ;count-1=0 ?
goto Ioop ;No.. Continue
bcf portb,rbT ;Set RB7 = 0
blfss portb,rbs ;IlB5 = 1 ?
goto S-1 ;No. I'iait
nowt porta, w ;Read PORTA
subLw b'000000101' ;check notor position
bnz drive2 ; Unmai.h
nov: node, ! ;il:dl mocie
suirlw d'1' ;Rrqht ?
bz drivel ; Yes. Right
nowlw b'00001001' ;No. set Left data
goto drive_end ;,Jump to PORTA wrlte

novfs b,00000110' ;Set Rlghr data


goto clrive_end ,Jump to PoRTA write
; -------
drive2
movf porta, w ;Read PoRTA
sDblw b'000000110' ;Check motor position
bnz driwe4 ; UnmaEch
movf node, r{ ;Read mode
sublu d' 1' ,Righc ?
bz drive3 ; Yes. Right
movlrr b'00000101' ;No. set ]-eft data
qolc d!.ive end rJunp ro PoRTA write

.?9
s.i:6) Plc c'rculis Gal{eJ} - 2 F't- Fm-i ei4J^, -{:d.,o - b:1r:LJ,

novlr l:,'0!.00M!.' ;-:ci rrghi C.1if,


qoto driri en.r ;Julir ro PoITA !r.i:c

aovf poria, N ;ilcad PORII-


sdblz b'0ll001lill' rChec{ nioio. p.siLion
br:j cri.je j ; unar.ch
movf mode, ri
sublw d'1r ;Right ?
bz .lri ve5 ; Yes. Right
movlw b'000001i0' ;No. SeL LefL daca
goto drive end ; Jun! to IORTA rite

novl{ b'00001001' ;Set Right data


goio drrre en.l ; Jur,p i:o PQRTA @rite

nov t- fi.5.:a/ r - ; R.-d.i IORTA


:Lblr b't00il!iLJlll' ;ih..f n.irr p.rria.ir
bnz drivea ;Urma_Lch
novf node, @

;Right ?
bz driveT
movlw b,00001010' ,No. ser Lefr data
goto drive end ;Jump to PORTA ,rrite
nowlw b'00000101' ;ser Righr data
goto drive end ;Junp to PORTA lrrite

movlB b'00000101' ;conpulslonsetting

;Write FORTA
; Jump to start

lrrLsec Tiner subroutine


movfw dr 200' . ;Set loop count
noa'wf count2 ;Save loop count'
;Time adjust
;rine adjust
decfsz count2,f ;count 1=0?
;Yes- count end

; END of Stepper l4otor controfler


-^t" _ ,.- -a.-: i r d8,ot.' -q - *"
.^' .6,
t: --
._r. p!"p , svr: ,i$3qi3 .i6-E. (srop) ts :.odr svv3 c4
-.1 q.qc',
$3o?d.R3 :6po,d rc\ i )3,43:cDeica:,,
Stepper Motor Conirotter oc3cu6:u,3!a:ro"!cco:Q.,i 6e-l:o8d9%3@ddr

9(9-G) Stepper Votor Cortro ler oc3cu6:co$eaocfco::Q

5-prr Room Temperature Controller


pcre16z-r
QcDo{caQco{o::oi ":1:i!1coc:eoc 3,a$:3},t{idi:c(,!c,tr6:o,6?4
".rc"f "d' glooS-5,"33
temperailrre se,rso,s 961c{3"4:S1,:or:,ilcrdr 016?9, 3:a9,06,,
3",i{$o?,-i 58, .a@::or31 y, -.Ei%3,*e{,i.,i ::c{ icp)@6er_rop!rr
gf oo9-3,6lt=,3o,"96ci:oi9. 3,ai,%€:3r\?{1.f ,f4:6uG6Gf€oG]Jr
e36€rD3ad
G3"iltr dr eo,-"-,G3. oa+91to,qp:3roi:0t8".- *a$,-6E"33 %i,Uli-Cp,? "g,'Sn,iJ..:c
e::: s:tqp:e@r6. sral:::?{6G€.ordoJrgol air-cond tloner ,ip,@3.6ep.n.a;"?ol e13,,5
g3, ::3 cl:Q9oocooc6f,r6o q$ ventitation fans qp,ois,.?:Gt6SGoodi r :aor;qo6 glooicu6:
dt:d {o5{t:661:.Dgp%3 oo:oii6 (sreenho!s€) 9p:c,i3rt{$.f dE:Go:ep%3 3re:Gde
e,,,"r2!,
.?aE:83o3:i,iirrd 3:oi:%3:.:?{icDdlg-8.ordcr"11€ fans q,::c{q0eo
ventiLarion
d:;%d 3r3q:E€o%3sr$3eso:: iemperatu.e sensorrD eeoSgdeo:dla:2ir
3:ai,Ge,,3r?{i:""r,i5e.{ 6s"-p35",{i4r%€r*Eai:0l6igcg,jtDd' c.,]rs,q?:,3--:ii
qlt€. t_-o-.1.! -r,o( ^ . J:-,66r\.6 I
5a4(g) Prc circuiis GaLlery-2 Prc qo5o{%$c.qo, 3..R,toc3.u6,r1pd?)

c.ntro! mode qE over preset f€- below preset o9.cf swiich o:6q83. e@rS:c;

Qfu -9) u"5-3,-pln:occAq.'i.oT$co::q


!-de.\t/ rrv u ub ua cry - z rrv ?o,on%96sM on:noooo:,tp:l?)
+5! IC?

fi
rT
iJr +

+5V

NO

Lti3SDZ F2
tk G0c-2t nF
us ortt
2,\k FLI

2SA10 t5
E
-$r. { TF I0

LE!] LED2
+5!

0lTt
0lT
o' 1n,, l o'j G
r:o
i lal
LED9 LED4
tl
TB5
TR]I

5, Nk

LE!5 LED6

]l

I DBI

p6t0rlv j ro! #{ 7005

i-'- lli'= LI +5!

N] a2

ll0tr 0.1 u. I 100 t,


3tl t0v

Q(g o) Room Temperature Controller odco6:Q


o4:(S) Plc circuiis carlery- 2 crc $ola$c6ico{oo oci:qodcus:qp:{?)

Q(9-g) noom rumperature controller odcDS:ocgcA rtow crrartQ-(c/9)


rr+lg) PIC Circurts Gallery 2 Prc €.3a$%1o{o ori:Elodo6:qP:(a)

YES (Tenpebtrre detect i@: l0N]

(500frs1
{Bead TEST mode) lYEs (Fsd oUT SIDE tenpernture)

l{rl

YES

out_temp?

{Cecd iN slDr tehErature)


-

Q(g co) coom tempe:'ature Conkcller <,ro5o:5:::gci r ow Cnad Q-(1/g)

39?
sa6:(9) Plc circu'ts caitery - 2 ptc qo5.i.aioqNi c.i:qloo!.i3:i1.,(?)

YES(TEST DFF)

inl0, inl

i!r-..lIE

out-templ - in-temF?

wEl-Elltrit-\.

r1(g.>c) Poon ter perature CorLrorter uo5cD8::aca4 -ro.t Cr"r9-(q/g)

499
re+:[9) PIC Cirdits Ga'lery-2 Prc qda{.Blo{cu, o.?:ElocBo6:qp:(?)

tqw4fi:ffiil

Q(9 .1) Room Temperature control er odcrS:3r%o5 Flo,"v chaii i-(g,/g)

c95
!?a$dj) Prc c rcuits Gallery - 2 Prc Ec8effc3;@qcD: :a{;noo!c,:3:qp:(1)

Lhit:500 nilliseconds

NO
-__::_::__) |

ir0 h'0078' = d'l?0'


120/0.5
NO

sltl.:li
NO
YES

m
YES

NO
lllti
YES
. ii.i):
NO
YES

NO

ri(g-c?) Room Temperature Conholler oo5co8,.ro3.i rtow ChartQ-(3/g)

Room Temperature controller ooEoS:ocg<'5 Source code file crfeorcAce3


"oT$c"ot
,-'1op!'

rtG
ea+!(C) Prc circ'rlts G8llery - 2 ptc
E.3a6%1cD{Cu. @.i:Eloo5cu6,qp,(?)

; Roon Temperature controller


; Device: PICI6F873
; Clock : 4MHz
; Autho- : Seiicni lnoue
Processor 16E8 7 3
,. inc
in lucle p16 i8 /
radix dec
_config h,3F32' j.s ES
'OSC
,'RB3,RB6,RB? are I/O
;Brown-out detecticn OFF
, Powe!-up timer ON
; Code protection oFF
; Data code protection OFE
; Watchdog timer OFF
; I-VP OEF
errorlevel -302 ;Suppress bank warning

cblock h'20 '


ourl0 ;1oth of out-side (BcD)
outl ;1st of out-srde (BCD)
in 10 10th of i.-side (BcD)
in1 lst of in-side(BcD)
presetl0 10th of preseL (BCD)
presetl 1st of preset (BCD)
;Out-side (8 bits)
;In-side (8 bits)
ou! tenp2 ;out-side (6 bits)
in teniP2 ; In-side (6 bits)
prese!2 ;Preset (5 bits)
; Interval sw(BCD)
;Mode (1:up 0: down)
; Test (2: oEE, 1: IN, C: oUT)
; Scanninq conter
;RC controf data
rb data ;RB dara
t25us cnt ;25 microseconds counrer
t200us cnt ;200 microseconds colrnter
tlns cnt ;1 millisecond counter
seg_ha ;7seg LED rable head adr
seg0
se91
seq2
seg3
seg4
se95
seg6
seg?
segS
s e99 i9
;A (Blank)
4di:(C) Ptc c r.urts GalleF/ -2 Prc F.&{.6;@{cur ${hroo5N5:€n:(")

,l'{ reg saY-_ ar"a


; STAIUS reg
lremp check ; Temperature check (2S)
cont-t1ag ; Control flag
;Binary convert conter
.epeat ; Frese! reDeai: c.rh.r
presein ; Preset iiorl< ar:a
Presetlk ; ?resel lasl fook
interval h ;9igher interral tiner
intervaf f ;Lower int:rval iiner
endc

fjag equ 0 ;control fl2g Positao.


01 eqD 2 ;CutPull .crtrol Pcailiol]
c2 equ 5 ;O-.r!put2 ccn_:r.l lJosll;on

; Prcgram sta'r

; In'-errupi vecior

;---- ---- Initlal lrocess ----


init
; ,' Do' :l Q

bsi status,rpo to EankL


;Change
nowltt ;AN!/'1l:/i'r': :lFr2,/5:cuT
b'C0011N11'
;Set RA port node
;Set RB port output mode
clrf trisc ;set RC Port output mode
*** Tiner 0 initialization (for temp detection : 1Ons)
novlw b'00000101r ;Ps:l:64
novfif option req ;set oPTroN REG register
bcf status,rpo ;chanqe to Banko
nowlw 100 ;256-10000us/64us:100
; Set TMRO
*** Tiner 1 initialization {for hold tiner : 50Oms)
' novlE b' 00110001 ' ; Pre=1:8 TMRl:Int-, TMRI=ON
movwf tlcon ;set TlcoN registei
movlw h'0b' ;6s536 500000u5/ 8us:3036
.n lh ;sar "i4Rl" '-o'srerj"!
n 'd.' ;1016-h'BD
; Sel Tl4RlL register
bsf status,rpo ,change to Bankl
bsf pie1,0 ; SeL TMRIrE
*** A/D converter initialization
novlw b,00000100, ;ADFM=Orcic:O100
m.vwf adcon L ; Set ADCONL register
bcf siatus,rP0 ;chanqe to Eanko
*** Tseg LtrD Patlern data setting
movlw seqo ;Sel LabLe head i.id.€ss
novwf seg ha
mov Lw b' 110 00000 ' ;A
@i:(3) Pro crrculs Gafiery - 2 Prc {o5ai,€io6M o1:qodjor5:qp:(?)

novwf s. g0
novfw b' 111i 10 0 r, i r
novwf sett
mowfw b' 10100100 ' )2
rnovwt seg2
novlw b,10110000, ;3
movwf seg3
movlw b'10011001, i4
mowt seg4
movlw b' 10 010010 ' i5
novkf seq5
mowfw b' 10000 010 ' i 6
movwf seq6
movlw b'11111000' i7
novwf seqT
movlw br10000000' ,8
s.98
movlw b'10010000' i9 '
movwf seg9
movlw b ' 11111111 ' ;A(BLank)
movwt sega
'*** work area initializatlon
; Cfear PORTA
movfw b' 11111111 '
; Set PORTB
; SEt POR?C

molvi scan cont ;set scanninq counter


; Display iurning o:l

movdf inl
novwi preseil0
novrf presehl
clr: preseL2
cL.- .e9:.r
.l)|
nonlif '.ei..re.k ;Tenlt cn.ck in-ci':rL(rt5)
clri ccrr_flag ;Clear conrrol flaq
; *** lnterrupilon control
Fovlr b'11100000' ;GIE:ON.PEIE:ON,T0IE=ON
nowf intcon ;Ser TNTCON regisre.
LED ar.1 SIi scanninq Pr:ocess

movf,r scan cont ;Read scanning ccurter


t-. 9
blfs. status. z ;9 ?
qo.o pr.c.ss1 /10th o! oul sidt disp
J'rovin scax c.n! ;Read scanni.q counr.r
s-b {
illsc sta.us, z ;8 ?
got. p-o.es:2 ;1st oi oui sid. disP
fr.vfu scan c.nt ;Rea.i sc:nrjn.r countcr

..aa
PIC circui's Gallery- 2 Prc €.,5a{,Bi@6M @e,alodcD6,qJ:(?)
',o4(O)
btfsc stalLrs,z j1 ?
goEo process3 ;10th of in-side disp
nowfa scan_cont ;Read scanning counte.
subfs 6
bLfsc stalus, z i6 ?
goto process4 ;1st of in-side dsip
movf scan cont ;Read scanning counter
sublr 5
btfsc status, z ;5 ?
goto pr:ocesss ;10th of preset disp
novfw scan conE ;Read scanning counter
sublw 4
btfsc status, z ;4 ?
qoto plocess6 ;1st of preset disp
mowfw scan cont ;Read scanning counter
subtr 3
btfsc stalus, z ,3 ?
goto processT ;10th of preset sw
movfk scan conl ;Read scanninq colrnter
subls 2
btisc siatus, z ;2 ?
goto processS ;1st of preseL sw
novfw scan cont ;Read scanning counter
subLw I
btfsc status, z ;l ?
goto processg ; lnterval si,r

mowlw 9
nowf scan_cont ;Set gcannlng counter
goto scan

novlw b' 1111.1110 '


novqf rc cont ;Set RC conti.ol data
novfw out10 ;Read 10!h of out-side
novwf rb data ;Set RB data
call led on ;call LED oN subroutine
goto Proc_end
novts b' 11111101 '
novwf rc cont ;Set RC conerol data
movf' outl ;Read 1st of out side
nowwf rb data ;Set RB data
call led on icalf LED oN subroutine
goto proc_end
process3
novlw b' 11111011 '
nowf rc cont ;Set RC controf daEa
n'ov fs in10 ;Reacl 10th of in-side
mowwf rb data ;Set RB clata
call led on ;call LED ON subroutlne
goto proc,end
movlw b ' 111101I1'
niovwf rc cont ;Sel RC control data
noviw in1 ;Read 1st or in-side
I -+<O ptc circuits calery- 2 prc
idai%i-i- -a,qjoasN6:qp(a)
movwf rb data ;Set RB data
: cafl led on ;Calf l-ED ON subroutine
goto proc end
process5
nowtw b'11101111,
nov{f rc cont ;Sel RC controL daLa
movfw presetlo ;Read 10rh of preset
, movwl rb data ;Set RB data
call led on ;Call LED ON sLrbrourine
goto proc end
process 6
movlw brr1011111'
movwi rc cont ;Set RC control data
movfw presetl ;Read 1st of preset
movwf rb data ;Set RB data
calL fed on ;calf I-ED oN subroutine
goto proc end
processT
movlw b ' 11111111 |

movwf po.tb ; ],ED OFE


bsf status,rpo ,.change ro Bankl
movlr b ' 01111111 | ;RBO-6:IN RB7:oUT
mowwf trisb ,.set RB port mode
. bcf statu!,rpo ;Change to Bank0
novlw b ' 10111111 '
mowi portc ;Set poRTC
- call t200us ;Wair 200 mic{oseconds
novfli portb ;Read PORTB
xorfw b ' 11111111 , ;Reverse bits
novwf presetlo ;Save 10th of preset
movlw b'00001111' ;Set nask
andtif presetlo.f ';Pick up sw data
qoto proc end
process I
rnovh b ' 01111111 |
novut po.rrc ;Set PORTC
call c2C0Lrs ;Wait 200 microseconds
novfw pcrt)r ; Read PORTB
iorlw b ' 11r 11111 ' ;Reverse biLs
movlif p.esetl ;Save 1st of preset
mowlw b'00001111' ;set nask
andwf presetl,w ;Pick up sw data
mowwf presetl ;Save 1st of preset
- novwf presetw ; Save preset (Binary)
novfw presetlo ;Read 10th of preset
incf presetlo.n ;10th of preset + 1
novwf presetb ; save count
proces s 81
decfsz p.esel:b,f ;count 1= 0 ?
qoto processS4 ;No.
novfw repeaL ;Yes. Read repeaE counter
btfss status,z ;Repeat counler:0 ?
goto process 82 ; No.
rovflr presetw ;Yes. Road preset data
movsf presetlk ;Save preset last look
-
o6id3) Prc circujts Ge ery - 2 Prc Q.6a{cei@{o,r ?r?:qoo5N5:"ic{?)

inc" 'epea!,f ;Rcpcr! j.:.ie: + l


goto proc_end
processS2
movfli presetlk ;Read ]ast look
subwf presetH,w ;preser - fast took
btfss sLatus,z ;Preset = fast took ?
goto precessS3 ;No.
incf repeat,f ;Yes. Repear coJlret + L
movlr 3 ,set reierence data
sLibwf repeat,w ;Repeat counter - 3
btfss status, z ;Rcpeat counrer : 3 ?
golo proc end ; No.
rovfw preserw ;Read preseL daba
notrrf preset2 ;set p.eset data
precess 83
cfrf repeat ;Clear repeaE conler
goto proc end

iovi.r I0
r:tl,:: .c:.jcL- r,: ;t)!,::- a
gci:o processEl

movlq b' 11111111 '


rnovwt portc ;sei PoRTc
bcf portb,T ----! ,Set PORTB
call t200us : ;Walt 200 microseconds
movfw portb ;Read PORTB
xorfw b' 11111111' ;Reverse birs
move,f inlervaf ;Save interwal data
movlv b' 00001111' ;Set nrask
andlif interwal,f ;Pick up sw data
novfw interval ;Read interwaf data
btfss stat.us,z ;Interval dara = 0 ?
golo process9l
novlw 10 ;Yes, Set 10
novrf interval ;Save inre.vat data
Process9i
bsf slatus,rpo ichange to Bankl
c].f trisb ;Set RB porr outpu! node
bcf status,rpO rchange to Banko
novlw b ' 11111111 '
morlrf portb ; LED oFF

' *r* UPIDOI{N node check


btfss porta,4 ;BA4 =1 ?
goto procgl ;No.

qoto proc end


proc9:
; se! fcli\ r.o.re
oaqd3) Plc circuits Gauery - 2 Prc qda{("$@6M @tri:ajoo3o6:qp,(?)

decfsz scan cont.f ;Scan end ?


9oto
goto scanl
LED ON subroutine

mowlw b ' 11111111 '


; LED OFF
movt{ rc cont ;Read Rc controf data
;Set PORTC
cafl l200Ds ;Wait 200 microseconds
nowf$r rb data ;Read disp digit
addwf seg_ha,w ;HA + Digit

;Read 7se9r data


;Set PORTB
cafl llns ;wait l millisecond
;----
i 2O0 nicroseconds subroutine
; --
t200us
movlw 4A
novwf t200us cnt ;set loop counter
t2 00us_loop

decfsz t200us cnt, f ; counter L


goto t200us loop rNot eird

; 1 millisecond subroutine

movlF 5
riL.vir: :rr: cnt ;se1. loorr ..r n-F.
i:lns loo!,
call i2l0 r s
decfsz r:lins cnt, i ;counter l
goto .lns lcop ;Not end
return

; Interruptior'r Proce s s

inr
novlrf ;Save tr register
;p6od I.r..s .6J
mcwwf ;Save STATUS reg
bcf staius,rpLr ;change io Bank0
blfsc intcon, t0if ; che.li Tl'1R0
; v0 -
blisc !,1.1, tn.1i f ;checl. Tl'/ia'l.r.E
goto out contrcl ;'fl4lli tirc .r1:
_

r3i
oa4d. ) Plc cncuiis Gallery 2 Prc {.3ii.sid4(\,, :i:;1oo3o€:qp:(p)

; END of Interruptioi Process

int end
movf\,r ;Read saved STATUS req
nowqf status ;Recover STATUS reg
swapf w_save, f ;Read saved W register
ssapf ; Recover I"l register
retfie
; tstgtt*?%*SgtBttt?g**tBtBtggt*tt%gt&tsgs%sB3*3EtB%%%?839*
; Tenperature detection Process (10ns)
; ?tBS*Stgat%s?39*tttB%stSt383ssBt?3*t*g%gg*ttt**g?t?t%?gg
bcf intcon, to-if ;clear TOrF
movlw 100 ;Set Time value
novwf tnr0 ;ttrite TMR0 register
decfsz t.enp_check' f ; count 1
goto int end
novlr 200
movwf lenp_check ;Sei 2 seconds
;--------- ----_ TEST mode check

nowt, b'01011001' ;ADcs=o1 cHs=AN3 ADON=ON


nowf adcon0 rset ADCONo register
calf t25us ;Wait 25 ndcroseconds
bsf adcono,2 ;stari A/D conversion
mode2
btfsc adcon0.2 ;Conversion end ?
goto rnode2 ;No.
movllt 168 ;set 3.3v
subwf adresh,w ;AN3 - 3.3v
btfss status,c ;AN3 >= 3.3v
goto node3 ;No.
mowfw 2 tYes.
lesr rode ;set TEST OFF
goto temp0
node3
novLw 87 ;set 1.7V
subt{f adresh,w ;AN3 - 1.7V
btfss statusrc ;AN3 >= 1.7V
goto mode4 ; No.
movfw 1 ;yes.
nowf test mode ;Set IN TEST
goto tempo

clrf test mode ;Set OVT TEST

j ----------- OUT-SIDE temperature detection


iemp0
novtw b,01001001, ;ADCS=0l CES=ANI ADON:ON
mowqf adcono ;Set ADCON0 registe.
call t25us ;l'lail 25 nicroseconds
bsf adcono,2 ; sLart A/D conversion

509
, *idc) Plc cncuirs Gallery-2 ptc
€do{.Bl.o{(v. -4:qod-5,qp,(1)
tenPl
btfsc adcon0.2 ;Conversion end ?
goto tenpt ;No.
novfw adresb ;Read resulr
addlw 8 ;Add 2deq-c
mowf ou! rempl ;Save (unit:O.2sdeq-c)
movwf out temp2 ;Set data
ttl our-tdp2, f ;Rotate Rign!
rlf out tenp2,f ;Rotale Right
movlir b,00111111, ;Se! nask
andwf out_tenp2, f rsave (unit:1cleg c)
; ------------ IN-SIDE tenperature detection
rnowlw br01000001r ;ADCS=ol CES=AN0 ADON=ON
nowwf adcon0 ;Set ADcoNO register
ca]Msus ;Walt 25 nicroseconds
bsf adcon0.2 ;Start A/D conversion
tenp2
btfsc adcono.Z ;Conversion end ?
goto tenp2 ;No.
movfw adresh ;Read resutt
addlvr I rAdd 2deq c
mowf in_tenp1 ;Save (unit:0.25deq-c)
r mowf in_temp2 ;Set data
rrf in tenp2,f ;Rotate Riqht
" rrf rn-!erp2,f ;Ro!a!e Rignc
* mowfw b,00111111t ;Set nask
andwf in_temp2, f ; Save (unit:ldeg-c)

; ' - - - - - - - - - - - - - - Display
dala conversion ------------.---- |
novfn test node ,Reacl test mode
subfr 2 .iset check dara
btfsc status. z ;Check
goto temp3o ;2 (TEST OFF)
movfw test_mode ;Read test node
subh I ;Set check data
btfsc status, z ;Check
goto temp4o ;1(IN-SIDE DATA)
goto lemp5o ;0 (OUT-SIDE DATA)
; *** TEST OFF
, (oUT-SIDE)
tenp30
. cl.f out10 ;Clear l0th of out-side
novfw out_tenp2 ;Read out-side 1de9 data
novNf outl ; Set data
movfw 10 ; Set divisor
!enp31
subqf ouLl,f ;TenP - 10
btfss status.c ;Result >= 0 ?
goto tenp32 - ;No. Junp to correction
incf outlo,f ;Yes. 10th of out side + I
goto tenp3l ;continue
teftp32
movlw l0 ;Correction value
_
'!,
3rc
2
.+ai.:(S) P c ci,clits c:rrelr - Pc q.i.i.?:-i., --,1o.i-*5,q:d;)
aaa- i o\t L. t ,a.,...".a.".
; (IN-SIDE)
i,-ml]:3
cI.: in10 ;Ciear 10th of in si.ie
nov:p in Lenp2 ;Read in ei.le l.leq dala
notif inl ; Set oala
rio.r_llr 10 ; sei divisor

ienp34
subqi ir1, i ;TerrP 10
btfss status,c ;Resull >: 0 ?
goio tenp35 ;No- Jur,P to corrcction
rnci in10,l ;Yes. 10ih of oul s:Ce + 1
qo|-a tenp34 t ConLj nue
t enp3 5
movlg 10 ,Co.recrrion vaLue
addwf in1,f ;Correc.lon
goiro conlo ;JumP to conlarison

' r+- IN-SIDE DATA d.isplay


tenp40
clrf out10 ;CLear 10th of out side
novfw in temp2 ;Read in-side ldeq data
nowl ouL I ;Sec data
novlw 10 ; Sets divisol:
-np4 t
subwf out1, f ;Tenp 10
btfss status.c ;Result >:0 ?
goto tenp42 ;No- JunP to correction
incf out1o,f ;Yes. 10th of out side + 1
goto tenP41 ;Conlinue
tenp4 2
novlw 10 ,Correction value
add!.,f oui1,f ;correction
temp4 3
btfss in temp1,1 ;Ix ?
qoto temp45 ;No 0x
btfss in temP1,O ;11 ?
qoto temp44 ;No- 10
movli{ 'l ;Set .75 deg
nowf in10
movlw 5
mowf in1
goto conpO ; JmP to conParison
novlw 5 ;set .50 deg
nowf in10
movlw 0
nowf inl
goio conpo ;JumP lo conparison
btfss in tenp1,O iA7 ?
goto tenp46 ;No.00
movlw .2 ; set .25 deq

troG
s6i:6) Prc circults Garery 2 Prc Fd66cei@{M o+:{oo6o5:qp(?)

nov f inL0
novlq 5
nowf inl
goLo compo ; Jump to iomParison
tenp46
novlu 0 ;Set.00 deg
novqf i n:'- 0
novlu 0
molvf in1
goto con'p0 ; Juiip to conparison
- *** OUT-SIDE DATA display
temp5 0
clri out10 ;Clear 10th of out-side
oL. Lerp2 ;Feao our qio6 rd6q od o

movlw 10
tenp51
subwf out1, f ;Temp 10
btfss status,c ;Result >= 0 ?
goto temp52 ;No. Jwp to correction
incf out10, f ;Yes. 10th of out-side + 1
goto tenP5L
tenp5 2
novle 10 ;Cofiection value
addvf outl, f
tenp53
btfss out_temp1,1 ilx ?
soto temp55 ;No: 0x
btfss out_temp1,0 i7l ?
qoto temps 4 ;No- 10
; set .75 deg
movlrf in10

golo comp0 ; Jnnp to cor.pa.i:or


n.vli 5 ;Sei .5C deE
novlil i.10
movlR C
ncv f inl
goto comp0 ;JumP to coinParison
tenp5 5
btfss out tenpl,0 ;01 ?
qo'-o ter,P56 ; No. 00
novtlr 2 ;'res. set .25 deg
novvif i nl0
movfw 5
novwi ini
E.ro cori9O ;Jur(LP t. cor,Ltarisor
(rrtlr 0 ,Se..O0.teg

ril.vri rn l

r3?
#q{o) Prc ci,cuits Gallery- 2 Plc qdaficei@qM e4=1o.3o:5,c1rdq)

.JaLa conip0 ; JrrllP to companson


; - - --- Tenperature conparison processlng
movfw node ;Read mode(1:up o:down)
' btfsc status,z ;Up ?
goto comp2 ; JunLp to down node

motfir j n_tcr!2 ;Re..i in-si.le


subrf preset2,!r ;presei in side
btfsc sLalus,c ;Presel >: in_siie ?

Eoio conpl ; (>=)


novi! ia_tcmp2 ; (<)Read i side
.ubif out ier.p2,e rout si.le in side
btfsc statr:s,c ;cut-side >: in side ?
goto cc npl ; l>=)
bEf ccni Il ag, ilag ; i<) se_. .ontrol ila(l
goro iril eid ; -iunlj io ijr. .rd

bci coni flag,il.,q ;CL.ar ccnlrcl ilag


g:oto int eno ; JLnp to ini: end

; +*+ (Do!n mode)

novfw p.eset2 ;Read preset


subwf in temp2, w in-side - p.esel
btfsc slatus, c in side >= presel ?
(>=)
bst conl la9,t-dg ; ( )S. 'onl ol l1a9
qoto int end ; JumP to int end
25 microseconds subroutine
2 5us
novlw 5
mowf t25us cnl ;Set loop counter
t25us loop
decfsz t25us cnt, f ;Counter 1
goto t25us loop ;Not end
return
; % : %: g
", : ? i : t ?'. s3 % ""
g % "' ". % t:"i "" % ".
."
". "" % "" % ? g S : g t g'. ". g 3 "" c s ". "" s "" "" %
"
; outPut conlrol P.ocess (500ns)

bcf pi.1, tmrlif ;Clear TMR1IF


novlH h'0b'
novwf rmrlh ;ser TMR1E regisrer
movlw L d.
novvf tnrtt ;set TMR1L reqister
novfw cont flag ;Read all control flags
blfsc stalus,z ;All flaqs oFF ?
goto int end ;Yes. JunP to int end

,50 |
3?eE(g) Plc circuils callery - 2 prc
€c5€{,€1@6o -4,q.dc!6,qpdq)
btrsc conr_ftag,o1 ;OUT1 controt f1a9 ON ?
goLo conll ; yes .
btfsc cont_f]ag,.o2 ;OUT2 controt ftaq ON ?
goto contl ; Yes.
; *** (1st controL)
bsf cont_flag,01 ;Set OUT1 conrrot ftag
bsf porta, 01 ;OUTI ON
call time set ;Set tiner vatue
goto int_end rJump to int end

decfsz interwal I.f ;time -1


goto 1nt end ;Nor tine out
nowlw I
subwf interval_h.f ;Higher vatue check
btfss status,c ;vafue >= 1 ?
goto cont2 .Va]ue : 0 (Time-out)
novlw hrff'
nowf interval f ;Set Lower vatue
goto int end ;Not time-our
cont2
btfss cont_ftag, flag ;Control ftaq ON ?
goto cont3 ; No.
bsf cant_flaq,o2 ,'Set output2 ftag
bsf porta, 02 ;OUT2 ON
call Eime ser ,Set timer vatue
goto :int_end ,. Junp to inr end
cont3
btfss con!_flaq,o2 ;Output2 ffaq ON ?
q'oto cont4 ,No.
bcf cont_flaq.o2 ;Cteir ourput2 ftag
bcf porEara2 ;OUT2 OEF
cafl rine set ;Set tiner value
qoto int_end ,Junp to inr end
bcf conE_flag.o1 ;Ctear ourputr ftag
bcf porta, 01 ,.OUT1 OEF
goLo int-end ;Jump ro ini: end
i --------'
; Time-out value settino subroutlne

mowfr interval ,'Read interwat sw value


sublw 1
btfsc status, z ;L ?
;sel value fou 1 ninute
novfw interval ;Read lntervat sw valDe
sublr 2
btfsc status, z i2 ?
goto set2 ;sel vafue fou 2 minutes
mowfF interval ;Read intervdt sw value
subfr 3
btfsc sEatus, z ;3 ?
;Set value fou 3 minutes
s4d3) prccncu s Garery- 2 prc
{do{.egcDiM o:i:nodo3,qp;(q)
novfw intervalRead inEerval sw value
sublr 4
blfsc sLaLus, z ;4 ?
goto set ;Set value fou 4 minuLes
novfe intervaf ;Read inUerwal sw value
subLH 5
btfsc status, z ;5 2
I goto set5 ,Set value fou 5 minutes
movf\.r interval ;Read interval sw walue
sublw 6
btfsc status,z i6 ?
gouo set6 ;set value fou 6 minutes
movfer interval ;Read interval se value
subl' 1
blfsc stalus,z - i1 ?.
goto sets7 ,Set-ivalue fou 7 minutes
novfH interval ;Read inte.wal sw value
9ub1w 8
btfsc stablrs, z i8 ?
goto set8 ;Set value fou 8 lTrinutes
movfw interwal ;Read interval sw walue
sublw 9
blfsc status, z ;9 ?
goto set9 ;set value fou 9 minutes
goto set10 ;Se!_va1ue fou 10 minutes
setl ' .,, -
nov.Iw h'0' ;Set l ninute
mov$f interval h
novlw h'78'
novvrf interval-l
return
set2
novlw h'0' ;Set 2 minuies
novi{f interval_h
novlw h'f0'
mov$,f interval I
return
set3
mov]w h'1' ;Set 3 ninutes
movwf interval h
movlw h'60 |
movl'f interval I
retsurn

novlw h'1' ;Se! 4 ninutes


movwf interval h
movlw h'e0 '
movwf interval I
relurn
set5
movlw }I'2' ;Set 5 ninutes
movHf interval h
movlw h' 58 '
novwf inteival t

oGo
Plc ckcuits Gallery - 2 Prc s.Ea{(r$@{M @ri!qoc6o3:ql,:(?)
'ei,(O)

novlH h' 2 ' ;5et 6 minules


rnovwf interval h

movwf intervaf I

rnovfw h'3' , Set 7 ninutes


movaf intervaf h
movfw h' 48 '
novdf lntelval I
seES
; Set I ninutes
movwf inlerva1 h
movfw h' c0'
movuf lnterval I
set 9
; Set 9 ninutes
movwf interval h
novlw hr38'
novwf interval_l
set10
, Set 10 ninuLes
movr{f interval h

movwi interval I

; END of Tenperature controller

orco(6o:l Room Temperature Controller r.:dcu6:9€po8o.6op) oeer:83oq.5o-cf qp,.'i


o3$cQnqp:oel eexf eoT$ol intemet website:

htto://www.hobbv-elecl.oro

cg8 oo391{€<io2!'

:Gc
lD4:(g) PIC circuiis Gallerr' - 2 P'\, v)rJ-t^,1r(D;r D .')?:q uortuo:dr:\?l

C-gn Uitrasonic Range fuieter

€rr5a6.?ico!'or.{ 3"c1:Glco?:6c>, lJllrasonic Range Meter odoS:


PlC16FS73
.a61cf ."TQ,:lo$'r grlodo:3,er\"p3"$-$9" urtrasonic o:5c$€:r{ ea:q:p1p: cacaosaeo:<ri
43'"-63,G6.rdr ooScuS:r{ Transmitter Q3:g3. neceiver 83:o?d"rQ€'i683,dE",-,,
"'Eir, "ac6c"aeo,f€'o'".$co2i og1ogpi'$ri.
Transmitter Q3:9 Utrasonic ca:'rc$€:oi
o9o5q86.c$d$,.frd Ulirasonic
0i-d""p"36.'n)d ooc.f;3:cf
Receiver Q3:9o3:<1ol
qda{ "B$-{..-.\ capture rnode eaQ3'9{3,--"1ogjl
@-ei-{${-D:!qc:g$9t{:cl9cc:tuHc?
PIC16F873
3r,?{961!3"c. t-ru ror 6/r AUt/ Jrtc:9LoLl9c
9mo$.?lcosor6'r
n"Togd<-,1opjl oi€:c',:q$eor e,"g,=aeo:r't cdl$qi-%rl5 7-sesment LED display (q)Ec'i
s?+:0tco.:dcJdr
Q(e-cg)ca8 .u3,ol el o6qoiq,jT@"or,E: Q(g-rg).a8
ljlkasonic Range lvleter @co::<.t1op!rr

Q(g-39) ordc.oro5cor:g:cu ultrasonic Range Meter oc3cD6:?

.GJ
@ai:(3) Prc crrcuits GarJery- 2 prc qd66%6@{o $+:El!o5o6aiJJ:i?)
:
nr lcl F5
1001{
ro!rrp fil
!l
1000F

o
@r; E6
D2
tss t00
c4
100[p
To.r ,, 0( lL,
.77

Ollr. rs
h
F l?

0.l4 5.8( + t2v


ct0
0. t4 GND

tr,r)
.+
I

,i7
a Bl4

:i'
!scz Il(

F88
FC4
ts j- 815

BE5
EEa iOs L/1
883 '
RR2
T\.] -
FEI
FEO

ICI: LLlslSll
IC2i Lli350ll
IC3: 4011
tsfi 0l5 IC4:40.49
I15: PlCl8Fg73
IC6: ?r105
ICI:78109

q-_F
? IrsPl
il30

Q(O-.e) uttrasonic Range tvfererocSorS:Q


3'"qdJ) Plc circuits Gellory -2 Prc {c3a6%E@6M 3ai:floo3o8,qFd?)

Source cocie fiie of Uitrasonic R.ange ivieter

Ultrasonic Range MeEe.

Devi.ce: PIC16F873
Author : seiicha Inoue

Iist p=pic16f873
include p16f8/1.:nc
_config _hs-osc & _wdt_off & _pwrte_on 6 _lvp_off
errorfevel -3O2 ;suppress bank warning

cblock hr20'
; send-out pulse counl adr
s adi ;A(itLrsiEe:i d:iid address
;Rotaie nalue save ad!
s_digit ; Digit cont Lrork address
g tinel ; cuald tiner address 1
q_tine2 ;Guard tiner address 2
; ProPagation L cnt aclr
r Propagation H cnt adr
diqit cnt ;Digit counter head adr
disp ha ;Dj.git head acldress
disp u ;1st digit address
disp L ,10th diqit address
disp h ;100!h diqit address
segT_ha ;? seglED table head adr
seq70 ; Pattern 0 set. adr
seg?1 ; Pattern I set adr
segl2 ; Patlern 2 set adr
seg73 , Pattern 3 set adr
seE74 ; Pattern 4 set adr
seq75 ; Patlern 5 set adr
se9?6 ; Pattern 6 set adr
;Pattern 7 set adr
seg78 , Pattern 8 set adr
se979 ; Pattern 9 set adr
; Patlern A set adr
seg?b i Pattern B set adr

h'01' ;RA1 port clesignation


h,021 ;RA2 port designalion
h'03' ;RA3 port desiqnation
h,05' ; B-AS po!t designation
h'02 ,
; CCPI (RC2) desiqnation

b' 010 0 000 0 , ; -gfeclcba Pattern 0


b ' 011110 01 ' ; Pattern 1

"GE
o6i:(e] Prc crrcuits Garrery-z prc
{djai.raii@io ori:alodo6:qp:(?)
segl 2 equ b' 00100100 ' ; pattern 2
segT : equ br00110000' ; partern 3
seg? 4 equ b' 00011001 ' ; partern 4
seq? 5 equ b'00010010 ' ; pattern 5
seg'/ 6 equ bt00000010, ; patrern 5
segT 7 equ b'01111000' ; patLern 7
segr I equ b'00000000, ; pattern 8
seqT_9 equ br00010000, ; Patrern 9
segT a equ b'01111111' ; Detecr erro.
segT_b equ b' 00100011 ' ; Illeqal int

ors 0 ;Reset vector


goto init
org a ; Interupt vector
goto int
Initial Process
init
*1r Porr: initialization
bsf status,rp0 ;change Lo Bankl
nowlw b'00000001 ' ;AN0 to input n\ode
movdf t.isa ;Set TRISA register
clrf trisb ;RB port to oLrrput node
novlw b'00000100' ;Rc2,/CCPI to input node
no\&i trisc rset TRISC regisler
sending period inltiafizarion (riner0)
novlw b'11010111 ' ;T0CS=0, PsA:0, PS=1:2 56
novwf oprion_req ;ser opTroN REG reqisler
bcf status.lpo ;change to Bank0
clrf tmrO ;Cfear TMRO regisrer
*** capture mode initialization (Tinerl)
novLd b'00000001' ;Pre:1:1 TMRI=Int TMRl:eN
F.nul 'i]con ;set TicoN registef
.1ri ccplcon ; Ca!1 otl

inltiaLizailor,
novtii b'01000001, ;ADcs=O1 cHs=ANo ADoN:oN
mov{i adcon0 ;Set ADcoN0 register
bsf status,rpo ;change to Bankl
mo\-l b' 0 0001110 ' ,ADFI,l=0 PCFG:1110
movrrf adconl ;Set ADCON1 reglster
bcf status/ rpO ; change to Banko

*** Display j niiialization (Tiner2)


movlr disp u ;set digit head address
ncvwf dlsp ha isave digit head sddress
rovlv h'0a' ; "Detecl error:,' dala
movLtf disp D ; set 1st digir
mowlrf disp t ;Set 10th diqir
movqf disp h ;SeL 100th diqit
; Digit counter

.Gg
@a{d5) Plc c'rcuits Garler/ - 2 Prc $c,so{do{cD e4:qjodo6:qP,(Q)

movt seg?O ;sei rscq head ad.l.ess


novHi seEl ha ;save ls--g head address
novlr soq? 0 rset Ts.qment pattern 0
nowf se!170 rsave patlern 0
movl'r se!r7_1 ;seL Tsegnent patlern 1
morrii seg?t ;Save pattern 1
movLw s.g1 2 ;set ?seqnen[ pattern 2
novif seq72 ;Save paite.n 2
novlw segT-3 ;sci TsegmenL pattern 3
mowwf seg73 ;Save paltern 3
no./lw .eg] A ;Set Tsegnent pattern 4
novwf se.l14 ;Sawe pattern 4
movlir seqT 5 rset Tsegment patiern 5
novwf seg75 ;Save palr'ern 5
novfw segT 5 ; Set Tseqnent pattern 6
nov!,f seq76 ;Save pallern 6
movlw seltl 7 ;set Tsegneot pattern 7
trLorirf 3.,.J 1 .1 ;save p.Llei.7
mtvl! !e9- d ; Set TsegnenL paLtern 8

movlo se.J1,9 ;set Tsegreni pattern 9


novwf seg79 ;save Pactetn 9
novle se97_a ;set Tsegnent patiern A
novwf segTa ;save pattern A
nov]N seq? b ;Set Tsegnent paltern B
novwf se97b ;save pattern B
movlw b' 0 0011110 0PS-1:4, T2-ON, EPS=1:15
movnf l2con " ;Set registe.
T2CoN
lsl siaius/rpo ;Chanqe to Bankl
movrw d' 15? t
;157264=10048usec
mowwf pr2 ;Sel PR2 .egister
bsf pie1, tnr2ie ;TMR2IE=ON
bcf status,r:po ;Change to Bank0

; *** lnterrltption control


movlv b'11100000' ; GIE:oN, PElE:oN, T0IE:ON
mowf intcon ;Sel INTcoN register

goto $ ; Interruption wait

novfw pirl ;Read !IR] reqister


btfsc pir1, ccplif ;captu.e oc.urred ?
goto capture ; Yes. "Capture"
btfsc pirl,tmr2if ;TMRZ time out ?
goto ]e.l cont ;Yes. "LED disPlay"
movfw intcon ;Read INTcoN registe.
btfsc intcon, roif ;TMR0 time out ?
goio send ;Yes. "Pulse send"

DGG
,ei:6) Plc circuits Gallery- 2 Prc qota{%i€{o, oi:noo3-3:qP(1)

il leqat
mowlw h'0b' ;SeL Illegaf disp diqit
addvf segT-ha.q ;segr E.Adr + digit
mov f fsr ;set FSF regrister
mowfk inclf ;Read seg/ data
movwf portb ;l,rriLe LED data
bcf porla, ra1 ; RA1=oN
bcf porta, ra2 ;RA2:oN
bcf porta, ra3 ;RA3=ON
goLo 5 ; Slop

retfie
pulse send-our psq6q55 *.,.,.,*', ii^."*
bcf intcon,toif ;Clear TMRo int flaq
clrf tmo ; Timer0 clear
;*1* Recerved Pu]se detection check
movfw portc ;Read PORTC register
btfsc portc, ccpl ;Detected ?
goto detect off ;Yes. Delected
movlw h'Oa' ;',Derecr error" data
movhf disp_u ;Set 1st digit
mo!.vf disp_t ;Se! 10th digit
movwf disp_h ;Set 100_Lh digi!
r*** Receive pulse detector of
detect off
bcf porta,ra5 ;Set detector OFF
; t** capture sta.t
clrf tnrlh ;Clear TMR1H regrster
.lff Lmril ;clcir Tl4Rl L regjster
clri ccp.lh ;Clear CCPRllt regisler
clrf ccp.1l ;clear CCPRI! regisLer
mowLw b'00000101' ; CCPlM=0101 (capture)
movlrf ccplcon ;Set CCP1CON register
bsf staLus,rpo ;Change to Bankl
bsf piel.ccplie ;CCPI inEerruptin enable
bcf status, rpo ;Change to Eank0
bcf pirl,ccplif ;Clear CCP1 int f]ag
'*** 40KHz pulse send ( 0.5 msec )
mowfv d'20' ;Send-out pufse count
movwf s coun! ;set count
cafl pulse ;ca]l Pulse send sub
decfsz s count,f ;End ?
goto s_toop ;No. Coitinue
:Da$dS) Plc circuits Gallery - 2 Prc qda{.Blcoi(\,' o4:xo$o:,s:(q)

bsf adcono,go ;Stare A/D conver!


btfsc adcono,go ;A,/D convert end ?
gcto ad check : iNo, Again
novf adresh ,Read ADRESH register
nowf s_adj ;Save converted data
novlH d'5' ;Set rotate vafue
novwf s_adj_count ;Save rotate value
rf s adj,f ;Rotate rigrbt 1 bit
decfsz s adj count;f tEnd ?
goto ad rotate ;No. Continue
novfws_adj ;Read rotated vafue
andlwb'00000111' ,Pick-up 3 bits
addfwdr54' ; (0 to 7) + 54 = 54 to 51
movwfs_adj ,save adjustnent data
;*** Cap_LL.e guard tiner ( 1 milisecound )
no?lw d'2' ;Set loop counterl
nowwf g_time1 ;save ]oop counterl
g loopl novl$, d'I24' iset -Ioop counter2
mov{f g_time2 ,save loop counter2
9_1oop2 nop ,Tine adjust
decfsz g_ti.nez;f: rg_time2 - 1 = 0 ?
qoto g_foop2 ;No. Continue
decfsz g_time1,f'_ ig-tine1 -1=0?
goto g_Ioop1 ;No. Continue
5

'**t Receive pufse detector on


bsf porta,ras ;Se! detector ON

goto int_end

pufse
novftr b' 00010000' ,RC4=ON
movsf portc ;Set PORTC reqister
caff tl2us ;CaIl l2usec timer
clrf portc -' ;RC4=OFF
qoto S+t
goto S+1
reLurn

t12us
goEo S+1
soto S+1
goio s+l
goto S+1
return

cGo
3"e1:(J) Plc circuits Gallery - 2 ptc
Eo56{%i@6M sa?:atoo8NS:qp(?)
* CaPture Process ***r******
bcf prrl,ccptif ,Clear CCpl rnt ffag
clrf p_countt ;Clear L count
clrf p_counth ;Clear H count
clrf ccptcon ; CCpl off

n'owfi{ s_adj ;Read adjusrnent dara


subwf ccprtf,f Lure - adjust
;Car
btfsc statusrz ;Resrlt = 0 ?
goto division2
btfsc status.c ;Result < 0 ?
goto divisionl ;No. r'R > 0n
goto division3 ;yes-,,R < otr
divisionl ;(R>0)
roowfvr d'1' ;Set lncrement wafue
addwf p_counrf, f ; Increment I count
btfss status, c ;Overflow ?
goto division ; No. continue
incf p_counth, f ;fncrement H count
goto division ; Jump next

division2 ;(R=0)
mowfw ccptlh ;Read CCPRIH
btfss status,z ;ccpRlH = 0 ?
goto divisionl ;No. Next
movlw dr1' ;Set increment vatue
addwf p_countl. f ; fncrement L count-
btfss st'atus,c ,Overflow ? -
goto digit_set to digit set
; Jurnp
incf p_counth, f ;Increnent tl count
goto digit set ;Junp to digit se!
division3 ;(R<0)
movf\{ ccpllh ; Read CCPRIH
btfss status,z ;CCpRlH = 0 ?
goto dlvision4 ;No. Borrow process
goto digit-set ;Junp to digit set
division4
decf ccprlhr f ;CCpRlH - 1
mowllr d'255' ;Borroh' vatue
addwf ccprll.f ;CCPRIL + 255
incf ccprll.f ;CCPRII + 1
goto division I ;Next

digit set
c-Irf disp_u ;Clear lst digit
clrf disp_t ;Clear 10th digit
clrf dasp_h ;clear 100th djgii:
odidJ) Plc circuits Gallery- 2 Plc {.3a{,?lcD{a,r a:i:qloc6o6'qt',(q)
. **:- i00Lh digir
digit h
movlw d' 100 '
subwf P counrl/ f ;DigiL - divide
btfsc ;Resu]t = 0 ?
goto digit h2
btfsc ; Result < 0 ?
diqiL h1 ; No. "R > O"
goto digit h3

digit h1 ,(R > 0 )


incf dlsp h, f ; Increment 100th counL
diqit_h ; Jump next

digit h2 ,(R=0)
novfw ;Read H counter
btfss iltcounter=0?
goto .ligit h1 ; No. Next
i ncf Cisp_h, f ; Increment 100th count
.ligi L I ;Jump to 10th digi! Pro
diqit_h3 ;( R<0 )
movfw rRead lt counter
bt fss iHcounter=0?
goto digit h4 ; No. Borrow process
movlw d'100' ; Divide vafue
add$rf p_countI, f , Return over sub value
goto diqit-t ;Junp to 10th digit pro !
diqit h4
decf ;It counter L
movlw d'255' ;Borros wafue
add!?f ;T. counter + 255
incf p_countl, f ;L counter + 1
digit_h1 , Next

, *** 1oth digit


digit t
; *** Range over
novfw disp_h ; Read 100th digit
sublw d' 9' 19 - (100th digit)
btfsc ; Result = 0 ?
digit to
bt fsc ;Resu]t < 0 ?
digit t0 'No. R > 0"
rnovlvt h' 0a' r "DeEeart error" data
movw! clisp u Set lst dlgit
;
movwf disp_t ; Set Loth diqit
movwf clisp h ;Se! 100th digit
9oto
di_qiL t0
mowlw d' 10'
subwf p countl / f ; Digil - divide

.eo
oa+:tt Plc ciro.iits Gallery - 2 Prc qo5.fi %i@{cv: otri:aposo$:qpd?)

o?
diqit t1
btfsc ; Result < 0?
goto digi! tl
goto digit_t2
digit_t1 (B>=0)
disp_t. f lncrement loth count
digit t
diqit_t2 ( R< 0 )
d'10, Divide
addwf p countL, f over sub vafue
cligit_u 1st digit pro
diglt
digit u
movfir p_countf ;Read propagetion counter
movwf disp_u ; save 1st count

goto int_end

bcf pir1, tmr2if ; clear TMR2 int flag


novfw diqil_cnt ; digit counter
Read
novwf s_digit ; digit counler
Save
decfsz €_digit, f ;1st digit ?
qoto d checkl ; No. Nert
bsf po.ta, ra1 ; RA1=OFF
bsf . .- .. porta, ra2 ;RA2:oFF
bcf ' porta, ra3 ;F-q3=ON
goto c_digit ; Jur,p to digit cont
d checkl
s_digit, f ;10th digat ?
d check2 ; No. i00ih di.Ji1-
; Ril1:QFa
bcf ; RA2=oN
bsf porta, ra3 ; RA3:OFF
c_digit ; Jump ro digrt cont
bcf porta, ra1 ;P.41=ON
bsf porea, ra2 ;Re2:OFF
bsf por!a, ra3 rRA3:OFF

c d igi r-
decf digit_cnt, $, ; Diqii coun! - 1
addwf disp_ha, w ; Digit H-adr + count
;SeE FsR register
novfw indf ;Read digit
add!{f segt_ha, i.l ; SegT H.Adr + digit
; seL FSR regisrer
novfw indf ; Read segl data
; irrrite LjiD da1:a

,
oaid3) Plc crrcuits Gallery - 2 Frc {dDi%ioicJ, 3?tr?:noo3o5,Qr(?)

decfsz digi! cnL,t ;Digit counl - 1


goto int end ;JumP Lo interrupE end
; rnitial wa l,je
movrf digit_cnL ; Se! initial value
goto int end ; Jump !o inlerrupt end

; END of Ultrasonic Range Meter

3-Jr RF Remote Controller

roFd4A gmag.8$,co\o): T,?{:L9Ler 66}3ctoq.?colgc. nao:coi:corcD6:c) . -


r-rL.
o,e.6ord{4 eoT$"1"p)l 66t8c$c$e:c{ Plc qc6a{c3$co6cr;r9 cooe qp:@8.d$:S:
cAdq88 eo:ole2irr o6'otre1$eor cqSc$ci€:? crde qprofco2!: Plc {da{%qco{oJrB3.o€
G{crrdGoTcao5oidl ,rdu
oo6o:3:9€ Transmitter odco6:9t Receiver <-rdcu6:c:2$ saQS:
56Q8:o1o3o1o$rr
o,>6Q3:q€:oe@cE:of -.,5coc6$",TSJ'$r'

g-O-cn Transmitter ooEcn6:

Q(g-cG)ce3 Transmitter odco6:Q9t. oo5cu6:o2)eeocci$:{"6.?,cor:creiolo3q{.cA


e<rTScca: o1 o$ rr

i[ Tro3
-r
RS
,47 R5 )-
-
n(" y 100

TRt4rp

B2

tk

ICI:PlC10F844
IC?:78105

9(q r9J lransmfferocD(,)c:?

r?.1
' 'e uruu{! udrery _ z P/c s..,5a{.8+o{o, 3?+:qlo0306:qpr(?)

Q(9-c9) Transmitter odoJ6:ord66or.r5$r{c6c2:co::og)e1oBQ

tow Chart qp:o? e"":cica E eoTQ"o:,,,1er2!


rr

---: 39a
oal:(0) Plc cilc'r'rscalrery- 2 Prc {daice6co{c',r :o4,Xodcos,9dl)

Set Pettern I
(PATTERN)

Q(g-co) Transmitter oo5c,:E,oqrf r{ow Chart g(c/G)

.w
.oa6:(g) Plc circuits Ga lery 2 Prc €.3a6q$c.qM s.i:qoo5o6:qP,(e)

inr)- .l,r"l2i -tov. .1 riJ/Gl

.?,
oal:(J) Plc circuits ca ery - 2 ptc q.,5a{,€i@6N- o:i:qloo5c!3:9pdq)

Prdrble code: l0l0l0l l0

9(g 3o) Transmitter "d.o6:cocarf Flowchart Q(?/0)

J?0
@a4:(J) Prc crrcuiis Garery 2 pra
i.n6qi.doqu a{:Aoo1o5:qp(?)
j
Nonl rol code : l)101)i0lI0lI0llio lI0 r:r[]xil ! 16

Q(3 1:) rransmitter odo:5,caca.6 t.torv clre Q(9,iG)


e+d!) Prc circuits Gar,ery - 2 Prc $;"eclol'u. -'i'1,$ 8*pd,)

iES

ISUBSTATUS=23)
ND{BA=1)

q(9-jJ) Transmitter rtow Charl 9(9/G)


".3-3,-cao5
eai:le) PIC crrcLrts ca|ery, 2

{[ODE DATA)

(PTl{l)

(PTN2 )

iB85=1,fi87=rl)

{RE5.0,EE?=l J

Set RL I ihe(500nsec)
(EELAY=58]

yraJ_J1J trdrli ao-uoro)d:3,%rr :tor,, Ch.rl


1,(G,b)

.?e
@a4dt) Plc Circuils Gallen/ - 2 Prc,?da{csicp6cu. s+:qloo5N5:qP:(?)

iransm'iler ou)coe:3ror(,i Sourcc coco 6D:ar) G6rlctctacc i irjcoa:rl3j5r

, Renote Contlof1er. Transnitter

; Author : Seiichi Inoue

list p:pic15f84a
include p15 f8 4 a. inc
_config _hs_ osc 6 6 Jerte_on e cp_off
-3O2-wdt_off;Eliminate bank warDing
I rl.or Fofi rr I ion
cblock hrOcl
;TX status save area
;TX substatus sawe area
; Patlern sawe area

ptnl egu b'111100001 ;Pattern 1 data


ptn2 equ b'00001111, ;Pattern 2 data
equ ;BA4 bit position

org 0 ;Reset vector


goto init
ors 4
goto int

init bsf , change to Bankl


movlw b' 00000011 ' ;83,4:OUT RA1,0: IN dode
; Set TRISA leg
movlw b' 00000101 ' ;RBPU/TOCS/PSA=o, PS:101
rnovwf option reg ; Set OPTION_BEG
bcf status, rpo ; Change to Banko

clrf porta ;stop wave emission


clrf tx stalus ;Clear TX status
clrf tx substatus ;clear TX subslatus

novlw b'00000001 ' ;Set mask paltern


andHf porta, w ; Pick up RAo
btfsc status. z ;RAo = 1 (SWl ON) ?
goto inl ; No. check next input
novfn ptnl ; set patternl data
in0 nowrf pattern rSave pattern data
; Jump to timer set
inl novlw b' 000 00010 ' ;Set mask pa!!ern
andwf porta, w ; Pick up FAl
btfsc status, z ;RA1 = 1 (Sw2 ON) ?
r No. Ilfegal input
novlw ptn2 ; Se! pattern2 data
ooidd Prc c rcu,rs calery 2 prc .?.3ai%lco6o ori: c3N5:qpd?)

f.i. inc ;Junp to Patrerrr save


tn mov14 d'100' ;256-100001rs/64us = 100
mcvui lnro :Set 1Onsec to TMRo
mavlri h'a0 ' ;GIE=1,ToIE=1
goio S ;l,iait interrupr-ion

int
bci intcon,toif ;Clear tiner inE flag
stchk0
movf tx status,w ;Read Tx status
blfss status,z ;TX status = 0 ?
goto stchkl ;No. Next

novlw d'7' ;Set check data


subwf tx substatus,w ;Substatus - check data
brrs_ slalLs.z ;Subsrdrus - 7 .

goto slinc ;Yes. substatus + 1


novlw d'8' ;Set check data
subwf tx substatus,w ;Substatus - check data
btfsc statDs?z ;Substatus = 8 ?
goto st 01 ;Yes.
movlw d,9' ;set check data
subqf !x substatus,w ;Substatus - check data
btfsc slatus,z ,SubsLatus = 9 ?
goto st02 ;Yes.
movlr b'00000001' ;Set inask pattern
andwf tx substat.us,w ;Pick up r,SB
btfss status,z ;],SB = 0 (Even) ?
goto st00 ;No. (Odd)
bsf portarra4 ;Start wawe enission
goto stinc ;Junp to subslatus + 1
st00 bcf porta,ra4 ;Stop wave erTdssion
goio sLinc ;Jump to Substatrrs + I
st01 bci porEa,ra4 ;Stop wawe emission
goto stinc ; Jurnp to substatus + 1
st02 bsf porta,ra4 ;Stalt wave enission
clrf tx substatus ;CIea. Tx substatus
incf tx status,f ;Set TX status:1
goEo int end ;Jump to tiner int end

stchkl
mowla d,1' ;Set check data
sub{f tx status,r ;TX status - check data
btfss status,z ;Tx status = 1 ?
goto stcr,\' ; No. N'xL

mowi tx substatus.w ;Read TX substatus


blfss slatus,z ;substatus = O ?
goto stl1 ; No. Next
movlq b' 00000C01 ' ; Set mask paiiern
and i patte.nrt
btfss s!aEus, z
goto st10 ;No. Data - 1
; Stop save enission
; Jump to Subsrarus -
sr10 bsf ; S tart wave enission
; Jump to Subst.aeus +

s r11 ;Set check daEa


subwf tx substatus, tr ; subslaeus - check data
btfss ; Substatus : 1 ?
st12
bcf ; Stop wave emission
9oto ;JmP to Substalus + I
st12 d'2 |
; Set check data
subwf _
tx substalus, w ;substaEus - check data
btfss ; Substatus = 2 ?
srt3
bsf ;stai! wave emissio:l
;Junp !o Subsiailrs + 1

sr13 movlw d' 3' ;Set check data


subwf tx_substatus,w ; substatus - check data
btfss sEatus, z ;Substatus = 3 ?
goto st15 ;No. Next
movfw b'000000101 ;Set nask patlern !
andnf patte.n, w ; Pick up data
btfss status, z
goto st14 ;No. Data = 1
bcf porLa/ra4 ; stoP wave enission
; Jump to subst.atus + I
st 14 bsf porta, ra4 ;start. wave emission
;Jump to subslalus + 1

st 15 ;Set' check data


tx substatus, r,t ; Substatus - check data
btfs s ; Substatus = 4 ?
sr16
bcf tstop irave enission
; JurnP to substatus + I

st16 d,5, ;set check data


subwf tx substatus,w ;Subslatus - check data
btfss ;Substatus : 5 ?
sr17
bsf ;Star! !,,ave enission
;Junp to substalus + I
st 17 .t'6' ; Set check dal-a
tx srrbstatus, w ;Substaaus check data
; Substatus = 6 ?
9t19
Lr'00n001001 ; set mask paEter.
3'aEdc) prc c'cuits Garery - 2 prc
€o3a{,?i@{M ori:flodo3:qp(?)
andviJ paitern, w ;Prck up.ia!a
br-fss status,z ;Data:0 ?
golo st18 ;No, Data - 1
bcf porta,ra4 istop wave enlssaon
golo sLlnc ;Junp to S,rbstatus + 1
st18 bsl porta, ra4 ;Scart {ave emission
goto slinc ;Jump to SubsiaLus + 1

st19 novl! d'?, iset check data


sub f tx substatus.w ;Substatus - check data
btfss sEatus,z ;Substalus = _r ?
goto st20 ;No. Next
bcf porta, ia4 ; Stop wave emission
goto stinc ;,lump to Substatus + 1

st20 novlw 8'


dr ; Set check data
subuf tx_substatus,w ;Substatus - check data
btfss status,z ;Substatus = 8 ?
goio sL21 ;No. Next
bsf porta, ra4 ; Starr nave emission
golo stinc ; Jump to Substatus + 1

st21 novlu dr 9 r ;Set check dala


sub\,rf tx substatus,{ ;Subsratus - check data
btfss status,z ,Substatus = 9 ?
qoto st23 ;No. Next
mov],, b, 00001000 ' ;Set nask pattern
andwf pattern,w ;Plck up daEa
btfss status, z ;Data:0 ?
qo[o st22 ;No. Data = 1
'Dcf porta,ra4 ,Stdp wave em_ission
goto stinc ;Jump to Substatus + 1
sE22 bsf porta, ra4 ;Stalt wave emission
goto sLinc ;Jump ro substatus + 1

st23 ncvlu d,10' ;se! check ctata


slrb l t: substatus,w ;Substatus - cleci dara
bLt:js sLatus, z ;Substatus = l0 ?
goto st24 ;No Next
bcf poria,ra4 ;St.op wave enission
goto stinc ; Junip to Substatus + I

st2A novlw dr11' ;Set check data


subrrf ta substatus,w ;Substatus - check data
btfss status.z ;Substatus = 11 ?
goEo st25 ;No. Next
bsf porta,ra4 ;Slart vave emission
qoto stinc ; JunLp to Substatus + 1

s!25 novl\d d'a2' ;set check data


subuf tx substatus,w ;Substatus - check daLa
btfss status,z ;substatus = 12 ?
goLo sE27 ; No. Next
novlw b'00010000' ;Set mask pattern
andwf pati:ern,w ;Pick uD data
€a6:(J prc circuirs Galery- 2 ptc qo5a{%6o6@ o.i=JooSNd:qp.(?)

btfss status. z ;Data:0 ?


goto st26 ;No. Data : 1
bcf porta,ra ;Srop wave enrssron
goto stinc ;Junp to Subsrarus + 1
st26 bsf porrarra4 ;Starr wave enission
goto stinc ; Junp to Substatus + L

sL21 novlw d'13' ;Set check data


subwf tx substatus,w ,SDbstatus check data
btfss status,z .;Substatus = 13 ?
goto st2A ;No. Next
bcf porta,ra4 ;Stop lrave emission
goto stinc ;Junp io Substa€us + 1
st28 movfw d'14' ;Ser check data
slbwf tx subslatus,u ;Subsi:atus - check data.
btfss staius, z ; Substatus = 14 ?
goto sL29 ;No- Nexl
bsf porba, ra4 ; Start vave emission
goto stinc ;Jump to Substatus + 1

st29 novllr d'15' ;Set check data


subwf tx substatus,w ,substatus check data
btfss status, z rsubstatus:15 ?
goto st31 ; No. Nexr
rLowLB b'00100000' ;Set nask patrern
andwf pattern,w ;Pick up data
btfss status,z ;Data = 0 ?
goto st30 ;No. Dala = 1
bcf porta,ra4 ;Stop wave emission
goto stinc ; Lfump to Substatus + 1
st30 bsf porta, ra4 ;Start wave emission
qoto slinc ; Junp to Substatus + 1

st31 movlw d'16' ;Set check data


subHf tx substaEus,w ;Subsrarus - check.tata
btfss status,z ;Substatus = 16 ?
goto st32 ,.No. Next
bcf porta,ra4 ;Stop wave emission
qoto stinc ;Jump to substatus + 1

5t-32 movlw d'17' ;Set check data


subwf i:x substatus,w ; Substatus check data
btfss sLatus, z ;Substatus : 17 ?
goto s tl3 ;No- Next
bsf porta/ra4 ;slart lave enission
goto stinc ;Junp to substarus + 1
sl33 novlw d'r8, ;Set check dara
subFf t: substatus,fl ;Substarus check data
btfss slatus, z ;Substatus : 18 ?
goio stl5 ;No. Next
novLw b,0100000C' ;set nask patrern
andwf patler.,to rPick up da.a
blfss staius.z ;Data = 0 ?
I -4,tcl Prc circuits Ga 6ry - 2 Prc €d5$.8$o{o, orr:qodN5:qPd?)
qoto st34
bcf porta/ ra4 ; Stop Dave cnission
goro stinc Jump to Substatus + 1
st34 bsf porta, ra4 Sta!t rave emission
goLo stinc Jump Lo substatus + 1

sL35 novlD d' 19' Set check data


sub f Lx substatus, w Substatus - check ctata
btfss status, z Substatus = 19 ?
goro sr36
bcf porta, ra4 Stoi save enission
goto stlnc Jump to Substatus + 1

st36 movlw d,2Al ; Set check data


subwf tx_substatus,w ; Substatus - check data
btfss ;Substatus = 20 ?
qoto =tatus,Z
st37
bsf porta,ra4 ;Start wave enission
goto stinc Jump to Substatus + 1

st37 movlw d.'2Il Set check dara


subwf tx substatus, r,r ;Substarus - check dara
btfss status,z ;Substatus = 21 ?
qoto st39 ;No. Next
nowlw b'10000000, ;Set nask pattern
andnf pattern,v ;pick Lrp data
btfss status,z ;Data = 0 ?
goto st38 ;No. Dara = I
bcf porta,ra4 ;Stop wave emission
qoto stinc ;,tunp, to Substatus + 1
st38 bsf porta.ra4 ;Starr wave enission
;Junp to Substatus + 1

st39 novlw d'22, ;Set check dara


subwf tx substatus,w ;Substatus - check data
btfss siatus,z ;substai:us = 22 ?
bcf Irorl:a, ra4 ;sLop Ra!.: emissaol
qotc, srjic ;Jump to Substatus + 1

st40 bef pctLa,ra4 ;SEart eave enission


clrt L.- srir::rstaEus ;clear Tx substatus
incf L:i_starrs, f ;Set TX status : 2
qoto in: end ;Jump to tiner int enat
E..j da1-a send Process ********
stchk2 movlw C,2' ;Set check data
subuf 'Lx substarus,w ;Substatus - check data
btfss status,z ;SubsEatus = 2 ?
goto stinc ;No.Junp to Substarus + 1
bcf porta,ra4 ;Stop save enission
cfrf rx subsratus ;Ctear TX substarus
cfrf tx status ;C1ear TX sraLus
goEo lDt end ;Jijnp to -Lirner int end

eoc
s6;:(J) Plc circuits Gall"ry - 2 Plc Q.3a6l?+@iM o4:qjo.5-*i:ii,(;)

slinc inci i: substatus,f ;substatus + I


of limer Inter.Lrption Pro.css ***"*t**+*+
End
int end novlr d' 100 ' ;256-r000Ous/64us = 100
novrdf tntro ; set 1Omsec to fMR(]
retfie ;End of inlerruption

J-g-J[ Receiver oc3ca8:

i(C-.fE).ae neceiver odcu6:Qg3. ,.,"3.o6,-gie.o.c6S,{ .,3o?:cc.,:cldol 05Qo?.4


..TS"r.'u1.tg! crdcoS:q3 FET amplifier oo5cu6'sr-3.96-3.c{ RF +oc33r@6
Receiver
'
ca1,Q1cm'<i::pjL, t'-ansmitter 9qg€.qo5{.5m, 3,flo5843:c4 G6:,rRg:6r4o5 f3"d?2,
@€. detectlor l!;"13- qfic\rrn.r, cocle sgral voiiage 4 voltage comparalci(l::l::,
no:1€:c$o5,jlerp)' lc1 gogrieoTo::eocQ.r:::{ ctc {oSa{caico{c'-"'\ RA1 !d%:
codtrJ3:cQc8$:€S"c,5 .{.q3@3. erc69.3-",qc6ea"1 oc5{39 control relav ql.:.{ enersize
G6.'o, di,qlp.Q.",cB{occ{ e8o3/sag3. ELe36.,:.,1 3rd,,
E4
1[k

lDIF Hil
ttL
DI I U.A0

2SH433

[5

+fi0
I l0:l
ELI
ll5f- l I]ND

77 ./.
Y
LED2
LEDI

ILll: Lltlil59r,l
l[!: Pll]EFI41
lr_r'J: l8Ltr5

,7(3 19) Recerver o;i:'i:9


;
g1"o5c"6,.:E! Trar jmitter c6€ san:@Lcor:eoo output RF amptifier €r\{di:c,jl
ro)dE: o8i:Ar5fis?,€3:ae oie@€:cbg3<i o2!r Fr/ fd:of6c{ @4:01{e6ei4dtm QQco:or
eo"di,18q.{ q6{36,,o36.cdr Receiver odcu6:sac6cr5 1m 51$orc antenna c{ sa1:Q1
$3p: rransmitter sacacA zocm g$n.', antenna .'?3?3i:01{3"1e>d' gfc,o5cu3,d1'"i ooor
Lock o$.cqo5 security Lock 3?{:G6edod, Q(g-Jg) %3 neceiver
"er2),-,o5-6'qp,q3
oo5co6:o:2ieeocciS: {.Eo?:co'-a:61dQoE eoT@cor:o1 o2irr

nf{T

g(9-1g) Recelver odo6,orple;-cA$'{cAq:coc:o$"1dQ

RF Remote ControlTer Circuit g€cilo€ecl Recerver ocDcDrr:3)cB.rJ l-row unart


Qqp:c{ e".-.6cA3.oTQ-",,io2iu $4o:l Flow chart qp:d 3?8ooi.r43, ;o<6o6"c',r.cor
@d6€:3rl@e. <,"5<u3,qp::ao16o23Q
=a<o€.;"€..{
s1.c-:cpqEcop!: caecooci:aq@fi6e oc36.e $ rr
c5fi9",.o2){€ @e <,c2!
'' o{oq8s'.{
Q1@€e
c4:b) Plc Crrcuiis Gallery -2 Prc $o56{qE@{or!, 3i5roc3N3:qD:r.)

iig yG) neceiver odcu6::acg.fi rtowcnar ql>rG)


-b+:\9 ' Lu urrcutts ual,ery - 2 |-ru id.i.2ts@{ry o ,jr" _o5ru":qpdql

NI]

=0)

YES(1)

Q(5-19) Recei,er ""3o:6:eacacf rtow Cnarr Q(3/G)


(g/d)i !eq3 /{ou o8oee:ecuSoo renreces (ol-G)'A

(I-'!8 s180J)
uorss t{s a,\rft }.r€ls

1a1dr,,r.-3..f ,g"-
^$-te"g"3.ol cra ; - f.;a;;e3 s;1nr.331a (G):feo
oa$:(!) PtC Crrcuirs calery- 2

P ick uF Eii{
(PATTEFN)
Ti SUB:]0 ?

iltop $a!e ern iss ion


TFI|RTA.FA4=[)

Starl riale em isrion


(P|RTA.nA4=1)

P ick up BitE
{PATTERN)
i{_SUE= 1N 1

(POFTA. RA+[)
TX 5116=14 l
Start $nve enis3ion
(PoRIA,RA4= l)

P jck !p Bit6
{PATTEBJ{)

Stop $aye em i\- ion


{PtlRTA.RA4:I])
Sl3=11 ?

l^tiri ka€ eh is: ion


iFOEIA.FA4.] }

Vi9 JC/ Reierver uo).rrd:3?(z.D riow Chart


9(9/G)
(

od$dg) PIC Circufs Galre;/ - 2 Prc qo5aEo:4cD6or ecl:qoo5cr:5:s:(q)

Q(g-qo) Receiver <-ro5of:sacac6 rtow }rart Q(g/G)


o$y't) P C Circ .irs Ca[Frv
.
2 ptc q-,S-iei6p1) o..:" .orts:!r:(\]

iTrl_STATUS.2)

c)(9- gc) Receiver odco6:acac,3 Frow chart


Q(G/G)
s{:(3J PrU Ullcurrs Garr€ry - 2 prc q.,5aice$co{cvJ oci.qoobN6:qp:(?)

Receiverc,o8cu3:acac,5 Source code qp:rf eocc6cg8eoTGcoc:ol r:$r'


l** *\r** **** * ** * *
Renote Controller Receiver
, i,urhor : -qeiichi Inoue

list p=pic16f84a
P'o 84 ' .nc
config _hs_osc & _'clt_off & _purie on & cp off
errolleve] 3A2 ;Elininate bank Farninq

Label Definition
cblock h'0c'
;RX sLatus
;RX subsCatus
; lnput edge check ffaq
; lnput last, lqok flag
; code check.ffag
, ConCroI Data
;Relay ON countet
ill ireq save area
; Status reg

ptnl b,11110000', ; l data


PaLt.ern
ptn2 b| 0 0 0 01111 ,
2 data
ra1 d'1' ;RA1 bit position
rb5 d, 5' bit ;RB5
bit ;RB7
. ********r***** ** Progrd start **********
org 0 ;Reset vector
goto init
org 4 ; Interrupt Vector
goto int
++ lnitiat Process +*,*.^r.r
init bsf sta!us,rpo , Change to Bankl
novlw b'00011111 ' ;RA4-0: IN node
; Se! TRISA reg
mowln b'00000000' ;RB7-0: OUT mode
; set TR15B reg
mowl\,, b'00000101' ; RBPU/TOCS/PsA:0, Ps:101
movwf option req ;SE! OPTION REG
bcf ; change ro Bank0

portb ;RLt, RL2 OaF


cl ri
clrf ;C.lear RX substatus
cl rf ;Clear Edge check flag
incf Last look, f ;Set Last I,ook flag oN
prc ori.Elocbo6rqp:(?)
{or.{aeioiQ,
clrf I codc
ck ; Clear code check flaq
clrf cont data ; C]ear Controt Data
cllf relay ;Clear Relay ON counter
novlw d' 100 ' ;256-10000us/64us = 100
movDt lmr0 ; set lOmsec to TMRo
movfH h,a0 ' ; GIE:1, TOIE=1
novwf intcon ; Interruption enable
check Process
btfss ; Input signaf oN ?
goto ;No. Siqnal OFF
btfsc Iast look,0 ;lasl look flag oFF ?
; No. lnput NOT changed
bcf ; Interruption disable
incf ;Se! code check flag ON
incf last_look, f ;Set Last Look f1a9 ON
d,178, ;25 6-5000us/ 64us = 178
rmr0 ;set 5nsec to TMRo
bsf ; lnterruption enable

btfss ;Input edge check ?


goto ;No. wail interuption
clrf ;C]ear edge check ftaq
;Jump to Input edge check
checkl
clrf last fook ;Se! l-ast i,ook flag oFF
goto ;Junp to Input edge check
.************ finer Inte!ruption
int
; Save W reglster
;Read STATUS req
;Save STATUS req
bcf sta!us, rp0 ; change !o Bank0
bcf intcon, t0i f ; C]ear tiner int flag
;React Relay ON counLer
; Counter = 0 ?
stchk0
decfsz relay, f ;Counter-1=0?
stchk0
clrf ; Re]ay OFF

stchk0
;Read code check flag
btfsc ;Flag ON ?
; No. End of interruption
; Read RX status
btfss ;Slatus : 0 ?
9oto stchkl

rx substalus, ;Read RX substatus


btfss ;Substa'Lus = 0 ?
@6E:fu) Fic ci.cuiis Gailery - 2 riu ycoi-+*ic-- el: qjo.i x =:i.j.r! rJ

goro sr00
99 LU \:L UL' lnpur signal oN ?
st00 nowl!' d'1' Set check data
subaf ix_substatus, w SubsLatus - check dala
bEfss slaLus? z subsEatus = 1?

9o!o st_off ;Input signal OFE ?


s t01 movlvr dr2' ;Set check data
suberf rx substatusr !r ;Substatus - check data
bifss status, z ;Substatus = 2 ?
golo sta2
goto st_on ; Input siqnal ON ?
st02 , ser check data
subi{f rx substalus,w ; subsEaEus - check data
btfss status, z ; Substatus =3 ?
goto sr03
golo st off ; Inpui signal QFF ?
; se! cleck data
subHf rx substatus, w ; substatus - check data
btfss status, z ; Substatus = 4 ?
goto st04
goto st_on ; Input signal ON ?
sl04 movlw d'5' ;Set check data
subwf rx substatus, w ; Substatus - check data
btfss status, z ; Substatus = 5 ?
goto sf05
goto st_off ; InPUC siqnal OFF ?
st l5 movh d' 6' ; se! check daca
subwf rx substatus, w ; Substatus - check data
b!fss status, z ; substatus = 6 ?
goto s!06 ;N..
goEo st_on ; Input sigrnal oN ?
set check data
subwf rx subslatus, w ; Substatus - check data
bEfss status? z ; substatus = 7 ?
goto st07 ; No. Substalus:8
goco st_on ; Input signal oN ?
sr.)7 btfsc porta,ral ; Input siqnal oFF ?
goto 11leqal ;No. Jun'p to itlegal
clrf rx substatus ;RX substatus = 0
incf .x status, f ;RX status -- 1
clrf cont data ; Clear count daLa
goto int end ; End of inlerruption

d'1' ; set check data


subwf ;RX sLatus - check dala
;RXstatus=1?
stchk2
controf data check Process
movf rx_substatus.w ;Read RX substatus
bLfss sialus,z ,substatus = 0 ?
.jo!o stl.o ;No. Next
3'a+r{Jr flY u,rcui's l,are.y 'z P c lma{,?ioiM ori'flodNdrqpd?)
qoto st_on ;Inpur siqnal o. ?
si10 novls d'1' iset check data
subwf rx subjtatus,w ;Substatus ch!.:k ijaL:
btfss status, z ;Substatus : 1 ?
goto s!11 ;No,
bLfss polLa, ra1 ;80 = 1 ?
goto Etinc ;Jump to Substatus + i
bsf con! data.o ;Set B0 = 1
goto slinc ;Junp to substatus + L
stll movlh d'2' ;set check data
subwf rx substatusrw ;Substatus check daEa
btfss status,z ;Substatus : 2 ?
qoto st 12 ;No.
goto st_off ;Input signal OFF ?
sE72 novlw d'3' ;set check data
subwf rx_substatus,w ;Substatus - check dala
btfss status,z ;Substatus = 3 ?
groto s!13 ;No.
qoto st_on ;Input signaf ON ?
st13 movlw clr4, ;seL check data
subwf rx substatus,w ;Substatus check dara
btfss status,z ;Substai:us : 4 ?
goto st14 ;No.
btfss porta,ral ;B1 = 1 ?
goto stinc iJump to substatus + 1
bsf cont data,l ;Set B1 = 1
goto stinc ;JunP to subsraEus + 1
st14 movlw d'5' rset check clata
subwf rx substatus,w ;Substarus - check dara
btfss status, z ;Substatus:5 ?
goto st15 ; No.
qoto st_off ;Input signal OFF ?
st15 novlw d,6' ;Set check data
subuf rx substatus,w ;Substatus - check data
btfss stalus,z ;SubsLatus = 6 ?
qoro sL15 ,No.
goto st_on ;Inpur siE.al clj ?
sL16 novllr dt?' ;Set check data
subqf rx substarus,vr ;Substatus - check daLa
btfss status,z ;Substatus = 7 ?
goto st 17 iNo.
btfss porta,r:a1 iB2 = I ?
goto stinc ;,Jumpto Substatus + 1
bsf cont data,2 ;Set 82 = 1
qoto stinc ;Jump to Substatus + 1
st17 nrovfw d'8' ;Set check data
subef rx substatusrv ; Substarus check data
blfss status,z ;SubsLatus : I ?
qoto st 18 ;No.
goio sl*otf ;Input siqnal OFF ?
st18 movlw d,9, ;Se! check data
subqf rx_substatus, ;Substatus - check dara
btfss sLatus,z ;substatus = 9 ?
qoio st 19 ;No.
_ooto s!_on ;lnput sig.al CN ?

.e<7
@aid3) Plc circuits Gallery - 2 r,! ti:ri%tesa, 3T:ijoeN4:qP:rir
s!49 -\ novlw d'10' ;sei check ddta
I subwf !x substatus,e ;SubstaEus - check data
. btfss slatus,z ;Substatus : 10 ?
goto st20 ;No.
btfss porta,ral ;B3 = 1 ?
goto slinc ;JunP to Substatus ? 1
bsf cont da, J, I ;sel 83 = 1
goto slinc ;JunP to Substatus + 1
st20 novlw drllr ;Set check data
sub f, rx substatus,w ;Substatus check data
btfss status,z ;Substatus = 11 ?
goEo s! 21 ; No.
qoto st_off ;Input signat oFF ?
st2a movlw d'12' ;set check data
subwf rx substatus.w ;Substatus - check data
bLfss status,z ;Substatus = 12 ?
goto st22 ; No.
qoto sE on ;Inpul signal oN ?
st22 novld d' 13 ' ; Se! check dara
subwi rx substaius,w ;SubstaLus _ check data
bLfss status, z ; subslalus = 13 ?
qoto st23 ;No.
btfss polta,ral )84 = I ?
goto stinc ,JunP to Substatus + 1
bsf cont data,4 ;set 84 = 1
goto stinc ,JunP to Substatus + 1
st23 howfs d'1.4' rset cbeck data
subwf rx substatus, ;Substatus check data
bLfss status,z ;Substatus : 14 ?
qoto st24 ;No.
goto st_off ;InPut signal oFE ?
si24 movlw d'15' ;set check data
subwf rx substatusrw ;Substatus - check data
btfss status,z ;Subslatus = 15 ?
goto Et25 ;No.
qoto s!_on ;InPu! signal ON ?
st25 novlw d'16' rset check daLa
subwf rx substatus,d ;Subslat'rs - check data
btfss status,z ,Substatus : 15 ?
qoto sL25 ; No.
btfss porta,ral ;85 = 1 ?
goto slinc ;Jump lo substatus + 1
bsf cont data.5 ;set 85 = 1
g, a stinc ; Jump !o substalus + 1
st25 movlw d'17r ;seE check data
subwf rx substatus,w ;subslaLus - check data
btfss status,z ;Substatus = 17 ?
goto sl:2',] ; No.
golo st_off ; lnput signal ofF ?
.-21 novls d' 18 ' ; Set cbeck daLa
subwf rx substatus,s ;SubsLatus - check daLa
, bttss status,z ;subscalus = 18 ?
goto st28 ;No.
qolo st_on t tnpL't signal oN ?
si2ll movlw d' L9' ,'rf ch-ack data
. @{dJ) prc ci'cu'q calery 2 prc
i.Sb{,"ico{^,, e+:floo8N;:qj,,ri,

--ffiffi bt r-s
goro
btfss
,u--, s,z
st29
porEa, rat
;Sub-Lar : = . j
; No.
;BO: t:
goto stinc ; JumP Lo subsrarus + 1
bsf cont clara,6 ;Set 86 = 1
goto sLinc ;JDmp to :ubsLalus + 1
st29 movl d, 20 , i Ser check dar.
subHf rx substarus,k ;Substarus - check dara
btfss st;Lus.z ;SubstatLs = 20 ?
goto st30 ;No.
goto st off ;Inpur signai oFF ?
st30 novt d,21 , ; Set check data
subwf rx substarus, w ;Substatus _ check data
btfss stttDs, z ;Substalus = 21 ?
goto sr3] ; No.
goto st on ;Input signat oN ?
st31 movlw d,22, ;Set check daLa
subwf rx substarus,w ;Substatus - check data
brfss st;Eus,z ;substalus = 22 ?
goto sr,32 ; No. Subsialus-23
btfss porta.ral ; B'1 = I ?
goto srinc ; Jurnp to substatus + 1
- bsf cont-data/7 ;Set B? = 1
- goto stinc ;Junp to subsLaius + 1
. st32 blfsc porta,ral ;Input siEnat OFF ?
I goto illegat ;No. ,rump ro lftegal
clrf rx substatus ;RX sutrstatus : 0
incf rx_status, f ;RX status = 2
got'o int end ;End of j-ntelruptjon
st on
btfss polta?ra1 ;Input signat ON ?
goto iflegal ;No. JumP to rt1e9a1
goto stinc ; ltu!l1]r to subs.atus + 1
sL off
blfsc rjorl a, ra1 ;Inpui sig-.,j ailt ?
goto l:lt egat ;No. Jlmp :o rltegar
9o!o siinc ;Jump to SubsLatus + I

srchk2 btfss porra.ral ;rnput siqnal oN ?


goto itlegat ;No. Jump to ittegaL
novt!{ d,2t ;Set check data
subwf rx subsratus,!r ;Subsratus - check data
btfss sratus,z ;subsrarus = 2 ?
goto stinc ;Jump to Substarus + 1

novf cont_data,w ;Read controt data


xorlw ptnl ; Check patternl
btfss status.z ;Data = paLternl ?
goto drchko ;No.
bcf porirb. rb7 ;RL2 oFF
bsf !-.trb, rb5 ;RL1 ON
saE:b) Plc circuits Ganery-2, , Plc {o5.6.8$coio -i,qu.5-6'qpdr)
goto dtchkl ;J:rD to Cl.l counter se!
ci!chk0
movf cont-da t a. w ; Read control data
xorhr p-LI)2 ; Check rattern2
btfss status, z ; nai3 = Patte:n2 ?
_ goto illegal ;ilo. Jusp 'Lo i lleqal
bcf portb, rb5 ;RLl Oll
bsf portb, rb7 ; RL2 ON
novfw d'50' ; Ser 50ornsec Relay oN
mowf relay ; Sa?e Relay ON counter

il1ega1 incf ;Edge check flag ON


cl.f rx subslatus ;RX substatus = 0
clrf ;Rx status = 0
cl rf ;C]ear'code check flag
;End of inlerruption
subsEatus Increnent Process **r*++++****++
rx subsEdLus,i ;sros!aEus ' I
,******** End of Tirer Interruption Process +**!*****r*
d'100 , ;256-10000us/64us = 100
lmr0 ; set lonsec E.o TMRo
;Read saved STATUS reg :

;Recover STATUS reg


seapf ;Read sawed W register
swapf ;Recover W register
retfie ; End of intelruption

END of Remote contlofler Receiver


i

You might also like