Professional Documents
Culture Documents
LMA) ဝင္းထက္ဝင္း PIC
LMA) ဝင္းထက္ဝင္း PIC
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
-d:ora:S$oo$op!:q:p!go8eq; r
oRn"q'f,'-dfloE(g)t1"
.
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)
PART (3)
eee
oc3@moe3
* 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
?-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
? - ?-J 1
o8<rsa{1:saoa:ooEoc6: Gg
r
:coco@:30 _rn _ co!1oS6o o$& oool
oo$:(c)
Example Programs in PicBasic
c-lr $s1$:
c-J-cr Program-l
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 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
c-J-?[ Program-3
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 '.:
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
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)
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
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
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
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 )
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
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
'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
'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
+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
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
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
ca
o"$:(1) Source Code eq:g2i:-1 et c Q
o5a{ q$-{* san:q<.roEco6,qp,(t)
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
r0
./
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'.
cG
saa$:(1) Source Code eqqpi:-..1 etc Qc6a{ q6-6* ocq:q1oc8co6'qp:(l)
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
sfAfus oa}t
3c)a
saa$:(1) Source Code eq:qg):-..y P:C {oAa{q$-.fi * ocg:ero.3co6r"p,(q)
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
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
\
,.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
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
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
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
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
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.
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.
:
J?
*n$/U) Scurce Code eqri$:-".1 Pl C 1oEafl %$co{eo CI{;qprc3or6:qpr(t)
r'
!+ !r'?,-.C of thc prJul:;tl.+++ *
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
J9
os$:(y) Source Code eq:ggl:-..1 etC $o5o{ ca$-fi sacq :q1oo8cu6rqp,(t)
-
Goto LABEL
. RETURN
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)
Delay loop q3
subroutine trt 3"ri:G1cqc;83:G8. qoo<.rfioq6og] 120 bytes
9 103
bytes cQ. oiUryrn@E: eog.@Eiteooglrr
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
to
JI
(:
"-- ei
oa$:(.1) Source Coce c;i:+$:-.i rt c { c5afi cA$cofi rq1oC.*-6,qir,(q)
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)
A B F
0 0 0
0 1 1
1 0 1
1 1 0
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
0 Current Output
EX-OR Wlrh 11 New Output
EX_OR WiIh 10 New OutpuL
=":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)
call- Delay l
,'
****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
go t-o Loopl ;
return
. x***End of the program***,k
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
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
OR
ABO/P
000
011
101
111
Arithmetic Operators
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
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
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
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
BCF
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
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>
or here if set to 0
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
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)
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 -+ ^ .
-?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
RA2\-/ RA1
RA3 RAO
RA4/RTCC OSC,l
/IVIULN UDUZ
VSS VDD
RBO/INT RB7
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
c.lc/..-c.l
c3:acDo I
e
o€oo8c[(]?ego I il
StartUP
GOTO Maln
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
'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
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
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
-gJ- o3:coc3o3:
^
Jooe ?+o
c
cqforqco
c 1e
,rn$t(1) SourceCodeeq:gg):-.1 - Plc €a6o{%$co{cwr sai:q1oc8co6:qp:(q)
cec
looG 193 .$Eo181co -cc- ocicocrloc:
s'a$:(J) Source Code
:-::--+------_-
eq:+aS:-..; ntC {c6a$q4-6* cr?:qoC.r:5,qp,(?)
---__
SooG q96
"fu.lfl- -gg- o6:cocAoS:
?
san$,(1) SourceCodeeeyEg):-.1 etc QcAofica$-{* ocq:q1,:oEo:3,qp:(t)
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
Ioop
movf COUNT,O ;Move the contents of COUNT into W
, ---.-
.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)
clear
cl-rf COUNT ; Set COUNT back to 0
,.
****** **** * * * * * * * * *Mr i n program* * * ** i- * * * * * ** * * * * * ***
ma.l-n
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
loop
movf COUNTT 0 ;lvlove the contents of Count into tr{
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
\\
J-cgl The Watchdog Timer "
"s^ro
WDT Times
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
2.1,0
0,1,1 18 144mS
lnstruction Tiryllg
"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$:
Proqrammer Software
RUN
ccc
jooG qgE -c9- oc:@cDoc:
"ft.li-
oa$:(1) Source Code eq:gp):-..1 etc Qc6o$q$-6* on:q1oo6co6:qp".g)
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
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
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.
return ;
END i
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$:
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)
"
c F
tl E
\,r/1;j'#..tL-tgEFltJill.coi..,l
4
5
PINO.COM
B
Go
Proje' ls with PlC16F62B et C Qo5a{ ca$cofi c"r :;:9'q1,-,o6co3:gp:(?)
"rn$,(q)
"
{.-'o5o6:oqc'5 QcAofic6$cofic,:cqp:e\ pin q6c$:riqp:c{ agarc8,.r'lQ(e-q)"A8
n.rTQcoot<i oglrr
Wv\\'V,IOSEPINO.COM
Q(t - e) Q
c'So{ q$ofi cucqp' e,\ pin q6c$:oiqp,n"T0Q
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)
{(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
+ 7.5 - 12 VoEs
DIGITAL LED CLOCK
J ,onaso1 can be reptaced with
aruv cMos NonJnver-ting
ft
74HC5411 buffer
+ 7.5 - 12 Votts
G1
,ru$,(q) Projects with PIC16F628 etC QcDo{cai-{- snntq,,,o8co6tqp,(t)
WVWV.JOSEPINO.COM
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
Digital Tachometer <.,o5co6:caqcr5 hex file 9c CD 9 Chapter 3-HEX Files folder qEfi
6f,, JP6283-1.hex @6c.'1
ogjrr
G1
ea$:(q) Prcjects with PlCl€F628 nlC Qciafi ca$-{ * s?e,ai,ro8co3,op,(q)
2
c
4
5
B
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)
lsvon WWWJOSEPINO.COM
2fi
3Gt6
4 (\t ls
sfrr+
6(O13
rrt2
Ifi
I t0
+ 5 Uolb
Fkt
SHIFT REGISTER GND
=
D0 Dt D2 D3 D4 0f U6 07 E5
Gg
*.$t{e) Projecis r,viih FiC16F628 rlc 8dafi ca$o"{..:r ean ;qooScuSrqpr(q)
"'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
Q
(
e-
"o) <.rc8co6:org) eaoocr5$:
{ c6 q : oo: od.l C i
Go
:aaQ:(q) Projects vrith PlC16F628 etC Qcfi afi o3$*Q* ocq:qodco3,qp,(q)
? - ? -c u o@<lo€*3s@€asoo5ol6:
RA3 RAO
RA4/RTCC OSCz
".GF-l A4CLR OSC1
toont
I'no" RBO/INT R
RB1 R
I:I
tt
il5
@e
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:
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.
Gg
:3og)@:3o -oL- co!;os$o g$& gool
*l'(E)
5 x7 Display Circuit-2
9-crr {e1f:
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
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..+
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
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
coniig h'3ff3'
'ln,,ar 1,1) .r'll- L-.Llr--G i,..,^ :,-,,- -,-,^r^^
, L - Jat_:- i.C, .i Lljq
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
DECFSZ 1Ah,1
GOTO Delay1
RETURN
END
$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
END
l4ain NOP
CALL Swltch
NOP
NOP
GOTO Main
END
;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
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
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
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
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
a€
o"$r(S) 5x7 Display Circuits-2 etC Qo5o{o3$co{,r.n ooq:q1<.,o5o:6:qp:(q)
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
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
,'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)
oJ
ou$,(E) 5x7 DisPlaY Circuits-2 PtC Qcfa{c?$-{- o1:qooEco6,qp,(q)
GOTO Scan
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
;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
*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
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
o?
s".$:(9) 5x7 Disptay Cii-cuits-2 r:C '$c'5e{q+:$"-_=:""J,rc.5"r3:'g-,:(?)
: - l:l:
=:::
END
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
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
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
/ 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
t:
B3
on$,(E) 5x7 Display Circuits-2 nt C'$o5o{o6$-{- ec1:qodo:6:qpr(q)
END
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
e?
*l'(E) 5x7 Display Circuits-2 PIC Qe'5a{qi-{- on:q1oo6cu6'qp,(l)
MOVWF O6h
CALL De]-D
RETURN
END
e9
o{,(E) 5x7 Display Circuits-2 ctC Qc'So{q$-{* on:qoolcu6,qpt(e)
t-cgu ANIfrTATION - 6
; 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
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
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
nlln
DI! U
ao
-u$dE) 5x7 Display Circurits-2 etc $c6o{q$-6- oa7:q1oo5co3:qp'(q)
go
oa$:(r) 5x7 Display Circuits-2 Plc EoBa$%$-6* on:qoo5co6,qpt(t)
MOVWF 14h
MOVLW 3Eh
MOVWF 15h
GOTO Scan
MOVWF O6h
CALL DefD
MOVF 15h/ 0 ;Move fife 15 into !V
I"IOVWF O 6h
CALL DefD
RETURN
---.::_
r-"ll
-
oe$:(g) 5x7 Display Circuits-? PtC {cia$c5$*{- :acq;q.:o co6:o;r:(q)
RETURid
END
*it(E) 5x7 Display Circuits-2 P lc q c'SoQqAE-{* on :qpo5co6:qp'(q)
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
JOJ
*$,(g) 5x7 Display Circuits-2 PIC QoEafi %$-6- oa7:qloo8o:6:qp,(t)
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
MOVWF OCh
Splash3 CALL Cell3 . ';Display Cel-l 3 for 100mS :,r-.
DECFSZ OCh
GOTO SpJ-ash3
CALI Splash
GoTO Mainl
END
;Bul-lrs Eye
Iist p:pic16f84
include p16f84. inc
_conf ig h' 3f f3'
errorlevel -302 ;El-iminate Bank warning
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
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
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.,_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
coo
-
oa$:(9) 5x7 Display Circuits-2 etc Qc6a{ca$-6- ocg:q1oo6or3,ep'(t)
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
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)
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.-,":
END
3ClJ
eai:(g) sxz D'spray ckcurts-2 Prc €o3a6.B1o$o orl, qoc3o6:qPdq)
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
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
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
BCF 05,0
RETURN
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
END
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
END
,'l1"d rr
END
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
.r3
ooidg) sx7 Disptay Circ'.rits-2 prc
Qc,ta{oa9co6cur oq:epo5c.,3:qD,(1)
CALL Beepl
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
END
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
END
cJJ
r
Prc q06.6,"io6M oJ?:qoc3os,qpd?)
.Ja
s+id9) 5x7 Display Circu,rs 2 Prc F.,5o$,E{o-qo, o:1:q<-ro5c.:3'cpdp)
1929
L/\cro l.'r
ii 1929 nicro
seco.ds semnds
<.,{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
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
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
.: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
;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
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
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
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
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)
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
(P,A,FB hod.)
(F€ Pu I I -@ oFF)
0110 ?
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)
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)
3?6
@b$do) Plc circujts callery - 2 Prc EcEo{%i@fi M ori,qoo6o6:,iP(?)
.?9
s.i:6) Plc c'rculis Gal{eJ} - 2 F't- Fm-i ei4J^, -{:d.,o - b:1r:LJ,
;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
;Write FORTA
; Jump to start
c.ntro! mode qE over preset f€- below preset o9.cf swiich o:6q83. e@rS:c;
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
N] a2
(500frs1
{Bead TEST mode) lYEs (Fsd oUT SIDE tenpernture)
l{rl
YES
out_temp?
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-\.
499
re+:[9) PIC Cirdits Ga'lery-2 Prc qda{.Blo{cu, o.?:ElocBo6:qp:(?)
tqw4fi:ffiil
c95
!?a$dj) Prc c rcuits Gallery - 2 Prc Ec8effc3;@qcD: :a{;noo!c,:3:qp:(1)
Lhit:500 nilliseconds
NO
-__::_::__) |
sltl.:li
NO
YES
m
YES
NO
lllti
YES
. ii.i):
NO
YES
NO
rtG
ea+!(C) Prc circ'rlts G8llery - 2 ptc
E.3a6%1cD{Cu. @.i:Eloo5cu6,qp,(?)
; Prcgram sta'r
; In'-errupi vecior
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
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
..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
iovi.r I0
r:tl,:: .c:.jcL- r,: ;t)!,::- a
gci:o processEl
; 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)
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
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
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
ril.vri rn l
r3?
#q{o) Prc ci,cuits Gallery- 2 Plc qdaficei@qM e4=1o.3o:5,c1rdq)
,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
oGo
Plc ckcuits Gallery - 2 Prc s.Ea{(r$@{M @ri!qoc6o3:ql,:(?)
'ei,(O)
movwf intervaf I
movwi interval I
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
.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?
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
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
"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
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
.Gg
@a{d5) Plc c'rcuits Garler/ - 2 Prc $c,so{do{cD e4:qjodo6:qP,(Q)
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)
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
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 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
.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
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(?)
i[ Tro3
-r
RS
,47 R5 )-
-
n(" y 100
TRt4rp
B2
tk
ICI:PlC10F844
IC?:78105
r?.1
' 'e uruu{! udrery _ z P/c s..,5a{.8+o{o, 3?+:qlo0306:qpr(?)
---: 39a
oal:(0) Plc cilc'r'rscalrery- 2 Prc {daice6co{c',r :o4,Xodcos,9dl)
Set Pettern I
(PATTERN)
.w
.oa6:(g) Plc circuits Ga lery 2 Prc €.3a6q$c.qM s.i:qoo5o6:qP,(e)
.?,
oal:(J) Plc circuits ca ery - 2 ptc q.,5a{,€i@6N- o:i:qloo5c!3:9pdq)
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
iES
ISUBSTATUS=23)
ND{BA=1)
{[ODE DATA)
(PTl{l)
(PTN2 )
iB85=1,fi87=rl)
{RE5.0,EE?=l J
Set RL I ihe(500nsec)
(EELAY=58]
.?e
@a4dt) Plc Circuils Gallen/ - 2 Prc,?da{csicp6cu. s+:qloo5N5:qP:(?)
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
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
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
eoc
s6;:(J) Plc circuits Gall"ry - 2 Plc Q.3a6l?+@iM o4:qjo.5-*i:ii,(;)
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
nf{T
NI]
=0)
YES(1)
(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 ?
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{)
iTrl_STATUS.2)
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
stchk0
;Read code check flag
btfsc ;Flag ON ?
; No. End of interruption
; Read RX status
btfss ;Slatus : 0 ?
9oto stchkl
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?
.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