You are on page 1of 198

.

. ^.
a a \ /^r?a.
J U\-t-lr--A-rcJ\J
JJJ
^r
A
cobro$$o
AU J
e#&
J
{-r,:cl

r:lse:cog$ o'3$:bs3$$*:$to:{o:cce$gco-
r :be go$9o$cca6 j9 go3ogErbll$-
r:bsgrot5e'3coe:g6c:fgo
3cesgghgclbso &or:1ss:ccc:Tfee r:clbg$ee8see$: !{:bs:ce'g$ rS"6p-
r:bs:cel$ 'g"4,1}*-
iftoee'g$3o;ogog g,o:(o:cccllEco-

r:bs$g&goo3o- ph&
cce3b:3p ?Sfo"eE$ $cc:ce*g86g$gofo |.r:(uglrgco:lss:o8:gEos93$-
r:bsgoces$co 3ccc9co:pilS'$:bsr8:g $1eego g:ctb{e$ee 3{cEogcoee 6o$fl :3bF0-
rdr*c'c1osg$c83$g g$o:be:c8: ggo&r:[bs-
r:lssgcee$co 3ceesgoco:p:l$${p* :$co}rc869o:lss:c8:g:o$ee Fe$sesprbs:fpng-

r :be
EcrcesF* gb gco g ccSF? 3 t crca so
c'' h'rm * "",,mfr :T"?t# f ;hTf ft:l? _

ilss : :
$ $
eeo t :cleco g$ *ssccoccJ.$#S$ 1$:f#%;H-

u
@: f1t6l'bsg9 Sgoac k rccrlb rcorc goheeo$$ geFfl -
g
0*k ttr r

rr
@ 3l'to'$* :cee$g 3 h F0 8gg&qo
crcago tn?"$u3t.r rgu fo:tss: 3eo$$pSoe ? g t -
u
O gl't"'t* :oesscblc tF gc,ll bgl {nio$e h tlruguoo :pgm? g } i6:tss gfl F-f"e ? 3 t -
rr@3lto't* sc€s:clbg ;q$:]ee : $fp]:hr*"F! -

S" 0 g $"qppco @c€ecgeegTb'ee


fr"Q.l.|flo SgpffiF totFo:c,cc3 gls t
3h
,b"Q"Eo63co"F0

cxJJ:-oc,g
o
+ cncAa

.(

uaflq @oL
JVS Bo'L,2e
Frc qda6ca6@fiM

-4,(c) Liquid Crystal Disptay(LCD) - 1 9?


J-c q"ri' 0?
9-J LcD module -.3$oSq$q05lpinlg:
.
3-? LcD q3c1:o|qp,i,%oB o6:o59oo3<u6:qp: 3J
3-9 06'115qJ"6G)l Basic lnstructions 0o
c-9 o6:a:6qI.,5(J)r Enter ng Text Gc
3-G ;6:])3qjc8(?)r Addressing G;
o6:a:6q1.3(e)r Shifting the Display GG

J-o o6:$3qJd(dr Character Entry Mode Go


o3,r>6nc6(G),' User-Defined craphics oe
c-co o3:-3ql.t(?)[. a-Bit Data rransrer t?

-4,(G) Liquid Crystal Display(LcD) - 2 9C


0-" q.16,
?3
6-1 Good Times ?3
G-q Eusy 11
G-9 PracticalChcuit ?o
G-g Podslnitialisation 1e
G-G LcDins subroutine
G-g LCDdata Subrour,ne o9
G-o Cursor or Display Shift lnstruction
G-g Display Data RAM EJ
G-oo Set Display Data RAIV|Address lnskuclron 03
G-rc Defne Table Directive (DT)
G-cJ Send Message Data to Display cot
G-c? Get Character Information and Wrile to LcD coc
G-cg character Address Calculator coG
0-re LCD rn 4 Bit llode
G-rG LcD with PicBasic Languages cre
G-.G-o Wlth PicBasic cce
0-rG-J With PicBasic Pro

-"ldl) Analog to Digital Conversion cJ?


tl-r cJ?
?-J Successive Approxirnation Convelter cJ?
?-? Conversion Clock Speed (Tad) JJ9
.t-9 Quantisalion Error CJG

?-c 0-5V Digital voltmeter JJ9


?-3-. RAI\4 Defin t ons

? t-J Ports and LCD lnitialisation cJe

looe ej6 eiqo16".


!^ (€LoJ+E 046 aoof

sletdsrC lua!u6aS 1 6urxstdrltntA g5


aa L!er6ord ralunoC Lt3I,1
S l]5
.J a Luer6ord 1u3LU63s 1 6a
aa V -uer6ord tuaur6as 1 d-5
c) ,{etds c luau6as 1 apoq}eC lorluroC B apoLv-uoururo3 l-5
ct ,tpb c6
ca IeldsrO luaur6os Z (l)'f"*
ol fXl NtM3tdS 6Lrlluer60rd G-)
LprM

6l EVtdt\ urqtr/1^].elord OISVg e 6u[earC 5-a


5t sYtdn u rltr/ oot abenbLet eLt) se CtSVgC d 6u|.atas a ;
el :r9:..o | €rs! F k eflar,1 '3{ I}
"r""scra c I
dt ,tpt
)t rolrdruoC a!se8.!d ql!/r\ EV-ldN 6utsn (r)!fef'
m (cct) ra66nqeo tncjr3 ul 6-t
0c atll acrnos e 6uruurer6ord pue 6ullrdrlloC g-l
0c uoqern6uu03 raruur;60rd pue -relquessv're duoo GI
dc uortern6UuoO orpnls apoCorcltA 5-t
)c :o$:co$o 1nc;:oqg tr%Joe dogsag p :Ctolnnls l-t'
:c$oAo 11e1su1 p "OoCorollt
opns.noco,"ly1 tt
=cr
'9p$
fol olpnls opoSorcrt l (f)'t*
6urruuer6ord p!e uo4ern 64uo3 .t aurut e.i60ld
t) arnpacotd 6utIeS sqled 6-c
I al! ecrnos e e rdlrloC of 9-c
a uoDern6!uoC atr l rau6lsecepoC G-c
5 ,cQ,co$o pcpoqs c&toe dollsaq |.: e11:au6rse6apo3 3c
I :.99Z'o tfersur L uorsre1 ouac old clsegcld d-c
I :3$5,tu le1su (,: e;r1 :eu6rsasepo3
,$L"b
fot reuOtsooapoc ("),t*

cKDg).a

-t%$-s"b cra
);j.6, + o3@ Prc Eo5o{oe$o6o o5i:qlodo3,?:(t)

9-3-Q Display the Vollmeter Messages


Conngure and Enable ihe A2D module .??
?-J-g
?-J-J Converung N bb e to ACS I Character .??
?-O-G Converting Hex data to Decimal value
?-g-? Multiplication and Drvrsron Subroutine r?8
9-g-o Hex to Binary Coded Decimal (BCD) Converter

9-G PlC16F877 A-D Experiments with PicBasic Pro rc?

--.t(") Disassembler 339


o-c q"1i, 33e
o-J S4disasmdle(Versron 1 1) JJE
o-? PIC-Disasm (Version 1 5) .G?

-.$de) Hardware Techniques for Plc Microcontrollers .Ge


s-c $31$: .Ge
e-J 3o€ec8eP:ct€ 0,63: .GG
g-.1-c cao8qcSo:61o:d:,"€ .Ge
"ac8qprSr.,?or3;otsac,i:Q1@3:
g-.J-.J oo39030,61o:ai:ca3 xeypad qp:.for3.o8 B?3i:06 3:
G-? LED 3aqp:3?l9':.t 3r3l: lgle.: 3?J

e-?-3 Seven-segment oisplays qp:Ba.{oa?:GG3: .19


e-9 ocga&o6qp: c{ eeto,@8: 3?3
e-9-. using Optorsolators as output Expansion c9J
e-9-J Using PlCmicro as Outpul Expansion 39?
cao€/oqc'Sqdqp,.f 3aS6:o?E3t{:@Ge:
g-6 cilo;1 eAo-,q9$cA.'5ep, r?e
e-j coq$oeoTeredl ear tllol.D8oole:

oo$,(co) Electronic Combination Lock with PIC


3o?
,rorc\)6:3,61e3c:6s r
19fl .') 3o?
co-? co?
ro-9 Software oo9
co-c Hardware
co-G oco€p:.9:3{qcor o 6o:lu:e+t.Dooe:D:ql.Dql.: co3
Combination Lock v2-023 for PlC16F84 coG
Combination Lock v2-024 for PlC16F628
30-0 Combination Lock v2-025 for PlC16F628 with LCD roe

r".e ir6 6qq,dqN -vri-


Prc €o5.ff ,iaqofr o r,tri;qloo5N6:qF(

oo$dc)
CodeDesigner IDE

1"11,

q(.-c) coceoes,gn"r IDE desktop Q

Ptc qc8a{%6co{c':" sari,ql,tq5cu6:qp:3aQe,(c)o::73c63 source fte qp:.f ptcBasic


langr.rage @E eq::c:S'e9aci nex nte o$8:i. compile ojSq:ca6 DOS version
@6a>:
pbc.exe .'? 3r{:EF.q6oodr o:3: pbc.exe ar$ wnaows 95/98/ivE user qjr:3-}%c'5
:aacfsa; o$eerScop!: windov/s 2oo0/NT/xP userqp:3,%.)6 3,.o3o6Gq6@r3: 6%.q6oodn

rooe e+6 6q{drqN


o.q{t codeDes,sF€r rDF, Prc 3o5ii.ai66M o3),eool(t.t:,,'p.(e)

gl:'aq:%36;lEoa: codeDes'qner tDE so.q.\,are 3)e: Dos {-.i,01",i.4-


Windows95,9B lvlE,2000 NT,XP oog! Windows env ronmenis
do3€ ptcBasic or ptcBasic
Pro language d@€.6q:3:'rcc/):63, source fite qp:4 hex fite o@6c$. compire ca8$3eo: rDE
(ntesrated Developmeni Enviror'rment) sonware o:61@3rjla:p! r
prosrammer boa.d
4.3"03 EptCWtN EXE
$€.{a6oiE, Eprc 4 e3t:Gr(r, hex nre 4 Q"5ag%ico6orD4€S
oca3,c$. rrosram .od.ts3,6.l:$€,r'lcc::o:dl
CodeDes,sner rDE 4 ,D931€€i$ MicroEnsineeing Labs, tnc
_ a deecD:6E:
gaoo$r Q(:-r) %i codeDesigner'DE desktop w,roow i(i e"fcco.:J!d,
codeDesisn€r IDE Futt version .{ o,l):cQ$€E gqi.o@6 ea:0IQ€61$ cooe rines
ica")ocea:Q:Q$€eo: codeDesisner Lite sotuvare 3?c@r3:4 coTfidlodr o.€,43:S",qoS
websiryA: www melabs.com
? iiee downtoad eSof$ed]]dr glor"6f3.G?qt:e,jl63ra:
CD ql8cBe codeDesigner Lite vercion 1 71 .'? cDlire zip fotdercp8 co$.o:co::dlo$rr

c-yrr CodeDesigner Lite.{ install o?36€:


gloas239€ 3?o7.il$eoa CD 9 codeDesigner Lite version 171 3? c; setup soflware
.,? CDLite zip ioaer 9 33o3{qgrco\ Had disk C c6€ corite uTeo: folder o:61e;orc6@:
extract q6o1rr

go8flo& N o€s'\%6q|to, Hard disk C $ procoeca€ PtcBasic compiter 3lpc?o6 ptcBasic


Pro compjler o:6Q? instatt o?60:ar:06c{qdl6d r (plcBasic compiter cf ptc qo6o{
e$;{* ^-.{,t""8-5:,rp: 3"8€:(toD?6i€.11:Qcr1$-eo: _cD 9 pbc lotder .63 <"pieo:
cor:lg: PlcBasic Pro comprter Demo version .4 glo*?3f3.3rc?oil$eo; CD q€
PBP-demo_rnstall zip fotaer $ co2lec':co::o1oE!,r)

c-qr PicBasic Pro Demo Verslon o? install a6EEr

glore6f€,3"o?,j1663r. CD caE PBP_demo_instatt zip rotder r{ Haro oist< o6e9


.p6p%€ extract e6cqdge PBP_demo_rnstall.exe fite sl$cDr6ooegrr rrl€:c'? doubte crick
q6cQcAql€ Q(c-J )q8e oTG.o'o2!sa{3: Welcome to PicBasic pro Demo Seiup Wizard
message box eoTc'r:eorr3! r
46q2c6 coTor6o" 'Next>" button qp:o? o,6:D3.El8r$3tr:q3 ngodni,
C:\PBPDE[4o folder 3 file qp:.a instatt o?6&:3,]:G6€c:c,)o95.6d'r

Q("-f )"a€-",-d-43: qac,5n:e<.'Tcv.",: Completing PicBasic Pro Demo Setup


Wizard nessage box 9 install l\,4rcrocode Studio IDE check box o? selecr so93.i
GtcStG:
finish o? $3c8o3;l n 4seol PicBasic Pro oemo Setup o76@3:
E:{:trcoc,96pdn
(Microcode studio tDE v 2 30 e6@o€:ci 3?oidj),?3 c3,6", ool@co,:dltr dD

rc,2 E93 do"l{o J


io$:(, codeDessne. DE Prc qc6'{calo{(v) ori,qjodN6:ep:(e)

Welconre to the PicBasic Pro


Compiler Demo Setup Wizard
ThF d I ihrl.l PcB aJ. Pro D em. .n yo!' cM.rn.:

It s.€comirpnd6d thalyou.ln:e il.tlsr aptid!'! n netcre

Cl.k Ne?l Lo.onLinue. d CnncE td EfllSelup

Q(r-J) We come to PicBasic Pro Compiler Demo Setup Wzard message box?
r-tr CodeDeslgn6r Lite r'? Desktop 6.>T€?3 Shortcut ,eQc8:S3:

windc,.ls Exploiei c'? oeen e3E:€q.d cacjeDesisner Lite .4 instarl o?icca,e::;

Desktop 6;ig cDliie shoncui 03 coub e d ck \-3.3d.513 QG 9)"e€


"AE-,-d

s"eoT".6 laain llenu 6 compile c{ ctict q6S: compiler options ci 66:q],.'5c$.;


6rr3?il Q(. O) 3Gco",-d3eo?3: complrer options dtop-down dialos box6oTc'],cooelr

1.o9 193 "$edr f,- ,


codeDesrq-" 'D o,L
'.::()) : i. -{leeo6 , ,r, : a ooiN6lq,r:(c

,r"_l
Nompiu eamarie

Cdnrndd Lie oplioN

T Ado Close Cohptd 0 utBt Sc,een inr 5 Secc

17 Don't Displa! 0!5 ttindow

Q(c-g) PrcBasic compiler Optons drop-down dra oq box


GoTc\r6

ffi
T Aulo Clo:eil.mFis|urFdScrE n tl:5S€cs

17 Diht Di.Flir D!5 wrido!.|

Q(o-G) PicBasrc Pro Compiter Options drop-down diatog box GoTcu)Q

3r6oT4:Gi6p%-e
^:ompiler ci -3!-+,0.;i compirer ci €
cS:q<l:6e{rye compiter pathname:
:oTcsceo{'2lr' emdd plcBasic pro Compite,
d
IP\PBPWOEI\IO.
rle Toolbar coT$ Device drop,down hst g
€€:alcsqoil6dn q(c9)c63 ercroreta
qp: (confsuration) @1ca3S:ee--:::a1 source

eo?i$6Giiotfia

---
r) CcdeDesisner I

r-Gn To Compile a Source File


CodeDesigner Lite IDE window o\ c6oTuc6 [4a]n Toolbar 6 Frle oi ctrck c95{!:qao5
otol?c:ai drotrdown lisl 9 New cA ctlck q3c$c6opi:ejl source code {oE+8xd work
space oo-lc,:'eoo$r' cutsor blinking G6€qe:r€grp9'.rEd source cooe{16{3a:plrr

g,.,e"-51o@6 Plc16F84A ei nBO qo3ca3 or3-3"co,e- LED or6ci,:ca


$.3o?o69c3eo5cD3:cqcoe$ source cooe{c;co:,Qd Q(.-q)"g3@d.il'

Edt eoir.iE FJ.or€mher Qtsone I4indoF lelp

$h@dSer'': f
Fr!!r:R tr.r n3r:rai t.a blrrrla a.r IEIJ coln=cted io RE

Erd ':n in:,1 1. ll-\,F ard b.Lrr,i: lDIr f.re'r

!
FBC

g(c-9) atint< uas source cooe{c6coc:Q

gacoc6cjl source code.4 Bllnk bas esd@3. save e66t43?%.3 3,.,-,TocE


"?€r,
Main Menu 6 File >> save as r{
clrck g3@:r EE save a?6oiDd fotder c{eg:q1cS@: save

e6qolcd, {efrd compile (ti


click c'?3cQ.'56--a1 compiler output text box coTcvr
6o3rd QG-o)%e@do1Lr {Qca€ rrror, warnins qp:coTQBS:6$ar03. compilalion success
@6e@:3:eca."ieocaiL' Esc kev oo7o5c{ $3c$c693 compiler output text box 8df,J,:6oee:t
source rile(Blink bas)6eor totaer .{@$g3@a;er8 Brrnk hex rL$.Dr6@e:6 .61c{r€eqn

looe pe6 "$a,ji{o G


,og:(c) codeoessn€ lDr= Prc {0506 io{(u 'ri:qloo5N5:ep:(t)

(6DyrasjLL l(:)
r. o6, cop9rioLE (cl 1ess,

{(c-o) comPiler outPul iext boxQ

r-?r Paths Sefting Procedure


sacnoS$ ::cociolsa6ooiooi€: compile e6.rdeal error qp: eoTcuri.qtrS oaths
setling c{ oiSc.or€qeoealn Paths setting:rpl oc1:$1eqe:n wrnaows version e<rTqo:$$
o;8eeo:tq1o3XQqp,$6rl)d r oJ3:o?.o? es;ac$rjls?43: d6.:coT!cor:,jb,dn

Windows 95/98/[4E

C drive (C:\) €l5 toot directory c63{ear: autoexec.bat file ca8 search path c{r:o39c3
eo:qo1rl$r Autoexec oat 4 Notepad cidpo:
text eoitor c.rSqca8 edit o26e1o1o$r
(windows es *"ed{qi. msconris cA runq6$€dlo2irD

Path ],a] PATH=path ipath2; u?€alr format 3?o?€!6€{ol.Ddn


statement 1

(4
8Es,{:GFd compiler line3?.?:<23 semicoon (;) @c:j cDdreS,.o,qdledn
eomn n PATH=CIWINDOWS;C:\PROGRA-I\[,]PLAB,C:\PBC
(o4

PATH=C:\W NDOWSiCIPROGRA-1\N4PLAB;clPBP

{cl. autoexec. bat file 14 edit e6E:6{..,5 c6Qqgo;:r{ restart o7 Sqcil eg) rr

Windows NT

Windows NT oBe path statement ct syslenr properties dialog box €i Environment tab
6%G€$3o1od, (lqqJtor"€rl deskiop c.JT$ ftay computer icon r'? right click
"oT€3
$6cQcfp: eroprties "
Environment tab .{ click cg8cQcAdlr SVstem Variables wndow 9
Path variable .A 60:qoso, cr,ck cy6$: highlisht of6.jlr +(o-e)q€@dolr variable g3.

?
ValLre bnboxes o?..Jel Pah info.mation 3?G3 aoT[e,,rcS3ppln EEs:c1:Qcp! compi]er
Value texLbox 3?+:6f epceS semicolon 1)@:$ cod.8E:c":6lotedr

eoo2 u %SystemRooto/o\System32\;CIPBC

(or)

%SystemRoot%\System32\ic:\PBP

{ci. eait o73@:e9cci ca{q1o.:c{ restart o96e1o:1o$rr

Q(c-o) Windows NTs d path setting qa?6Q

Windows 2000/XP

Path statemenl Environment Variables dialos box 3 c%Geq3dlrrdl 4.fqp.l.


r{
6strdqE3?%.'5 c6Qq1o'ral desktop eoT$ lrly computer icon.4 risht cticx $3c$ddl r {6q,c;
Propedies >> Advanced >> Environment Variables 4.d or6:o€,ql€: crick caSc$ricil r System

r.,7 o+6 eiadlio


rFq;(r) codeDes,sner rDE Fr! ?m-\j.6+@itM D.i:iluo!)d
varabres wndows 9 Path variabte c{ 6B:qcS(D drck o)3&: hrshtisht c93d1rr 9"q..6 eott
,{ dlck e34d.;1, 9(r-oo)%8@dolln qroS{:6oTMqD Edit system variabre diarog box
%3 33@]?:Et6d compiter r{
variabte Vatue lextbox 3,a?:ct6p%€ senlcoton (r) :d
E
od.8€:6o:1dl6d
poor %SystemRoot%\System32\;C\PBC

(or)

%SystemRoot%\Syslem32\;C:\PBP

{ct. eoit .p6@:eq.d c6{<1p:c{ restart q6e1o1e2! r

(i(c-ro) windows 200O/xPs(?c3 palh setrins


otc,?3Q

c
Fat:(r) codcoessne,rpE Pc io:.-q%;6{aD.a{:itoo!--3:Ep{9)

3-on ProgrammeiConfiguiation and Programming


CodeDesigner Lite IDE wndow er\ gae<,Toc; Vlan l\ilenu fi Programmer .{ click
e3g:6f,c3 oXCuDd drop down rist Programmet options
9 .i c ick .y-6.$"5-d.-1
Programmer Options dialog box 6cilc\r ."o2!' 1.r.13,.63 88"a"i'GL.ai Progranrmer @6e:::
EPlcWin .4 Go:flcsqdledlr oc'54e6p Programmer Paihname i€. command Line options
4.-d-d, ocQsaeolccf es:x"si!,c,: G56q6,rc36.odn G3"rdl-,1 QG-oo)%€l@d.jr,

<2{c-cc) Programmer options dialog boxQ

{c$, Programmer c{ie:q1oiglcf4c3 caeoTocA tvain Menu 6 Programmer .4 chck


cqo8oa>:s?at ec,Tc"ror$ Urop-down list Launch Programmer c{ ctict< oTScfcAoplsa.1
9
Q(.-t)"ag*,T8""",-dooi€: EPlcwin Prosrammer menu eoTc:aeotl2lrr {s:af :atri,G1
sd q.66{oaqco{o>ls?88.,i EPlc Prosrammet board %3er66Deg: program q€'$3eo
eo'r..:2iLr

Q(c-rJ) eetcwin erogrammer menu Q

(9o8ql.6r n
PlcBasic compiler software g3. EPlc Programmer software 4.cf Plc
EcSa{%icD{c', ea1:q1c'dco3:qp: 3?Q3:G)o.e693.?,o)o1$or cD 9 pbc forder $3. ep c
folder o9.%€ co$e,-':coc,ia:p!rr pbc exe pbp exe, pbpw-exe, epicwin exe 9€. cdlite exe
4.cra: Hard diskol8?o>d: (eoer c:\) c63 instattcg6@:o>r:@Seqqdle$ D

.oo1 1,a6 o$qdr{o


@$:( ) M,c.ocode studio roE Prc EoSo{,"1@SM otri:qpdN5:qp(9)

-n$t)
MicroCode Studio IDE

1-crr {s1$:

Q(J-c) I\ricrocode Studio IDE desktop Q

,-'a$:(t%36o186.61 coceDesisner Lite sonv/are d.r9.cl€ Dos d -.i,GL"L6


cc$a wnoows environment 5 PicBasic source flle ql.:.'i hex file o@6ci. compite o?6cD,
Qr'5o{ce6-6"-43E-%3:a?. o{o6t6e3:Go:{€ec, compilation & pros,ammins software
o:8i@6crpi [.4icrocode studio oc@.€:ct cDE66,,TG,jlE,"drr o€,cfcog!: MicmEngineering
goe c8cgecor:6€: GSolodn
Labs. rnc.
lvlicrocode Sludio cJd 3?cgi3?e6: cD.393Jd lnlegrated Development
Environment (lDE) sofiware o)5?G6,jlrdll Nlicrococle Studro IDE (€3 Code explorer
<11$o@3, source coOe g€.il.€"q..- include files, defines, constants, variables. aTiases and
modiflers, symbols and labels oc:d({.€fi o:degq,ci 3rogoSorc? rfl:Gfd$Se:d
'
8E-.i,GFai cornpiler, assembrer 93. prosrammer o?..,?cud, 3rcq3"€ofo59'6g63: (auto
search) @3. oqgcSo:q setup o95$5og! r {.s:@3 error resu ts window ol6c:@€. compilation
and assembler errors qt":c{ s:qg.So"p 5negeolcacS@: GGeq€olod'
rJo6:( ) Mrcrocode Stld Prc €.6e6,"6o{M -4,n.do8,qp,(e)
Jli-lG3" sen:l port
tulicr.corie S1,d,o IDE 0?6 eerLel C.ninrun catrons wlndow
monLto, es@s,si.c4.rj: ...,sso5+36'r:'rd, 4 -03.'13'.1 Prcaas c Prc
-d.s,,563'f3.
- r; cl,cult Debussins {rco) ::q5{1:c{o:21: qi'o:
""'pir"' ia. Qo.;33+,|!,r"d{..re
6€c,r.3,,Jrd,
4"-iiS rn crrcuii Debusser (cD) (o3. PicBasic proqram 06132%.; rtc
Q.'5"6,?EcD6.Dr 4e3-%3,o$oq3 run 6{oi variable values, speciar Function Resistets
tsrni -"...v 9€.'eeenbv 4.4 @dqt$863', PicBasic code tine or51ql8:s.,Q3ol6Q'4
b,eakpoint qt : 3,oS9.3d 6c.,.co.€€63' 66o,esc3$e"1 srdr
"-d4..4
1-1rr MicroCode Studio IDE cE lnstall q3@3:

gloreS+3.3"o?dl cur€3- cD ? N'lrcrococie Sludio IDE versron 23 o%d zlp flle

iQ6-2!-""."i:co 'ip .i lrard disk fi io cler -31093(goo:r D \[i]rcroco.Je studio) %3


extraci crsdl i{.r .;).:3l4dd'

.J Gtq' b in lort cJ :r:]


.
-l.l
::.
I Pr. DEa'enb d r0s
!r., 1
fi:l
':lL)

:
-prck6io$iiD€7\ -ii!l
frt
vEl
1-
I il wM{eertt Fqd6)
=l

{0-J) sEruP launcher icon Q

.J."? ir6 "Eq"lqo


r \4,crccooe srud,o IDE Plc 9 "-iTi@{N e; rr 6 -:c :l
"-;1

e8E:qi8 4 fode, cd6 seiup rauncher icon.4qrE: doL,be click


cqr9. extract
.,?Sici.d, 4"f..6 ."Tcu:er': menu qp:9 Nexi>' .4-6603.A3' ctrck o7Saa,ol
er>.6a:e.T.u:eu complete setup menu ,%3 'Finsh .4 click o93ddoei3?il Frard dsk
J N/r.'oroce SrLoio Dr .i ,rstal );13:rr-: G6-s^:-dA"S

J-?n Microcode Studio IDE .{ Desktop eoTcaE Shoftcut oio8#!

Desktop wlndow6oi[9 Start >> A I Programs >> lvicrocode Studio Fold$ >> Mrcrocode
Srudto exe tr9..Sa:E:6?c6 Microcode Studio exe .4 isht click $3J1" 6oTcvr€o' drop-clown lrsi
send To >> Desktop (create shortcut) .4 eg:qpS@: click c96o1rr {sao1 Dest<top eoTca3
9
N,,licrocode Studio uic:r, shortcut icon 6oTot6oc35.odn

J-90 Microcode Studio Configuration

Desktop 6()Tg I\licrocode Siudio shodcui .q double cticl cai,cQo5q91€ !(1 :) c23
€oTG-d:-d3rcr?6, Microcode siudio IDE desktop window GoTcu,co€el! 4Q e3,."T..;
6$6pg Maln lMenu , Edji Toolbar, compile and Program Toolbar lcD Toolbar, Code Explorer
l\4ain studio text editor o?.o1o€ @ ol 3)d n

Marn lvlenu 9 \Iew rf click ca6S:


eaitor oplions ..
.8 cricr< c93c$.,:e::*ail
options menu oox or6q e,,'Tc,':.o-$ r o3:c6€ Generat, Hrghlighter Prcgram Header f€.
ontine updat.ns oop! tal qp, o1o3@,i13rd, o3eql3:o?cS:qlcSo". EEE€3@td*e3,cor:
qt:c{ ed,te3€3€o-e:n options menu box.4 +(J-r)%36oTEcD.:,jl-dr

General Option ce. 'rvr or mer I f'i.


Derdri solrce Fooer q.? 68:qJ Dr)o.)
qd$e,i3)in Ofu ?)%3@do1n Environment option ca8 soirlce code nle g3.oo5oc6ec>
q3[3-.ac.oqp:rf 6s,a1cSc,.39o5$38', source code f:te c36:co::op) Folder .4 defauLi
oG6 3rc39c6oiate- Default source Foldet option cg6 cnange.. button .4 click oi30:
c8:qJ
ceoaral lHrgr, llter I croaram Hiad i onlin' rlFnilnt I

g shcv' line nlmbe6 in lEtt auller


gshow riqht qlttEr zt,60 ^ chBr.cler5
gUre,.ft6,t t.bs
gconlert tibr !o spa.es, Nldth it 4 ; ip€.sr
gAutomiii.illr ndent
Ewrip d.cunent sele.uDn tnbs
g Aut. rntrEly )ump t. fist enor
gC e.r undo hi+!r/ ifter.omF e
gopen lb+ nre(!) when.ppk.tioi ndrB
EDirplay fullnEname path in appli tiDn tillE bd
EFrrop! f fie relond Eqtrad
!:l A!t! .h:n'_e jd4tiilis
lll-5".FsF!J FEa.s dEf.uit ertennon on fie sate

oefault 50urce Folder

f-;a__l fc--", lf'r"b_-l

Q(J ?) Editor Options 9 General Optrons tab Q

Main studio text editor a>A! source code qp:.{ eqo:'$3opi work space o:61@3
cjb:pjrr ee1.cr:ogi source code sadL,*-,{ saeep3{1,Q@3. 6oTQ6o:dl3re! code -qF
oo:,-.$oB saeepSsaft:3,or:.4c'd: 338oE@1c6e6:nosrc39o5$3o:1o2!rr Hiehrishter optron
tab Font Propert€s, ltem Propedies 13. Reserved word rormatting eg:noS-.; {..{
%3
eo6 $3o1odr Q(t-s)"ee@d.]'
Ssecyorc$ source code ei font d1:oor:98. sSos3?o':.{ Font Propertres option
cA€eg,qjos$so1aragr ltem Properlies opton cBe source code :ac1:p1co:ro2) comment )
R;served Word, ldentifier, Symbol, slrng, Number, Assembler oi.mcari oe9€:a{1's:-,c{
eg,noS$Sola:elr Bod, ltalic, underlineu?$ styte c{copi:e6:qlosi3oileo,or2l
Resewed Word Formattins opuon €
r3:e:$.dE :co.:oJd oo:c:o,i:qP: (2oo'-
symbor, Poke) r{ uppercase, Lowercase oo2! od3i"-G$3"-,{t'G3. "OG*4-d4
eg, x,rs 3rc3e ot{ € dl a: e9 L,

varn ulnu 9 File.A click e3E: New.{ ctrcx o23c$cBea:r:aa1 header o69 r2i
:a$::ecaprf e oTc.:reoo$n { neaaer q3 Nlame, Author, copvright 9€. oate oo2)
oarJE.D.6qp: oloq@dld' Q(t-.)"a€@ddl, Header 4 ed og3opqJ€ erosram
pcader tab 4 es:qcSp: .rutnor t3. copytisht o?.ca edit ci6$3Jl-iil,, ,)(J-9)c?3lqid,jl
'

Ge.erat H:qhl!' (er le'"e'", ne"*' I r -eroc"L-ql

I sdrlr]?le reserteo no.d dnd slrrnE

IIlCf,UDE "Froq!am.b6s"

' sernp.le ieserted n.crC drli dssabzer


'axttTbdxes

n8ob Ellt.tic I undcd"e

RJ.*ed Word Form.ttinq


OiJi,ii guip*** "r CLowrjrcare al

l-lt'-l l-c-".d I l- Hde -l

+(J-9) Edilor options 9 Hrghliqhter Options labE

looo oa6 ofa"l{^,


si;d r) rM c.ocode stud,o LDE Plc {q5.i.B6o{M -.i'qlod--6,9P,(9)

Q(J-O) Editor Options I Program Header Options tab Q

J-gr Compiler, Assembler and Programmer Configuration


Lrlain View .4 click q8p; gornprle and ProgEm options .A dick
lvlenu g
e3cQc36-: 3;l
compile and Prosram opiions tab box €oTcur€o"eg, a0-G)"4@d.jl,
compiler tab q3
EEs:cQr@ppi cornpiler ('i
qpili Find Autometic€lly button click 4
q3c$o8q13 r66,itr'',m s?c$3?€.,ipo39.8, c\pbc L?6f,, o2"'i'eoTo,
eotl2lrr rinJ Manually... button ci c ck ol r qeo: window eoTco:eEir
o.:€:9 pbc exe $er:: poc fotaei c{ eg:ryS E.9"6;"-",.1 c:\pbc o?6tr
o.or$: eoTc.,e,r6dL,

exat:S$ eicaasrc Pro demo .43'il:DtcQq1e c:\PBPDEMo rolder cA €B:qFSE: oK


4 c.?3c$o363)roi1 c:\pbpdemo o?6D
crjck coTo,6"6d, Q(J-r).a€@d,,1'
'4o$:
Microcode studio cg3 oeraut ."GB -.i,Gic.a'r.d assemblet oa! PlcBas,c
complje, r€3?o?Al{eo]fio2! evexe
"eG56o3)dn
o:3:r:2! vicrocnip co 9cqo3ca3
MPASrr4 Assmembler codo,qi€ cr56.0.€?QQ$€oq-d' {..J-d'

.1".? er6 Gqio'lE- .6


)
i:.$:!) MErccode studio roE Prc {c,Sofr.ef@iM o.i:qto.3o6,qp(9)

Prclsxtx(x) dtr? 63J. Q"5.{.BE-{.",qp,"4 PrcBasic B8.oe:Gtc:d:aJ{t:%3 N,lPASl\4

Assmembrer {-"i,Grqi 8Qr,3...f.@'3:G 6rr,€l

g(j-G) compile anu erogram options 9 compiler tab € ctpUc cfero8go8Q

comnre'
lnseffire' I rrosramne, I

Q(J-?) compile and Prcgram options g compilertab%3 cr\pbpdemo crlocSgo5Q

Joo? ef6 cifc;tqN


l4lcrcCode.Studo IDE

Assembler tab qJt MPASM Assembrer 4


gr6li I\IPASIM selection box check cy6 4
Find Automatically bulton 3i.cu?o5 Find uanually button.'? clck CASE: 5r,6g
"l"E[9'"e"6
.$.,5car"3?a1 Q(j-r)"e€eoT$c"r,-d-4€: clprogram f les\microchip\mpasm suite o?6a,

",o)1:6oro,€o"d,
(go8qlc;rr r we.+stvl .{ PicBasic P.o complierGS.])' 3,3i:0tF3,jl Ddr)

Prosrammer tab o3t Prosrammer .{


9.qi QC-e) 3..T!coc:o2i:;{€: oeiaurt
Prog€mmer selection text box ql€ microEngineedns Labs EPlc cq 68,{,,5q.""dr 4carc8
ot< luiton ci$3c$c6@: conrisuration .Bgc{ raq'oo3ep"-2!'
Target Processor egepcaS oetault processor -@6 16F877 coTGTDe:r 46i6p%e
383-i:ELe$ processor c{ e@:3:de6:x<:5qdlop!l

compter assembLr leroq'emme, I

suite
c\proqram tiler\mioorhip\Dp.sm suit(
I Fnd AutoMti.all? ll Fnd I'lan!alv,,
E ute [1PA5r4

lslpprerr
Ll5lpprerr PEc e\tensons
extensions e) nHxsr'l
ElLirrng file (,1tNNl85

E Maco .xpmsion C IrJ-Di32

I Cros' rererere Re

E care isibve

[- o"__l fr]dp I

{(J-o) Compile and Program Options 9 AssemblertabQ

1."e pe8 ciqdl fl-


.,=r r Mrcrocoie sruoro roE Prc €.6a6.aioio o1:qrodoS]ip(9)

Add LleL{ Pro.rdih€r , , Remove Programer Enhy

! erpress P8a e{eiliotu OINFtAsr,4

ElLbthqr e (-1NHX85

nuxro expansion OINHX32


Dcro'!,efe'enc frle

ncase sentiilve

Q(1-g) comp'te ano erogram options 9 P.ogrammer tab Q

J-Gr Compiling and Programming a Source File


eacocAcaSeo$a.opi conriguration.B9qp:Gla?68,6t:cs?61 Prosram Header o:lo€
6o? Untitled r-'2sall2!ol3co:o2! source code {c6$Eo$ wo* space egepcgS cursor
blrnkins G66f6o, o?3'9o@3d source code {c6{€eoer$rr

goaaorSqca@6 Plc16F84A .r15 Rso qc8q€ or6s"6co::m:: LED o>6c,i:<;i qdc?o6


qo6.?.Aoe,6{co"d source code c{ {o8$co.:o1 c:dil,i(J-co)%€@do1 n

looe oe8 "fuol{o


34:C) Microcode srudio roE "'c
qS"$.8:t-$-
"{.{.

Qfu-co) source code dc,5cna:Q

gaco.,5u1 source code r{ Btink bas ,{.cr" .r,rd@€. save o76c$sacgcE oeoTocS
Main lrenu $ as c{ ctict o26@ir EB save'ti&c$o$ fotdei r{eg:1<$@: save
File >> save
e6qolcdr' 4o9. save c93::$oa1 file extension ( pbc) olo€eoo blink.pbc a?86 save c'?6
eoc86.c$rr
{egao8 wtain Menu 6 Projecl >> comprte and Program .'? click o23c$rfqg3 error
o:6{o:69 e$,icn ,?(J--)Gco:lcrd window eoTcr::eoe$r o3:cg8 compilation success
86"@cer4 wndow o5eo:riag:ocSoc6.coc8.eo"pca€ Success: 103 words used c?6:;r
programmer o5 EPlcwin Programmer menu
--$,ft:@€,arTQe oe $r {Jeo? EPlc 13.
EPlCWin Configuration setection box4.oe9:oo?qr,? GoTor€co('dn
4oa1 EEo3i:qcia)d confisuralion settinss { EPlcWin configuration seleclion box
cg8eg:$,rSqolo$r
ile tarset processor
"ae -"i,GL'd
EPlCWin Programmer menu 93, Blink.hex
(Prc16F84A) 4.c{ c{acc\pc6€odos€'E:4,:G56r€c€: c G€{8ccladn {os1ca:)'@1

"$ Qc,5ofiq$.o{co:{e3.{ EPtc erogrammer board q€o:&o€S:


prosram 383:{E
nuuo:r.o$',

p"e Ea6 eie"l{o


Prc €o6'i%{oia- 'e:'''jod.5:'iP:(t)
i4Q-yr19g::L!M-

Fle 'fieN Run ConfkuratEn oDt,ons nep


E

eQi Sl.rEl g'a4lPdsftl{ j]


tr,t*r aff tEr ,:-,11.8..-.; x. P,i
'De]a| f.r -5 s...1:::
':. .b:.1 ar lLrp djd }'irr.E ,i

Q(J-cc) Success winaow, EPlCWin Configuration menu 5€. EPlcwin menu {.eollo:cQ

seorasd compile and Prosram .4 cticr .YScQc6r:plsaa1 source code 3 error


0,60016qr6,jrm aL-c.r)0-,a,d3,oi3: error window or6q[o]d:or6oTo,co6dr
'enor
u:3rcg8 @6eEopi source code line 69qr.4 hishrisht G3. 6"TEcor:E: whdow €i
a.r .Jcp . oe r i\ t-- .,3," - , - text box ie@r€: error t,ne qp:c{ {d1c3qr:,
.,r3d .-.G-:68r3,6.,a.06$e,jr 3Jd'

ca{cil error qp'o?03{.;g:o1o coo,pile and Prosram oi ctict c93c$cBr:pi::al


.IrJ.rr qcg(D:'P EPlCWin-Configuratron menu
4. 6'rro"..lo€ocs5.od
cai:l) Ml.rccoce stldio IDE Prc 6o3o{0:$@6o otr?:, o

Q(J-.J) cotpit"tion "rrorswindow coTcD"+

g-9r ln Circuit Debugger (lCD)


ln ckcuit Debugger (lcD) G6. PicBasic Pro prosram or6qo, d PIC QoSo{
c6$co{co: :fle8eca3:o{oe16 run"qoi
varjable values. rs (sFR)'
,n'"rno,y 1e.'rennbv {.*"75qS*q"4 @d9FES,' o'61n6'
s,e6e3,icn breakpointqp: oc39c6$ eco. '$e@e:
oo
lcD alp9 standatd PicBasic prosram qP5'c8.3 3eoi:€Dl+36Xrr gfoca?6oJe:
Standard PicB;c program qP:3?qc6f,), ftIicrocode Studio 4 *{'GLE' compile and
erosram cB..S.?g.QLoi3Q 3 qi qdsoSB:c6r3,:co':G3,e@3. tco sJi:GiQs€@o3:o?
sarrl,S{$ eeqoa:ec'::.ci1.q1r
PicBasic Pro -"i,GL.icp,-d rcD reii:G,isG@€:.4 *$c$"1m v ctocooe
studio Help Frle %e 110696€@dlsrdrr

r.oe er6 @i$olqN 'JJ


.":,(r) Usng MPLAB with PrcBas,c compJer Plc {.66{.:i65c- '+:qjodo6:qPdt)

saa$:(q)
Using MPLAB with PicBasic Compiler

1-on $a1$:

prc qo5o{%Ec"{- -4:qloc8c',8,qp,3'QE,(1)ee. caQSdq)o]3?6qp:cee


source file qp:.fl assembly language G3. G6I3r:E:€{'c6 hex file o@619. assemble cyE
cpcaE wndow version @8eo: vlPLAB loE *.i,GLss@:, G€6cg.5.q8,G36"rrd,,
4
gf3aa$:q3 veLAs €i tor caqS:jo3 Dos version qp:@6e>: PlcBaslc ae. PlcBasic Pro
{. :"qcA source coae e<1.cro:@3:r source fie cA hex tite sa@6e$. compile o76@3: oopi
cEsqp: c€o'Esc6$36r$3?,?d e6c4:oJqp'0dsc8q+o,i.<l? 6oTGo1"d,

?-Jr PlcBasic t3. MPLAB ol.c{ install o?6SE:

Pjc Q.6a{ ?{.oio,. 3,+' q


"oo,5:qp:i'3€:(r) o.erf..'ao? 1s"6r,'r cD .z€
PlcBasic compile(pbc exe) 13. EPlc programmer (EPLCW|n exe) {.c{co2!e<-r,cco,@,r etC
Qda{cei@{<uc 3".i:qloo6cu6:qp:3?83dJ) o.e6r3.3?9cjl{er, cD 3 MPLAB IDE
version 7.20 ([4PAsr,.'lw.n ere) .AcDd6o:cor:df Ddr :acorAcj] sonware qp:c{ E,{F.ro\
Hard Disk Dnve or6iord,6,JT5 (gt'rer c:t) eo:do1:a{8: inslarloT6@:*:: GSeqJl"d'
C:\pbc IPlCBasic exe]
Cr\pbp IPBPW exel
Clepic IEPlCWin exe]
ClProgram Files\[Iicrochip\MPASII Suite IMPASlvlwin-exe]

{6joo6 gfor:?6i€.s'c?ciloeu co %3tl16 PBPlusins z,p nre 4 cr\pbc folder %3


extract oT8eyjlopll {{. extracr .73p,egac6 c:tplc fo der c;3 6"Fd$.,'r6o,
bal' c{ double cllck<ySercjl6a!r
'PBresister
o:69$:r,::@3. (stad >> Run >> clpbc\PBresister bat).{ oK c{ click
"8,fl,j58:
e6dcud,6l{3r:dr :arn,lS$ E3%$qf':,al cl c2€ PlcBasrc Pro compire(pbpw exe)
6.qb.elecDd: PBPlusins zrp file .{ PlcBasic Pro compiler 6G a folder (eoe'clpbp) %€
extract oT3elileplrr 4{. extract .j6@,e1..4 crplp forder ,?3 oepcS$c,.o"oc
"PBresister bat" c{ nun o25e1rjlc2!rr
or6f&",:G€. (stari >> Run >> clpbc\PBresister.baO cfl "g,qlrs@: oK c{ click
c?sdord,q8e!dn
s,coc'5o1s:8oopsacft 3:
c.or€edE:G{2.,5 3'66(rr:aQ5(. q)"?3".TG-,-d*"?6,
Paths setlins Prccedure r:i cr?36.013qol6dr

4ol.6cor3s.3@'e,d6Q5€:6sqp: c"oiliooS.q:d?$*qi %; qto-,.{ restad e6


ci.iredr

J.o9 ?ed o{{oiEN -J?-


,ai:(?) usin-q MPL4Dwrlh PicBasic cornpier _ Prc 8.,ia8('A@tM sr),ijodo6sJ.(t)

?-r Selecting PICBASIC as the Language Tooiwithin MPLAB


I
veLes tor cflg€.S:eioc6 MeLnvenug Projecl >> Set Lansuase Tool Locafons .{
crlck e8cQo6al3 Q(?-o)%e@cco,r,d:aoi3: set Lansuase rool Locations qG., window
i

- ir.::*opg.r

+(?-r) set Lansuase rool Location window

window g Registered Toois box cd6 f,).;{e6.p Toolsuiie Name (microEnginee ng


4
PrcBasic Toolsuile 3i.br,?o) r.ic otng reering PrcBasic Pro Toolsuiie) c$6pq (+) crick .i
a?6o1n 469.c8 Execltables .9epi G) .{ .;66d
crick c,?8p,.q"c8 eoTcu'ca,r
microEngineering PicBasic Conrpiler (pbc exe) cf ctct< og8c$c8euool Location text box
e96p%€ crpbc\PBc.EXE Dor$,6oT..>,6oed {(q-c)ce8@$"1r (*-.sd<l:3:o.o:1:e6oT
r

qg3 Browse. button .A click o73p: PBC exE $cc:; roTder .S'qrcSq.jl"dD
"f"pd
{egcr6.eppty button .{ cLick o,?38: oK button .{ click cf3q.jl6e9, 43,a;l MPTAB
rDE (Be PcBasrc r'? rangJage roorsrlgo bg:turf)o)?cDLg: lgo6o6c.r,.!p r

?-9n Creating a BASIC project within MPLAB

%€ project o'r69ord..orc66lE Main lMenu 9 ProjecL (4 click CASE: Project


MPLAB
wEard ($ crick d?8qcjl€dn 43,a1 +(? ,%36olEcDr:3id3,ol3: wercomer window
6oT.o'6,,6dn tlle:e Nexi>.4 crick ot6c'?.,5qfl€ Q(?-?),%3."T8-,-a:ooi3: step one
winaow eoTcuoeoe$, o:3:9 device €E"p,€3 Plc16F8aA .4 6E:qlcSG, Next> .f .rick
e6c$del3 Q(? 9),%36oTEc!a:.rd3'o?€: step rwo: w ndow 6oTc.,6o6dn

rooe ?e3 eEfolqN J'


usins MPLAB w,th F,cBas,c comF rer Prc qdai%ioio '{:floc3o3:ePdt)
'a$:(?)

gl? lJ vvercomer wnoow g

9l? - ?/ stepune wnaov/ I

J:
"',i,1;)
u;,rg I":FLAB ri,rh p ce"s i cn,np:rer ptc
Edafi.Si6{.--r -.i,qr"":.J,ir,,(r)

Q(? 9) srep rwo window Q


Q(Q-t)%€ ranguage Toolsujte ci select o?3el466dlardn Active Toolsuiie: text box
€ microEngineering PrcBasjc Toolsuiie .i"S,al.r5cD.:G:r Toolsuite Contents text box 3
mlcroEngineering PicBasjc Compller (pbcexe) .46€:{cScDz:cD Locatron text box %3
c \pbc\PBc EXE.46ol!c-,,6@r3: 6 .G3q-"d'
{epc6 t'text' .i
crcr t;.9.F^ f
Q(r-s)"ea" 'TP-"',.:a! a{€: step rhree
winoow eoTcu:eoop!r 4q%3 Project Name 6frpg brhk ci6c8co$E: project Directory
egepg c:\pbc\sANlPLEs c{ erowse 9or:o3. arcSgc8eo:<yilo2in
(9o8n.,5, ,
Projeci Name n9"pi otrnt o9{.36€::>d c: dq pbc cdfi sAMPLES cd6
BLINK BAs (J?63r' source fire .{
compire q6c$ca,G@.6.G6rrdr)
{cf.o.39.3@'.9.8 Next' .i
cr,ck e6oic3q3 Q(?-G)%3coTGco.:]rdeo?3:
siep Four: window GoTorrc,red r cQ,ic8€3,o5oo3 terl box q brinkbas oic8:qf,iE:6f,.6
Add>> button c4$3c\?c393 p'o.; text box %3 c:\pbc\SAMpLES\BLtNK BAS
c,rTcD'Go€dn Nexr>.4 crick eEo?o6qi3 Q(q-9)qE summary window
6oTcurcosdn Finish.{ cick otScqc8et8 Q(?-o) 3
""TG-.',-2isa{€:
6oT!cor,-ei3"43: Brinkmcp window
.oT","o6dr o,€:9 brink bas .i doubre c ick e6cE.3el3 +(? 0)%e6,,TDcD',r,d3'43:
BLINK BAS tri6a, source codewindow o?G%G€6l.,red
'
{.q,.6 t/l" " Menu 9 projeci 4 c|ck ebB: comprre .4 c|ck e8qdt€d 43?at
Q(? ro)ce36rl,'Gc"",-2!ooi3: ouLput winoow".TcD.6""a:n

.loo? ir6 @i{ol qo -1G-


n.8:{r) us,ns MPLAB wrh P,cBssc corhpLrer Plc €'6€{'?i@$M o4:qpdo6:'rP(9)

Q(1-9) sien Three. wnoow q

Add an], cN slinq fil$ lo ,our projecr '

I fl C:!ot'cUAr.'1FLEs\eU NK EAS

tF*.;l

t_.
I

lhe hos to coFr thE lih to rhe

Q(?-6) step Four: window Q

.;oc9 q93 $;c1{o -J9-


Q(q-9) summarv wincdw q

Q(? o) Blink mcp wrndow {

looe ee6 eiqorlQo -Jo-


MPLAB w th PicBasic Comprl€r

Q(q g) et,nt< tas sour"" code window Q

Q(q .") ortPut ,r'lnclorv q

j..? n;3 cieol io


Q(? o.) EPtCWin Prosrammer menu +

?dfld, Eprcw,r piosremn,e, @{:GrQo? prc E.;a6%i.ci.!- c+ierod,c.,5:6r.::iQ3:(.)


-3?3,?3 3'6.tr'33.0.0."4'r.E'03,jr -a:'

?o o3:odo8:
PLc {d.6.8$@{o :qpo5o5:qp:(9)
t) TSesmenLDsplay

-4de)
7 Segment Display

E-"' {tl'
gl.?a$:c33 elc qda{%ico6oro.4e+:GL6: 7 sesment Display qp:ecJlc63
(disirs) +3. o.o?:qp: (characrers) QcoT$8+.{ 3,6o:86013GcDo'dl3)dn
"8i,.*$,cp'
{ sa@3 wr,ttiptexing Sd,{-"i,GE, or6oi:coo6$or 7 sesrnent Display qp:eoTcg8
cBQ:"m$:qP:e3. o.cQ:qp: +q,GEQ 3,6@.3:o?o)d, oreGcor,,jr 63r,3id,

g-Jn Common-Anode & Common-Cathode 7 Segment Display

B
G

E
c C
D D

DP DP

(ca) common-anoae (d) Uommon-calnooe


-

+(9 t 7 sesment DisPraY qr': a.od:.-:g

s"coo5,jlQ, r:%e6orc-:qcA'6e:e1 7 sesment Disp ay qp,q3 a, e, c, D, E, F. G


DP{Decimal Foi,t) qirai segment o8qqt3:.4 LED @3{,3G3. d.od:cor,6@"€: 6c?.G:83

Joog ?16 oiqcjllio


Jo2! r Comnon-anooe c{1:or:qE eroi
:oc33,-,5c,:: sesment a:31qf:ai cathode
segmenl qp: co8:cox<-'c$r commcn-cathod
cm 0v (GND)g€. a:cfcg,-SS: sesment o:,5
e>16{€9 seqment qp:.i o,8;Go$€dlr:d,
'ay qP:.8 .4,.'3:a'):3?dii[ .};6P'1"; :T'{i(: i3)'I'+3"i1:it:19'.
, q9q.""@6 ises.ent oisprav -61o\ 9o6 ioin) qp' se3"or:GQ
"3
* ercS r
"Tli.ca:o;l

C
o
G F i\l A

E DC C DP
o
M
Displav o69ol9o8qp, oeqsacoa:QQ
Q(9-J) 7 sesment

c
D

DP

?(9
.)J common calhode 7 Segmenl Displav cDBi-D%3: LED qP:$o$:<D?:')

e${"il{o -?J-
1oo2 1e6
g-?n 7 Segment Program- A

plc16F84a pod B (?3 common cathode-7 Segment Disptay o3ec4 Q(9-9)


ei
%36oTG,ro',r'd-.?3' .oc3.8,$cor:E: sesment or6i{3:o? iG 3)%66o1EcD,:r,d3"o?3:
o.6cad3-3=oed,r{oq6or6i 3?6@.€:4..t8.,1'd' oQ"6"q8-t-"aio? 7 sesmenr
erosram ro?eaT@o1Q.rr

MCLR
RBO
oscl RB1
RB2
osc2 RB3

RB5
R86

i(9-9) 7 segment oisplay o6:o6q1c'5oc8cu3:Q

?(9-e) 7 Segment Display 9 segment orsiElS:N3:6$Q

s-.6o1lo6oq6@%.E source fite ca€ ej:p:ga Header code .,ic6t:E:6Sao3 Laber


Derinition qp:.{ ro69o3olod'
{eqcc6 porr qp,€,\e6c6,"i.i r..B9.6ot3rd, LED
segment qc:c{ ."+f.af
drccs{3:6G, or69dE c\rt'6o.$3?%.6 Generat purpose RArvl
%36ce:r Dispray o? oo5?o6cor:od rcsrsterca8 aataloinaryl) 4 coa9.B3:E:cf,d RLF
(RotaLe Left File) instruction er53,o?odG8. oata c{ ooSoc8ei.qg"S€o,"1.rdn
pod B r9.8..r, LED sesment qp:.{ sao?a9.{c.,3:€ocjl(,e!r
4Gf..;

.Joo? ?16 eisolqo


m]l:(9) 7 sesmenr Dispray Prc qdaqqi@{o o:i,qso,$o3:.;;:(9)

RLF rnsructron oi3?+:OL-d3?J srArus Resister e1i carry Flas.A"l €.dd


-.i,orq."-d' srArus Res srer srl 3,e3,c.,,d 6-,.6Jifc-c)%3 G€€%.i€,,13.d1
carry F Es (c) 3ra: SIATUS Register e\ llL c @5ol-31
'

RP1 RPO TO PD Z DC C

STATUS REG STER

!(9 G) srA'usREG srER al: bir tF: ora:i€i,i


RLF instft,ction e@:3. nispray regisier 3rc?3: bii qp:cg.onc:+t€. carry Flag 6\
3'o{r,rrd6"pdn85.c,TQ4.4 !3,cD3:coTG,iod,
3:8. L,rsiil:y resister qE c?89Qor$i: 00cu0c01 "o,3$6oE,r carry ras c4oai:
cary = 0 G6osa:c set o73coa:o3!a$,ilQ.rr RLF DispLay c?6tr:, instruction ,rioo3 sri:Gl
cqc'srrd::il Drsplay resister ca3$eo: rit qp:xd rcSoc6ri. carry lit c{@o5@: eg.ol":
3e':@6oc86.od, aG-r--)4@d.r'

STATUS CARRY STATUS CARRY

DISPLAY DISPLAY
(-)

DISPLAY D]SPLAY
G)

Q(9-?) srArus REGISTER €rl bir Qp: r,osocEr9.68.eiQ

Joo? ?d6 4qoirqo 1e .3,-.6.3,


$:{3: uspray resister ce€G6coTo,6o,
co3,e".i1-2!rr q.ctn: Decimal Point (DP)
bsic 1 G6tr8.:6oc>e9r Q(s-c*){@d.l'
ooocoor .$. reset S{SEcBc:p:r o{oq6!el
(E-o)ca€ z sesment Program A s?c8.3 flow

Q(9-o) 7 Segment erogram A ocgoS iowcharlg

7 segment Program A crl- source code c{eear,5ci1-.iS,-rTQ6er<i;$u

Title "7 Segnen! ?logram A"


Iist p=pic16f84a ; processor t\are
incLude p15f 84a. inc
_config h'3ff1'
PICi 6 Fg4A
clystal Oscillator xT:4MHz
coNnon Cathode 7 Segnent Display
This progran is used to control a 7 Segnent Display
The display is connected to PortB
The ploglam eners!ses each segnent

looe i16 o$4o1{o


sidg) 7 seemenl Display PIc {;.$,"1@$o,, ori:qoc3-5:qp'(9)

lortB equ 0x06 ; PoILB HAi4 address


TlisA equ 0x85 ; TRISA P,AM address
lrisB equ 0x86 ; TRISB R]\M address
Stalus equ 0x03 ; S!.l!us RANI addiess
Carry equ 0x00 ; Sratus Carry flag : bi! 0
RPo equ 0x05 ; Slalus RPo lrit = bit 5
Delayl equ 0x0C ; cielay registei LO:t byie
Delay!4 equ 0x0D ; de.Laylegister i4ID byEe
DelayH equ 0x0E ; dclay leglsLer lIGn byte
Display equ 0x0F ; display data
,i, ***"*****"**** I

; PROGRAM START /'

oig 0h ; stalluP aCdress : 0000

bsf Status,RDo ; seE RPo fo! R.cV -o_.te I


clrf TlisA i all Po!!A : oui5uts
cLrf TrisB ; a]L PortB = ourputs
bcf Status,RPo- ; set RPo fo! RAM page 0
!oop1 novlw th ; set.DisP]ay va ue - l
Laop2 novf Disp.Lay,w ; put Display into w reglsler
novwf PortB ; now.send this va-Iue to PortB
cau De1ay500 /' execute a 500nS delay
bcf Status, carry
llf Display ; shlft Display value left
bCfss Status,Carly ; test ca!!y bit
goEo lroop2 ) catty = O' do LooP 2
goEo Loopl ... i carry = 1, do Loop 1

; SUEROUTINE: wa6!e line for 500nS

De1ay500 c.rrf Delayl . ; clear Delayt to 0


cllf DeIayM ; clear DeIayM to 0
nc;vuf DelaiE : -_
_,:.set DeIayIi to 3
t{aitl ; subtract 1 fron Delayl,
golo IJai!1 ; if not 0, goco liaiLl
decfsz DelayM ; subtlact 1 fron DelayM
if Dot 0, goto tqaitl
decfsz DeIayH sublract 1 fron DerayH
goro l,ia itl lf no! 0. goto Waitl
finished the deray
end

looe q96 e$qil{o -qG- : o8:oo5o€:


-.;:(el : seemenr D,splay P,c qo-ical@io. o\:d-m ;r'.c
Program- B
9-9n 7 Segment
(D?0r(,6 0 to ,
c3q:ocDi:o? 6e',3q,66r%d+s4€: oc!,i:o,66i,q13,4 cornmon
cathode-7 sesment Dispray oSqcs€ a6,,T6o:€do{oq6.4 ."dc'.ScoTGdlp:"d' tG e)%e
.dlEcD,'.rds:o?3, port B 6l RBo og8 segment A .4ed:6c,,3: RB1 %3 sesment B
{.u21:ecace: RB2 %€ sesment c .4c\rd:6or3:r RB3 t33 sesment D .4cDd,c,,?e:
o.rd@3. 3'c5,33::oc8q.S.oa,::$sacac6 0 Lo s .Bi:qp:.{ ,leoTc,pqi€ 3,.3{€"p
;6,.-i,cp,4 ,i6oT6o:*d sesment qlc:e3.{€e3, 4er{-$Q,cpd oN=1 oFF=0 )d
w register 9o::o€. portB 4.8.6o:E: Q€,;IB€6,-rrrd, e,-ltlr- oori' o c{ QeoT-.Qqe13
sesment A, B, c. D, E 9€. F
4. dr€:6oqo1edll 4@€. 4e+i o,EE: 00111111 c{
eo:c8o1 instruction q"G€. w resister 9cD:o€. portB oi.Q.co:E: Q€oli8co3rdu

novle b'00111111' ; this is digit 0 value


movL{f PortB ; qrite it !o FortB
ca<.:o,o7r-rt -1Qc3$:qp:.Ac' d: c:c;436p {eE{-$$,qp'{ w resister gor.o3. portB

{.8.6'',8: Q6''Tq36"r'd
Q(9 - g)oe€ -.5{e,p c8i:oor1:qp,c4+6oT6p%3 cDe:6red sesment qp: 93.{3er::
{;si",6q,cP,4 ?:Q6oTG cDr:,jt 3rd,

E 00'1111'11
B 01101101

00000110 01111101
@ @
01 01 101 T 00000111
@ @
0100111't 01111111
@ @
01100110 0110111 1

@ @

Q(e e) 0 to s c86,".,$:qp:.4 3,.3436p43eqdi,qp,G€.r,.i..;rE-,i

Decimal Poini (DP) .{3,"i,eGL3,d3?Ed 3,cc.3oll6ilp:%3 bit 7 rd 3,o53?G o G3


eEooogl

1".e 1e6 oi1d]rl., -?9-


di'.*,i,c1r,4 +6oT6p%3 c8o5o?63n{d,c,r3,-3i9, Lookup rabre 4 -"i,QL|ie,
9dro3@66o3Jd r Lookup rable {opig" p'oera,n RoM 3?.oo?o5 RA[,'l 3,%€:$ data byle
qp:o? oEs?o03"cic3336:.Dd,cor:$dco,:o? €aToirrJd,
Lookup rable 4-ri'EL"p"a€ saEmc:ci'$Fieo: RErLw (RErurn rrom the
subrouiine wlth a Literel value in w resister) instruction cae@€:{ 3,B.r3co.:"tEcqo13rdil
RErl,'t instruction o? cALL inskuction gE QocSooi:q6"r.6dl.reqn D:rarabre
trt63, subroutine r{ cai,r, .93::p!aa1e3,ddl3?4e,c.l:ndr

calt DataTable ; put dlgi! value in 't


sacocSol inswction er5caSc$:oip stack qE RoM address Gt .'53rr6o:61(n to n+1)
r'f save or PUSH Gte6$:6$2o6 Datarabre ocD36o.€.t9$ cooe:$. i$c?,rA,6o,'l1lrrdn
w regrster %e 6-.","DcSg o"$$: 0h $6q])alr?c,i.oG, Datarable o?G:D, subrolllne
crd d)d:m"rd013e43:6-do?,ri.odr
DataTabl e rerlq h,'001111l'l' )0
oJe0to?6qtld instruction a:e9 neriw @6eooe@3. c,{"oc6ao:rp! subroutine
er5o{: G66@,€,r368:r stack 3"6<'lT{:9 RO, address c{ erogram counter (PC) ca€ load
qE.r:r' o3, Rorvladdress eqepfi code 3?4€: .Do6cDc8e36.o3o1rrd',
o{.Dc6:D-rd subrouline gQlor6o.3?o1 W register caE o-$Q: on 9 arn :1,
e@€:qo:eoo$u (3Fh arel {€f{o-48: 00111111 €$ rrex o:$Q:@6oplD smc$S) 6gcd
inskuction rJal w regrster o:4Q:.{ eorte cf.cl.Qpoo${q1e 7 Sesmenl Display o3€
oco{: o rie<-rTe oA3p2! rr

call DataTable d!91! value i. ',{


movFt PortB djsplay neq diqit

sacocS$ o"c"t"rr" subrouline c?3 63"roEo1s:o?3: .B$,qp,co3o?:c$dq23 6d{.


06cdol eco.cor@o18.il

rettr b , 00111111 ' jO


retlq b'00000110' )L
retlw b ' 01011011 ' ,2

3:E3or:83.G5ts3ca163r2),.?co€qe.$n>$: oco€ RErtlr instruction og8e;ro€p:e1acr5


o@l:ocnQ:qp:ol *-4.d{.qc?q.d{a,d{ 633$3e:G3. slqo{€, o.:"r.ui.
sub'ouline .f
car,r, o93:r2)oaa1 subroutine e:el w register q€ ocD6: 0 s$ €3o-rqp,
.{o? 3,"i-D."c"eod.3 rerurn o73qe ,-'cE8.e 3!'r
gls,a.3-5.{ Prosram counte(Pc) €'\3?o?3?d.?$iE: e@n€:$Eo1op!rr tnstruaron
{€,o2! oooon 9o6ir prosram memory o5 RoM address o:6egepc{ Q8{€@dld,r Pc
ca€ co.6$ nstrucrron o\ accress o$,!:$e1@', ,jlcjloo8 ot'l cqc6co,3"a'l 0 cae set @6

looe qe6 "iq.'l fl-


ecute) G:43: Pc a,d oqQ:o6E o?:e,:rJd ,

-"59.383,iqqJ6 pc
insrruction o)E?QG€.
3'dr
RAIM register cD6?cf PcL(Program Counter
Low) u?caTJloeqn
3?&):ecl RAIV register q1r:ci,33,o€ PCL %8cud: read or write o98{Ecr$r ecr
,?3 @Eq:or6eoi write q6qg€ Pc o5 lower s bits e,a!coe:: cGDS:cJ3S.:f, o{:Dd:ol
er2! {eQo3:oia3o:ein RoM addrcss sao69 eea,:cfo76:qo$ raouwr, srJBlrF, BsF
'
9€. noowF oerpi instruction qp:.{ PcL oa8 @3i:GG:, Pc o5o.liQ:o? 60o€:{3@o1a,dil
Pc 13. PcL 4..Do6r,$c{,ic{@do1 n
"o:c8olEooca€
Program Countet PCL R€glster

00A0 A0 (160)
0100 oo (0)
O3FF FF (255)
oolA 1A (26)

Datarable subroutine 3?QeioQ.,? errriolo{8:eqicor:.-:1"?ql

DacaTabfe addwf PcL


!etIw b'0011111r' 0
!e!lq b'00000110' I
retlw b ' 01011011 ' 2
letIk b I 010 01111 ' 3
!et1k b! 01100110 ' 4
!e!Ik b'01101101t 5
!et1u b' 01111101' 6
retlu b'000001111 '1

letlw b' 01111111 ' I


ret.Iw b' 01101111 I 9

oatarable subroltne sioo6 inskuction @6.-: aoo"r rcl a:g) XcoocoocaS


Ro[,4 address 001Ah
3 $3)dq oisodlcelr tnsrruction adduf pcr,3,d ,r6.ooE.o'.{ \'v
resister $o:$Q:93. PcL register 6oriq:o?.c46o1e:Q&E: qar€.{ pcl register ceSQ$rg6:
ie:a)d,, eoc"sd w c36 0 o)${:$q 8 pcl %e€G"8:dE3:(, 6e xrr ci.eo5co$, ec ca€
c.4Q:o,6io?:r.:odr
ecr c63 cr:i{: lAh fi&:, w ca€ 0 6od4qi8 aia"r pcr, o76e;o:3S:er::eo1
PcL oa€to,:orEQ: iAh ,.,€6a,cDp!:, pc q3 o)qQ:o)6?4:.D? 0018h G63a.:.rain
46@"€. o{:Do3.orqd tc8o) insrruction @6e.:': 'etr" b'00r111r1 ,.4 ctSc;3
noeo-,:.o$rr or3: instruction o:e: subroutine c{o{:-o56og: w
%3 ocm$: o qr\e:@qp:
c{ co$eo:cgc8eoo2lrr
ocDos!! subroutine c'f o.73-e;3?{$,?3 w 5 -FQ, 1 6qie add"f pcr,
ce6c:D.3@:6rlr3?a1 pcL
""ri
%€ o,g{:o)8?4,d 1Bh .9"&3,a.,a,eir pc Di9c\,a::o-,E{:

Joor Ri8 eftolSro '?0-


$o+:\9/ / segmefr u,sp ay Prc Q"5a{d-fr(!D :{tod5N6:qF:(t)

0018h Gs38o:]]dn {np.6 ec aE oi{:or59{:rs,S: 00rch G6t:}dn d6@3.


rettp b'00000i10'.{ c93.a':o8oc,no::,o S, .u€: insirr:ctLon r:ai sL5;uriie-.4 ,r.?;05
6oE: w %3 ocrjq: 1 6,i"3o,qp:.i coEi.r.,,cgc6e r.,og,
:;co.6o1eq,e5,n.6qp:c{ rist Rre qE GE@dqi8 G3??o5.jl-4€:6%G3936"-d,,
REri,?{ instruction 6'5 Hex o)EQ:?. :+ @6arE!r{ 3r.8GFocQo1rtrd" 34xx 3 xx De9
cDd+E,csr,.- 8 bit 63oDoriq:03-dn
c01A 0782 00012 DalaTabIe addqf PCL
0018 343F 0007 3 .e L1! b, 0 0111111 |
0
corc 3406 000? 4 reELq b' 00c00110 ,
1
001B 345A 0007 5 retlw b, 010 r 1011 , 2
001c 344F 000?6 retl! b' 010 01 111 '
0 018 3466 000?? retlt b' 01100110 ' 4

oatarable subroutine { 3ari:ELodoal .Q3"6qlc6?. W register c?3 0 ro I


-t8'cp'5,.r"G,' subrourine @6@38:{:car:{€: w resistersE d$:oo$:or6ifle:d ;"J
i3q:,-i8,qp,Q3{e€i61ed 43rd3;fl .6,)3G6-rJdll
".,"$ or,Ji l,3i,ocg,q:orqq:o? o cDdo6.a5os,i6oqi3i.3Gtq6oed, :acocaciee8:o6,ndqp,
.{ ca,c6,)1 flow chari 3 6oT&cor,,jl3)dn L':qo{o6t6q€ oLsptay register s?o.: Po.nter
resister .4e@3:$ 6Ta,:co,:G@?e: 3ro3@Foo?ol3rdr

Q(9-Jo) 7 Segment Program B flowchartg


'cA.i

1oo9 pe8 o$eo'l{o


--!n.t z seoment Dlsptay Prc €dai.ei@6o o:t:qloc3o3:qP:(9)

corts qp:c{ initialise e3E:6D3ral Pointer regrster (8 erac6ril instruction @3. zero
setr,ns cy6qdlce9N

loopl clrl PornLer ; reset the poirrcr t! (]

dc+".6 loorup tabre .43,ri:GG:L Po B r9. c8E:oc']$: 63o,qP:c4 q.6o:6lo1"dn


p:gc eointeroi$:c{ w 4.E0: Datarable subroutine c{ car I q6qo1e2!
4{.GL.lbq$
Loop2 novf Pointe!,H ; put Pointe! rnto Id
call DataTable ; Put digit value in !i

r,oop1 et. r.""ez of.o2! aow chart Es3 "d{.-diq-d4 GEordo6c€",


@d.1,
7 segment oo:{,o$$:qp:.{ oat.r.ure ql€oc39.68:cf'c6 eortB el. eserc,5cil

instruction @E.Q.q<J op!rr

novf PortB ; now disPlay neq digit

46{acB Delay500 subroutine.{ caII c96qolJJa)D


carl Delaysoo ; execute a 500ns detav
INCF(lNcrement a File regjstet by 1) iilsiruction 4 3?r?:&E:r Pointer register ql8 1

c{ eL;le:co$<i1arg! rr

incf Pointer ; add 1 to Poin!€! value

Po nter r€srster o,6$:xp! omoSd Pointer tesister


s cooSoec'?Fooc.$ c:o8@tqoledil
o:iQ,-a: 1o G5W:q2e g8eltileplr
reset xoRwF ( Excrusive
"ce{.GQ-d
oR the W and a Frle resister ) insirucrion c{3,Q:qqo;l€?irl
"Q"Ee-.a"6
XoR rosic runction c4 €,?o3o1s:o13: 6%Ge$3o13dn

A B BesuLt

000
011
101
110
A tc. B q. o?qnc qc\,3 u l9o6t9cc:€%.qcoeall

XoRWF instruciion o|s::i:qrriii3tol qo,5 o @6qn8 STATUS resister el\ 2 flag


o2! setl=t1 GA*''-d,

.1oo2 195 oQ9oi131o -9.- o€:o.;o3'


$l:(r) 7 scsnlcnt oispla Prc Q.,5oq%r@iaD -.e,{""!-[,cp'(:)
w cAE d'10' 4-d8,.9..; eoinrer or$Q:93. xoRWF o?6@aidledrr elcu:5=ae,,i[
fioaid BrFss inslruciion .{3?3?:GLG: srArus resister ol z nas o6$o6f.AoEear:Jlo?:i
G3"].E.)1 3?o?€:€6r:5ro1 od,
see if Pointer = 10
xor$f Poih ter, N if ii is, leset it to 0
btfss status, z
Z=otcoLoop2
Z=t.dotoopl

7 segmenl Program B615 source code:r@$ca{ c{ eo:cEc;ls:ci3:eoT@co::,llop!rr

Tltle "? Segnent Prosra B"


Iist p-pic15f84a ; plocessor type
lnclude p 16I6 a. inc
4

_config b' 3ff1'


; lrocesso! = PICl6F8 4A
; Crystaf Oscitlator XT=4MHZ
; Co@on Cathode ? Seqnent Drsplay
; This plograrn is used Eo contlol a ? Segnent Display
; The d:isplay is connected to PortB
, The proglan counts fron 0 to 9 and lhen lepeats
LabeI Definitron
Pcl- equ 0x02 ; PcL RAM address
PortB equ 0x06 ; PoitB RAM address
TrisA equ 0a85 ; TRISA RAM address
TrisB equ 0x86 ; TRISB RAM address
Status equ 0x03 ; status RAM address
z equ 0x02 ; status Z flag : brt 2
RPo equ 0x05 , status RPo bit = bit 5
Delayt- equ 0x0c ; Ce]ay reqister LOIi byte
DelayM eq! 0x0D ; delay regrster !4ID byte
DetayH equ 0x0E ; delay legister qIGH byte
Pointe! equ 0x0F ; display data pointe!
;............"".
; PROGRAM STAiT

olq 0h ; staltup addless = 0000


bsf Staius,RPo ; set R!0 fo! RAM page I
clrf TrisA ; all Porta = outputs
cllf TrisB ; all PortB - outputs
bcf status,RPo ; set RPo fo! RAl, paqe 0
lcopl clrf Pointe! , leset the poinLer to 0
r,aap2 novt Pointe!/ , put Pointer inbo i'{

?r3 o{qolqo -9J-


-too?
oa6:(r) 7 sesmeit D,sp ay Prc {c;a{doio ori:qloo5N3:qp-(9)

call I)ataTable ; put dlgit value an fl


novqf Poi LB ; nos cllsplay neu diqit
call De1aY5n0 ; execute a 5!oms delay
incl PoinLer ; a.id t to PornLe! vaiue
novl d':L 0 ' ; see if lointer = 10
xorwt Pornte.'w ; if it is, resec ir: lo Q
btfss scalus.z ; test Zero bil
qoto !ooP2 ;z=0,doLoop2
goto LooF:L ;z=l,doLoopl
;..,.."".."-...... ._ 'o'
; SUBoOJTTNE: Le tF I 004S

De1ay500 clrf DeIayL , clear Defayl ro 0


clrf DeIayM ; clear DelayM lo 0
novlw 3h ; set DelavH to 3
novwf DeIaYH
liaill decfsz Delayt subtract l fron Delayl
goto I'iai t 1 if not 0, goto waitl
decfsz DeIayM subtract 1 fron DelayM
goto Itait 1 if not 0, goto Itaitl
decfsz DeIayH subtract 1 flom DelayH
goto Itait 1 if no! 0. goto l,laitl
reidrn finiahed the delay

SUBROUTINE: lookup table fo! display data


R1i0:RBo=sednenrA
Bii 1= RBI = sdgnent B
Bit2:RB2:segnentC
Bit3=RB3=segnentD
Bit4:RB4=segnentE
Bit5=RB5=segnentF
Bit6=RB6=segnentG
Bit 7 = RB? = Decinal Foint
taTable add f PC!, f ..la ti '...1r. I tr Pai
re tlw bI 00111111 ' il .hi. :. t!:p=a l..cLr..
retfw b' 0 0000110 '
retlw b' 01011011 ' 2
retlw b' 01001111' 3
ietlw b' 011 0C 110 ' 4
rerl b' 01101101 '
retlw b' 01111101 ' 6
retlw b' 00000111 '
retl; b' 01111111' I
retla b' 0110111i '
oo$:(r) 7 sesmenr o spray _____l,c Ej:!f-{3 r:|!r"g-"!rJt_
,-€d oSoqicf asserno'e caie,€f.d, qr...,-:_D ner rrc cE opgcopcu:3€Eca8
ccpi@: run @21q6 i sFsment Displ;y;;t5 o 9 ri --.s "."'E,1p, -.b.r$a
".r.*.',6.;
_ -
cor.ole.e$:3?6qG;. ,ie"Tocni:4,.8 o 9 ::cB s , o:o{ s e 0 3?c9 3:l"fr?qi
eor.,Qi:, oe 4 9c3g:lf tuoBA:qp:+a.q.4EJ;.T",G;,, pEx seqr.:erce @5n,,. ir z:,r.
:
5,6,7,8,s,Ab,c,d.E,F
6octorrJPL
"i..4 6,iT6o6€,oud coae qp:cf e @E:cne e,:"--.6, ,S,_S@d

t-gn Switch Counter Program


sacocidlo{oq6ca3 7 Segmenr Disptay

9e
-3
aeo5qp:.4 3,.i,GL3ra)s}€1 boucins
6o?o5.?gul9:{1+;.C;"bo'0:
f.,?e1."4j,
tgtc\?oqora)e

CLOSED ...1--

SWTCH BOUNCE

,i(9-co) sWtTcH DEBoUNctNG eac6c6 DEL y coaico.:Q

o€oo6d€€,€B:{.3qp,.{ Q(9-"J)"e36,T0cor:r:2! now chart ca8a:2!: ecu.cuc$€


^ ^
"1-d,
f
" ^191.^gr"l ^."?o&j8oE€f3.
ac?oDc'?968:Dlo;c8cqcr69o:
3c3G:{1o?.q13 codrs:co,:c@o€:6 .8€qs,,Lrdil
ocog:s:r:69: o,6?fl€:c&€:rJ,:.,d4-c"3q"E16S..-s1,

aoic8oai:qE: oclr$:,i6oTod,r{oq€.{ 6cDCDrgEq43,ceoS swirch counter prosram


:acgci source rite r{ 6.c.ln3oa€ cillto:olDdn

Joog ?i5 e{eoiEo 99- o3:oo3"3,


sgdq) 7 sesrneni D spray PLc Qc,5a6oa+@{o on,ql".3o6,,ip,(s)

Q(s .J) Switch Counter Program oc?05 fiow chad Q

Title "Swilch counter Frogran"


List p=16f84 / processor type
include p16fB 4a. inc
_config h'3ff1'
Processo! = PIC16Fe 4A
Crys!a1 Oscilfator XT=4MHz
Comon Cathode 7 Seqnent Display
This progran is used to contrcl a ? seqnent display
The display is connectecl to !o!lB

1oo1 EeS oiq.oi{o -er- .€,-,-t.3,


oo$:(9) 7 sesment Dispray Prc
in56i"si@{M '{:qodNS:ep,(r)
; The Plogram cou^is fron 0 io 9 and then repeats
; each tine a switch connecLed Eo RAo is plessed
Label Definiti 6n

PCL equ 0x02 ; PCL RAM address


PoltA equ 0x05 ; PoltA RAU address
Switch equ 0x00 ; SHitch - PoltA pih RAo
PortB equ 0x06 ; PortB RAl4 address
TrisA equ 0x85 ; TRISA RAM address
TlisB equ 0x86 ; TRISB RAM address
stalus equ 0x03 ; stalus RAl4 addless
z equ 0x02 ; Slalus z flaq = biE 2
RPo equ 0x05 ; Slatus RPo bit : bit 5
Pointe! equ 0x20 ; ctlsplay data pointe!
DelayA equ 0x21 ; clelay coDnter A byte
DelayB equ 0x22 ; delay coDnter B byte

; PROGRAM START

org 0h ; slarcup address = 0000


clrf PortB ; display is blank
bsf slatus,RPo , set RPo for RAM page 1
novlw b,00011111' ; s€t al1 poltA as inpuls
novwf TrisA ; the rest are outpurs
c]lf TtisB ; aII PortB : outputs
bcf Slatus,RPo ; set RPo for RAM paqe 0
Loopl c]lf Pointer , leset the pointer to 0
loop2 btfsc PortA,Switch ; test the switch sraEe
goto Loop2 ; it is ope.
cal.I Delay5o ; execute a 50ns delay
loop3 btfss PortA,Switch ; !es! the switch state
goto !oop3 I it is still closed
caII Oelay5o ; execute a 50ns detay
movf Poi.ter,w ; Put Pointer rnto Ir
caII DataTable ; put digit value in fl
novwf PortB ; nou display new diqiE
incf Pointer ; add 1 to Pointer value
novlw d'10! ; see -if Pointer : 10
xorwf Pointer,s ; if it is, reset it to 0
btfss Status,Z ; test Zero bit
goto looP2 ; z = 0, do toop 2
goto !ooP1 ; z = I, do LaaP a

Jooe $6 4}olqo -9G- oE:@o3o3:


I
7 segm€nl DisPlaY Plc €.te .3o6,QP'(e)

, S0BRoUTiNtj: waste tine for 50mS

DeIay5 0 cllf DeIayA ; clear DelayA to 0


movlw 40h ; set DelayB to 40h
$aiE1 decfsz DelayA ; sublract 1 froft DelayA
goto Ilaitl ; if not 0, goto waitl
declsz DeIayB ;-,subt!act I fron DelayB
goto tiaitl ; if not 0, goto I'iait1
relurn ; finished the defay

SOBRoUTINE: lookup table for display data


Bit0:RBo=sesnentA
Bit 1= RB1 = segrnenc B
Bit2=RB2=segrnentC
I Bit3=RB3=segnentD
Bit4=RB4=segnentE ,
t Bit5=RB5=seqnentF
I Bit6=RB5=seSnentG
Bit 7 = RB? = Decihal Polnt
I
add*f PCL add lr value to PCl,
retlw t,'00111111' 0
retlw b'00000110' I
rel]w b' 01011011 ' 2
!e!Iw b' 010 01111 | 3
r€llw b' 0110 0110 ' 4
letIe b' 01101101 ' 5
retlH L, ' 01 I 11101 ' 5
retlw b'00000111' 1
!e!1{ b' 01111111 ' I
retlq b' 01101111 ' 9

Joog ei5 e6{o1qo -92-


rl:(e) 7 s.sment Dispra! Prc q"Sifi.sl6{- -1l,qj"":(o3aP(t)

g-Gr I9ultiplcxing 7 Segment Displays

uriorol 7 sesment Display $6Er :,i:ir ocu:9 oerg!{.g3 multiplexins g$:@3.


orcQ:qp: ca:d.3i. QeoT$3Qc{ e
2! rr
"odo:.6eoT0oll

Ptc15F844

9(9-c?) 7 sesment Disptav 961c63QeoTQ

-c1)q3 e oTScca:o2)sa{6: DisPlay A +3. Displav a oi.93 oco{:qp:


eacocAol q(9

QcoTq{ooect o2$e::r segment ep:o? s?Et3.oc6.B,-Sco",E,"q"c3


,D€:o?.{ pod B er5 pin
gr1€.
"ocAqcS"-,.jl.rei
r Dlsplay o:EEq13:e\ common cathode pin rl| NPN 3toEqr
-.ti"9.'l:qp,55 or'ro coq$osazqp:a5mr.6qp,c,l {o9oro:6Q:E
5S: portA o5 pin qp:
<,c6cu6:saca3ca qr€ coT0cca,.;l]Jd,,

1oo9 1ed o{qol{o -to- oloc3o3,


Q(g-ca) Multiplexing 7 Segment Displays Program s" c; flowchartQ

e5r:p:go Port qp:c{8963?<96e6€€coq$rqc6 setup q&io$r


{e4oci oco$, ' t
1d.{ie::a escrrqp:.i PortB r}i.co:g: 3"cb{:co9$ogo-, Ol c{ oN 66q}oec3.} PodA 6\
I
RAo 3 losic c{ sel caSec':s1o11oe! r Display r, gE oor$: 't'
ergeoTeo$:eqr.;
(Di:oa) oFF lgd38r:6oldr .ocdcDmd ocl)+: 2 $t.{46f,, cao-irqp:t PodB
$o8E'coq{"9o]r oz .fl oN 6oe63' d PodA €,5 RA1 (€3 losrc 1 .4 sei
'1.8.6,,:G,
olo6o:6torrJl9|isoraytJ c8c ocD./: z 6q d "oE:€t:)] LDc:3re UFF goad.:sora
glqd'*"?€, @$ot',: oisptay A i3. Dispray B 4.%3 ' 1 '9e. 'z 'oo:$:93o{, s,:"c8eQc;
"oTca6o60,.3rd,

[,,lultiplexing 7 segment Program A €i source coAe saS$ra,icfl caa:c8cil3ro?8'


eoTSco:: o1 o$r
Title " r4ultiplezinq ? Seqment Program A "
list p=pic16f8.la ; processor type
include p16f84a. inc
_config h'3f i1 '
; r* r****** ** *++++*
; Processor = ! Ic16 Fg 4A
; Ctys ta1 OscillaLcr XT=4l1Hz

poe 1jB efuo1€yo -94 o::o.'1"::


@E,(r) 7 sesmenr Dispray Prc Q.'5.{%1@{o o:i:qoo5N6:tD:(e)

; Comon Caihocie ? scgnen! Displays


; This proglah rs used to nulripl"cr !!o ? segnen! disPlays
; The display segruenLs ale cornectcd !o PortB
, Display A is contlolled by PortA BA0
; Display B is controlled by PortA RAl
; The proglan shows the numbe! t1' and'2' on the displavs

PortA equ 0x05 ; PoltA RAl4 address


PoltB equ 0x06 ; Po!EB RAM address
TlisA equ Ox85 ; TRISA FGM addless
TrisB equ 0x86 ; IRISB RAM addless
Status equ 0x03 ; status RAM address
RPo equ Ox05 ; sCatus RPO t,it = bit 5
DlspA equ 0x00 ; DisPlaY A = RAo
DispB equ 0x0l ; DisPlaY B = RAI

; PPOGI Al4 rll...

olq Oh ; staltup add.ess = 0000h


cLrf PorlA ; nake sure arl disPlays are off
cllf PorLB ; moke sure aII segmenLs dre off
bsf status,RPo ; set RPo fo! RAM page 1
clrf TrasA ; aII PortA = oulPuls
crrf TnsB ; aII PoltB = oulputs
bcf Status,RPo ; set RPo for RAl4 Paqe 0
Loopl novlD b'00000110' ; segnenE data for displaying digit 'r'
novwi PorrB ; send it to PorlB
bsf Po!!A, DrspA ; {0) tuln display A on

bcf PortA, DispA ; {0) tuln display A off


novls b'01011011' ; segmenE data for clisPlaying digil '2'
novHf PoltB ; send !! to PoitB
bsf PollA.DispB ; (1) luln display B on

bcf Po!EA, DispB ; {1) tLrln dj.splay B off


soto Loopl ; contrnue and lepeat

s?.Do5d Display (q)iqt r,z,s,.a o?eM ocD$:(9)Q:.{ QeoTcQolor {(9-cq) oe€


G-,,-d-"?E, ,-,o3.o3,c{:oc6r;oS$: source code %€ a?3?3alc6qp:.{ Gde"E""t-,Q{
6sD(')oroo?c:6(Jr i9cor:ur DPn

Title " MuIEiplexing ? Segment Proglan B "


Irl p p c16f84a iP e'or Evi_

Jooe er6 oq{dqo -eq' o€,-.6o€,


label Definition
PoltA equ 0x05 ; Po!!A RAt{ address
PortB equ 0x05 ; Po!!B RAM addless
TrrsA equ 0x85 ; TRISA RAM address
TlisB equ 0xA6 ; TRISB RAl4 address
Status equ Ox03 ; Status BAM address
Rpo equ Ox05 ; StaEus RPo bit : bit s
DispA equ 0x00 ; DisPfaY A = RAo
DispB equ ox01 ; D.isplay B = t{A1
Dispc equ ox02 ; Dlsplay C - ttA2
OispD equ 0x03 i Disp-Iay D - F{A3

; PFOGRAM START i

olg 0h ; 'btartup address = 0000h


clrf PoltA ; rnake sure a1I displays ale off
clrf PortB ; nake sure alf seghents are off
bsf Status,RPo ; set RPo lor RAlvl page 1
cllf TrisA i a.If PortA = outputs
cflf TrisB ; aff PoltB = outputs
bcf Status,RPO ; set RPo for RAU page 0
Loopl nov]w b'000Q0110' ; segnent data for displaying diglr '1'
novwf PortB , send it to PortB
bsf PoltA,DispA ; (0) tuln display A on
nop
noP
bcf PoitA,DispA ; ( ) tuln display A off :
rnovlw b'01011011' , segnen! dala for displaying d19it '2'
novwf PortB ; send it to PortB
bsf PortA,DispB ; (1) lurn display B on

bcf PortA,DispB ; (1) !u!n display B off


FovI\., b'01001111' , segment data for displaytnq digir '3.
rnovwf PortB : , send it to PoltB
bsf PorlA,Dispc _ .i -l?) !uJ! gispl.ay c on
noP
nop
bcf PortA.Dispc , {2) tuln disptay c off
!ovlw b'01100110' ; segnent ctata for displaying dtgi! i4,
, send it to PortB
bsf PorlA,DispD ; (3) lurn disptay D or

bcf PortA,DispD ; (3) tuln disptay D ofi


golo Loopl ; continue and repeai
% 3
e 22p 4MHz q
2 1L

AG-.c) ...$(s)a,e"oTc$oo5c"3'Q

B
3"
s!:(q) Lqu,d crystal Display(LcD) 1 Plc qo566€l6io oa:qloc3.\6:qP,(t)

-nlde)
Liquid Crystal Display(LCD) - 1

o-.. {"11

S:5.eo: sao{:cA8 7 sesment LED oisptay r{sm9:Qfi: .BE,o*,E,qp,' -"i,qp,o?


A6oTE€ Q.{6oTE5.,i :ldn sl3?o1:%€
LcD (Liquid crysiar Display) G3. .8qncnl:qp:,
orot:q2: (characlers)r ooe@c3:qp:(strinssl !6Qqp: (animations)c4 {eoTeo:$3Qci aoo6orr'5
o,3@oledr LcD qp:Da9 LED Display coc6o:q913 o1o1o::a1:1 o?cglqd:o1:o@€. e1o55
("rcD.DQGe. 3?ai:qt61a:d oo3co6:ft:oe€ eci:01,1i 3?$4oecoi5co-d!
LcD qp:oe: Qa{p{Se.ogo8eoTAr.olo2!' oagp:sa,:@e. Hilachi HD44780 controlret
4€3o? s,.65o.d6:D,c,5co::@: o:o7:saeqcaca.6 8, 16, 20, z+, ez +o {.c{ o:3c$3:r
96c.?€,, cN,cq8: oo$qepo?.ce8 Q6oT6o:q3@ollod, {.s:Q€ epc6aoc':3:eep€eoTp{3
er2i:ad1,.eo+ (backlit type) qp:cDe9: cgc6eoT6iol@r
sl3aal:%E {€:o,6oi€:ca8 oci,:ee1 Gc)c'i,6orQq€rld c$€:e8c$€'cioe$: e{.rc6;
.?"r3:cqr€"fi.r'r 2 line xf6 chaecter (non back ht) @qJl:3?o.: LCD c4 caorro86:aec6qp:
(data control switches) r{san:Qpr:: c8$:oco{,9p,' ,r"oi:qp:, oo6@r3:qp:r {6,iqp:,i6tlT$3i
.,?o,€G-,@:, caa{(6)o3€ Prc Qc8afi c6Eco{cu'qp:f3. Qo.6ori,Gg: Qcoq€e ec@?e:
.a o,eGco.:olsdll

g-1rr LCD module eorAqc$.$9o5(pinhp:

2x16 LcD modure 3?qp:9%3 :oc;Sosqq to5 (p,n) (rG)i olo€oloplrr {.er:6o:p!:
(.)"(re) .,.3 c.E("s)e"t"- 3?3-c"",8, !rd.8.'s-{,Gi.-.$.;r-d, eos+dr.S(.c) +3.
(r0)4.9r cJ,.333?cue:66p€ Oack lishtrnsF?q1.8 G8;l-d' Q(C-.)oa€ rco modure 3?{t:
3?aD:3"{Lo\ dloSQqp:4""t8-'8, eu::dc)c?3 zxto LcD modure $\ ro5lolo5qp:r€.
,D€:o?€fie5c4:oEqP:c{ coTocD.:o1Ddn
eo3(ce)1e€ rc3{tl1o6GXJ)r€i?)o?.od Q.3;o:6o3oo?e:sloacE sDi,&qqeosqp:
G6E, rc,54,jro5GXg)f31G)o?.3)d 3?dq:e05(?)iG6o,, efi,.i"E(e)e("e)",c3 eo6(o)i
of.op! e:o-,o9c8qp: G6@odn .DdNo5E:qdo$19,3.\ ..TG.l.p9'
"et'c{:oiqp,.i
r-+.1"6G).,? cG{dcq€: (0\493.oo6*csqE, i.3qdlo5(J)c{ Q.se]:3?Gol€:(+sv)
93. :o.fqcSqolo$r
r.61.1de)-d s:cu€::aeec€lconrrast; ,--.,ed,-sp,.{{i"o:ealQ.r,:
(vee).'?
c"d",r:€I3rdroS @6o1o3ir, ',ce .sv
se. cGq"S.q€'-@r: eocf]Jo6er:o$ o{:oo6
Qor€{t8o.o€rl :acu,;S9o39 qcg{8ol-p!r'
"i
o{;ea:. LcD 3adt:oa:cae vee c{ sa61d$.rl::(-zv)
3)o3€o:1o,c6,',13d,

.1oo9 1E3 ei1o1{o -3?


ao$,(O) Liq!ld crystal Dlsplay(LcD) - 1 r r 9DDlldJl@5,M in:iLoo)NrrlI:(9 r

q-$d1"6(E)"? RS (Resister setectl o7eaTo1o2!r ,,Je,!o6od ev,c$8:ql (Dara


Bus") eoTc63$eleur e:o-,:ca{1::a"a,.{ }@,oo6eo3eo:o1o2)rr tu8:ceeE -,,:€3.(0v)G56oT
egq913 rco {.4.*,-d byte qlr:.{ commands or instructions c? clo69o5$'r cD8:q.8c?€
E.G-,:G3.Csv) GSGoTGrelE LcD {.8.6o:]]ai byte qp:.i characler e:o-n g o"59c8
r-d'
to34o1o6(9)oi RAr'r' (Read^A/rite) o?6aT"llJ)d' ,,,3:cAeQ.3-,86.(0UG660T"{qi8
63c.,qp:c{ LcD ci.Q.Go:@3: (wrire moae) c{q3cor8@:r ot:to5ql3 q.s,:G€.(+s\4 G36oT
qq13 rco 9 eco-:'qp:.'i ogc8q@8: (nead moae) cQ o93e-o:3o1or2![
tc'5+o1o5(G)c{ E (Enable) qeiTciop! sacoc8olsaoiS: ns 9c6@€. esarua{1:l>e",
4 i&,B,.q"d LcD ,r, c?8ci:oo e3."cD€$3qEs,%os rc31o1o5(c)o' 4:Bo5€o:Jl3)d,r
E ec6c:d 8.3,46.c6eq.-,,GeF64.o?,.G,e:E:, E.D:G3G6eq.3,,:q3.e6:i.0ieo3: (roggre)
Dd-i.E%e RS rc8G3.])c39o6cqdtrJd cao,oft3,"r'ooao5 LcD 1'e9 q6ci:oiqp,cfl
o28e.o8 dl ec.r:.o2! rr

Q(s-c) rco :a{1,r,o::ea{6o\o1c3qqp:

Joog ir5 s{fcilqN 'c9- c€.oc;ci,


$a4(J) Lq!dcrvsral Dispav(LCD)- 1 P c F.3J{,"1o$@ ,r:tj.c6tu5:d:15 )

)eoi a@o?e:9p: (Dala Bus) u?6aTc;ba9,


, a btt I bbre
ote mode sa@6 3,3i:GFcD.icjl3Ja9

{eio:,{c.,ae3.o)oc,53'i:0t3)d3,il vo rc3(e)
s
ype LCo :a{1:oo:ca3 back lght 3?c3.; olldl
.",q.,€€ -ri:0rlo,jr],d
@c?qlLo? or 6H

RS = 0 (lnsiruciion mode)
RS = 1 (Data entry mode)

R/W = 0 ( Wite mode, to write instructions or characier data to LCD)


R/W = 1 ( Read mode, to read character data or status information from its register)

E = 1 io 0 kansition ofthe signal, daia !s iransferred when wdie to the LCD


E = 0 io 1 transrtron ofthe signal, data can be read from the LCD

Pin No. Name

1 Ground
2 vdd +ve suppty
3 Contrast
4 RS Register Select
5
6 E Enable
7 DO Data bit 0
8 D1 Data bit 1
9 D2 Data bit 2
10 D3 Data bit 3
'tl D4 Data brt 4
12 D5 Data bit 5
D6 Data bit 6
14 D7 Data bit 7
15 NC No Conneciion
16 NC No Connection

eo:::(c) zxte rcolnon back-lit) €,5 e d1()1o5qP:$€ oJ€:4€,te8ci:o0qp:

g-qr LCD o16c{:olqp'oca.f o6,o69u"5c"6,q:r

2x16 Lco .4
€c3a6%6@6cDr+3.o)od3,.i,,jGr3,,,Je:o5e8ci:ojqp:oi o3,3J3
o8c:.,6.i$3?ced +(3-J)'?36.J'''Gco":3)doo3c!6,c8 ,r2)eao:c6q.jled, 4oc8cD3,o?
"fi,xc8
a.5@.:r6?4-c'5o)G: o,>d€.o.q5$3dl3Jdr ""-4€,,ig4 8-way D rL (Duar rn Line)
switch Sdcoal+3:q.jl..ra)x sway D.lL swltch 6+9P%6 sub-mrniature hexadecimal rotary
swircrr
e6q:c{ 3?{:&dcud:6i$€,,t)d
Sub-m;niature hexaiiecimal roiary swjich qp:od 33{r:1Eo} fJ)ql:6J.rd,
oco6s{L:sro.:9: oN = 0 type @6@,r oN = 1 type GSdlc:air
1d--{paaD;p

J"o? ?e3 e4sdqo !: o3:or6oi,


o.3:(r) LiqL,.i cryskL Display{LcD) - 1 ptc e,rSe8q$o8o o4ao"5o6,ep,(9)

.,.06-{1,*-,9" '0'6iep%39dc.a:qne
qoSsa:q, (r,2,4, s) ?3. n (conrmon) to5
c 3,@':cA; shoi' G6€qlOE:, "r" 9pca3"7p!o:::rs3 ro33'r:oi: 93. c og
open @3
.r@-d'
fc8or3,{t:3"6D:p "o'9epca3o9p)co::q1€ qds::r:q: (t, 2, a, 8) $3. n (ccmr,ron)
gc8 c a,@.,cae open G6GelOE:, 'r" 6{6p"?3eelco5,et€ eds"r:{: r€. c a:d short
Gs"+@-d'
,i(S-l--)"Se ocoosa{1:s,oc: oN = 0 type, sub miniature hexadecimal rotary switch
e6oi:c{ 3"ri:|qtco.:63, o6:"J3,rc3o,6:c4coT0cDr:S:r Q(3-j a)o3€ ro3or3,{[3eo,: oN = 1
type, sub-miniature hexadecrmal rolary switch $6oi:ci :a{:GFor:ee:r 05,rr6oc5or5:o? 6oTG
co.:dtQd,,
Hex switch ol5t3ra! eso,orq$:g uexadecima ocn$:or6qr{
'?cSoo,Gprd,, e"-,-
63o-,or$Q: $3s 4 set cjScQ::ei{alS ocoo hei iwitch ca€ ":" c{ set q8$:r qo3o hex
sw;tch %€ "8".{ set caEq<-rlc$r
6cac8 ss .43?"i;0toe:s:a1 bouncing GuJe.G6coTo'o53r03. -3,--, Q(3 e)c3
Debouncins switch <;06c.'6,,it"i ::.o:4,o6.,j1eldr (Debouncns syJrtch
".f|!-,-d
oo6c"6:o?3c!6Qci 016t1?6q:c,:co.:63r. %6Ql6oo5dodcosi:E6oca?3 €r5 o,qldfr(3o")
%3@d.jrD
o6:o6iqp:3rd write mode 4 oSoDco':E: e66.ore6dG66.,6@"€. rd4 dl
"3(c)
K/w c? uv(br\u) +c, crtcD$maDcD:eurcDr:6tor3)Pfl
,)q"odqo)€6po, vR1 Ge. 3'c.,€:/.cqq (contrasr) o?{id+3o1])eir vRi€15 E:
o:6oc6r,f qgoEcoc:eo5<oa9: aTKo flogo-::,5$ oeo13:c$3:93..Dd3cScD,:$3o13rd r (3,flc8
Q€:or36cQsa6er:: Lco module qp:3ace.t trl8:ci aTKa qogor,5d seqd{.rac:c$€:qt.
-"61.5 q,it
"2! ")

Q(9-1) zxro rcool q3"1',iqp'4 05,-6.oTc?c3€doo3a,6:Q

.1oo9 iq,6 o{aol81o -36


Q(9 g-.a) Hexalecimal rotary switch (ON = 0type) Cp,.i -.i,Gtcoreoco6:o3oc5<u3:Q
s$:(3) Liquid cryslat oisplsy(LcD)- I Plc td.{oe;@ia re:qjoosc$:3"(9)
+5V

7 ttcDULE
PrN 6(E)

9(3-?J ueDouncrng sw'tcr oqt(\.)u:t

a.!cE s1 to s8 o?.])d g€.Grq9l8 6oc.,cq€:Dei tosic t @6$:1 8o6ciiqi3 bs'c 0


G6Ddn ao?o8qp:.4€r6pipr€-"1' cac., bit D7 tra: "?cS,..33?,%3$G:r bit D0 opi ;ec
oc3{:%€6ca3qlc,r, l.i {.s- 63",1+4 4+qc,:$,?:qp:3;G6 cDdse:Df 3;. i
"d,
o.oeGGRe6ocss.Ed,
0,8. vR1 c4 eooc6m{:3i.oedcD.:6€'G3. vee c4 ov e3. eoc'qoSeoqcilo2lrr
acao3 s10(RS) r{g€.co::S:r aqc8 ss1e1 .4 s93$c"o:qoledn *o.'oo?dqp: s1 to ss
o2! eE!a:2ior$Q:o3ec{co::+3olrdrr
g)ca8 rco module 3i. instruction lE. character do,qp:4 codQ€!611 3e.D3o3.
G6are:>.6@r3. eerc66oT$ol o8'oSnc6q:c{ aoricor6o26eao:3$€eoeo.rc,co$rr

9-9r oE:cr81r6(c)r Basic lnstructions


aoSc,cQe:Q.oc'c{oo+eo:c$c'5ec,cil LcD coT$ c$3:@6i%t e4c6espS eco,e"13.
3?.A.,5co5 (character cell) qp:eoTcu,eod6palrr *a:c6dlQ(3-9)o3€@2|o1rr oE: celi qp:
::p! orr state q8$e9@eoer$rr <D€:cacscrcuiqp,r{ o3q$q4@36curo8i$€6po6cd s,c8
vnr r{ o:oSor;o$. Gd:?e8:sr o?dco:qdled,

i(l-t) character Ce ,il.:i

.jldlog€.{Eoa€ LcD op! g<ono: reset ::e@saeq@6eo: branked off t23 ocDe
olod, 4o"63:€4qr3 eea,cqp:.a coa;a€,e3,6cD$: +6or6",$eGe:('{c{ 46@3. LcD
r{ ot,t state ci.66pc66,€ insrruction @a:Go:1o1ee9n rnstruct,on qF,€@'€:oi G,-,(-l)

Joog eF8 @iiolqo -3o


truction o:61Et€:93.{36., 4€qq"riQ:r3. h€x orqQ:
{1"a36.q"- 9o:":c39.3q"5qp, (nlia settinss) .i

Binary
lnstruction Hex
D7 D6 05 D4 D3 D2 D1 DO

Crear OisPlaY 0 0 0 0 0 0 0 1 01

Dsplay & Cursor Home 0 0 0 0 0 0 '| 02 or 03

Character Entry Mocle 0 0 0 0 0 1 1tD S 04 to 07


Orsplay ON/OFF & 0 0 0 0 D
1 U B 08 to 0F

Display/Cursor Shifr 0 0 0 D/C 10 to 1F

Function Set 0 0 1 at4 2t1 10n 20 to 3F

Set CGRAM Address 0 1 40 lo 7F

Set Display Address 1 80 to FF

1/0 1= lncrement',0 = Decrement RyL 1= RightShift,0= Left Shift


S 1= Display shin ON, 0 = OFF. AA 1= 8 bit interface*,0 = 4-bit intedace

D 1= DisplayON,0=OFF 211 1=2linemode,0= l line mode'

U 1 = Cursor underline ON,0= OFF' 1017 1= 5x10dotfonnat,0= 5x7 dot format'


B 1 = Cursor blink ON,0 = OFF' A = Current CursorAddress

D/C 1= Drsplay shift,0 =Cursormove x= Don't care .= tnitialsettings

cor:(J) lnsiruclion control codes

rnstruction t€. cnaracter *o::qp:c{eoT!r,d3,a1, {€qq otrgQ:G3.co1!c$q913 &bit


D r L switch63cDoE$:oeo33"{[3,o':o? 3?{:Dt6cD.6E'r hexadecimar ."fG{qir€
hexadecimal rotary s tch 63o,d6:aac6o{t:3?o":.{ s"{:Gpo.6o1 rrdil "'iQ'Ge.
Display oN/OFF inskuction J.€. cursor instruction oi.::p! Oisptay oN G66oDei 4
_
o[od cursor 6\ siyte cia]pi: 4:Gcrl6o:Jlrrdn
E:s. underrine 83. ,$c3"dqc5G6e'qtr d
cursor QGJf€oqi6<1qog cooe er2i
".",),(t)"a8
..'lE*,ta3'q 00001111 {sor) @$e@3:eq.ele o"e:( s rrai Hexadecimat
o,ir$:{ G66@"i:4 6,'ra&:,1 !i!r,

yooj q96 o$qJfio -ce-


,6q:i!l Lro! d c./si:l Eisr .jlL. Dr ' I p c i d.e.?i@ic-- -i2,epi--.i<p.{c)

63(Da\-c3 s1 io se o? 000c1111 (sor) o$Q:sic:o3 sei o?3o1n RS = 0 {rcEic 0) G3


ero€."id slolRsl 4 set "f8Jl0 4#] LcD cr\oig3cra: nstrucLion mole ca3{.5"3! r

46?d ooicS ss(E) 4or6qtc8B6o?.Ari, Dispray ca3 cursor ])a!) uncertine @3. $o8o2o8
'
q&osG5qi.s 6,jlo,6o.36"od,, Q(r .r)"a€@aidl'

Q(t-s) orsrLayqS cursor::p! underrine@3. $"So?dqd?cEGSqidcoTcD,Q

s,-.Sd .83,r6.Q3:€oT.oG:, 8-!rii d3te, 5x7 foftrat .{o.i:Dld1;13 e:lo;oc9.5'qp,


d {hi-qF, 00111000($38) c23 set g3or Rstsl0) 4 ic'i' (0) %3car:csl.i E(sel
ooTdo?43cQd.rorlodil {.sac,5 vat 4""+d-cs4:.,,,.id.ei3 Q(o-G)%3G..,,,-*
3?4€: characrercerqp: oi€,s8a3?Gd6oTc',c".33.dd,

Q(3-6) oisptayca€ character cetr qt': c$3:f6f %3coTc.,Q

Q(s-G--) oiilptav.a3'A' o.c!:6oTolQ

4.SDd Rs(s10) .A hish(1) %3cor:q d "--A'@, (capital A) €ri Asc I code


G6e.., rihi",Eq: 01000001($41) o? 63o,.e.3qP'%3 ser c93cmr E(ss) oclo3.4
A' ora,6"Tc.]reocB6.e2!rr oo7o3-5
",6qj"s$3c$d".ds?al Q(5-G-,D)cB€Gc-:3rd3,o?3,
A" r,T+s3 uouncins Ga).+"G56.,Te$63r.
aldql€,-36q3"Jd-il4€, -.e:or6oi,qte:ce
6@6r E{ss) aecS€9.p"a8 Q(C-r)g debouncins swiich acyo3"4 --'4'.:ei:@tqcrlod '
Dlspay ca3eoitegeo: or+,qp,.4qfd"".qqn3 crear Display instruction !i;"f,'
3?3iFro,iE, 00000001($ot) c{ €a'ac!o5qP:cA3 set o73l!:r RS(s10) .{ ow(o) %3--:
cat.D t a.!orqluqmq.Jr6P
,69:(j)LicudcrysralD,splay(Lcorr P'cE.,5o{%i6{@G{.qtodN6:eF(9)

3,-l5,qJLS""Tl0ql.3
'&o:3qldG)s"oe.6
(c) Displav oN and biinkrnq cursor wiih underline G660€6-
Code = 00001111 ($0F)
51 to 58 = 00001111 ( or ) HEX-SW1 = 0; HEX SW2 = F
RS=0
E=1to0andthen1
f r) Functjon Set 12 li1e. 8-b l. sxTDixelformar
Code = 00111000 ($38)
51 to S8 = 00111000 (or ) HEX-SW1 = 3; HEX-SW2 = 8
RS=0
E=1to0andthen1

(?) Capital lelter "A" character o,rc!:Q6oTqq -


Code = 01000001 ($41)
51 to 58 = 01000001 ( or ) HEX.SWI = 4; HEX-SW2 = 1
RS=1
E=1to0andlhen1

(9) pisplay ctear l.arq$qt


Code = 00000001 ($01)
S1 toSS=00000001 (or)HEX-SW1 =0; HEX-SW2= I
RS=0
E=1to0andthen1

3-g' "6,c"6n.6(g)r Entering Text

slo8:rr6Elc6o?Gto?39?q3 Q(3-1-m)e€. (9-1 a)"i. e".T@."',63, hexadec,mar


roiary swirch 63o,acqc8qp: cil o363, o3:o6oc6o6:qL,cA 3"3i:Qtqeel8
SQ:aaDec$,jl 3rdn
LcD module 3 i6.frE$36r-:. o,oi:a{t:3?-,qJ.:.,? cc,rr(?)%8 edlEc.a:,iod,
4.,,-'4"-..-@dq€'"\i,r1.,, :. )r tr4863r. code 4 { 35 qDig:f 3. hex orqQ:4.G8.
code 6i 3rcso.3s8q (mosi sisniricanl bils)or (upper a
".1E-o:6@,3,.%..1.,r"d,
=-
bits) (9)e-ei co,,.fd583, c,coe3?o,i: 3 ordiE:,
e",rotues6(reasr sisnrncant birs) or
(rower 4 bits) (9hord @,i,:ai ocooecnScuc23 ordgcf dlc:d,
oroi:3",ir.:93rd Asc r standard 3?oi6:G5@G,L ,loqo.ci,c'{!.93. oqo,a:s,{rcDd,
dtoeca@cjt3Jdn
od5rd"6,trr6oc3-5,qrr4.{ *.i,01G, co,:(?)cs€c,iE.oo,3)d c8$:ocl,q:qp,r3.
-"i,cp,4Q.6r@d$ee oosi r RS(s10) ac9o5c{ rogic 1 %€.,r':d +6oTcQ63, oooi:+8.
r.d{3.r1 code.4 set e38; E ac!o3.? trigger qSqoloa:r
code (rG)1[[,e::: 00000000 9 00cc1111 ($00 to $cF) s?cs.{
- ^-,(.1)*\.-.
.i.iqt,;,,Tcac8c'u: )rd .q8o;@.i:ql.: (useFdenned sraphic characters) 3a%d 3,{:GLB8
oei cGRAl,4 [Character Generator RAM (random access memory)] .4
,D3,4..4 3>{,GrE:, "i,sor,ol,rl.rd
r-o:oe13,5qrc, (barglaphs) , EtGL,Qldqj.33)6mo,, ,: (flashins synrbor)

1co1 196 o{eo't {o G:-


o!{:(9) Liquid Crystal DisFlay(LcD) 1 r u 9f,a6t.tao\t@ r!:aD.iro!:or.:(c)

0 l 2 3 4 5 6 7 B 9 B c D E F
toDa Jnor l0l! s )r 0a IcI )l tc )llr t00c 100t 10 t0 l0l1 rll 1t4l I]IJ ll|l
0
-r00u
it I

l
lttl t'i

)n
2
r(
l.F |: I'
I
3 I
001 r

4 ._,t
I

5
Lll il I

6 f'I t! I tt -{ tt
)r rc

7
lrl I
la Ll r! f.r -.t -t..
:r II

I tt t.. !l
I
r00c

9 I t! I ,t
t00l 1 .J llr

t0i0
rl ri 1.! .L

lr'
rc
B
I q
l t- I
rl r it J'i*

C
t
I
.'|.
1
I
I
-l {.
1r0{
L.r
0 n'r J.
i'l I I I .t.

t-
t!
i!i
F t!
il tt I

c,r,:(?)n orci:qp:ci 4€+qre. hexo'1Q,qp:Ge.-o5eo6cca:e

Joog er6 oifolqo -61- o6,ocAo,l,


) Lquid C.,stal D sP aY(LcD) 1 Prc q.;3i.8i6io $r,qlodo3:qP:(r)

s,:.2qp: (an mared .ha a"t"rs) --elci..?" d1 -€,4.c4 setup eqSeleo::;


a]i:b.ycq- Jb- o rr: c8 ! 'P"
9 00011111 (sl0 t
Codes 00010000 f3. 10000000 9 10011111 ($80 to
$sF) s?d4..4@+:6Dri-'
jl::2! code qp:3rAl 00100000 (s20) ?oo3B:, 01111111
'asct (sAO
to $Dfl 3?d]Jei el,rl@{:qp:o%c3B53Jdr
lszD q€;9:o2!, 101 00000 9 1 01 1 1 1 1 1

codes 111000009 1 1 1 1 1 1 1 1 ($E0 to $FF) 3?d-d


3?c8l8oEoeaD:oqrco,3'o1r,d
e\ea>e5;9:e.'fo96"3;cal "fl':"mor:aqp:qo'1o3e:)5Nd, g, jp q and yo?.d.ri. ower
ca* -.q'"p,-5,"t.1-f E--$' c,r3:4.:ld 6i; rpoer-.ase o:o':r1.':ei eral.'\S"$c:
.Dc3o.ate *",c3.9.66oi5rd8c36q@6@ce: rJo30t36oo33.ed, cD3:4..i 5x7 dot matrir
rormai G3. Q6oT!loq$3d 5x10 dot nratrix format Ge.a, Q6oT+€6oc36.oagr
one line LcD modure %3 5x10 dot rnairix rormat { {c6{c6s:4,0tqq -o3.G$€
6@'3:G%.q-d' 5x7 h^7o line display 3?%.6 5x10 dot matrix rormat c{3?e:olcq]J ji{qll8
rdo,cqe,e 3,.oT83: pixer row (q)1 r{ 3.ri:or$€G,Ed
-s9",d'i'-dqd'4
cQo$.3ae:AqE-,€.; RS .$€:.i row(0) %eco,:&, .3-oo?o5qp:9 00r10100 ($3a)
ol set c93ci1, E aec34$3Jl , oi6+.d Rs cQ3:4 hish(1) %3cor:6:, -^(Dr:(?)€rl 6f'oE+:
6(),5c'r$6?$ cooe qp:{ e:araoTc8qp:ecDdE:6f..3 E 00106.,?93;l a..TEa:$€€o3)il

o3,-3qla6(J)3e%d 3,.ari:qnSGoTEqlcS

(r) oisplay Clear GtorSqS


Code = 00000001 ($01)
Sl to 58 = 00000001 ( or) HEX-SW1 = 0i HEX-SW2 = 1

RS=0
E=lto0andthenl
(J) Displav oN and bllnkinq cursorwith underline G66oqS-
Code:00001111 ($0F)
S1 to S8 = 00001111 ( or ) HEX SW1 = 0; HEX-SW2 = F
RS=0

(?)
Code = 00111000 (938)
51 to 58 = 00111000 ( or ) HEX-SWI = 3; HEX-SW2 = 8
RS=0
E=1lo0andthen1

code = 01000001 ($41) to 01011010 (95A)


S1 to SB = 010C0001 ( or ) HEX-SW1 : 4; HEX-SW2 = 1

to
51 to 58 = 01011010 ( or ) HEX SrVl = 5; HEX-SW2 = A

E = 1 to 0 and ihen 1(ior each character entr/)

G?
sg:(J) Liqu,o c'ysrar D,sptay(LcD) i ptc qdsai,"le{,u, oi:qlodr:3:qp(9)

(C) 5x1oformatec?.6 simutate cvsns-


Code = 00110100 (S34)
51 io SB = 00110100 ( or ) HEX-SWI = 3i HEX-SW2 = 4
RS=0
E=1to0andthen1

Code = 11i00000 (SEo) io1 1111111($FF)


51 to Sg = 11100000 ( or) HEX-SWI = E; HEX-SW2 = 0
to
51 to 58 = 11'111111 ( or ) HEX-SWI = F; HEX-SW2 = F
RS=1
E = 1 to 0 and then 1(for each character entry)

3-Gr o6:::6q1c6(p)n Addressing

LcD mcduie.t c;loloorE.o,c$"5eu:s,a1 cursor ar$ ,rco€c.i3:6rl 3:o6fcpge ord$


€{,dlcldn 4E.p3rd address (s00) G6::a: 6{.d-3o:c'?:o:Eca:co$.$rf
' cursor {3,
::$r eqar; address qa:@6a:c ($01), (s02) o3rd.f6pqp:4 o,6.oe.+:6g.3S,:dbrd,L
slr9. 3?a?3,6oil:o36s.J,G€:c@.8. ocq:e6r3'qp:3,@:olo8ec,o o:e@8:qp:ciQeoTcpce3
ooci:o,8c\i:E3a%cD aooress o:6qq3:r{ !c39.6qiecqco,.rr@€. oc9$€.o8.G6@e€:
ecaqolr:$rr
o:e@€:o\ ooegpr{ ocooc$€:er5 cE6{:eqepgeo:n ('d3)d6fFor6??osEe{
e$n8:oipr oo"Ei;oTc$qXt {
address e46pcieep.ieooe!
e4q:c{eepcieoo instruction c{ saci:@g6t6o"air
$oo $3. $7F sa@::$ (cgo) ?6o. address e16pqp:c{ .&E:aioo69o5$Sco:ldn clFtr$
c,d: o?3:o,6.$e,%36q.p (p.) GE. o?€:e6i3?ce.A er
(oo) c{a,, Q6,!Tg€c,r3)d,
4c?. address egepe @E:cir:o39c8e'dcEg.r| c.Dr€Bd6I1s?%.6 i:sa Funclion set
instruclion q33 2line, 8-bit, sxTpixel format c{ set qEeoeo: code = 00111000 ($38)c{3ro6
rr
9o6s1e,.,e2!
and Cursor instruction
Display ON/OFF and inslr!chon %d
%3 display ON with underline and blanking
cursorol set cp6co63, c{aro8 go8qeoe$'r
code = 000011 I 1 (goF)
{eg:.6 cursor 4 oo0olooo($o8) address e4cpo3cfe6.eoq6 Set Disptay Address
rnstructron cAe cooe = 10001000($88tr4 oc59o6@:r nS bgic (0) ca8co2:c.i.6 e
4 4
trisser o76c'fc6eo:oe1 cursor cc$ qo€6@rc34sp [00oo10oo($08)l {se..A,,n,,cSE r
"ai
63"'.)6,',1E(3-?)%€@d,',1n

Q(g 9) cL,rso, o2! qoeeG,oS€9qr [o0o01 00 0(g0 8)l r9.6e.c8.r: Q

1oo9 196 o{aolfio G9-


2.
9,
?
@trtrEEtrE@trtr88tr1.Itrtr tr tr tr tr E tr tr E E E E tr trEtr T,I tri-'I E FI
EEtrtrEtrEEEEEEtrIEtrE 20 characl€r 1 in€ (TLcrI2011)

16 Chahcle, 2 line OLCM 16?l ( trro15L)


E E tr E E E E E E @ E] tq EIF;] EI F;I

EtrEEEtrEEEEEEtrtrtrtrEtrtrE trtrtr8Etrtr88tr8trtrtrtrtr
trtrtrE8tr88trtr8trtrtrtrtrtrtrtr8 EEtrEEtrEEEtrEtrtrtrtrtr
20 Chabcler2 in€ (LMo32L)
trEEtrEEtrEtrEEtrtrtrtrtr
1€ Cha6dd4lne (SMCle40A OR LM041L)

EtrtrBEtrEEEtrEEtrEtrtrEtrtrEEtrEEEEEE trtrtrEEtrtrEtrEEE
trE tr tr 8trtr8tr EEtr trEtrtr EtrtrEE trtrF' E t,'E,G4 tr El I.i El t4 Et F;t Fl F;t F;t t;l G;t

40cha€.ler2lrne{TLcM4021 orLi 013L)

Q(3-") LcD [,4osule qp'ol eooress f3. Display Location :o<63eu9XqP|Q


"-n"1.q'g,".,
L,qurd CryElal Oisplay(LCD) - 1 Prc io!6{,?i@{M *.1,n,o5o3,,lP,(e)
9c3f,):,qee:3"q1"5?r- Display Address instruclion.{ set o?36p%3 Qc.)ffet8: address
.A 10000000($80)6();13:.od-'qole€,r
acDc8c:1f d:oo?€: crui address qp:3"%o6,i6oTed€*6prr6.406:rr8@ddl il
a)dGrq6deqc,5?c-
Display address 00101000 to 00111111($28 to $3F)13, 01101000 to 01111111($68 to
$7F) o?.oi sri:Gdeq,jlil 3"ri:GL!d rco sa{p:ao::eoToopi$ address 93. dsplay locat,on
4..Dc6.Sosh'od €G,e:oJorc3,.,1o,dn o:2oryan:qp:eoc LcD module qp:eri address 93.
dispray location ol. aoriT,:Sgqp,.{,i(J-o)%3 coTQcor:oLrdn

o6:e>6qjc,3(?)o%c6 s'o?i:qn6GoT6ql.;

(c) Displav clear Ge6q$-


Code = 00000001 ($01)
51 to 58 = 00000001 (or)HEX-SW1 =0;HEX-SW2=1
RS=0
E=llo0andthen1

Code = 00111000 (538)


51 to 58 = 00111000 ( or) HEX-SW1 = 3; HEX-SW2 = I
RS=0
E=1to0andthen1

Code = 00001111 ($0F)


Sl to 58 = 00001111 (or ) HEX-SW1 = 0: HEX-SW2 = F
RS=0
E=1to0andthen1

(9) cursor.'? acoress lav Address lnstruction setc1)S


Code = 10001000 (S88)
51 to Sg ='10001000 ( or) HEX-SW1 -- 8; HEX-SW2 = I
RS=0
E=1to0andthen1
Note: Oisplay Address ln6truction = Cutr€nt Curso.Address + 10000000 ($80)

g-9r o6:o8q<B(9)r Shifting the Display


6eia,el LcD modute caft.s,o.:,,j3$56o Q6oTG$€63}]ci.pa,d Go)D.6,iOd,
ogcSsao::e o:co5e o: modure qp:qle e@3€%q€€fl, r9.6c:5.'d: cr,-'so.;
"r"pG.)..i,.t .e.Ed-d-"r
{p"r.8 e'".34. .$6€,G€. Ge$3."-dn 4o9.3ros/e" Adderss +3.
Display Location of.;""6"8us9 cGDS:oio,a6r,GE. 3?q:onQc,5qct:lldn
ege G"r3:qo6:o5qlc33rqcf l:g: ctear Display lnstruction, Function Set lnstructron.
Display oN/oFF le. cursor lnslrlction oi.c4 {:63!oie: setup q6<lcilepir {6q..4 oecS

1oo9 1j6 e{qol(o GG


oa6:(t) Liquid Cryslal Dspray(LcD) - 1 Prc qcfb{o:6@6M oci:qoo5o3:qp:(e)

RS .4 rosic t ca3.n<;1, e,D(?)%3."T$cca,$d eocs6oat'i:3"@: (re)


"e'4.-"?d
ceorc code o61q13:r{ ..-a.9c8qp:ca3 set o93p: acacS E .4 trisser e6,', cod!8e,
qdl€d, 439.-d38€,-d3"al orA: A g P ocSD 16-characier dispray %6 or6a:fl€:
6oTc.:"8: oitio.rQ'qp'3rd dispray 6\e"oa366:ca3 eecBc6rn3,'@.".36..e!' {(c e)"a€
@d"il'
43?51 Display/culsor Shifr Lefr lnstruction @6eoc 0001f000($1sl .i-'i,GfG,
o,ai:qp:c4 r,,rso.3ri.6s.{e:c$c3sd4 qs8 o e z s.E o.ri:qp:GoTo,xdd
""aGeq
eocEEp2lr sac'<)s$ Display/cursor Shin Risht lnstructron E6ca}] 00011100($1cH co36
3'ri:Glc$a8{rd4e3 -.{,cr,,-d e"oo63i. G6o)desc,J"@c@3: 6%G€q6oc36.ea:,

e6-d -.i, Ae P 3;ld€oTo)rQ

code = 00000001 ($01)


51 to 58 = 00000001 ( or ) HEX SW1 = 0; HEX-SW2 = 1
RS=0
E=1to0andthenl

(J) Function Sei ( 2 line, 8-bit, 5xTpixel format ) ELQ5q5-


Code = 00111000 ($38)
51 io SE = 00111cll ( or ) HEX SW1 = 3; HEX S',4,r2 = e
RS=0
E=1to0andthcn1

51 to 58 = 01000001 ( oi ) HEX-S'W1 = 4; HEX-SW2 = 1


1o
S1 to S8 = 0101i010 (oi) HEX SW1=5;HFX-SW2=A

roo? 116 cErJ qo G?.


caE:lJ LiqLrld crystal Dlsplay(LcD) 1 rru 9oaq.litcte
(r) o'{:qp:.'? .pL$oc8r9.c$.og -
Code = 00011000($18)
Sl to 58 = 00011000 ( or ) HEX-SWj = 1; HEX-SW2 = 8
RS=0
E=1to0andihen1
(0) r,irp4?pe-:iesrL
Code 00011100($tC)
=
S't to 58 = 00011100 ( or ) FEX-SW1 = 1; HEX-SW2 = C
RS=0
E=1to0andlhen1

eo8u:q13?fl.'5?,,' 3?.Dn3dld.ci. -e:qp:c{,1,5/e. €s€8:.r$ orai:qF$ere€.


address sD6ri. -6rprf qp:E€:eu?d:Dr address brock or,Sioi:Dd3,

{GoT$.8r2G€"D6q'dc6t o,j6/4o 6sE€:3,G5,i])dr

O-"lr o.5:-*3fl.'5(dn Character Entry Mode

cor:(r€6oT@co";r:d Characrer Eftry [,lode tnstruction -.@"€:4 :Dc6co.6


6o.c.lr@olcdn s:cocfca8eo:.co:e cs.finciqp:oq ooca:qp:c{co2i:s3:eo@o2loe1 curso,
address e>al cac$aro1p.3o:69cfl:@€: (auto-incrementins) GEe@c€:6,".st6o6dr sa.'r,,5d
4{-$*a1 oc$e*c.pr6":61eqp.@€: (auto-decremennns) .{ oJd:oai:q$3o1Ddr 4.
3?GE 3?o?@6on c6o$io?:G3:f€. eoF?Gotp.6o61eo1p$€' i6qtc{6,i1€:do:d: ;:1:q
$3c@.8:6oa.q6orld n

ocoi:eo1E:ori (carcuratot o3?<?€ Q..tE€,4^..-@d"d"qqi€ E's.'0" o.,Ec?,


od:c:. erootu 864:eg epc63 oo:€eoTegeocd,, octr$:qt":oi copig€:c$rf eo:sao1
(De:4.3)d 3:68.3e.:@6ood, slQa{1,4 LcD %e QcoTEded{ele
",o5oo64.or6cBo6fl
.r-cEdl 3r4e:e666o.e@qdl,d,,

E:ga Clear Display lnstruction, Function Sel lnstruction, Display ON/OFF l€. Cursor
lnshuction o?,.8 og:6saoi€: setup e8qoled,r 4Gt.t cursor address .i 00010000($10)
ca€ set q6s$ 1OO1OOOO($90) c4coaldlr Cheracter Entry tnstruciion G663)r 00000111(907)
r{co2io1rr o€:o2! auto-incremenudisptay shift
"r,ioa63i,or6%o6{3:@<{saeqpcieg.r."r"
left instructrcn saft:saoc:@Soplrr {ei. setup o?Ep:c+,os' €<r>'d?)g "0" ro "9, 32q3.;
63ororqq:qprG6@6D 00110000 to oo111oo1 ($30 to $3s) c{ codaAS:@dqie
"""1,cp,-d e,."6-,si9 oo,e6oT-8, ( s 8 7 6 54 3 2 I 0 ) o?6rr,.,E3"oJG€.o,o5ocE3l.
,r6.i,il€: 6se.:@3idc{c%.q€o"d,

oor:(g)o3€ Character Eniry lnstructon mode sa{1:sao:d9){1: 00000i00 to OOOO011t


(s04 io $07) c,? 3?ri:GL$3c@"e, .,;lE.o.:,,1odn or€:o?.,,5?ql3:4 06,-3@S ed4et3
-.6c%.qte 3?3i:0$oiG66i3qp,.'i 636%.@q6trc36.sd"

oo? ?rE airoitEo 'Go-


s"qi,qrsooTGqr.;
"!efu!e)-caoi-
(c) pisptay crear .rq$qt
Code = 00000001 ($01)
51 to58=00000001 (or) HEX-SW1 =0; HEXSW2=1
RS=0
E=1to0andlhen1

f ,) Functron Set r ? lrne. 8-bit. sxToixel fomat ) 6ro3di.


Code = 00111000 ($38)
S1 to 58 = 00111000 ( or ) HEX-SW1 = 3; HEX-SW2 = I
RS=0
E:1io0andlhen1

(?) Disptav ON and blnkino cursorwth underline G66o6$-


Code = 00001111 ($0F)
S1 io 58 = 0000'1111 ( or ) HEX-SW1 = 0; HEX-SW2 = F
RS=0
E=lto0andthen1
(9) cursoraddress 00010000($10)6a6pdjElqbL
code = 00010000 + 10000000= 10010000 [($10) + (580)= (990)]
51 to 58 = 10010000 ( or ) HEX-SWI = I, HEX-SW2 = 0
RS=0
E=1to0andthen1

(C) ChaEcter Entrv lnslruction Nlode cE seto?6ot-


Code = 00000011($07)
Sl to 58 = 00000011 { or ) HEX-SWI = 0: HEX-SW2 = 7
RS=0
E=1lo0andthen1
(c)
Code = 0C11C000 (S30) to 00111001 ($39)
S1 to S8 = 00110000 ( or ) HEX-SW1 = 3; HEX-SW2 = 0
to
51 to SB = 00111001 ( or ) HEX-SW1 = 3; HEX-SW2 = I
RS= l
E = 1 to 0 and lhen 1(lor each character enlry)

9-gr o6:rr6qd(6),i User-Defined Graphics

oo,":(J)%€6,,T$car,o,dcode 01000000 (940) to 01111111($7F) 4.od oq6o5o?oil


e:r Qog4qp:c? -.i,G1od"r- 8d@r.6o1d,E: Q6(,Tep%3 3)e:GLgLe!21 (use,-
derined sraphics insrrucL,on) qP:G6@oal, CGRAM
4
-{,Gf0, 3o6@Lc6+rfpa6,ijr:.,i
,'ic3:c\i63:G6,jlc:d, eos,o:6i3a.+Ge. eroricil.TSe:o:€qld.4 ecu.-@p!cl1r,

joc? er6 4r.13r..)


' I
"!_t4"i a9i- 1ij:j9{:q!i
ucuid crrstar oispray(LcD)
-.1:(o) _

g:g. Function Set lnstruction, Display ON/OFF, Cursor lnstruction 13. Clear Display
lnsrruction o?..8 q:,is:{3: setup <\$qo]"a:r {ef,c8 cursor address 4 00000000($00)
qE set c93q$ Drsplay Address lnstruction 10000000($80) o?cDd,jlf,]d' oo5cDdd s"3i:q
$€sal ccRALa 6+rG)ics€ xc'::x"-, ci"SEer- ecp'4..18dq1 cao,' 00000000 to
00000111(soo to so7) 4.4 cDEiqlS,-dJl-dn e2!eeg.:a{1""1eo1qp, cgd.oTc.,'oo
:edr

4.S,; -"i'Gpd oq3o6oo.9: o-3da: cGRAr.a address .'i


set e5.jlo,dr 4
CGRAM address Dal 01000000 and 01111111 ($a0 and $7F) eca€,fl e$::$6{9oSe
e{86$€dlard, ec.r,"cwrsouSs,:,@3. 01000000($40).'? {:aol cursor o2!
"g,nc,5"1"alr
q o9oci8:oo"r"p3l. tiw=,-d' sl{G66€:r,d 3?csrie@:t.,1 6al,
Qc,iTcQ3rd63o-qp, 00001110. 0001000T, 00001110, 00000100. 00011111,
00000100,00001010,0001000i (50E, 511, soE, S04, $1F, So4, $0A, 511) 4.4 o)SeEj€:
codA3,c$.'56r*?e1 o.ooc$3,'o:3::s!€r6p"a3 or3c8€:q3, (row by row) {6oTo:oa,d.A
6%G8q6,nrdn cod6o:c9.5oJd63-od o?o>6cc'>ro8 o:o313oo6;ciG' 686..ao6.':c,d
q8.+-S " stick man " Qsacgc8 @6o1o2!r' ca$:ec.:re."a lyre (o)1.{ <o36 e6:q1,r5
3"rir$tdd4olcD o.6{E6poq3o3Q"r6? cg.3c{rTarr6o{'dr sacur:c2 oq3o6Qeo13do)1 c,i
,q"?$3(,1-e:' Q(3-co)qe@2io1,r
"{of

Q(g-co)oq craraaer cell o:51::2! I pixels s?G3.68:, s pixas acr1.,5$o1ar2!rr


3,qp:s"r:GE. QaoTeoosal 3r6oTQ3, 7 rows.,i":ccan'@1ec..$@:r *c6a9, row r{
underline cursor o c; 3ro69c3co.-oJ.{o13rdr Cnaracter o6log! s pixets saap$fo@3.
eec., bitsoto4c,h,3?oir@1co::::p!l bils5loT (:or.r5oc6sagE$ bit oi:?) c{ o13oX191cca'
.t-d'
ccRAlI qpra>a! volatile memory cq[3?o.r,G66$o6@"8. dl d Ec&Q"6eoaea'l user-
defned sraphics qp:3rd 6.i,cicS2,@6cD€o,.od' qo6"{a3lco6.oo96. .ioo3sao,i:@pp)
{q E user-defined sraphics qp:of €c6.{,?4co{o,e$ EPRoM ca€ p:g'.36:cD":p:9 s?ii:Q
..,r.{@oirsdD

.ro"e ?i5 "i{o1q-


*i*F€+d--*s.d; l*drf*ii*!*;,:*-;-i-irili-
I
l
{
tr
!
z a
o_

OE (00001110) 4l s
7g p.
11 (00010001) 19 79
(00001110)
(00000100)
:>,c .TB
a4 4S

(000r1111) 1C

a4 (00000100) 40 fo
(000010i0) 4E 7E
i
11 (00010001)

Q(g-co) eixel o61q€:9€.ercr5{€cr:e ccRAM address


ep,.{ ".fEQ

!].
B
g"
o.;:(t) Liqli.l Crrstal Drsprav(LcD), 1 Flc qda4.do{M o.7'q1oo5-3:.12(9)

o3:tr)3qc3(G)3ecs,r5 3"oli:fl 56(,iEer,;

G)
code = 00111000 ($38)
51 to 58 = 00111000 [ or ) HEX-SW1 = 3; HEX-SW2 = 8

E=lto0andthenl

0) Displav ON and blinkinq cursorw'th undenine G66016


Code = 00001111 ($0F)
51 to 58 = 00001111 ( or ) HEX SW1 = 0; HEX'SW2 = F
RS=0
E=lto0andthenj

(?J urspray (.reat Lq|slgqt


code = 00000001 ($01)
51 toSS = 00000001 (or)HEX-SW1 =0;HEX-SW2=1
RS=0
E=1to0andthen1

(9) cursor ss 0001 0000($00) €f 6.pd__!q!s$gt


add re
Code = 00000000 + 10000000= 10010000 [ (900) + ($80)= ($80)]
51 io Sg = 10000000 ( or ) HEX-SW1 = 8; HEX-SW2 = 0
RS=0
E=lto0andthen1

(3) Display conient qp:ci O6olAa:qEoand setcpEqS-


Code = 00000000 io 00000111 ($00 to $07)
51 to 58 = 00000000 ( or ) HEX-SW1 = 0; HEX SW2 = 0
to
51 to 58 = 00000111 ( or ) HEX SW1 = 0; HEX-SW2 = 7
RS=1
E = 1 to 0 and then 1(for each data entry)

(G) cGRAN/r Address lnstrucrron.4 set calql


Code = 01000000 ($40)
51 io 58 = 01000000 ( or ) HEX-SW1 = 4: HEX-SW2 = 0
RS=0
E=1to0andthen1

(r)

Codes = 00001110 1S0E)


ST lo 58 = 00001110 ( or) HEX SWl = 0 HEX-SW2 = E

9J
,6al:(r) Lrqud crysrar D spray(LcD) - 1 F'r i.;.6€iofi€ o4:Xoo3o3:qJ',(9)

Codes = 00010001 ($11)


s, to s8 = 0001000, \ o, )
L1t /s -:i -\-s^2=
Codes = 00001 110 ($0E)
51 lo 58 = 00001110 (or ) HEX SWI = 0, HEX-SW2 = E

Codes = 00000100 ($M)


51 to 58 = 00000100 ( or ) HEX,SWI = 0i HEX SW2 = 4

Codes = 00011111($1F)
51 to 58 = 00001110 ( or ) HEX-SW1 = 0; HEX-SW2 : E

Codes = 00000100 ($04)


51 to 58 = 00000100 (or ) HEX-SWI : 0: HEX,SW2 = 4

Codes = 00001010 ($0A)


51 to SO = 00001010 (or ) HEX SWI = 0. HEX-SW2 = A

Codes = 00010001 ($11)


51 to Sg = 00010001 ( or ) HEX SWl = 1, HEX-SW2 = 1

RS=1
E - 1 to 0 and lhen 1(for each data entry)

3-corr o6:rc5qp6(9)r' 4-Bit Data Transfei

HD44780 I c d .43?rl:qcor:6r, LCD module qlD:?e instruction byre l€.


control ch'p
630, byle qp:c'?cDde3,ar$saa1 +uit $6o1dd c"dt€olDd,,
Shd,-d LcD module
."x'ai {c6s{or3cn6o:"ep'93, Qc.;-1,Q::jsal i/o fir lc)a.'3.-- -ri:Grq6.S::aEer@s_
b.$3:;.:606@"3:6%.,r;l-d, {{. a.br 4 1;.:,t..rJi.""' ::,:.ri:!)qp:p6@e::: c;
to D7 c4r's?a:GqE:, D0 io D3 09 64.,rd.a.3:r:.:at,;c aE ca8dq8c3cc.: (Roati!l
dcr;od:co"r€:, 47ka qoso-,ro,6e:50: o101.ie'0-)6?i%3 {;-,,d"..3-d*.,-e,
Eoicor,q"lsd,,

4-b t mode oi 3?3i:Qtqq3?c6c6 er,:c8oi1s:Ssaops:oi€:e.DreSo8q,jl ed,L


ololg€{9:6f,o6 ;ea;:acpcSqc:ca€ ,l.b,t nrode insr,ucton G,56!, 00101000 (g2s) .A
ser ct8o1r Rs acio64 0 ql:cor:qod'
{e9o.3 oo to D3 6€.{36a,:6:c/-,ao?o6%6
0000(HEX-sW2=o) c$.oqo5 rrrrluexsw2=1) .i
ser c,?sjl, .,ra:oad4 .p.3co6ec6
eleo-,:.o1 r
{egrc8 Display ON and blinking cursor wiih t]nderline insiruction G8"tr 00001111
..":o.o7o5ca3 0000(HEX-sw1=0)d sei
x swl=F) 4
sel a5E: E aecEc4
o2o5$6€{.n" cursor eoTo:reoc$u
.AEcor:E: Da to Dz 93. {3ea::

J".e e+6 -??-


"{{olqN
o4(d Liquid crystal Dispiay(Lco) - 1

cod313:$€c,)60,r.3)dn

o6:p3Elc5(e)-%c3 so?i: 3.oTGqtc3

(3) Function set ( 2 line. a bit, sxTprxelformat ) Glct3q5-


Code = 00'101000 ($28)
51 to 58 = 00101000 ( or ) HEX-SWI = 2; HEX SW2 : 8
RS=0
F=1ro0andlhen1

(J) Dispav oN andblinkirqcursorwirhurderine G56o(S


51 io 54 = 0000,i HEX-SW2 = 0 (o4 51 to 54 = 1111 / HEX-SW2 = F
RS=0
code = 00001111 ($0F)
55 to 58 = 0000 ( or ) HEX-SW1 =0
E.ltooandthenl
55 to 58 = 1111 ( or ) HEX-SW1 = F
E=1to0andthen1
(?)' A'-.i,.i Q."TlEplq6-"R"6 setaSq$-
Sl to 54 = 0000/ HEX-SW2 = 0 (or) s1 to54=1111/HEX-SW2=F
Code = 01000001 ($41)
55 to 58 = 0100 (or ) HEX-SWI = 4
E=1to0andthen1
55 to 58 = 0001 { or ) HEX-SW1 = 1
E='1 to 0 and then 1

looe 1e5 -,)9-


"iq"1{o
@6i(6) Llqurd crystar Disptay(LcD) - 2 ptc €.,b6drg@6o oe,apo-6,Cp,(r)
:

oag(G)
Liquid Crystal Display(LCD) - 2
G-crr {e1{:

.16
lg:o.6ar3?6i:%a 2 tine x character (non backlit) €{fs?oc: LCD modute %€
ch qc:93, rota switch qD:.{
G3o-qP:oi cD ai-*i,+,,
+6or+d+c{ qc8qr:fe.oroa

: LcD modute .r| Qc6a{r€tco{o:rg:9€..,:


e..A
6 LcD modute .Q ptc16F84A qr,566,?i_fi(u"+e.
:€e,
G-1rr Good Times

-.Di

Q(6-c) HD44780 timing d'asram

1oo2 1E3 o{<dio -9i-


-.E,(G) uqui,j cryJial oispray(LcD) 2 P c qdai,"iolio srt:qloo5o,S:qp,(r)

{so3Qc6a$"a$..{.",c4soi,|!r-d::61 ,D€:0?.:;6{G3. 63olcQ3:rip:.,? s?Ec8sa,s€.


BLe3tr,d3,a1 01609$s 3:5 3"@3arq:r8.{E' .,.,&,Gi*r.;i'"r-G€. FrDa4780
contrcrler chip 3"ei03. €or:ea?,3,6@oe,c6q,in66p%€ s;o363"n @deoqQocAd c{ii3.
oobrc8d OcEGt5l13?6@3:q": fi
-@e"eoa.o2)rr

De5cription
Addrci: 5cl !p tjmc 140nr min
!Ah Address hold ilne 1oDs min
r0s 200ns min
IDH 2016 nrin
roA Dald ccuess ti e I
J20nq nrir
€H Enable hrgh lme rrme
I
rl50ns lnlll
IEL Enrhie lorr '-5 | 500ns min
tnf ili:c,;-.il:r'iir I

@or:(JJ HDaa, 80 Timing Para-relers

Qrfe{ce$co{c.r- "6 r.,$oepe q:ar$sao1 rimins diasram 93. ctDodc)ci1 saql.'5


scoc8qp:o? co&A8:oi:oze d4qi3 HD44780 controrler chip ore! eeorca;c{ c6$:Elt39
%3 oga:aoB8:€$c; 3:o€e3"x$8.oo38pd'
prc
EoEa6ceicoio'sceo8 "fi"q6cq:])dsaal p:sa ico ol RS cqE,o? 9i.,:i6r,
..uc..16oe@ ( 0 or 1) co:c'r:qic93?Edlodn o9.9r, LcD op!
contrcl command (or
rnstruction) tt.character informatron (or data) {.cf d6",+2,cDd$e€ocS6.tldr cacr:.:,o2t,3
LcD 3?{c63?o'c6qp:c{ Gq.uji read o?8ed{at3 nru c$8:c{ ecu.q6cae6 (t) nu'-",
I
Q.c$o6o1o$ r {cl.co?.3; wrjte 3,o?6ed{dl.,r ,D3:o?6Gqd"?3, 6o,:q6s?€E (o)rQ.
aocAq,:5co:: qcil cEj rr

Qcr5afic6Qco{cu:ca"a9€. sao.dol ns 9€. Rlw c$8:f8eoi or@1€9c6orp!:c63


eoro2!:erm8:r o$1i!'9o169eo5copi,ecr,:3: setup o7E$3o1o2!'r
:aee1@:o$eanc69c- E oi8:od ecu:.q16 1t; c$.eeep.,38 cieo-,:3:9eoc o{$
eca€:g ns tt. Rivv c$8:e6eoa,-d o'dE66E (stabre) %e e9d{ej@s1o1c2!lri(C-c)
4*{$-d " tAs " (b'.re address setup) G6E:, ac,:'d")s'"1 140ns 3aid'a+! $q,.,1,,ai,,
"ae
,D3:coc6Qlt6e>5c,d, -3,coo8coSdot"ll Gat,,
E cq3:3rd €c.,r.q6 (1) .9.6qpo8$'eqec8 c:{$ rsons 3"Ed'+, @"8:9c, 6c.,..6
(0) 39.G$.o3:6tdlrtd,
",','(t%3 4-{$4
lEH " (iime enable rrign) u?crc69c6oloe9lr
-xu::qoE eco-:rcg3'qp,(ohooi:od 'rc643p6cvr.fl53,6G.J",q3 serup @6egq$oo3c6
"+d,'i,*{$ r" iDs
" (time'data s€tup)=200ns
"$.@l_3'9-
a "96'-d ec.r:.r16 tol e9.
!$a"€:"iole$ 9c6o:,q$:ao1c39,- E 4€:3rd ecv:.q15 1rt o :c-':.r1i' 1t1 cf. eQn€:oj
i!36o, 6a,r.QlE (1) o 6c.-.3 ror d. 6E €,::dG66o ai'a!*lr;',': 6xc,c$3'qp:a>a!
setup G5qe3)dStrrA3ri.i.;..r;- j,

-r ?16 oq{o1qN ,C-


--::tcl Leud crysral D€play(LcD) - 2 Plc Edo{(BE@{M -d:ePo3o3:9Plt,

) r9. c@De:e>d3,af " HH " (tme- address h,) 1,,

e, $6a.4 cDd?s3:o0:cD,qi.,?3?3co$'5, t/\,


ai.6cto,3:d.;odGcE616alo?."Ta6,G,,' rp'
6GD3:o;dordlD6rqcdc?e6rai,or 3)d,
"5-5E $,il€r,,",dll
o€:9: " iEL '(rime- enabie
' tEL =soons 6&rc;o,r
"iEcca,,e6+E:93,
n E o?e:3?%o8 tRF " (time riseliall)=25n-

o$..4,,1ccd,€.6q8 one cycle time 9a = 1ps @6o1o$11 46@€. LcD 3?. o{$o6og2i,.
:ao3i'c63 r ri.l,o'] hslruclion {pu:d t m t,ior oata co.6qd .Q,q€6"j

G-?i BusY

oc6ecg.c6S LcD 3?, insttuction Te. 63orqp:4 Q.eo,qpo3€ trming oiasrai


ee"TE..a:eo: s,{iql.:cDcs QQd@G€p"- a.t"v -{$cp,.,?-"i,GFro1-d sfr6.'.
instruction/ccmmand qp:a,ei rco oi.€.p.,58,"r'o5 3re6e3qE 3?{E3,qd:ccSoi@6.\.ii
'
t:l.Jdr 43:{1"? execution time '{..C"3 '
busy " o{iqeaTdlo2ll tnstructior
oqp:gore9 ousy @6{$ +o ps .Q.{@@'' -"9,-@;." rhe crear Display "f3. " cursor lJome
instruction 4.::e9 Q@rco:.6@oloJdn e<.u:(g)c63 rnstructron ec:q,s,cAc6 "execution lln-r
,rP,.i c,rrEco,,,:r .)d'

Cleor Obplay E2us ta I 64ms


Dsplay & Cursor Home 40us t6 1.64ns
Charnctcr EntN Nlcic 40us
Dlsp ay On/Oll & Cursor 40!s
ll.srl?y/C1r.r shili

Sel Di$il3V Ac.lrFss 40rs


Wrilc Dala zl0xs
Rerd Onla 40us
Read SlaiLls

Go':(J) lnstruction qp:3,%d 'execuiion time ".iDi

oJ3:4.%3 LcD 4. 'xlite e3l$3,a1 s?rl:Oilai rnstructron ero:i€. rcl or


e:cr: 9€. statrs read T$a:ei3"ol .r,+:Gioig inst,ucricn 1o,c.:;5: lo€o1r:$'r
""'..?
Read co3-:Sgiil 3?3?:ot])al instruclion G1P,-6@3,"? ordc,€..,cy3@d..Fcr:
e];.Da!, status op,c8 reac c93$€,::3! LcD .G: bus/ DS,.D6c3 !
' "-.:[:;olGSdtr']\Ll
.
36q(6) Liquid crysrar D spray(LcD) 2 plc
ld.{.rt-{- -.i,q@
<.,c3c%..'e,ql.-3."1 .,',,(J)ca8 6,jr0"o.:63), execL,lon r me ::alcAecuc8qp:
4 11Eet9, nstructrcn o5913.o:31s,14.,c?6 ci6o,o:6- deay iime qt :.{ scor:co:
e co.$@rJlo2! r

LCD cai ousy


G6.o]Jd 3]6",.r,3?npoejo,619, oll;loo,38€.G:o 10 to lsms
@'63:D3D{EG6,il3,dil 43?{6e%3,%3 oelDel instrucrion c{e execute,resgsol6flll
{s:q1c8e@:€. Q.3.ia;-{cu,3%.s 6q:3,:63'o{o6r56\ Gog€:g :J€.6cij5ctr r deray
time c{ cod.8€:cD,:qo1$ei,

G-tr Practical Circuit

2x16 LcD modure .{ prcr6F84A qdo{%EcD{",re. sdE: 3:ri:G[663a%c,5


esa:c6ci,i(G -1)casSco::3)d,ro5c,3:3,oi3: €Dosec6qcit oa:n

prc16Fo4A
Q(G-J) 2x16 LcD modure 4 QctoficSEco{",$€.Aoc8mi:otQ

sacor6c,llqsaq Ptc16F8aA q.AaficBqcoqcur po.t B €r\ Reo to nez 4LcD modLjte


d$
-oo
to D7 T€..oder)sco.:8, Po.i A €i RAo 4 RS %3c.,ai:6o,e,r RA1 .4 E ql8
or$:ecm8: eaa5:c3:aod.8osco.r:o1xd,, R^,{ c,l€rc{a.Dr: .GQ.3cg3:i3. -.,5eo5;,
,ril?,_dr s?c2c6€@,3.+63r5 .DcEcD.'56,'TG€do3:er61.3p:og wnte mode
4r, 3?a:0t
.,g!
ed@66a,r6@2€. G8,jbrd, .
Gs,jbrdll 3','rcSd
:acocSg read
reau mode 3?ri:ELcQale oi
d
R/w
3?oi:Elc\9o?re R.nru o?
"E
cGqoSre,
.GE.A+E.
ecoo5$ Qrio{c6gcoficD"€r\ Port A 9 9c3o61q1€. ;D.8toSE:, sonware o{oq69o::o€.
d{:elEeo: {e ob:e!,,
Q(e-1)qe""Ts-,""-o €, :oc6a3csqqp:Qte3E:c+..,5, oo6c!6:.t dtol
e<.':c$rieo:eaa1 LCD modure o\ g€ ,i(G-?E€ G;,;d-.?€: characrer ce
qp:er.'Tcure oe p! Preset vR1 o? character cel o?.€i 3r..rS,/-qE",l:cn.4 {tg9
€o:$e,i]]dn

Joo? ir6 oft.rqo


!.{(6) Lq! d crystal Displav{LcDE Plc Q.'5.{oaq@{@ ori:qoo5o6:qp:(9)

Q(G ?) cha'acrer cell ql.:(

6-Cr Ports lnitialisation

€.3a{oSqcD{a,€rl Porr A i6. por.t I 4.9 Sd6oTc\,6a, 6c-q6s?6@qp:$d


@:;.eocoa$(s)9€ eoTQ5 er:c
eco.,:c8$:ao?c8qp:f€. 96oo?c8qpro\ <96cg,olqp'oo?€:
.16eo:€ $3eoo$ databus ge. controtbit 9p:@6@o1o2!r
:0tl6c,r.'58: Qo6a{cBlcoqcDr%E,r{oq8r9€:qe2i source code(.asm nte) 6TQ
e"1:12! :a:o8.o8 ol eoT$de$ r source code( asm Jite) g:ee1a:c:@:egcc6 assmbte cy3.r,
q$cr::eo: nex file cA qc,5e{o3qco{c',roee cDd.S3:qoledr rco modute €{9c'rao8
i6oTE€:.4 qe36o(,dG6,i ],dn
Q(e-1)q€eoTQco.,-$eo?3: EoSa{%1"o{a:Dle. LcD modure "f.r{"oo8"g"S$'
eq,.6 Q.ra{ ,ico{cD.er\ eort e 93. Poft B 4.9 6cur.Qt63?6@p:e[n€:ci9@gEcm r-co
moaure c{ s:ca6o76{3:o1edr qoso{%6cDio:ae\qc6qp:s-{d RAo 1,pi Rs
4"e6,flt38,
nn1 $el E .'? di'$ed@6dl-d' 4.@3.
-e,4.rh.{ source code €'58o8&c'd€
ccD.6o1s"43: define o76cor:q<ile$rr

lcdRs equ 0h ; RAo = tCD RS


lcdE equ th ; RA1 =LCDE Pin

Port qp:.,?cud:@tor€d initaTise c!.!cor:.':r u{oc13 cooe r{ aooress O 9oo:3cgi


a6:?.c:.? 63,)cDo r3?crlc:6T 1).:61(] iiPn

orq 0000h sEarE acdress = 0000b


novlw 0x00 PORTA = all .Low

PORTB = all Iotr


novwf PORTB
bsf STATUS, RPo RA", Page I
novls 0x00 PoRTA = al] outputs
novkf TRISA
PORTB : all outputs
moavf TRISB
bcf STATUS. RPo

oroi "o3o3:4 ,-'lloloo:€e ,,:{o6 LcD 3 busy G66r6aio{E 15ms c{ 6.'?5qp:$3


^
eiiocao6 oTecu:r6er:: detay 3'{i.{ zsms cqero6go-:S: ecr.6il.oo?e: 6$c:':.tolcdn

'1e
'dq:(G)
Liquid crystar Dispray(LcD)- 2 ptc idafic3io{c.- s,{:{odo3:q5,(t)

i'ovr ?cb t 251. n.'.x up .leLa,v i: .i.lll:


lnovri tei avH ; -Liij.l.: s\eeE savs !,ris
clri Delayl
FUPD decfsz DeiayL, a
qloio PU-.D
decfsz DelayH, F
ooto PU PL)

:aco.6cil cetay statement %3 oeraya 13. Delayt o?cor variable 951cilo3


c',r:dr ,,Je,o?.o? cBrocK siatement %3 6o,03o1o{ei define eScor:qdled r

PrClGFBaA 3'c8d CBLocK RArVt address rJd 0x0c aocDSo;l$d:n

CbLCCii 0 xoc

ENDC

PoRr B E' -Tc3co!ip,G6l-61t RB0-R87 rtrii LcD nrcdule 9 D0-D7 oio:


dq:flrSco:.ilrJJ, ns = o ca€o::G:ec-,:3,a1 RBo RB7 4.?cs.;rdn _.sS 6",15*:G
qp:f€. oc3436r, data bus 4 LCD module s:qc6 tnstructlon or Conrmand data qp:3:G6
a,dyc3,rla,dr { aata ous elei Function ser lnstructron 3'%c3G6cA3 Q,i3r:G3.0011't"
s?o5€: 66rcosai,,c) 3ia! (0) tri.o,J?o8 (1) G5€eo13)dn {e@:3. runction sei rnstruction
ocAc6,oata uus 3)a! 00110000 or 00111111 G8$€,ic)dr
.....,'4{.RS=0 cA€ aata lus c+ o011o0oo.or 00111111 ecD:E:€q,c8 Ect c.Dr.Ql6
(r) s (o){. €E;3,.,,ij1€dll 43?.€G;3:Dd;a1ce3o)d, e.,oB3:fie$6oq1 0?60,8:63,
cetay cn616p:e@n3:e1ol€el, Data sheet 3a6t 46qre-r, deray orp! 40$s .,9d,{'6q

"d"t4"--d, .i6(D.3?6coe 200!s a1.66$. de ay c{eea:c6dl subroutine G5 qoi


€€,',13)dn

n.vlw 40h

..cfs z DeLayL, i

slri.46o."3,.or oaay c{e1op@:mrs,o1 LcD modure J,d 6d3rda36oeqc8


or6qor6epsee36.or333e{$ 41ms oi. Go']3.{€,qqoi3,3o1-d, 4-{14 egar6(.,rl oms
detay subrouiine G3.q.,r$3dl ]Ja:r

clri Delayl, ; about a 6ms delav G 4Msz

.le.fs: De Iatt, a

.i;.is z rreiar ll. !

Joo? ?rii clfc;r Eo


Liquid cryslsl Display{LcD) - 2 Plc {.6a{cSE@$M ecl:Rjoo5N6:qF(9)
',$:(6)
C-Gn LCDins Subroutine

Instruction ql2:.i -@3@33,"i,Gt$eq6 rnstruction subroutine .{ LCDlns q label


o>3E: 6ms delay subrouttne 13.eo13:o erac6,Jlaaof€: tod:cor:ctl€dr

LcDins
bcf IORTA,.lcdRS qJii!e "instruc!ion"
calI clock
bsf PoRTA.lcdE
call clock
bcf PoRTA,lcdE
; 6fts delay between instructions
clrf Delayl, abour a 6ns delay 0 4MHz
(ovlw th
frovwf DelayH
crlp1 decfsz Delayl, F

decfsz DelayH, F

.,F".i:GI0! LCD module (8 iniUatise cysoa$3za] Funcrion


Function Set lnstrucrion
S€t lnstruction cD6lelt'6sced code qp:c[ w register ceScD$@:qoc8 LCDins .E o@E
@6eoTq$E,io$rr eracieoTScli lcdl asm r4co.oroil rr :

list P - 15F84a
lnclude " P]6fg 4 a. inc"
_conf ig h'3ff1'
CRYSIAL = 4MHz
I,CD RTI PIN IS TIED TO GROOND
PORTB 0 - 7 = LCD DATA PINS 0

Srrbol DescriptioD
1 Ground Vss
2 vdd Loqic supply vdd
3 LcD coNTiAsi Wiper of 5K pot connecied ber.
4 RS Regi sler se ectron RAo
5 RII Pead/firite Tred to GND
6 D E1:iil: :ta\ I
1 DBO Data bit 0 R90
8- DB1 Data bit 1 nB1
9 DB2 Dai. bia 2 RB2
10 DB3 Data bit 3 R93
l1 DB4 RD4
I2 DB5 Data bit 5
13 DB6 Data bit 6 RB5

roo? idE +.i6_ o&6.f63:


sol:(o) L,quid cr/star Dispray(LcD) - 2 Prc {&{€Eo{cE o:q,x.o5o.6np,(i)

i 14 DE7 Data bit ? RB?


; 15 No ConnecEion
; 16 No cornection
i ----------:-----:---l
; USER R.AM DEFINIIIONS
; ---_----------------
CBLOCK 0x0C
DelayL
Delaylt
ENDC

IcdRS equ 0h ; RAO = LCD RS pin


IcdE equ th ; RA1 = ]-CD E pin

olg 0000h ; stalt addless : 0000h

novlw 0x00 ; PoRTA = all loN


novwf PORTA
novlu 0x00 ; PoRTB = alf ]ow

novwf PORTB
bsf STATUS,RPo ; RAM Page 1
nowlw 0x00 ; PoRTA = alf outputs
' dolvf TRISA
novlk_ 0x00 , PoBTB = all outputs
bcf STATUS, RPo ; RAll Page 0

lnov]w ZOh ; 25nS po er up delay G 4l'!Hz


novwf DeIayH ; tCD data sheet says 15nS
clrf DeIayL
PUPD decfsz Detayt, F
qoto PUPD
decfsz DefayH, F
goto PUPD
; SEND INITIAUSATION DATA TO DISPLAY
; --------
novlw b'00110000' ; function set I bits
caI]. Dins
novlw b'00110000' ; function set I blts
calr ],cDins
novls b'00110000' ; funclion set I bits
call LCDrns
aovrw b'00111000' ; function set I bits, 2 ]ines, 5x7 dot fomat
ca]l LCDi.s
hovtk b'00001100' , display on, culsor off, blink off
call 1JcDins
novls b'00000001' ; ctear rhe dtsplay
call lcDins
novlw b'00000110r ; incrsent - no disp-Iay shift

Joo? ?16 oholqo


,.$:(G) Liquid crystar D,spray(LcD) 2 Plc €.3o{%i@{M on:qloc3o3:qp(9)

call LCDills
here goto here
; OUTPUT 1 INSTNUC'IION BYTE TO DISPLAY

i,coi." .o*t pon." put instruction on PORTB


call Clock
bcf PoRTA,lcdRs Itrite "instruction"
call clock
bsf PORTA,IcdE
caf] clock
bcf PORTA,IcdE
; 6nS deLay betkeeo instructions
clrf DeIayL ; about a 6nS delay l-a 4MHz
novlw th
novsf DelayH
ctlpl decfsz DeIayL, F
goto ct]pl
decfsz DelayH, F
goto ct]pl

; CLOCKING DELAY 200uS l-a 4MH2

Clo \ u 40h
movl
nowf De1ayl,
kdloop decfsz DelayL, F
goto kdloop

3,-d.jl rcdi asm 4 MPAS[rwtN $€. assemote .!38,.9"e5 qic\,6tr rcdl.hex


'* a ?o a!?tcos \r%c o5.oqo:Bc:t9:69cm oorc\Jb:3reL:
.o.,5rsosG: irn Ede]8 d:*rcso1q,(G: e)cs€ 6oTGd;rr --6.33. chdracter cett qp: 96cQ€:
ooi,%36,rr6rodc{ €,".83q€oc36.ed,
oaA:(G) LiquLd crystal Display{LcD) - 2 flu 5mrn.u9@9M ,rjoJN6,aJ'(e)

Funciion Set lnsiruciion ocer; data byte @6eor 0011*- 9 €ta.3.?: bit[9ho?
,"!;:(.\e . o :rJ).2;6 iT;;.rd rc?i: es:{J'-yo'j[: :'o- i :r.'ce code %LG::o:
6q:tr :9: t6orL9etc6oDPr eebr-
frov1r b'C0111000' ; function set 3 bits, 2 li.es, 5x7 ilo! forna!
call LcDins
q.P%c-
movlw b'001100Q0' , function set I bils, 1 lines. 5x7 Cot formai
call LcDins

4so.:4,6q:al6 Q(G-e)3?o?E:6%6€qedn

Q(G s) cnaracter cett qp: o,6cq€:c833,6oT6{Q

b , 00001100 ,

I-CDins
€{qr%c-
b | 00001111 '
LCDins

doo?:4:Gqiet8 Q(c-c)e4€: cursor $dgc3$do2c3 Gs.E-dd ."aGeq"d'

Q(G-G) oisptay cg3 cursora:$ ooertine @3. qc8o?d6o8c?oSG6atcBcoTcD"Q

G-?r LCDdata Subroutine

.oo6orc3$: orc,?:3?fl.lfl QeoTe$:ac6c6 soLrce cooe 6e:r,.,'"?e"TGJdd' sl{."q:


o::9ca3 aata oyte o2! characier data byte G36@oe:oi c:o8?dqq RS €r56oe.Ql63:66ord
losic (1) G6q6o6alr 4.8ga:%c6 subroutine .{ LcDdata o?6r, label 3rc39c8B:
cs,c6,)1 so?3:66r:6!1 6dl

Joo? ie8 @i{olqo


,,&(G) Liqurd crystal D spray(Lc D) 2 Prc Q.,5o{%q@{M o..i,qlodo6:ep(9)

LCDdata nowf PoIITB


call C]ock
bsf PORTA,lcdRs
call clock
bsf PORTA,IcdE
call Clock
bcf PORTA,lcdE
return

9(Le-?', urspray %c A oocP:6olc\r9

oaoT:.{Qe"T.'.Q93 source

6o.r6oat6oTQco::6r, rcd2 asm ce8 3?Galoq6610cor:3rdciccD.c.dl t

; lcd2.asm
list P = 16F8 4a
inc lude "Pl6 8/a. 'n _ '
_conf iq h'3ff1 '
CRYSTA], = 4MHZ

USER RAM DEFTNTTIONS

CBLOCK 0x0C
DelayL

ENDC

IcdRS ; RAo : LCD


lcdE ; RA1 : LCD

CODE START AND INITIAI,ISE PORTS

; start adoress 0000h

.r..e i$6 qN
"irci
-.f:(:) Ln:rrrJc,tslal L-.i?r::rlLCD) I Plc i..5.i-;l-.!.o -.i,.rp"!o!,.r,19)
io-ll !:{!ia ; tCiliA = :r1l l.?
n..-rr lolTl
no.rtir 0!00 , aoP.lj = alL 1.:i
novri FOR!3
L - 5:A . 9
raorlv 0xC0 ; lcnll = ali .u:Prhs
nol r IiISA
Jnovlr C-.r00 ; IOR!ts - all curFut3
norit Tl15F
bci STa,TUs,tFo ; :1rx.1 Paqe 0
novlw 2..i , 25ns !oae. up deLay 0 4MHz
novrf Delayr ; ICD data shc.t says i5ms
clit Dciayl
PUPD .lecisz Dclayl, F
goto tUF 0
decf.-z D:layH,I'
goto ilLr,.J

; 5E D iliriilllsA1IC\ D]!Ta! iO DIS?tAl

movla b'00110000' i functior sei 8 bies


ca11 l-CDins
novlw b'00110000' : function sel B bits
cd.l I lCl,n5
novlr b'0011C0110' ; funcc:on sel I bits
call LCDins
movlq b'0r1111000' ; fun.tion set A bits, 2 tines, 5xr dot fornai
call LCD:Irs
novls b'00001100' ; clisplay on. cursor off, blink off
call LCDrns
nowlr b'00000001' ; clea! the display
ca11 lcDins
novlr b'00000110' ; increment - no display shift
calt !CDins
i --------------
; WRITE A CHAIACTER TO THE DISPIAY
i --------
novlv 'A'
calf LCDdata
here goto here
j -------------'
; OUTPUT 1 TNSTRUCTION BYTE TO DISPLAY

LcDans novHf FoRTB ; put instruction on PoRTB


calf Clock
bcf PoRTA,lcdRs ; Write rtinst.uction"
call CLock

1ooe eq8 .$e,;li- o8- "3:oc6"3'


r6ldc) Liqud crystal D spray(LcD) - 2 Prc €o5a{,€4o{M 6i:{oc3o3:qla(9)

bsf PORTA,IcdE
call cLock
bcf PO!TA,IcdE
; 6nS deIaY betwee. instructions
clrf Delay], ; about a 645 defay La 4MHz
novld Bh
- novlf Defayll
cttpl decfsz Delavt, F
goto ct1P1
decfsz DelayH.F
goto ctlP1

OOTPUT l DATA BYTE TO DISPLAY

LC Ddata novef PoRTB


bsf PORTA,lcclRs
cal1 Clock
bsf POR?A,1cdE
call clock
bcf PORTA,IcdE
catl Clock

; CLOCfiING DEI-AY - 2CCJS l4l.lliz

C]ock novlw 40h


novHf De1ay1,
ldloop decfsz Delayt,, F
goto kdlooP

sl9d,*{e, 886oTEcQ6r,, ooq:qp:c{ cd2asm q e3"ro8dlorQ5

IIRITE A CI1ARACTER TO THE DISPLAY

ei,-p%6 e3'.do:l@Q543:o.:4,G,.q"d' HELLo-woRLD" .?..--""i,4


e"o,Ed$€.it-d,,
?::=-

.i'.? i+,i, eito:ltN -.,9- o€,o,i.3,


ee{dG) L'quid crysral Display(LcD) - 2 Plc 6o5o{cAE@So o5i,apo3o}5:qp'(9)
j -----------------
,. IiRITE A CHARACTER TO TqE DISP',AY

movlw rH'
ca]I rcDdala
calI LCDdala

calL LCDdata

caII LCDdala
novlw 'O'
calI LCDdata

call LCOdata

caII LCDdata

call LCDdata

call LCDdata

call LCOdaEa
here goto hele

G-or Cursor or Display Shift lnstructlon


.oc,ScooEE: o"ci:c.t (co)<,[:c{ coae mp 92!:@3. Q6,,1EdEo1Q.n p:sa cBr,ocx
q€ co""t {o$ varialte o:51co6o}eo:ry1e$rr

cBLocK oxoc

DeIay!
DeIayH

ENDC

{e4arr5 code loop c{eo:rfiiloof€:e spqcilc$rr


cllf count
I6op novf Coun!,9r
addlv 'A'
ca]I LcDdata
incf count
novlv d'18' ; l8 characters to write
xorwf Count,fi
btfss STATUS, z
qoto ]oop
hele goto hele

-3ooe
s5 {d{o dteo60S'
3?coc8dl66l.r,:flc'5oq{q e Ascll character'A s:%d HEX o,qQ,$d 41h G6E
o,4Q:-d 42h G6])dl1 {3, c"""1 csE o{Q:or6i
3. A 3,%.6 HEX o)qq A B c oo.)alG3.'A ro R'
,€c,r-q-"dr ,9.cr's 3..r[-,.:a.{. I' to c
od occQdce)o,i="T- ."To,c@.e,6%.q6,,od,

Q(G-o) orscLavcA€'A'to'P' o'cy:qpreoTM+


,p, 3'c63'6oTq63,e" .$3:016? 3 o,oi:(3G)ci:DGoT+ecD6@,3.G5Odn o$6a
'R oi.-el LcD3, 3:$Gr63rgc'd: 683q3.q1 Q(G e)%8@ddl,
"id.1)oi,'o'r€.

?(s ei urso'ay c q fc. x or.l:qp: 6qpD6{u

LcD module %8oe!: Plc d.3l.o8 RAI\/ location qp:od$ol3rdr rco el.co$q€:
cqctard oaci:qp,:rl€ sa{o1 anu bcat,on qle:%8 eqcpqolc6fi@o1:r$'r lco ol
controtler chip 3ral RAM location qp:%3cfcpoioio36@cc,r o"oi:9p:.'?o66.o:6€:S8 Q6,,7
co:@e:q6c$:o$qp:.{ .73"".o3eo,ci1 o$rr
LcD %3 oDe:qrD:$qroi833,ei RA[,4 loc-ation qgeol3: G")6.1-d' caeoTcQ8:q8
(eo) $p:r en+c$E:ca6 (i.)i,t-S'
o€o6rl::@3. LcD-Dc! -D4,1RA\rr tocaton (cG)e5
Qo:E:ecilcB lwinAowl oS@bdl::d Cursor or Display Shift instruciion ci eo:ciLll:e{e:
+a@r-+,GG, wrndow d
-csoos{.s8@E €O.ie,cic8ar3 'A f3. B,oi. G€.83:e
o es. n {.eorctae oc36.,rd, Q(c-3")%3@dil ,
"epda",E,
movlw b'000110!0' ; shitt display window ]eft 1 posrtion
call LCDins
novls b'00c11CC0' ; shift display LrindoN left 1 position
cal I LcDi ns

Q(G-co) oisrtavqE 'o 9€. 'R' ore:qp:co1oJ,?

Jvll9J!+rtwl| ' oc6ot:


,)il:(G) Liq!id crysiai Display(LcD) - 2 Prc i?s!{%Eo{o :qodN3:qp:(t)

3ro.3%36oT@d.6r, display wrndow shift !!3e$s:c6cA source cooe { m"ro56"]E,jr


rcd3 asm 3o?3: 6T3':E:€,6,-3@d€3orrrd,

; shi:: d:ispi.t, ,i.do, lefr: 2 poslLr.:l


lisr P - 16Fg 4 a
include "P16f8 4a - i.c"
./ir::.j h':if1'
; C:tJSTr-!! = 4!,iH z

; USER F-A!I DEFINITIONS

CDiOaK 0r0C
lelayL

Ell
'-
Lcdjls :q! arr / Ri! = l,Ca :lS frr
Icdi ecu -r:1 ; RAl = LC! I prr

; CODE STtRi AID INITIALISa ?ORTS


; ---- -
or9 :!oaL ; start addjess = 0000h

mo--.:r Ortrl. ; ForTj\ =:ll lorr


nolJl L:O:.li!
norrrl Lr:.r.r I FORTB = :11 lon
nolrf POR:B
bst STATUS,RPO ; Rl,lrl Paqe 1
novLe O:-la ; PORTI = a Ll o!r]o!Ls
n.,rr: TRISi
notLa 0t00 ; PORTB = all .drprt:
no! : llRisi
bcf STlTijS/R:0 ; R!,]i Fage ii

ro1-1 20h ; 25nS pofrer up .ielay 0 4lttrz


novui DeLayH ; LCD .laia sieeL srys 1!rS
.l ri Dela.i1,
Pij!D Cecis z DeIayL, F
goto !tj?D
decfsz DelayH? F

SEND INITIALISATION DA!.l TO DISPI,AY

novlw b'00i1r1000' ; function set B bits


..rl: LCDi. s

.1."e qe8 eiq"]fl- eo-


e.{!(G) Liqud crystar o,spray(LcD) - 2 Ptc io5a6.€E@{M oi,qpd(v5rqr}(9)

novlw b'0011000!' , functioD set I bits


calI l,CDin s
novrw b'00110000' ; function ser 8 birs
call LCDins
novlH b'00111000' ; functron set I bits, 2 5x?
catl LCDins
movlw br00001100' ; disptay on, curso! off,
novl{ b'00000001r ; crea! lhe dasplay
calt LCDans
novt{ b'000001r0, , incrdent - no display
cafl LCDins

IIB]TE 18 CHARACTERS TO THE DISPI,AY TEEN SHIFT I-EFT IIiICE

clrf Count
Loop novf Count, vi
addlw 'A'
call tcDdatd
incf count
novla d'18' ; 18 characters co w.ite
btfss STATUS, Z

novlw b'00011000' ; shift display uindow left 1 position


calI LCDins
novlw b'00011000' ; shlfE dispray window left I position
call LCDins
here goeo here

; OUTPUT 1 INSTRUCTION BYTE TO D1SPLAY

l,CDi ns novsf PORTB ; pur inslrucLron .i. rCIiT!


call Clock
bcf PORTA, LCdRS ; rrJII !rislrLCLioi
call CIock
bsf PoRTA,lcdE ; clock it h
caII Clock
bcf PORTA,IcdE

;6nS delay bervrccn inst!uct!ons

c]lf Delayl,

decfsz Delay!. F
goto ctlpl
decfsz DelayH. F

Joo? $d ahdlqc\) -e.- o8rc.8o€:


-4,(6) Liquid Crystar DisplBy(LCD) 2 M o{:qroo5o3:qp:(9)

; OUTPUT 1 DATA BYTE TO DI9PIAY

bs! !OaTA/ L.dRS

bsf PoRlA,lcdE
bcf :oRTA,lcdE

::::1lI:,:::::___::::: 9 1:l:
Clock aorLr' 4 0:l
I.rrt::).r.ri
.: !i .!r 1:.::: l-_!-lat/L/|
E--:. idi,ro:n
r:lu:n

G-Cr Display Data RAM


f

etc Qc;a{cg$c<i{ona8 RANI address $or;.o$. rco c6tco2i: RAM address


$a-d, Sl RAM 3?rit:3"o':c4 Display Data RAl\' or DD n.av qeaT cilo$rr
s"€c:T.Es,ord address 0x80 caSoof@: aaaress oxrz ca3{:ol1::2!rr er,:cAag:
c.$€:oE! accress oxco cA€oco8B:r address oxET %€+:olodn 0x80 to 0xA7 93. oxco to
oxez sa@:c63 eq6pcDS@66fo13,elr c.?€,0,6?8%€ address saeqeaqrf G.)6,J-d,
e,'csd oroi::aeqsa.ca.6(ec)oi:cAQG"T€"."d{qi3 ecqeSa.6o:o,i:oE! e@rdo?e:€i
u-.nqq,"a€ e.-,T.""nu.2jl egalc6cjl lcd4 asm %e€oT@cor:e:d3roie: '0'throush to'x' .{
run @dqJ€+(G cc) c6eeoTQcoc:a:pis,o?3: eo?GG.cE x'o.e:r,d eooScQ€:ei "-"
.{6P ,?3*d ""T"qoe:.{ G(€.6eq6oc35."dn

?tb-Jr.l GJEro-?:'Pc:ce- ^ aoa:qP:6c c!v'9

; l..l l asn
;11': ch:iacier display on 2'd line
l:sr P = 16F84a _

i..1rde "P15fg 4a. inc"


...\ai.-i hiffflI

;oo9 196 "iq;]fl- 8J


r6idc) L.qu,d crysrdro,splavrLcD) - 2 prc q rd{?6oiM ori:Wo3o6:qp.(9,

' CRYSTAL = 4MHz

, USER RAM DEFINITIONS


t ---1
CBLOCK 0x0C
DefaYL
DelaYll

ENDC

; RAo : LCD RS pin


; RA1 = LCD E pin

CODE START AND ]NI?IALISE PORTS

orq 0000h ; start address = 0000h

; PORTA : all low


NOVWf PORTA
; PORTB : all low
novwf PoRIB
b6f STATUS, RPO
; PORTA = all outputs
NOVFf TRISA
; PORTB - all outputs
nowf TRISB
bcf €TATUS, RPo
novlN 20h , 25ns poser up delay e 4MHz
novwf Delaytt ; l,CD data ,sheet says 15mS
clrf Delayl
PoPD decfs z Delayl, F
goto PUID
decfsz DelayH. F
_ooto PUPD

; SEND INIT]ALISATION DATA TO DISII,AY


; ------ ------.
hovlk b'00110000, ; functlon sei I birs
novfN b'00110000t ; function set I bils
nor:Ir h'011110000' ; :uncircn s:r I Lrrts
movtr br00111000r ; tu.crion ser I bits, 2 tines. 5x? dor formar
novl! b'00001100' ; display on. cursor off, blink oif
nov1 br0000000l' ; clear thc cilsplay

16", it6 eifiqo -et oe:@,troS:


ool:(G) Liqlid crystal Dispray(LcD)- 2 prc
Qdo{oa+6qNo o.i:qloo5(\)6,qp,(e)
caII i,CDrns
novlr b'00000110, ; increoenr - no disptay shlft
call LCDins

; I,iRITE 41 CHARACTERS TO THE DISPLAY


; -----------
clrf Count
Loop novf Count.li
addle'0,
call LCDdata
incf Counr
nov]H d'41, I 41 ctiaiacters !o lrite
xorwf Count,w
btfss STATUS, Z
goto Loop

here qoto here

; OUTPUT 1 INSTRUCTION BYTE TO DISPIAY

t-cDins rnovwf PoRTB ; puc insEruction on poRTB


cal.I Clock
bcf PORTA,lcdRs ; i{rite "iDstructlon"
calt Clock
bsf PORTA,ICdE ; clock it in
calI CIock
bcf PORTA,lcclE
;6ns delay between instructions
clrf DeIayI- ; abou! a 6ms detay G 4MHz
nov]}l th
novxf OetayH
ctlp1 decfsz Delayl,, F
golo ctIpl
decfsz Delaylt, E
goto c!lp1
return
; -_ ------------
; OUTPUT 1 DATA BYTE TO DISPIAy
i--
LCDdata novwf PORTB
bsf PORTA.ICdRS ; w.iEe "data"
call Clock
bsf PoRTA,IcdE ; clock it 1n
ca.II Clock
bcf PoRrA, tcdE

Joo? ir8 o&olqc.J 'e9-


,o6:(G) Liquid crysial Dispray(Lco) - 2 Plc E.6a{cS1(Dio @.l!qlodN&{iP:(9)
ca 1l CIock

CI,OCKING DELAY - 200uS 0 4MHz

it..* novlw 4oh


movwf oe]ayl
kdlooP decfsz Delay1,, F
goto kdloop

o@o8olQcdliol rc$o.'5rl.ord:Go"C:' gcoc6c{.copi:ernc8: 6g-6o6a:/r tnstruction


cp'4-"i'GLg, G66{rTcur-dqcDr5..t 6c.,.o,r@d6oc$(',1e)dn

G-ror Set Display Data RAM Address lnstruction

occQ:o:3cQ:r$ cdard6f.psdis{ €
set Display Data RAM acldress
o<rl€6oT6oc$q
(o"f..',ro5e-,@€. Set DD RA[, adiress)instructron c{ o+:Gtl8olodR o@tl DD RAM
address o$ oxSo (1ooooo00'in binary; @6e@:€: oc8@1eoc$ci1or$rr Set Display address
$?qc'reg: '10000000'o€G66:1r6E e. DD RAIvt address 4 ,nstruction data ab.cl.o3s"ri:GL
{eol])dll
ora?:cA,lcoe<q€:cl\t,co.lq<p9 oore{ooTcQqi€ eorS.iooft:eslcr.rf Etilogr

movlw 0x8 0
caII LcDins ; start chalacters froli l't on top -Line.

o'o?:cf ocoscqS:€$ordtDq99 oo,€{eorcqq€ 63",n6o13"o?3:6qir,?rFt(,1a)dn


novlw 0x82
call LcDiDs ; start chalacters frorn 3'd on rop ]irieii
€?rc6<':1 Q(G-rj)oS€6oT0co::ard.rl. <-rcoocQ€:crloec69cpg Q
code crf lcAs.asmeaof€:er1<iolep!rr

+(0-c.l) o@ocQ€,o1 oa66+ePe o,oi: tp: o 63 Gdr.ori

Joog tt5 cg+delo -0c- c3,o.5ot,


saE(G)LicuidcrysralDispray(LcD)-2 Plcqdo{.Bi@{cb-1,qloo:N5:qp(s)
; Icd5 - asn
,DEMO OF SETTING RAII ADDRESS
fisL P l6E84a
include "Pl6f84a. inc"
_confiq h'3ff1'
; CRYSTAT = 4l"1Hz

; USER FAM DgFINITIONS

CBLOCK 0x0c
DelayL
DeIayH

ENDC

IcdRS equ 0h ; rA0 = ICD RS pin


IcdE equ th ; RA1 - lCD E iin

r CODE START AND INITIAI,ISE PORTS


; --------------- _'

o.9 0000h ; 6tarE address = 0000h

movlw OXO-O ; PORTA = aII 10w


IDowf PORTL
nowlw 0xO0 ; PoRTB - aII ]ow
novwf PORTB
bsf STATUS,RPo ; RAM Page 1
novlF 0x00 ,' PORTA = a]l outputs
novwf IRISA
novlw 0x00 ; PORTB = all outputs
novwf TRISB
bcf STATUS,RPo ; BA!, Page 0

novLw 20h ; 25mS poaer up delay e 4MHz


novwf DeIayH ; LCD data shee! says 15nS
cl rf Delayl
PUPD decfsz Delayt, F
goto PUPD
decfsz Defayl. F
goto PUPD

; SEND INITIaI,ISATIoN DATA TO DISPLAY

novlw b'00110000' ; function set I bits


call LcDins
novh b'00110000' ; funclion set 8 bits
call LCDins
hovle b'00110000' ; function sec I bics

1oo9 1eE e{eo1fio '90-


caII LCDins
rnovlw br 0 0111000 ' function set 6 bits. 2 ]!nes, 5x7 io: io:a.r-
call lcDins
n'ovIw b' 00001100t drspLay on, .L, ro! ort, btr.l ot:
ca]I tcDins
movlw b'00000001 t clear the di sp tay
ca]I LcDins
novlw br 00000110' increment - ro display shift

DEMO OE SETTING RAM ADDRESS

; start on line 1 char 5


caII LCDins

caII LCDdala

call LCDdata

caII LcDdata

ca]I LCDdata

call LCDdara

caff lcDdata
call lcDdata
caIl lcDdata
call Lcmata
calf LCDdata

calf I-CDdata

OUTPUT ] INSTRUCTION BYTE TO DISPLAY

LcDrns novrrf poRiB ; cui insrluciion on FoRTB


cell Cio.k
bcf PORTA,IcdRS ; r'iriLe "insrructionr
call ciock
bsf lORTA,lcdE ; cloci iL i.
call cloclt
bcf PoRTA. tcdE

Joo? er8 ol{.cjlEo


Liquid Crysral Display(LCO) -2
; 6nS de.lay between instructions
cl!f Delayl ; abirc j iirS .lelay ,Q 4t1llz
novlw th
novHf DeIaYH
cttpl decfsz De]ayl, F
goto ctLPl
decfsz DeIayH, F
goro ctl.Pl

:1r::r r ?ili_::T_l:_T:i1l
I.c Ddata novwf PORTB
bsf PORTA.IcdRs
call Clock
L'sf PORTA,lcclE
cail Cl.ock
bcf gORTA,lcdE
calI clock

CLoCKING DET AY - 200us I 4MHz

Clock novlD 40h


nowf DelayL
kdloop decfsz DelayL, F
qoto kdloop

eoocS<;l{(6-cq)oo?€: ldoc$€,ot r.,cocq<pgoca€$ .a<'i:$.!,i6oT@dcQqi8


source code cA lcd6.asm oolS:eqqcile2!

Q(C-cq) 1c8rl:c$8:cli
r-rcoe999 orcQ:qFoo8coTca?Q

-co-
Joo? ?r3 .EiolqN
Liquid crystal D'spray(Lco) - 2 ptc €"5a{,?i-{ca' orl:qloo8NS:qp:(t)
'ef(G)
;DEMO OF SETTING RAM ADDRESS O\ IJNE 2
lisl P = 16F84a
include "P16f84a, inc "
_coniig h!3ff1'
CRYSIAL:4MHZ

USER RAM DEFINITIONS

CBrcCI( OxOc
DelayL
D€]AYH

ENDC

lcdRs equ 0h ; FAo = i,cD RS pin


IcdE equ th ; RA1 = LcD E ptn

; LCD RW PIN IS TIED TO GROUND

; CODE STATT AND INITIALISE PORTS

or9 0000h ; sEart address = 0000h


novlw 0x00 ; FORTA = aII Lou
mowf PoRIA
movls 0x00 i PORTB = aII ]oh,
MOVWf PORTB
bsf STATUS, RPO I RAM Page I
nov]H 0x00 i PORTA = aI.I oulpuLs
MOVWf TBISA
trrovlw 0x00 PORTE = a 1.1 oulPuL€
NOVAf TRISB
bcf STATUS,RPO RAM P:rge 0

rnovlE 20h ;
novwf D€-IayE
cllf De1ayt
gUPD decfsz DeLavt,F
goto PUPD
decfsz DelayH. F
gOtO PUPD

SEND INITIA!]SATION DATA TO DISPTA;

morl b,00110000, ; fun.tion :ict 8 trirs


call LCDins
nrovlH bt00110C00, ; ilrnci:on sEL e birs

J--y Ito -Ee.- oerc.,5o€.


''lorqo
oal:(G) Liquid crystar Dispray(Lco) -2 Plc {o5a{.A{o{o -e,q,d^e,1P(9)
calI LcDins
novlw bt00110000' ; funcrion ser I birs
call I,COins
novlw b'00111000' ; funclion set I bits, 2 lines, 5x7 do! fornat
call LCDins
novlw br00001100' ; display on, curso! off, bllnk off
calI LCDins
novlw b'00000001' ; clear the drsplay
call LCDins
novlw b'000001I0r ; increment - no display shif!
catl LCDins

; DEMO OF SETTING RAM ADDRESS ON I,INE 2

novlw 0xc0 , starE on ]lne 2 ctlar I


call LCDins

call LCDdata

calI Ddata
carl !CDclata

call lCDdata
novlw'I'
carL !CDdata
movlurN'
call LCDdata
novls'E'
carl, !CDdata
movt!, ' '
carl, lcDdata
nowfw12'
caIl LCDdata

hele goto here

; OUTPUT 1 INSTRUCTION BITE TO DISPLAY

LCDrns novaf PORTB ; put instruction on PORTB


caLl crock
bcf PORTA,IcdRS ; wrile 'iinstluction"
call Clock
bsf PORTA,ICdE , clock it in
call clock
bcf PORTA,IcdE
; SnLS delay betwee. instructlons
cllf Delayl ; about a 6ns delay @ 4MHz
novl! 8h

Jooe ?16 +o1qo o€'oc3.-3:


Liquid crystal Display(LcD)- 2 .,5e{ca6-6o ori:fl oo5o6:qp:(e)
""6,(6)

.. ipl decfsz oeta!,L,9


gotb ct]pl
decfsz Delayll, F

OUTFUT 1 DATA BYTE TO DISPLAY

lcDdata nov;f PoRTB


bsf PoRTA,lcdRs
caIl clock
bsf PoRTA,lcdE
call clock
bcf PoRTA,IcdE
call Clock
return

: CLoCKING DEIaY - 2OOuS (i 4MHz

clock novlu 40h


noviif DelayL
-*dioop clecfsz Delay!, F
ooto kdfoob
!e!u-n

G-ccrr Deline Table Directive (DT)

o:e@:€: (strins) 6rp:.,i code €tr,r:6pcS3 qqoX6N6


Q€oT6l13!cAc,5 source
a33od:EoqE3"qr.3 rabte Dircdive (Dr) 4 3:n:Gtg€oll6o:]Jein Dr 066i,'lEc!a:€o,
or@:8:c{ uersv Dag assemble q6o$aa1 retlw instruction Q6solE:G5"1ardr
""rE-,Ge. reuw @S.espocrgfc{ Dr3?G66G'€:66[cioEEE:oE@Sioopll eoo.'5olgoeoot

!et1}'

.to.e i;6 o{qol{o: o€:o.303:


-.i(G) Liquid CrystatDi:ptay(LcD) - 2 .s$oio s+,r1o0506:.rp:(r)

,46$3r':co2:)d 'N,4essage #T' , Nlessage #2' -.@3,qp,4 Dir€ctive DT G3.


e@8'de q:or:cal{qn8 eocBcilcacflS:661:qdlcdn .'l3:ce3 Messr, Mess2 raoer
qP:G6@.jr3rd,,
"f.o2!

DT
DT

glc$.e1:o:::qlc693 raber qp:G6[06r' Messr T3. Meis? 4.4 Rorl address qp:
3?G6sri:GG:cf.o6 PCL(Lower order 8 bits of Program counter) regisler modjry eSG: .{
ca.$$"o2!eoo.rcc{ qor63:66o1odll oai:b)qre ecr c{('p!af. moarry a9SQc{eq5S:
G66o3)dn or6Do8ord:poe PCLATH(write butter for upper 5 bits of the program Counter)
resister c,?cue!: set o73q$ 3?8orcq3?6eo.,ei,,
"3.aCl.$E,
messase op! pas; boundaries ooEgo8nr6 256 word .4 €6.e]E
RA[,t
""fp{-d
oa6ql 3ro30n6(,cd, e,Dosd€.nFos$5.qi€ 63o-,qp:.A ?ioisrq,{$3"ri-%"6 QQ5,p3
6cg:6r, qp!.t $i:Gt6t6ocE6.€dn
code
ecc.rcc{ etc memory e'5 eg!,.:p!ca9g€e{ 13E:co,):{eE, -€,o?.ddtr?.Gio)d
6oTqo8$e,i.{ 6c,,.oJr@ded{qlle e.o-,co:E1n3:erl 00,€6or address o? 6oTqo3Req6
6oTqo3$e,i.{ 6c,,.oJ"@ded{ee
l\.,lPAs[.l o$ assemble ec96E or{p{e.p .,51c6?qp:.4 e:Br0Le66o:dodr

Tinel equ d'50' ; define Tmel = 50


Tine2 equ Tirel + d'50' ; define Tine2 = 100

movlw Tinel ; ll = 50
rlow.Iw Tine2 ;W=100
Resister cD6i.D c\)c8Sq8ca,o(')C0rG6aral 8 bits wide (o - zso coc;Q$ co$:g€:
Eq13 compiter cn wamlng message @er.:c€5.e2!'r

rine3 equ Tire2 * 3


novlw Tine3 ; W = 300
''{a.ninq [202] C:\TEST.AsM 72 : n.gune'rr out of .ange, LeasL slgni;icani

.oe e+6 eqrdlqN


:

' s?coc6d warnins messase 6o'l!qld3?q rime3=300 o,p) zss coo6Q@:cfe:,e@3.


300.'? 255 te. AND operatron olcySc,)r (300 AND 255 = 44) 6I6€r.3r€G 44 cA w resisier
. co8ec:co:eoroP1,
'Hish' t3. Low' operaior qp,4-.i,GG' 16 bit 63cr,9p:4 nev ecAs:ci.
@dr8€:+3(')16rr:3jdll 300 dec = 012c hex 836',.@'3. €"rc3o13,4€,.q:$eol3)dn

novlw High (Tlne3) =1 0x01

mowlq LoH {rine3) = 44 Q!.2C

vessase o:61erl oolecf,r address.{ cacBX.6"p93 *.3.1qd,c4 e.i,Gt$8


",-d,
s?o:oSg) RONI address 104Fh ca8$egoo:: message 8 bit
'r6?.46cocorodqqne
,r1.oc8Ejo66@re. novlw 104Fh o?666l$36fln o:3:::or: upper 8 bft value (10h) c4 ROtt/l
pase @6e:rD PCLATH resister€i -iq'3"G6"ro39c30: lower s bitvalue (aFh) rf o3: nov
page e onsel3agosrcrr9cDolDagn

novlw Hiqh (104Fh)


nowf PCLATIi ; PCLATH = 10h
novlF l-od (104Fh)
cal.l Messaqes

rinel DT "Mes sageli l"

Ii is ai.f..i.ers 1i,i I
e is ai..iiress:1050
s is at a.iciress 105:L
s is aL adclress 1052
a is aL addlcss 1053
q rs ai address 1054
e is at address 1055
* is ar address 1056
l is at address 105?

Hig]r (l,rne1)
PCLATI]
rnr = 4th
-!.'r,c)

sld.3i. RoM address 6ecpqe:069o3@,eq..6 o:e@8:o5e o.Q:or6e el8:.46oTq03


qi3? cl6 otrset varue o?3err:q pcL.{ modiry c'?6qqc.l3?6o13re!r
offset value 3? oA stretr (,2:aep!or6cc.::o:el RA,1 resister o,6?4 3?oi,ondl€dll
,De,Dd oa.@,e:c6e o"{,o,3oi:{€,cA ecoccS@<,2! pointer oeo,:{p$8o]ar$r'
ocD€o.cQ: o%c8 offset value rie9 o @6eoqicaqc,5 strPtr resister .{ -1,o@€ swr = o
c'i6c.D instruc(ion .4 €:gas"ri:G[co]:qt:1 edr
@6eo:3 "r.t-st.et.
oocE?e:6$3{:tro6cicp.{ orr oxrr
@€.@6eor @€.@6eo ::c3ec8er.,:eycicc$rr
o9,s,:,@3. oh 4 3,e:qco).fiol]]d,,

Linel DT "Mes sa( *1'. 0h


Line2 DT "Messa( 12" , Ah

m5c3 e"'-,113'...s message oae@€:olceq:ooBca3 0h o?6c,


instruction oloSoc;.3i. coSgc8i€€ood DT direclive messase op!
-.@S,.{etor:
,p € cEq:qp:, orcyqp,, or-l -,
:9F:o? Gdna \.
) oll 819.:11:€$.- eepegoeelo::g3.@
;r-d,
G-cgu Send Message Data to Display

coc,5oc6@: message -"@r€'c{6oT0{erard subroutine r:e@a8:c{ ecu.<u:@


,ie$n p:go w register ca6ecpc6$eg6o)? message lD number o? uessw* ,noo6goEco::
6cn variable q3r36:.o?g:coo,c;lc$r
uessr,iner er2! oroec$t:o\ address OXSO e999oo:3E:r Messline2 a)Ag
1o8ox$3,.5 addrcss oxco cqqpgoorScoqi ca?".Eo1oo?e: setc96<ieplr

Messl,lnel rovqf ; EemP store nessage n-onber


; stalt LCD line 1 address
Messline2 nowf ; lenp store nessaqe numbei
; start LCD rine 2 add-ess
InMess call tCDins ; l'rlEe it to the LCD
4 subroutine qp:€,i3?"Qe,6oT!qlc,:3r$ message ocDtlle! address 4IeD ol DD
RAlvl pointer <2e 6{pqcor:c,,'63:G6eoa:p}rr {eqcp",$ orc@.e:€,5 clcD,'oroi:QcoT€d
cf rpoSE6ola:dn oaoi:3?c613"%c6 (cG)Q:eooc6cioEea:a o:e@,o3:qp:ecAo6.iqJe to3:o?.
])d,i?iGeq3€3,Ee,?3:ca3 QeoTco:@eoc$rr
{ng".A .e""age lD number .{s?r?:Qfi: message o$ memory erlo$o$cqgq3
$eqoplr{ subroutine 3?, 3eo3eo:s}i@6olrrd' 4{.GLqOq$-"a"1 PcL .A modiry cp6
.dqd,.,?"E o:2:&e1o1e;{rrvessase o2j memory oleplo2i6q6p%3"{46{{eE, oJ8:od
RoM pase s\oso6"?od' .qE@oE{eoslrr 4.@e. 4Q..x"4.o5cnr:$3q43?cec6
specialcode -if4
-+,En *d'
Messase rD number cA 3ari:q$: ofiset c{oioE:dlee:tr o:3,c{p,g" M"""N". ce€
o36, cor: dl t,dl

Joog ?16 c$rc;lqo


;t:rG) Lquid crysral Drspray(LcD) 2 Prc Eo5a6c81@{M o.i,qloo3o6,Ep:(9)

novf MessNln,it ; gct stored nessage nunber

shd:G8. 1
dl dor6?r;il>o5gdiaG3. subroutine 4 memory o5o$og!e9epcf.e{
+-4€, rD number oai o @6q913 u.."0 cl.?Eer:E:, s?o',isd 1
G6qse
0 ol audress c{ep;$3eo:: qEe:oc8ql.6$p:r
Messaqe
EessL subroutine op! v."""q.1 €i address o?6tq?B86.rr cf6e€o,eqtd$olrrpqr
- ues.ase laber qp'ct s:rt:G1@:cr:3:4.::s! memory a €: 6dodcq6rrgo36:6od:
coropir{ eoTcao6$3o1 opi r

novlw Hiqh (Messaqe0)


novqf MessAddH
novla l,ow (Messaqe0) get page ot tset
nonlw High (Messagel )
novdf MessaddH
novh l,ow (Message1) get page offset
movsf [4essAddr,

Messase data o:d$a,d€Eq.r€.,ro53ro56c, crorS:oqlctu'oro8qp:.{ or6;De.qt8:


q6.D'e:c':,a@Go::d,, s'cocSdl6oT@AcA%3 MessAddH .{ messase oo:€o$ nou pase
gE set cjScoo:p:r MessAddl %3 oflsetvalue $egoloplrr
eoer- Messasel o2! nov aoares! 0x10FA ceSora:iel€ MeEsAddH %€ oxlo
{G:r MessAddr %3 oxFA $dloeq,

G-J?r Get Character lnformation and Write to LCD

a>d"Jc'5cf 66"o.e.1"d3,Q3:9r strins pointer vadable o? resei strpt.


"t8@,"1od
messase
9 ore:or6c!: €:ci s,+:tr o8c,d€{q, o.9.5"q3, e"T"9"5.","1"!}r
c1!f SirPtr
call I,4essages
nov]F Fiqh (S)
novFi PCLATIi
novf temp/Il
test if zero byte
btfs. STATUs, z

call LcDCaia scnd character to display


inci Strlitr.F set ready for next characLer
gcio lless!ocp geL ne:t character

roor ?r5 oE.4q-) ior- "3,-d.t,


@aq:(o) Liqud crysraL Display(Lco) . 2 Prc {o!.
Gr.c683:,"36oTG6d Messaecs subroutine g$cgc;or.rds?a1 w resisrer,Zs
oo{:o6,?:qp:ciloSo,dlcid, o.c@r€:6toai:oo3e orejepci. e"p.3 onepc6 3366i63c%o3
xoRi,ll oh instruction .? orf,Gi.l.1-d' -i{,-6f"t 0h 9€. xoR q6..rce'n1
gcoa{{roe@3:e xrr o9.e'5 o.oi:o,6Q: ( w o,1{,)eoTto,dd srArus resisrer ? z nas 4
set c!.eu1c8 ctear @5so,i:r:p!rr w = o @5qqt z = 1 G6E:' w = o"G6ql€ z = 0
G6edn
Zbrt 4 btfsc srerus,z @€, o.5."o:cir:2irr
sLbrourine oJ€ pcLATH resister sl o1$:Dd6Qo€:o;6f$: sd$dqr.<rr
_ !"...?"" lnstruction
s{Udiacoodr movl. Hiqh(s) e>ei coc6$o$oq6ore9cq9 (cu(ent program
address) srl hish value cioiqi assembrer
4 4 6o{€:63:06oil3Jdrr 4 high vatue .4
PCLATH %3cDdca3:c$d@: cALr, 9€. coro {,o$ RoM pase 3 igi-.r6q6@
e oec.rc.o$r'

G-c9r Character Address Calculator

orcg:ql.:ol address 4 %.8fldArrd coae :ae@€:r{eoc6<oc8e3!Li1e$r ts tir


fier:: Ronr address o? qq?e dG6ea.::e@3. ro oit 13.{3op) cao5a.3?,it:.,? 0to?361
olc2lrr Message aata oi::o@1elg!eq9.{ MessAddH l€. u..saaar, of.cA8 c93::o$:co::
€'3'358:@6o1a)d,r sr.etr ca8c96:cor,oal offset vatue.'? ,D€:o?.r3. 6dl€:0:Gqco5
oe@c{ nrosram counter q3co2}a3:c$r8clloglrr Upper o bits.{ PCLATH caecDalp:GJac8r
lower I bits c{ pcL
%€coe;o:loa:' ghd,G8. orai:{ip:eie2oE{: adoress of cao5qp'o1
cilopirr

Messages movf MessAddH,lr ; ftigh aOOr".s byte to PCLATH


novqf PCLAT1I
novf MessAddl, tt ; get lo address byle
addwf StlPtr,W ; add chalacte! offset
btfsc STATUS,C ; lest carry
lncf PCLATH,F , overf.Iow - inciement PCLATH
movwl PCl, ; Iow byte to PCI-

cacoci ieoft qlcf c{ 2,-,oqp:@3.e-,a::EEeco."-@d@d g,Q.'

Message oe! address Ox1OFA ca8 oco8o2!,;2o7;ooitl$rr


ox1 0 (E PCLATH resister cAe corc8dl s?o?8:codq€:c$n5oll a:g!rr

llessaqes movf MessAddH,lt ; high address byte to PCIATE


novwf PCIATH

oxFA c{ord: W resister cBEcD$3e8:E: cr>8:.{ srrprr 13. e,rt3:<r:c s,e@c{ w


oaE,':€E4codcor:rl1::dr

rnovf MessAddl,W ; get lo1{ addless byle


addwf StlPtr,u ; add character offse!

Joo? i+6 oqr.jrEo


dld6) L,qu,d crysrar oLspray(LcD) - 2 Plc q.'5ai.A{co{M o.i:{oo6N3!qF(t)

6o13:o,5.rd 25s cDd@:q91€ srATUs resister €rl carry flag rJe9 I G6 ?;":dl,rdn
orn<js$ edl€:coSarg! 0 {.oo?o5 255 codcc$qi3 srArus resister oi carry flas o$ 0 $6
+'.t;0' e*. "",,vn"s"i"s.-,-d-.t r @a",6{q1e ecmrn c{ rof:eocio$rr
bLfsc STA'IUS,C ; iest carly
incf PCLATH, F ; ovelflo - inc.enent PCLATH

I
Prc c:ei bit r€.436:r,r%dqlo6i4p.,?3>c@1o?3+36Jo:dj:' 16 bit t€$ecco,
ql:4@ie66o62i coae c{ es,:cBcilo{€:ee1:o::$6<ic:E)rr
%o5qo6fr

255+1=0

3acooEoldgl6€'rd c21i64.@q c.r.'55$3goge$ea$o$: etc cncuc65$Eeoer$l


.u3: c,2!.or.'5"1 e.1 c>r,{d598.?$oel,r

o:1eaa1 wo2! o +8d-du?oi.Dq €-

11111111 255 FFh


+ 00000001 1 th
100000000 256 100h

ococ,Solopc$qcfgol o€Goet lower I bits = oooooooo G66@r€:cra6todn @€:rod


w qScuris{3o2!r
o:c,i:o:i$:99ed€:o$ zss <or3@:ergioal 9i.n{eo"q.iq1.69 GL"ll"t.d4"3$
c$oEeoer$rr {sa c'5c{ sr,rrus resister€r5 carry flag @3. o6eao:$€o2!rr
I bit variable qp:@6@ee, valueB f€. var".l {.cfeo13,'3c$.6qi3 16 bil variable
G3?8.:+31,dn
u"r".ti = 9€. varuer = 255 05A13 l6bittotat=255 G6Da:r
ecxrS$ va:.uer, %€ 1 ..j13,-d.-E 16bittotat=256 cf.cqcS otoon @6op!n {oal
:
varueu 1 l€. varuel, = 0 G63d,, gle,,,'rGoTGAcS.{ eo:c6,ieaof3,eq.o::fl8o2!'r

btfsc STATUS, C

3'co.;%:6o-G5.-$ Nressases sJorourine cra! {:anoSqp:.{ -.6d8,""1 $''""''


^- -
l9er$6tllr:$rr Messases subroutine €fi6.p.3ai:or€,@t:qle6olQco:::,$:a{3' re uir
address orl lovlerbyte (4 PcL register c$.co$er::c$c6@e:@6,io$rr

rnovuf Pct ; low byte !o Pct

Pcq 196 o$1o1{o -3o9- o3:@.to3,


r,'.i:(G) Lquid cry5lal Disphy(LcD) -2

caar.E%8 66TGCo):]]d ..68 3:


i66@.€'.4 i.aEd.d{r: _

r{essage0 DT " HelIo fron E\e., Oh


l,lessagel DT " PIC16.e84n,, Oil
PCLATH 98. PcL 4..4 modify q6$,.9cc6 te bt address @::D64 ser q8@:m:r
Prc ])ai 4 address :aer39oo3@: oDci:qp:4€3,d,jl Q6o5.3i.6oTqo5dl trid;

Messases subrcurine
-d '"'"t w %€ codp:G$or":lplr
,e'
'n'o2) o cu2c8
o@e. o€:cfl QooTeo@: st.err cA or6ioi:o, eqcr;ooq: o? Q6oT6oo13d,r
sl9d,*4e, q$-e,cp,4 o6ci:qj3:qc\iE, Q6drco:,jl€oro.Odn

r?coc-oc-?o-rLc. rd 6c:crr_:qlfqr:.? ?oc:t.: -=.i. tc4. rsm %.-rtlycor:

; DEMO OF DISPLAYING 2 STRINGS ON 2I,INES


tist P: l,6F8 4 a
include "P15f8 4a. anc"
_conf 19 hr3f f 1 |
CRYSTAT, = 4MHz

;RAo= LCD BS pin


ICD E pin

CODE START AND INITIALISE PORTS

orq 0000h start address = 0000h

PORTA = a1l 1ow

rooe ir6 oqiolqo


F6d6) Lqud c rysraL DispraylLc D) 2 Plc {.5a{.81@{M sd:qtoo5o3:qp:(9)
NOV i PORTA
novlw 0x00 PORTB = all low
novrl loRTB
bsf STATUS, RPO
novlw 0x0C PoRTA = all outputs
NOWf TRISA
novlq 0x00 PoRTB = all oDLputs
NOVWf TRISB
bcf STATUS, RP0

novls 20h 25nS powerup delay r,a 4MHz


novwf DelayH LCD data sheet savs 15nS
ctrf Delayl
PUPD decfsz Delayl-. F
goto PUPD
decfsz DelayH, F
goto PUID

SEND INI:|IALISATION DATA TO DISPLAY

novlw b'00110000' ; iunciion set t .rls


caII LCDins
novlw b'00110000' ; Iu.,ctic- sei 3 i :s
novlN b'00110000' ; fLrncti.r sei a ir::s
ca]l I-CDins
novlw b'00111000' , furction s.r 8 bits/ 2 raes, 5sl dot fornat
movfu b'00001100' ; displ.y on, .Lr:or oif/ bLink off
cafl LCDins
movl! b'00000001' ; clear the oi s.l av
call l,CDins
novfw b' 00000110 ' , i:crcmen. r. { r.: a.,, shift

MAIN PROGRAM I-OOP

c ; drsplay message 0

; dispLay nessage l

SEND MESSAGE DATA TO DISPI,AY

;essLinel novrf MessNun ; r en,r store


novla 0x80 ; siart iCD ':ia: f .i:loiess
qoto InMess
MesELine2 novuf MessNun , tei. stoje i.::.:9e lLrt:ir..
novla 0xc0 , si.rri LCLr li:e 2 aa.:1::r:
s;:(G)LiquucrystarDispray(LcD)-2 Prceo5.{.6i@$o3a:floo5o6:qra(9)
InMess calf i.CDins ; Hrile 1! to the LCD
rnovf MessNurn.l'l ; get stoled iessage nurol'er
addwf Pcl-, F
goto Messo
goto lless1

i VESSAGE 0

Messo novl Hrqh(Messagc0) ; set RoM page


movuf MessAddil ; temp store ii
movlH !o;.vess. aeo) ; oeL pega o sbL
9oLo Conruess

MESSAGE 1

tligh {Messagel)
; tenp slore it
; get Page offset
; tenp slore it

GET CHAIACTER INFORMATION AND $7RITE TO ].CD


_----_--------'i__

clrf strPt! ; zero lhe character offset


Itess!oop call Messages lhe character
novsf tdp / _--get
; terP stole the chalacter
movle High (S) ; restore PCLATn fo! lhis ROI{ paqe
novxf PCI,ATH
novf tenp.l,l
xo!18 0h ; tesE if zero byCe
blfsc STATUS, Z

call l-CDdata send chalacter bo dlgplay


,lncf st!Pt!, F i set leady for next character
9olo Messloop ; get next characte!

; -----------------
; qtAnACtER ADDRESS CALCULAIOR
t ---"------------
Messages movf MessAddH, !i high addless byte to pcLATn
MOVHf PCLATH
rLovf MessAddl, !i qet low add.ess byte
actdef StrPEr,9l acld chalacter offser
btfsc STATUS, C ;
.tncf PCLATH,I_ overflow - ucrement PCLATH
movkf PCL i low byte to PCL

l@? 65 .$olqN o&or,So8:


Liquid cryslal obplay(LcD) - 2

lourrut t rNsrRucrroN ByrE To DrspLAy

;CDins nov f FoRTB ; puc inslruction on PORTB


catt Clock
bcf PORtA,IcdRS ; Write "lnslruction"
call Clock
bsf PoRTA,.IcdE ; clock it in
ca1l clock
bcf PORTA,IcdD
; 5mS delay betNeen inslructions
cl-rf Derayl, ; about a 6ns deray G 4MHz
novlH th
nowf DelayH
cttpl decfsz Delayl,, F
goto ctlpl
decfsz DelayH, F
goto cE1p1

OIJTPUT l DATA BYTE TO DISPLAY

LCDdata novHf PORTB


bsf PoRTA, l cdRS
call clock
bsf PORTA,lcdE
calt clock
bcf PORTA, tcdE
, caU Clock
return
,
; CI,oCKING DEIAY - 20OuS @ 4MHz
; ---- ----
ir".* novr' 4oh
movsf DelavL
(dloop decfs z DeIayL, F
goto kdroop
retu!n
; ---------- ----
; MESSAGE STRINGS

Lesra., O D1 n-l to I ro- I h, ", 0h


hess.9e1 DT " t.rc16FB4A", 0h

I 1oo9 195 a{p131o o8,-.,5o8,


t
t
UquidCryslal Oisplay(LcD) - 2

s,,,,-,ss) .oc@e:qp,EeoTx.{ z sec .i.-{,i&,&, go5eosqcso?.,sG66ocgerE


Main Prosram Loop ? codeLoop subrcutine c{ eorc8cjlsa{€: G3;o€66i.-:Jr:q,jldJtr
4.oGe
% sec deray subroutile .+o:2!,
"{oq;e,\o:6apep%e Edg.3cDd6o,,t-1,$i
-

r,AIN PROGRA}I I,OOP

display nessaqe nuntrer


display nessage nunber
calI BiqDel Hait 1/2 second
clear the display
caLI LcDlns
calI BiqDel wait 1/2 seccnd

% sec delay rourine


?. 6i"?o5o1a4€:G6dlrrdr

ABOUT A HALF SECOND DELAY G 4Mflz

BiqDeI clrf Delayl


clrf DefayM
novlP 5h
novwf De1ayfi
BDloop decfsz Delayl,, F
goto BDIoop
decfsz Delay ,F
goto BDIoop
decfsz DelayB, F
goro BDIoop

G-cAn LCD in 4 Bit Mode

LcD modlle c{^ctc QcrSo{c6{co{cu:t3. €o.63,3i:G1ccrro?a1 ptc q3E uo


*11?:6 ..!*yfS6q;.9€ e bit mode interracing frdr: 4 bit mocre inGrracing io6
'c,i
bri:q$€olLrdn 4oi. 4 bit mode 43'3t:EjLora:o?a1(?e Rs rE. E o?.ct3'3i:Dtq0:,
eealcqdqp:q€ D0 to D3 4..8 o1:G1.S€.q6cr,.ri Da to D7 o?.c,?3), 3?a:G1qicqo6o1
c)el,, 8 bit63o-,4 a bit6€3, nibbte 96iddcs:S:Q.ec,:qoL,gu
a-b( mode src3.6 source coae eeprrlc,SQt :$el I bir mode c r,5 eel ca:qrBqp:
- 3?GofuorEc?d@doe:n
t3. LCDdata subroutine q€. LCDins subrourine
4..{ ."f"9-4.61

Jooe $6 GhdtlN
tiJara9' {per5"so'r9p:.t 4 bit 661)' niuote 951 @6e3?:3 moaig (.?6eo:qollo2lrr
rnrhsetion code f3. Function set insiruction 4." d-Sd,."s e@3:oi9$@ciiar$rr + ort mooe
,,"sc6 oo6co3:o:pleo:.'5Q.{ Q(G-oe)"63 6oT$co':ol",d'

Q(6-c9) I tit moce caq.8 oc8co6:orplecociQ

cacorAolricA8 Rs 9E E 4.c,? RBo f3. RB1 o?.ql€ 60o€!ots6D!teo5c.":6@t8:


Do30t6oc$o1 od n

LCDdata gE
bit $6a'r nibbre t6iG66s"re modify e8co:qdlcelll 4ol&La AND!W
instruction of.c{ caci,$@qcn o$l

oco(Dor ?.ao?c:or6l!4.c!qP:oe 9c,'rcr?cri9cD

; Dill{O Ol' 4-BtT MODE


Iis! p = 16F64a
: include "P16f84a.inc"
_corf iq h'3ff1'

r..? ?f5 .{i"lEN -.ct, o8:ocfct:


:D.s,(G) Liqdid crystar Dispray(LcD) -2 Prc q.'a{C2i@6o ol.qjocto6:qp,(9)

; CRYSTAI = 4Mtlz

EN OC

; RBo = :CD !,S Fin


; RB1 = I-CD E pin
r LCD Rii FIN IS TIgD TO GROUND
; PORTB 1 _ ? = I-CD DATA PINS ,1 - 7

I FI,AG1 BIT DEFINITIONS

LCDhd equ 0h

; CODE START AND INITIAI,ISE PORTS

olg 0000h ; start address = 0000h

; PORTB = all low


; PORTB - all low
novHf PoRTB
bsf STATUS,RPo ; FAr.i Page L
; PORTA = all outputs
novldf TRISA
; PORTB = al] outputs
novwf TRISE
bcf STATUS,RPo ; BAl4 Page 0 l

novLw 20h ; 25nS Fckerup delay G 4MHz


novwf DeIaylt ; LCO cla:a sheeE says 15nS
clrf Delayl
PUPD decfsz DeLayl, F
goto PUPD-
decfsz DelayH, F

Joo? 6 akdiN
! i:(6) L,qu,d crystar DEpray(LcD)- 2 ptc
Q.6e{(8{@6c\rr e5i:epo5oSrqF(9)
gotd PUPD

SEND INITIAIISATION DATA TO DISPI,A'

clrf Fl. a91 ; send instruction as 8 bi! node

novls b'001100001 ; funcEion set I bits


ca1] LCDi.ns
novlw b'00110000' ; function set I brts
call LCD.ins
novlP b'00110000' ; funcClon set 8 bits
call ]JCDinE
novls b'001000001 ; funcEion set 4 bits
caII lcDins
bsf Flagl, LCDnd ; do 4 bit node flof, here on

novlw br00101000r , function sel 4 bi!s, 2 lines, 5x? dot fornat


call l,CDins
novl' br0OoO1000l ; disPlay = off
call I,CDins
novlw b'0000000I' ; clear the display
call LCDlns
novls br00000110r , increnent - no display shlft
car.I IJcDins
novlw b'00001100t ; dlsplay on, curso! off, blink off
caII LCDiDs

i -------------_ --
; MAIN PROGRAM I,OOP

Eov]q 0h ; dlsplay nessage nuniber 0


cal] Messl,inel ; on line 1
irovlw rh ; clisplay nessage numbe. 1
call MessliDe2 : on line 2
call BiqDel ; vrait 1/2 second
mov]H th ; clear the displaY'
caII LcDins _; i\'alt 1/2 second
call BiqDel ,

SEND !4ESSAGE DATA TO DISPI,AY

ten\p stole nessage nunber


lrtovlN 0x80 s!ar! i,CD line l a.idress

tcmP store nessage bmber


novtu 0xC0 sEart LCD 11fe 2 address
ca 1I LcDins alite ic to lhe LcD
9ct stored iGssage nunbe!

?e5 4{olqN -r.3- o8,<ocrSo3'


+'4:(G) Liquid c.ysrar Dispray(LcD) - 2 Prc i.6o$.Bq@{@ a+:flooqr\r3:qp:(9)

MESSAGE O

FovI! Hiqh (!essage0) 9e! ROM Page


movql MessAdda
ntovlw tow (Messa9c0) qe! Paqe .ffset

IIESSAGE 1

High(Messagel) ; get RoM pase


MessActdH ; tenP stole il

mov-lw -oe Li.{essageLi ; qe! Page offset


cont!4ess novwf MessAddl ; tenp store it

GET CHARACTER INFORMAIION AND WRITE TO ICD

zero lhe characler offset


l4essLoop call uessages geE ttie character
movwf tdP temp store the chalacter
novlu niqh{S) rescole PCLATIT for this RoM
MOVWf PCI.ATH
movf temp,I'l
xollw 0h tes! if zero byte
btfsc STAT0S, Z

; Yes/ al] done


caIMNata send chalacter ro display
incf StrPt!, F set ready for next character
goto vesslooP ; get nex! characEe!

; CHAT(ACTER ADDRESS CA].CUI,ATOR

lressages novf ltessaddHrrl high address byte to PCLATn


NOWf PCLATH
rnovf }tessAddl?W get low addre5s byte
addwf StrPtr,li add character offset
blfsc STATUs, C
incf PCI,ATH, E ovelf]of - increnent PCLATH
loH byle to PcI

Joog ?tE c{roilqN


rl:(G) L,qud crysrar Display(LcD) - 2 Plc Eo5aQo8l@io oci:qpo!NS:ep:(9)

OUTPUT 1 INSTRUCTION BYTE T(-] NISPT.AY 4 BIT MODE

lcDios novuf tenP temp save instruction


andlw 0xF0 send hrqh nibble first
NOVWf PORTB
call Clock
bsf PORTB,lcclE
cal] CLock
bcf PORTB,ICCIE
call Clock
btfss F1a91, LCftnd test if sending byte or 2 nibbles
goto bitsS
swapf tenP,li now send ]ower n$b]e
andlw 0xF0
NOVWf PORTB
calt CIock
bsf PORTB,IcdE enable instruction
call Clock
bcf PORTB.IcdE
bits8 clrf Delayl about a 6nS delay @ 4MHz
novld th
nolvf DelayH
ctlpl decfsz DelayL,F
goto ctlpl
declsz uelayH, E

goto ctlpl

::::::_1_:i:i_:l::_::_31::il___1_:ll_T::
-acdala nc1,wf tenp ; tent save data
andle 0xF0 ; send hish nibble fllst
NOVUf PORTB
ca1l clock
,bs! PORTB,IcdRS ; tirlte "Caia"
call crock
bsf IORTB,ICdE ; clock jL in
call clock
bc! PCRTB, lcdE
caII clock
seapf tenp/li ; nov iend lo"er nibbte
ancllv 0rF0
NOVFf PORTB
call clock
bsf lCRTts,lcdRs ; HriLe "da!a"

rc.? ar6 6irdl.1o -c5?- o8:co.,5oa:


3a;:(G) L,cuid c,-siaL D,spray(LcD) 2 prc iri: j-iS:T:(r)
io.g.?ieip ,t,J

ca.i I Clocn
trsi PORTts,1.dC , enable insriuction
ca LI atock
bci PORTB,IcdE

CiOC(ING DELAY - 200uS.6 4MHz

Clock novlw 40h


novwf Delayl,
kdloop decfsz DeIayL, F
goto kdloop

; ABO0T A i:Ala SECOND DEI,A1 !a 4iriiz

tsigDel clrf Delayl


clrf DeIayM
novlw 5h
novwf DelayH
BDloop decfsz Delayl, F
goio BDloop
decfsz DelayM, F
goto BD.LooP
decfsz DelayH, F
goto BDLoop

MESSAGE STRINCS

lressage0 DT " This tCD is", 0h


Messaqel DT " in 4 bit node", 0h

:a LcD modute
t8:6q"c; LCD module Cp,"""@3,.i
c.r.:""..ir , S
-4,(c)"Be ."TE.a:
."TE.d o-sv Disita
vortmeier co3d6%.q6ai6,.rc33j:€a:jr

Jooe ?16 c4{oiqN o3:o,jo€:


6-oGrr LCD with PicBasic Languages

Assembly ransuase .43?3i,GLG, LcD qp:%3 oroi:qp:+6,,T$e-d3:6@.3:.4


o"or'5ca8 sao1,,5-o3. a'rQa&,G6.oo:d, PicBasic f3. PicBasic Pro lansuage {..'?
.,;,fgr4-.i,G@' LcD qp:%e ocoi:qp:eeoTepcee .46o,64963rd:cu insiruction qP:Ge.
'o'..e 'oae
n"r..,.,$3Qci :o;-.6o-: I r"ll'
2x16 LcD module %3 4 bit mode 4-"i,GfE,"ae "Hello" "world" (j?63)r orc.)$:qp,
cd o:.9t9o6Lrr6o6h Hrctrasrc 19. c?,r.trr Fo?-:66i:t( 6oDl9' LLU fc. 9.D.Q%6co$curc.?.
o.SqtcSnqp:"i source code e'5saoQ€'caf cDd,SI'""f$c,r,:.jlld.

' o-cG-crr With PicBasic-

' Denonstlate operataon of an ]-CD in 4 bit node


' using PicBasic language
' ],CD should be connected as folloss:
LCD PIcnicro
DB4 PortA.0
DB5 PoxlA.1
DB6 Par."A,2
DR7 PortA - 3
RS PortA.4 (add 4,lK pullup resistor to 5 volts)
E Po!tB- 3

' Vdd 5 volts


vo 20K potentionele! (or qiound)
' DB0-3 No con.ect
Slmbcl Port4 = 5 'PortA is legiste. 5
s.,rbol TrisA = 985 'PoriA data Clrection is register heradecjnal
a.,a!.i L.de - 3 '1cd enablc line is Pin:l
rcir€ TrisA, 0 'set all PortA lines to outPut
Loq 1..1e 'srarr lith Iccl enable 10s
Gosub lcdinit 'initialize the lcd
loop: cosub 1c.1c1r 'ctear 1cd screen
Fo! 84 = 0 to 4 'sen.t string to 1cd one Letter
Lookup 84, ("Hello"),E2 'geL: letter fron slrinq
G.sub lcddala 'scnd lctter in B2 to lcd
Next IJ4
Pause 500 'irair 5 se.ond
Gosub l.dclr 'cIear 1cd sc.een
For F4 = 0lo 4 'sen.l sirrig to IcC one lctler
l,ookup E4. ("No!]d" ) ,82 'get letLer flonr sElinq
cosub Icddaia 'send Lerler in ll2 to 1cd
!'aus.5a0 t ait -5 second

roo? r+6 eifJqN .re-


-e;:(G) -rquid crysi.r Dspray(LcD) 2 Prc io-\a{Aie8.u -i,n""1.!3,,ij.{r)

' subrc!iire to ifitiaLize ihLr t..t :::s:2 an.] Ill


Ic.li.iL: laise 15 'a:ir: at least 15ns

irolia rrc.LA,: 'i.nr.i:alrzE the 1cd


Coslb l.dacg ':cqgle :h. 1cd =i::ble lr:!e
Faui_e 5 'iiait aL lcast,l,Ins
Pole l,oriA,: 'rnrai.lize the Icd
Costb lcdt.J 't.q_q-e the Lcd enable lin:
t!ii r at least 10ous

Poke PortA,3 'initiaLize the lcd


Gosub lcdtog 'toggle the lc.l enabte line
'lraii on.e nore for good luck
Poke PortA,2 'put ]cd into 4 bit no.le
cosub ]cdlog 'toggle the lcd enable Irne
82 = 52A '4 bit node. 2 lines, 5x-7 font
Gosub lcclcon 'send B2 to tcd
B2 = $0c '1cd .lispla]- on, no cu.sor, no blink
Gosub lcdcon rsend E2 to lcd
82 : $05 'Icd entry mocle set, increnent. no shift
Goto lcdcon 'exir through send tcd comand
' subroutine !o cleai Lhe 1cd screen - uses 82 and 83
lcdclr: 82 = 1 'set B2 to clear comancl and fail through to lcdcon
' subroutane to send a comand to the lcd - uses 82 and 83
Icdcon: 83 = 82 / 16 lshift top 4 biis down to botton 4 bits
Poke !o!tA,B3 'send upper 4 bits to 1cd
Gosub lcdtoq 'toggle the lcd enable line
.\
B3 = B2 & 15 'isolate boaton 4 bits
Poke PortA,B3 'send lose): 4 bits to lcd
cosub lcdtog rtoggLe the lcd enable Line
rwai[ 1ms for qrite to conp]ele
Return
I subioutine to send data to the 1..1 _ uses 82 and 83

lcddaia: 83 = B2 / 16 'shri. top 4 bits down to bo.tom 4 biis


tsl = 83 + 16 Ia.ld in reqister selecL Lo indrcate d3ia
loke PortA,BS Isen.i uPper 4 bits to lcd

Joor ie6 o{qoitEo


,d1:(6) Lqu,d c rvstal DsprayllcD ) 2 prc
{da{,€ioi(u oi:qloo:N6:ep:(t)
cosub lcdtog 'toggte rhe lcd enable ti.e
B: = 82 e 15 ,isolare borron 4 blts
B3 = 83 + 16 ,.dd in reqisrer seLecr ro rrdica:: dara
loke PoraA,B3 ,ser.1 loacr 4 bits to 1cd
cosDb lcdrog 'roggle rhe tcd enabte line
pause 1 ,wair :Lns for write to conplere
Return

' subroutine to toggle the fcd enable Line


Iccltog: Hiqh Lcde 'ser lcd enabte line
Low l-cde tsei 1cd enabte line high
loq
Return

G-cG-1n With PicBasic Pro

,lcdpro.bas .. J .,, '..


'PicBasic prbqiamrto denonstlate operation'of an LcD in 4-bit node
'! Using PicBasic Pio language
LCD should be connected as folloas:
' LCD PIC
' DE4 PortA.O
DB5 PortA.l
' DB6 Dort^._
' DB7 Po!tA,3
' RS Po!tA.4 {add 4,?K putlup resasror to 5 votts)
PortB,3
' Rli cround
' vdd 5 volrs
vss
t' vo
cround
20K potentioneter (or qround)
I DB0-3 No connect
Pause 500 ' !,ait lor LCD to starrup
i.op: i-cdour Sle, 1 ' ctear r,cD screen
tcdout "He11o" ' Display tetLo
Pause 500 ' I'iait .5 second
Lcdout $fe, 1 t clear LcD screen
l,cdoul "i{or1d"
Pause 500 r 9iait ,5 second
Goto ]oop ' Do it forever

"Hello" oce@s:c{,r-,rc$3:%e.,),re:,,worrd" 016@.€:4


r;i" catr mol3ao?€:G8"ol6.t,r.,.:8f .; .{r
?c3,))cg6:%S6oTcocF

<
o1d e
#{dG) Liquid crystal Display(Lco) -2 Plc qo5+{c8{@{o -.7,it,,o5.s6,qp(t)
500
Pause I tlait for l,co to startuP
toop: Lcdout $fe, 1 | clear I,CD screen
Lcdo'rt "ge]lo" '| Dispfav He.l]o
Pause 500 fiaiL .5 second

Lcdout Sfe, 1 ' clear I,CD screen


lcdout Sfe,sco ' Display l{olLd on second rine
Pause 500 ' llniF .5 seconcl
Goto loop t Do it foreve!

9o51c6r,,
. > PicBasic Pro otsa3i:G6€'-d QQ<rXEcu6c33o2l:9fie@€'ec6.qec'ogl r

! ocociol eicsasic E€. PrcBasic Pro u{o6i6qp:.{ c,e$:!)ca€""T$-:,eoc


Microcode Studio IDE %3 Compilation and programming Qo?6$€eooeg
> ,,6oq6ep:o€ae:c{
PicBasic Pro c3r@:c.rq8e Tor?:ca06€."S -6o00$tl1
e@,t: @or€oc3eo:o3o1o$r

foj 1qi ai{ol{- -5JJ'


, j!:(o) Anaroe lo Dis,tal conversLoi P c {c3c{,"i@6o on,Ao.6o3;qpd9)

@agd?)
Analog to Digital Conversion

9-c'r {s1f'

Analog to Digiial modute rilo8eo: etc Qo5a{c6$co{o:gp:( P1c16F873, P1c16F874,


ptc16F876, Plc16F877.oodd?.) ud
seSqcecu:.ooo:c{ 36q6.,,r5or6q: 3:G6r9.6@c3:c$
so:[€eoo2!rr oSqcec':a.c'f a6.2l6o,,rsa@3eQ'?3:o5@:cr2n8 6t66o,o*{,.'? LcD modure $:
6€.6oTGq3o1
a>dil E3"r:o?3:dqo,qp:, sae{$cfl €:c8{u>cqp: r c6et6o'osQ.Eo-r,p:... osal
4..i @d.-'"E"p%€ o4dqc6o{%i{o,rqp4 LcD modure qp:gE.o)oot ori:G1$e
e,.,rp!r gfsae{:%€ Plc16F876A "{ 2x16 LcD module t3.Qoc6E: o-sv c6q6o:dQ.Eo:
o'd6:D'.6i3r€Crl.i :aeo,36eoT[oleplrr PicBasic Pro {*"i'GG, PIc16F877A o?2r20
Lco module 98.o)o.'58: Aoc {3:-,caqp,Qro?8$€,ic{cud: sao?E:Xt6or3@co::o1o2!rr

?-Ji Successive Approximation Converter

otqcoc,:c.Q.rac{ c6.U6o".SQ.o-,-@6.@€:o9cae qa::3?{1:ft:{3rd34aE Prc


{c6e{c6qcD{orrqp:ae8 oci:Q1eo:Tei:p Successive Approximation q$:@6o1o$r
49d:Ge. 3,egoco,'Q.ra::c{ cdq16o:cSQ.ocrmG6 cdal.60;E:6+cA 3,cgc6o?4:{.:o:d
oe:.:cerilc6eoqQ Analos to Digital converter (AzD) oc@e:{
=:o1j:e[8$eoT$oleelr
clc Qr6o{ca$co{o:aqp:e>e9 8-bit device ep:G6@€3r?€@r3. o3:{.o2) o-zss
oeccosaq3: rx93og6$3@ardil ::c/rosd A2o ::p)co$: 8-bit device G6qi3 soe#92
6o,'.Q.3,r:.,?rodp: o-zss ooror:aos€:$ea:: s6q6o?o5ollq:4 a@E,eo:$3eoo96p2!n
3i{16r, A2D qp:::$ lo-oit, 16 bit device qp'G6@3)dr A2D ce€ bil qp:qn8 aqES
o3o?! tesoluton) 86.,,e:d3)dn Plc16F876A 93. etcterazzr 4..?:to8o, A2D arei
10-bit device
Ed€rrGE e. *.g.;"5q6odQ.3--'o{'r.Df)e9 0-1023(oo00h - 03FFh) s? 31
qil3..-d'
successive Approximation Ep!:@8. o€qoeo'.Q.r,:,.{ e6rilEg?osQ.f,r:rr@6e@€rcn
9q3 oe@s,io€.rsl 3'3$3'83:qp:o? Q(2-.)q€""T@."r,.;1":$'
saoS:a8gcetl::.Q.r,::ar2! -.,$8o,.c{ 'charoe c96dlop)rr Acquisition rime ot
samplins rime,;1eaTa:pi :a{$ceQE:a@::o:Qc2$aQ,eo:oa1 3'oeE.3"r:cl mooS6ar:
9€.
ooc6::e3c5@c8cQc8p: o:o.SEo::q€$aE"oc aEo6<.'ec-c{ or2!@3e@ {steadv state)
qt noto caSco:,arpll SleSci,oi.i sampre and troto qeaTo2irr .no,.:S6o-rcg8@6e oT
curerrQ.r,::.1 comparator r"oSgcSodqcaScopi33:eo:coc:o2! r Comparator
"o5o3:er5
.:o5cu8:o\ :a@r:oo€qc8o;1ca8 :6Ql3o:u593?€q.ec.>r.4.c@€:e3roo6cD6: Disiter to Analos
conveder (DAc)
9 set oTSeorea;:Q.ra:cf m2! c33:eo:ccar op)l
42o oo5cu6:9 ari:GtF€6]r2 3'S':{:36q6orc,5oiQ:oocco-5 cocSoo6@6eoa o:QQ'
.f r,4sB goo:€d sei oiSG: DAc ,,J3:3rd 10 bit converter
"o8co6':Q.co2i:g3:eo:dloJdn

joo? iiS {Eidt..rN -eJ?-


4('|j f91"!9!rcry: Prc $d"{ei-ri- -+'
3a%d 512 or 200h (Qd3?]:1q3. 10 0000 c0o0) G8-d' 4"i.01e36,.?.cScompararor al
-c€o58;, 4.d3Edolod' 4:'csdQ3,xd-6Q,+i,".r\i D.{c a.?
j o'-i.D€..3):
bit .A set ai6G,J:lg: DAC ? ccnrparrior {.6",+:,"rDQ.r,,-? re3.-3-,
"6,x3-.5
,ilrtrd, ( id@:GS. I I oooo oooo; ."-.f $ con,parator o\s:qc3Q3,%3 -i$,rd,?6..'qi3
Dec c63 opcAors o:€D3.G3..!) :6q5ocS u;t .A set e66o,Eq"1.rdr( ,7ao:$3. I I
1000 0400) 3,mcSFtr compararor elocsciQ!,%i oriq,rl.,a-,"ui e9;::{: t {. :ei .13;.
63, bii ci 0 4. 0qil8,, €e..6o8 brt 4 1 {. set or36o:.jl3rd I (Qd3':[43. 11 0100
0000)

Vino
lrinl
\''in2 Sta't
virf
Vin4
Yi5 Uutprt
Vin6
Vini
Ch0 select€d

(A2D) o.3oJ6:s6653,833"8e:qP:+
Q(9-c) success:ve epproximatjon converter

nrc Qo6a{cpQcofi c',:ep:.:e: A2D co3cD6:3"c!0cr3s$:?%.5 crock sLsna .{cQc36o:


til::$, conversion o16l$5|!:6G.':$3,%c'5 l2clockcyclec\i3?Sdl3rp!',r3:c{ conversion
rme q6alul3)a9r
oco.6cllQ(e c)ca3 -3q,eM.-.3 channer te.cjlsdoho? 6oTG.-'o1c:d'
Prc16F877 %3 channa e Eril$p:, Plc16F876 (ZE cnannet s 1:::ol $ci1r2! r .':3:oi.cf /
eo51,jl.3 RAo, RAl RA2. RA3 t3. RAs .i.,ze D3i:Gt$8,jl],d,

9-1rr Cirnversion Clock Speed (Tad)

3'3E46o'.$.3"''4 36.dso,cs$.3-'-G6€0oe:dq$ qd6q%Eor$o,%3 A2D .4


sci:01c:d3?o1 3,3e46cv,.Q.3'.,.4-dr:,,ri *.i,Gpd channer oi €:s.6€:qlosoc8eos
qoloa:r 3'coa6,ilQ(9 c)ca8 channet 0 o?6s:qloscco:o'13Jdn controt rosc odcu6:9 sampe
and Hold switch .4 3c'56o,13, -"d3",4 channel 0 6qep%3$eo,Q.o:c23 ctrarse
cf8codlrrdr Acqu srtion rlme .!{n;3J,'e3',3,a1sample and Hold swltcn :r2! g3.:3c:@:

Joca e+6 @h.iqN


*i:to) Aiatos ro D srar convers,on Prc qdo6,z$@{M oci:qpo5o6:qp:(9)

I Comparator
iQ:o? -3.r
cgdeoTcD.
63,,: s6r16ocso$Q:r:a: v,no cB3o3c6p.;cw,.l>: caspec.::. Q.3:c:o? .4,rso':Gprodn
Sn4c.6 cor..o -os.c-ial:' Lolvercbn 8:4:sE€,4 :a
j",,:,',j r'rdo' co,verso,
rroc) caaldG{ cao36r:ixd, Eoc 4 software G3. o66-,.36$3c'13rd' slid,G8.
:5q6oc5o{Q,ci oor{E:6r
- 6
oqoqsqr'%6 cEd,,4 :ar,Gr{} 6,6o".,.c:dn
A2o oir".i:Grxairail r,.3Qrdc8E2.rod3,qj.33"{1.'? orSQolsd, sampre and Hord
moc$E',$d .o,.36,c'?d.-q.3,:s,€orc3 q13od:33:eca€ 3a{6or6ioiqolc:d,
orn,.,5$ o€'mocSSo-,:61 charse/discharse c.,5:6@4:%e o4:€oc8e5q3?qp:e@o:6oT6o1rr5
c{q € A13o6383'"p.S€ 6f:?J,:g: o?d63, source voltase :acaci c2$ecrqq6o6 cq$$8
eo,:eqlr {3aa'l nzo eocSqq$e3,Q.3-,:o,4Q:]]d 3,aiq.3-,:olqQ:cori eqp.gg:e1eo
og8pdn 46@13. Microchrp ?8.!5m source resistance c$.er-'1c6 source impedance c'?
roxo co.5"eoT5cg{eoqg uc3go5cor:dcrd, 4.3"G3 3,Q{4fE input capacrance d$$:
A2D e,L,c8.3.,$Q,.,? c8q.,s$3;l6rr:oG6. o:3:oi.c{ oata sheet qp:ca8 eoft
"?.],do)a!,
co::q1c3qp:cfl
"-.-@deG, osQcsq,jr3)dn
A2D oc6N6:3rd Q943'e6e3qis?%c6 ctock o€e13:o:61c$s:6<,ilo$rL conversion
or5@68:6@rc36t$3:%.3 12 crock cycte.,?sSol:ra:, ctock eli o{qe8::$ @$$3r€6l@:,il
-dil 3,3,,S6@"3.4615 A2D rrlodure trrd c8o8oncas,e6eS€3q1.: aa2!:aQ:cgo3 d
63' conversion crock speed m$.-c3ato66cEctr €@.3.G6dtrrdn(De,o4q:3,d *+d,"i,
1.6f s per clock cycre $q6dG6Jl-dr
-e'-fQ,.A rad qeaTcil:r:p!rr Q(r-.1)"a3@d.1'

Clotk I Clock 12

Sta't
I I.6uS
'(
F.oc Llir_Linrurn

Q(9-1) rao .,"39"5q

3",Dcssl Q.,5a{%4o{c.,oei aMHz G3. 3,e3e36eoddel; A2D rnodure 3?%d


rad ])e: 250ns (= 1/4rvHz) G63rd, or3:"rd 3,9d,.i,c$3,3qtd 16us coc6qp:s,*9.,.
s$'"f-d'
43]Er.,sc,? ed:l)qe5:G3. .G5)€,966o3rd,
ocoe+a::gr A2D module (%€

{c$,Dq;1i
".i".flrd,G;-d ilr-r)ca€ p
Tad op! zsons:. sz a"s =
9p, g,e
"rpc8g,,f
or g,

1oo2 +e6 egqcjt:io .J!-


$a3:(9) Aneros io D,s rar corvercion Prc ics.i.d@{o se,aloo:o6:a:p:(r)

i(? l) ?osrscaler +

rcS,Drd:9" qda{%$co{c\:o{833'%€,5o,d€".ac3co.:cr:r ntemar Rc oscirrator 9


ctoct< c{ ocl:Qpq913 rad r:a: 2Fs i3. 6ps 3"@r:6t6$errg), crip o3193. or61s:@::
c6:o1c,5e€. 3",i{q60D3:a;?o?.61o.3.,D€:cDE$:3rd 3?6G.3:3?d066rcrr3cDd, -qd,"i,
ct3?oqtcD ,.o.rs cocDlg:e6]):r.,tgc. 6orja9 n
"'rr: Lrrt+c

?-9r Quantisation Error

coS6d3rcS@rqods?fl.,5o3{der ouanrisation rrror qeaTrs)o$$;oEG6a>d, Prc


torezon Qo3a{r6$co{o).dll A2D arai 1o bit converter cD8QG661,]6@.3. oJ€,3)d 46rq
or$Q: 102a .{ 0 e 1023 @d$6r, step qp:Ge.8€:6c:83Gogeud, s,,.Sd A2D a)e! 0 to
5V o?4erored{qlJ8 step o:5qq3:oeE9€. s volts/1023 steps or4gmv per step o{Q:
cGoS:o;?G6cr6ordn o,6qd,3,,G3. A2D oE) step of1o16gs:@r: + emv -qQ,"G"3'";
9.'lo: coc;,seaco€6cB$€G, 4smv o$Q,codccs6J, cDc356.o.3s.'5G€:
"o]e,d?qp,"i
"0{e*'
?orr:Loc,- 3?cY)6or.atoc9.!-r:o-9q:3)E zYlb vols Eio3rP.?uLe.' uic:o-/t9:.?
ezoa:$ sdq6o:c6cip@€'q1€ zortr loosoecl C."TE*.d'

60e c{ 3?3q,6cDr$66&3:@aiet3 (60s/1023)x5 = 2 e76 vo ts ci qeoeei r glca8Qc.,


o,$8:f8.oqdrco5%.6.:?66q6@,3:6€s..l6o€d' 4.a"&'1dd euantisation error u2e iI
dl]Jalr ouanusatron Enor c{ecapog!,e"c$96 uit qp:qp: (ao6'" 16 blr, fe.3?coc8)3?3i:0t$3
6r, A2D converter{t:.{ 6S ql,JS3ni: Ettrr8.coDelj r
I

looe 113.{q.1lo .JG'


m€3)' oelgdlJ+qJJc:r,o)qr:ip:+ ooXj:ejn3r,:G€. rsf
LcD modure f f .€oo3E:3?+:GG: 0 5v 36q6oro5Q-3o,
@d@d{.,

?-Cr 0.5V
Digital Vottmeter

.4 2x16 LcD modute g8.c6oci@: o_sv :6q6o:c.5Q.3o-a q)2leoccfQ


- "l91utg6l
4 oGD:336oTG,isd,, i(r r)"a8 o_sv 36q6,;q€ -;"i;,*1"sq.4 la6_",
.;lo$'

ftiE !- Re

s i;t

osc, i 3 6

Q(9-9) o-sv oisir"r votrmeter oo8coS:ar2)*o:c6Q

roo.-.e e qo4"1o3qp:9€.
.. " 1o,
bnot],e,
:o
prc16r 8764 si io,+Jtotqp:9o
Qi,c6,6"oras.;qr"6qr.,d _"6d6)"nss.[;e,
.',oi,' " " -
"_."5.j1J(?_C-"?€,b;j

,i(2-3) ercrorazon e)l qd4dlcsqp:Q

:
t."2 19a.+1Aq-
sol:(?) Analos 1o Dlsi[al ccnversion

7 9€. atrc533cs co.r: o;t _a! , LcD


3.6o:cor,dlodr write nrode .i
.jt-d,
c39.6cD.:E:, *3r".",.
RA1 9 LcD 3r%d RS

3'E.''98qed"i5c$,,iqp:cf 6s,c3o13"43:

Plc16F876A c{ initiarise g3@3:


moduted initiatise .\?368:
2x16 LCD
. A2D moduled confrgure and erabte q3@€:
"volt mete/' messase .{ a".1G3,
i6oT3rdorqE:o? "x xxx vo]lr +d,G€.colEEe:

A.Q6@.d
.odcD.n6(J
*d: ee3'coc$il3?E1"33?cD"3,ip:.f
I I tr
source code %S cod?sS,6"ro,",+3:.os..o€.d
L9'r

g-9-cr RAM Definitions

_ _p:go
source code crf-9q.er::@:eqcc6 cBLocK directive .{
oc1:Q1p: nAM defnitions -6,'-4"-j6, rco oq.S o4:eo2j
Rs 9€. E o?.4 equ direct

Title "Diqitaf Volrnete!"


Iist P = 15F8?6A
include nP16f 8764. incD
; CRYSI|AL = 4MHz

; -------- ----
; RAI4 DEFINITIoNS

CBLOCK 0x20
DetayL
DeIayH

:
.Joo? ?t3 ol+olqo _rJ6_ os:@oSo€:
,s{d9) Analos to D,starconveGion P c {.to{q+@fiM o.i:qloc3o5,,rpd9)

BCDvalir
BCDvalM
!cDvalL

shiftll
shiftM
shiftL
ENDC

; R\1 = LCD RS pin


IcdE equ 2h ; RA2 = LCD E pin

; IJCD RI'{ PIN IS TIED TO GROUND

; PORTB O -' = I,CD DATA PINS O - ]


; Pin No. Sgnbol Description
; I vss Ground
t 2 Vdd I-ogic supply vdd
i 3 Vo LCD CONTRAST Wiper of 5K pot connected between
5V and cND
) 4 RS RegisLer Selection RA1
; 5 RW Read/I,irite
; 6 E Enab]e
) 1 DtsC Dara bit 0 iiB0
; A DBL Dat. bil 1 fts1
, 9 DB2 Dala bit 2 RE2
i 10 DB3 Data bit 3 nEl
i 11 DB4 Data bit 4
: 12 DRs Daia bir s PE5
; 13 DB6 Dare bit 6 tE6
; L4 DB7 Data bit l
; 15 No Lonnecrion
; 16 No Connection

?-J-Jr Ports and LCD lnitialisation

3e8qcccu?.E..".,c"drS3;"o'"d *o5ed+8. LCD module f€. .od3,$ Ga3i:GFd


port qp:r{ rnrtiatise e6q,isdn 46{od LcD modute %e ,i6oTff"%o3 oh?6ql.6qp:
[9b6f,, instruciion setup. dala setup, delay subrouiine setul c{co2!: initialse o?6qdl€e:
,D3:o?.c,?eerc8ci3?o?3: source code
%3 3?aDe..o3.codrB3,66rr,:61016d,,

J..? ad6 dtclis -...ir o3:@do3:


@4d9) Anaros ro Disiiar conveGion prc qahg%i@{@ o{:iloo5N3:?p:(e)

; INITIALISE PORTS

start novlw 0x0 0 iroliTA = rll 1ci


nrovwt PORTA
novlw 0r00 PoRTB = all loli
movwf PORTB
bsf STATUS, RPO
novlw 0k01 PORTA = a]l oucputs except fo! RAo
rnovwf TRISA
novlw 0x0 0 PORTB = aII outpuls
movwf TRISB
bcf STATUS, Rpo RAM Page 0

cafl Deray25 25nS delay. LCD dara sheet says ItnS


;--------------
; SEND INITIALISATION DITA TO DI5P1,AY

Rovlw br00110000' i function set I bits


call LCDins
novlw b'00110000' ; function set I birs
caIMDins
inovlw b'00110000' ; func,tion set I birs
novlw b'OO111OOO' ; function let 8 bits, 2 ]1nes, 5xr dot fornaE
call LCDins
novlw b'00001100' ; displ?]/ off, blirk off
caII LcDins
novlq b'00000001' ; clear the clisplay
call LCDins
novlw b'00000110' ; increment - no display sh.ift
cal.l tcDins
; OUTPUT 1 INSTRUCTION BYTE TO DISPLAY

LCDins movwf PORTB ; put 1nslruction on IORTB


call Clock
bcf PORTA,lcclRs ; W!l!e "insrructio
caII clock
bsf PoRrA,IcdE , clock it in
call clock
bcf PoRTA,lcdE
;5ns delay belleen instluctions
clrf Delay'. ; about a 6ns delay !a 4MHz
novls ah
novwf DelayH
ctlpl decfsz DeIayL, F
9o!o ctlPl
clecfsz Del ayH, I

Joog er8 c{rolqN -5?o- o6:o.6"8:


Analog to Digilat ConveBion

OUTPUT 1 DA1A BYTE TO DISPI,AY

NOVWf PORTB
bsf PORTA,IcdRS
bsf PORTA,lcdE

bcf PORTA,lcctE

CI,OCKING DELAY - 200uS c 4Mttz

decfsz De1ayl,, F

.eEurn

25nS DELAY 4Mnz


"6

Delay2S

ILIPD dec!sz DelayL, F

decfsz Delays, E
goto PUPD
retu.rn

?-C-?n Display the Voltmeter Messages

_ {.ydsetup
:o€goeal:.$.ar98 $ec:r 36q6cr:,iSor${:.,?6Jf!6}i LcD modute cae Dr
o261ci{'p!rr (-"idc)qr8
:,:1'""" lgE'. Dr directive s?]?:Gl+eg,4 *"",,E6$e;*€,b.
U:t9dorodD
, _ -j-.3G, Lco_modute oee ocosc$€:f€. roE,DC$8.4.%S messase qp::acar6
c{6pqp:c,?r,o6ec6qdl{'d!
'16,,r€o€d

Joog ?r5 a{rolqN -3?J- o3:ocros:


Analog lo Digital Convetsion

; -- _-----------
; DISPI-AY MESSAGES
; oxFF in ]ast position mea.s

Dl"sp1ett novfMessP!,W
addFf PCl,, F
DT ( 0-5V ) VOIT_METER". oxFF
DT "volTsr, oaFF

; DISPLAY THE VO],T METER MESSAGE ON LINE 1

moele l,ow {vMness) ; { to-sv) voLT_ i.lETUR "


call DoDisp]ay

DISIIAY THE VOLTS IJESSAGS ON L]NE 2 - CHAR 6

novlw 0xc6 daia stalts at characEer poslrion 6


call LcDins
novlE I-ow (vTness)
call DoDisplay

; DISP]-AY TEXT

, Messase address offset is ln w

DoDisplay novqf MessPt


novrw tow (DisPTextJ +
subvf MessPt, F

DoDsl,oop calfDisPText
xorl! oxFF
btfsc srATUs. z
return
xollw OXFF
calr l,cDdata
incf MessPt,F
goto DoDsLoop

Joo? ?+E oE olEo -5?J-


,{q) A"a Prc qosa{.a4o6M
"9!!!!f!15119
g-g-t( configure and Enable the A2D module
A2D module f6. aodoSgl sae2:Q1coc:ea;: resisier 3?cc.iqp:qp:$dlD2!rr glodqlc'5
qS ori,@1co:,eoo resister q?:9: €a:.6c,1 s?48:G6,jl c:d,,

ADRESH A2D result h19h


iTCRESL
DCON0 a2D contlol register 0
Ao.oN, A2D control legrste! I
PORTA A2D input pin (RAo)
fRlsa A2D pin (RAo) set as input
sa3qceo::.eo€Q.o::c{coc35spl PoRrA €i RAo c{er,:c6o1 coae @3, oo5go8coot
.;1c,$'
; PORTA = aI1 outputs expect for RAo
mov(f TRISA

analos channel (9)


Q(9-c)caSeorp;c:$o{E: Plcl6F876A Qc6a{,"$cD{o,sa%c6
e{@3:e%a;qe oa)alll
Sl.{q"8"AE channel 0 (RAo) 3lci:EFor:dlDdil PIc qdo6.B$co$orr%e A2D
4
ctranner port o\ qc'5qp:r{ o'8q.6o,. 4.eo?c6 s6q6o:,io@68o5@1c'5e g:
93.ocA{3a::
no5 a:c3e.3Q3."-2!,, slo6.n.3qr€ o€qcecuc.9o3o61c{oc-.i'q{8, qrkdqp,4
s6q6o:c6sa@3o.39c8cib:p!r {:l.oo69cfur'5.{ Ae6€o','d resrster 9c ADcoNl G3

"t-d, oc,::,"2"3 A2o aca.,S o4{:Q.o:: (reference voltege) c{cop!: a:o69o5{3o1a:$rr


Mo 3d 43aai:q.3"r:.{ o6,D:oEq:3"GE eri:Grola:dn oqp:er:G8. Ptc EoEe{ceEco{
corqproei +3E3'%€:s?g$:Q.o:: (intemal reference voltase) o? aa?:GFcr>.6@r 4Q.--d
36q6orc,5o:6Q: 000 to 3FF s,%d o - 5v ranse 6,-l13rdn s6q6o,u6or$Q: ooo to 3FF
oqc8 Q€oe,g$,Q.sl-, (external reference voLtase) 0 - 3v ranse oicr,e:: 3?3i:0tqedl6or
odn
Plc16F876A QoSa{.S$cD{c.r"o\ ADcoN0 resister T3. ADcoNl regjster (4.%;
cjlo8eo: bit c,",*@.3'4 Q(9-G)93.Q(9-2)"fl.q3 .oT0..D'"trrd I ADcoM resister 9
PCFG bits 0 - 3 4.3:6oTfiodd qc39:q3 caSgceo::.1 e6qj5o"c'5 93.:ag$:Q.sJ):qP:
066oT,i.{ ce"o6or cq,,,€&,,TGco.: 3id ,',1 n

{(?-9)3?61 ADcoNl register 9 PCFG bits o - 3 cA lt10 t4$ eg:1o8oo69o8


c,lciqlt glo{c1c6:acari c$o6ncr59€.c{c,62!eor:2!rr nzo 9e$cr:cer::ae@.t ADRESH t3.
ADRESL o?cc:, resisier4.oat co$q8: a96:6oel:co,:olDei'r
ADcoNl resister c83ciloteoc ADFM bir.{ 0 a?po?c6 I "? -.59d."'E€,-,,8e.
$cv:ea::cae@c{ 6"".5"1Q6s48: r36::Dd:{ed3rdr

ADRESH ADFESL

0 I-LL],LLLL 11,000000 left j ustified lesu It


I 000000RR riqht j ustified res u Lt

Joog ?r3 cgr;14".


GADCONO ( A,/D converter control .l
register O ) Fh
The A/D c!nvcrier co.diijcn is
€cftrolted v/rth inis reg ster

4 -..!!l-j!L-1_0, r,',, ro, t", c{r)


The vatue jn the parenthesis i turning on.

;ADCS1 ADCSO : A/D conversron clock se ect bits


ADcs'l ADcso the crock is criven r,om an RC
0 0 ",.* [i,i,l"?]"t
Fosc/2
0 I Fasc/B
j 0 Fcsc/32
liRC

iICH52,CHS 1, CHSO : Anatos channetsetect bits

CHs2 cHSl CHSo tnput;hannel


0 0 0 :chanfet o ( RAo/ANo )
0 0 1 :Channet j (RA1/AN1 )
0 T 0 Channel 2 ( RA2/AN2 )
r I Cninner: 1 ne:leN: I
1 0 0 Channel 4 a RA5/AN4 )

,'GO/DONE : A/D conversion status bt


1 : A/D converston in progress
0 . A/Dcolver5ion not,n p,ogJecs(,njs
nardware
bit is automatic€ y cteared by
)

3ADON : A,/D oN bit


1: AJD conversion modute is operatinj\.,
0: AJD conversion module is shutoffand operairng
current

Q(? G) ADcoNo resisler a\ bir cags:cor,:Q


€ei:(r) anaros to Detarconvercion Prc €da{cB$@{M @a:qloo3N6:qp:(9)

L'ADCONl (F/D converter control register 1 ) gFh


The A/D converter condition is controtTed wiih ihis regisler.
7(0) 6(0) 5(0) 1(0) 3(0) 2(0) I (0) 0(0)

The value in the parenthesis is in lhe conditrcn immediately after the turning on.

JADFM : A./D result format select

1: Rightjustified 6 most significant brts ofADRESH are read as 0


0: Lefr justified. 6 least sign icant bils ofADRESL are read as 0-

,TPCFG3,PCFG2,PCFG1 ,PCFG0 : AJD port configuration controt bits

PCFG Port
Remarks
szro 67",.iu ir.il rli.enirN irN+
lbooo n A "ua
A A A A A A
doornnnAVREF,AAA
OO]ODDDAAAAA
OO11 D D D AVFEF'A A A
O1OODDDDADAA
O1O1 D D D DVREF.D A A

O11O D D D D D D D - 0111
sameaq
orTl D D D D D D D orlo
'
1000 A A A A vn.r,v., A A
1OO1 D DA A A A AA
lOlODDAAVFEfuAAA
Itor'o D A e v"...-v^.r. p. e
Ittoo-io o te {.r.[.r-tn la 1e:nnaroqport
i1101 .D:D.Do tD
ltibi.o:o- r-o v*.,
iv*-,v*,.. n iA
!*'.. A i,q iD:Disirarport
iy 1,g'L1ll*
iriro:e:o o-r-o 5'b olA '
'"i'u?;"""'"",'"n"
:D D.,..
l-a : VREF: Low
ir1,t_ ?__o 'D VREF.:VREF-
*__ I rererence vonage

i(?-q) locot':t register c$ bit o6f$co.:?

. o.t r+6 -.e3-


-.i:(?) A.a os t. Diorial co.veeion

AD=NI = 0 lE;o?ii
'6G.rd r,j,do;d (isft rLrsiirred) cLilYg:r ADFNa = 1 G6q 3
€6LJ 1.);)JlJ 6 J :r,ri t ru\|,fie,])- l- ji . ,? r0:,ls i."1:[ior:[:: .rsoLro,
3.€o,re:{,G56oq$3;,zo5 ADFr,t = 1{rishi rLrsH eo .i.g,ndo1e2)l
e,:o.60I l-d r.a.-v-qp:1i.r; "!r a . coderp:." -? . Jscia:6T j^Jr

; ENABLE 'II]! ANAI-OG TO DIGIT T CCN'ER1'!R

; LJslng RAo prn for the analog lnput


; Anaiog d:ia is riqht iustified
novlx b'10001110'
novlql ADCO\1
bct STAToS,RPO ; RAM Paqe 0

sl code c4 rRrs qt , ser e38:])ei6j.dce3 6d.s3:erot€d 3>,csqco8.4cJ


ADCONI -aj RAi,r pase %3ficrr.€@'3_G6.'l])d c!€:{6ijB:at,.; )rci siAi:rs, i..l
1

G6. RAM P.se o 1q.Ei.*r:q,jlDdn


3?co,',5dlo43:6q:o5:qldo2! nao d 3,€E cN..3?o3eo33,G6-.i,GG,, 03,re
3,eBE,q.3"):6cQt A2D€,5o6G],d sht jusirred G6"@,3'.i prc a,:3,o36o:o?d6e:oeG6
.t-d"
:Dc6cuo5@, .:€f26o,.o,1{:c4oc686qqs%d prc €$
RAr!.4 pase c?8goo, 0
ADcoNo resrster .5
bito(ADoN) .A set e6qJl6e:, c':3:o2! eoor = o
G6el3 A2D
module o2! off (defautt) GSE: ADON = 1 D,i,cn; A2D modute tr)d on
G6,,1€dn 4.s"Ge
od 3r€Sc6c',.3?o33eG; .{,ptr$
AocoN0 resister channet eg:qoS99€.::r6{3eqcil
]]d, gl"6qd 3 channer 0 (RAo) .4 -+,oL.dG;d ADCON0 resister €r5 cHs2, cHS1,
cHS0 bits ql,:o? ooo qe6:qpsaroSgc'5qcilog)r
oroi ADCONo resister s$ bit 6(ADcso) 13. br 7(ADCS1)4.G3. externat oscitalor
3?%d posr scarer 3?,ir:3?o,,$3. internar Rc osci aior 3?{t--,4.c4 oD4.Do6cor:G."r.

ADcs bfts qp:.{ tt <1::d9o5@: internal R-c osc ator 3,{[3"o,:.{ ce:n,$,jled
3?codo1 3retdqp,.i eoc6d code c63 e6,,1 3:Gdrc$3,j1 ud I

; ENABLE AI.IALOG MOD0LE


-:;;- ';;--
; ;. ;.;;-
novl r]'11O0OOO1'
n.va I ADaON0

GqcdcoS ADcoN0 resister ei bii2 (Go_DoNE f i."d) ;!J:"fld]'C\).3.? o+GJ€dr


or3:3rd 3,€i,6c.,o.o:$E,e 36a6o,o5-qq:c?.61o;:Nr.!:c6:oi,-i azo.4
oo-,€ or,5e5o,i 6iQ

-xd60:.)d b rGs;l-ai '

joo? l+5 6f&"tic.


d:(?l Analos to D,g arconversron Prc Qosa{%l@$M

bsi- ADCONo, CO DONE ;.n.;t? .::.Loq reading


c3o5e>::aa1 Rno 9c69o€eepr6ueu *tgr

A2Dtlait blfsc ADCONO,CO DO|E


9o!o A2Dwaii

9-3-9rr Converting Nibble to ACSII Character

o ci.SQ reset G6cd,:ca,-;1 A2D orlQ:qp:.4 ADRESH


ADRESL
"o-00"" -:Jd
o?.? 6to? 3 6o6cr,.od
+e.
{ n

or?3:{1oe€ %63o?.qio':63r.
(D€:o?..i AscI characters
Q6ri.60oe:E
ADRES o4q:3ri!) ro birs
6])16€.
4"@e. -i.i,*,"i,4 Qcorqgo%.,s
60;3:cn6,,:$cqo6colle:r ASclt character

0!1 1 (3) cocSodsrd3?e1gtl€o?5q86€Ec{,,


.4 o:Tdo?o?.3o?.,r? Asctt characier rg.

€eisG8.{:3"8€:G6€r)r ADRsEH g ocDo

nc'j i ADREST!, u
andls b'0000001r' ; ias! un.r-:reC .l: ia
call ToASCtI
call LCDdata

-i'-qe b,ooooooll' o?6f,>)- code r"ra! bit 2 9 brl 7 ::cgeqepo33


^ -andl'
.d])d?EQ:ee$6o31 , cp,":gq.,J6 .ms: (nrask .ro -,,.qj6e,gaa-5, + uit
nibble^ ASC ctraracter o@6c$..@3:co:6$. ToASCtr .ut-riin" -4n"-;-;o4e,
-4
6%G3g3dt3'd,
_

To ,scri addaf pct. E


retla '0'
!etlH '1'
reE-Iu '2'
!etlr '3'
!ctIH '4 '

+-_ _
r.2 196 eir,.1f1o
.aralog !o Oigirar Con!€sion

subroutine 9 G1*"--$Q'4 Lco c6€


- ^ToAscll
cyJa,$,
QeoTeo:q$ eca:c8r.,1s:of8:{€:

.oC,6cDdE' RAM pase I €o)d{G{6,r1 ADRESL res,ster 9cao,(}?ocSJlsd,,


^ 9 nibble qp:r{ 6f6pocao5 (swapf) cqc,5ulrrdil tower o,bbte
JrE
€q,.;-AoRESL .i Ascl
4 orS:cqo6@:
uppernibbte character rl6G;€:E: Q6oT{J,,Lrp5,

bsf STATUS.RPo .RA!4 Paqe 1


sqapf ADRESI-, l! geL upper Djbble
bcl STATUS, RPo RAM Page 0
nask off .Iower nibble
call ToASCII
display uppe! nibble

4cl.o8 ADRESL g tower nibbre.,? Asc characrer 3gG&€:E: +6oTc$.,So1Dplir

bsf STATUS, RPo RAM Page I


novf ADREST,/fi get loker nibble
bcf STATUS,RPo r.A.!4 Paqe 0
andl! 0!h mask off uppe! nibble
call ToASCII
dlsplay lower nibbte
*-df Gio|or8ol o5@,{!q3ar6o:eo1 eq.ccf co8o€ocec>r eso.rcoo8c{ cuc6s
^ ^ ^ toop
{€$ "'6t.a8 "o6"+qu1"a9o

9oto 42Dloop

?-O-G! Converting Hex data to Decimal value

_ .a$0-d.-d uex o{Q:coc6o:q913 decimat qp:.ir, 3,AS:o)oS 5re:$:E:3,:


@6uc@'3. Hex.E decimat fc@at:),d{d:c'6:4 lr,@@"r"*d,
' ' G56r

Joog ?r3 @qiolqo


"3:coc3"€:
-J'(?) taros io Dis ra convers o, prc
ic66{qg@{o }ii:{!o:o6:qp:(e)
.
jr: 5v a3?{:l9tcY. s -0 o di ct I 9
v
3. ocsqcsd.?-d
"6ar6o,c6q.-,o)i$,d
6oc!,4:(r)+,d o€c\td 0000 ro 5000 vorrs

eoot'F:lgc, u uuu d <Leo r^: .l?Ddl 0 00r vot.5 41., 0 00o


vorts(0 004e + 0 004s) .,tfG6oc36..d,
"3)dlG8.
qq3"(?.6 trJ{p43e%c6qj.61qrD, Joio:aqe"6-.trJ gr)"i1d%€
q...d.:e, FV GscDcl-'€. oit:o,q66}ro,qq,1P,.,J 5v ts.
g,d
eo€.3"r,G3. 3v o{g:-d s,G€.ai: 5v ,,5 d:{ 3i:Q (3/5ihs or 5U G6cre:,
^
-edT,"Ge. erc a:g! uex 000h to srrn s€r,c6'E: ;d
",lQ:..i 4A,.-$S-OS. ;v
3FFh-i cl:Q e:Q (3/5ths of 3FFh) G6sJair
000h = 0 decimal
3FFh = 1023 decimatG3€r,6lO'3.
3v ],e: 1023sfi il:+
3t:Q (3/5ths of 1023) GSxdr
3;c'o5d o,4g:qp:4 mi jvort (mv).G6o?e,,,6dqqrlS 5v 3)ai 5000mv
G6-a9ll
000h=0decimal=0000mV
3FFh = 1023 decimat= 500omvG663rcE 6.
azo ol3:o::e1fi 6]:: mv d,qQ:crd 6D.;,jl 3?o?E: aoc6o66eot rJeir

mV = (A?D Reading x 5000) / 1023

3:.oc3o1 i,:3]Td:"a3o1o3.r, rrip{ecp,".Bqlcfu 4 gresqGoodr ADRESH f s.


ADRESL ,16"* -$Q,ep,4 5000dec(1388h)
+€. ;G;"58,'q"-54 1023dec(3FFh)
^o?.9
+3. otr:qcjtod,

?-J-g[ Multiplication and Division Subroutine


i\,rlicrochrp web site (23 iiC qp;::ogc3 t/tutripiicatro/r subroutne
_ 93. Djvjston subrowfe
,iD:.fi (ANsaa - U ity ftr]arh Rouiines) App icairon Notes c€€ free cownioal casoi$S,jlxd
r\4urtipty code qr €"rc3cjl3,4e:G6,jt .,rd,,
novi ADRESLt, fi
andh 03h rrasL off ura:rt..i d.:a
novHf NmaHi
bsf STATUS/R!0
movl ADRESL, !i
bcf STATUS/ RL,O
novrf Numalo
novln' 0x13 50!.0.leL- = 138 8i.!
novwi Nudrlli
mo'/1H 0xE I
novlif l.Junbl,o
ce11 tiuLtiply 32 bit result ln N'rrLbpi/Lo nsltaHi/Lo

Joo? ?r5 eitotiN 3ic-


G.i:r?) Anarcs ro Die,iar convers,on *j€j:=:Sj9!!3 =33:Iq:!q
Multply sLbroutine 3)ei NumaHi/NrmaLc .\3. NunrbFit/NLrmbl-o cfl.c6SJ8:a.i),-",
.Fol-5 32 bit 4 NumbHirNumblo 6i.

r3. ADRESL 4.t-1$,qp,4 set a8o:lg:

,c
:p6
j:.::;;E-u".n
roo -rqc.,s:,ra: ,,,n,u *ni0"il,Tuff,''"Pl;f;%"tlJ*,," = ,,,.
c2;1<- x.r,ear;.tno2; :Io o.l.

03FFh x 1388h = 00 4E 0C 78h


1023 x 5000 = 5, 115, 000 dec

lvlurtipry subroutine oei .@c6o:,5 rz bii (a byre) d c?c,5€;f6o:G.J5cDd: 3"\p:{:


24 bit (3 byre)
"4r,3,.r,Gtgcga3.la€:
-d der,r3 G;-,.,,.tr 6r,c3{:6G.d-5
e

cA::S ntr,:sion sulrout ne :acac8 -eq:@,."


.Jra.:n. 24 b t (3 byte) 43r. -d.B3,oi,-,

Drvision subruutjne s:%c; cooe qp:9. e:a:dJl o{3:@6!e!r

; 1023.]ec = 000-lr I!ei

; > nralorfl .ratorNJ nrator]-

3?cD<.r5Jl6oTDqlcS%€ Muttipty subrouti


Numerator regrsler Cp,GS@"- nraiorH nra
6@,3:6%63€€0,, io23 ( oo 03 FF) ogQ:
denomH, denomt\,4
9€. aenomr dcpS|@::g] co
Divrsion subrouline
e 66.0,3 al.3E, €o,
4.%€code€:.p:E:, 3,Ge,.i remainH, remainN.4 t€. rema;nr {.ca8co2ies8:co::<,i1op! r

_ ao6D-,G3.- r'zo er5qo:5op! 265h ( 3 votts approx ) G6q9l3


66,dG:6:D,3,ir
265h x 1388h = 2EC4A8b (613 x 5000 =s 06s.000)

N!.nHr = 0 0t!
Nr.ll.o = 2 tih
ls l -. tl: = a1h
lslirL. A9r
o"f,(2) ena oe ro Dieitat conuers on p c Q.,5o{%16flM ee:qoo5o3:qp(9)
.rrE:6rr:s,"1
2FC4A8 / 3rl - Ba4n (3 065 00{,) 02j = 2996) . 3 voll

nratortl = 00h
nratolM = oEh
nratoll, = E4h

66@'3,rr.EDtE.,r.d, ())e,r'd 3?€q,GoD.Q.-: 0-5 vorL s€ocpri


nratorH q33 00h
o.isa@ ootr a>r@66E6oc36.ed" 4.@.e.,,,e: nratorH crf oq6o119$€ecro$rr nratorM
r3. nrato,L 4.o3€$cDro:$r!:qp: BBah.{r>c cf"d{:s:6@%E code€:oa:o.r:ql cfte66,,
6c.,.xe9, BBah De: 2es6 mrivor or 2.se6 vori r8dgtdle,d' ,',3'o:qq:eral 3 vott
9a,c'5eqe"o$rr 10 bit A2D step limitation 6@e. 3.000 volt '{6f)]36G{.ol G,;Ic?o3@:+€
o96ps!",2.6.q1'

?-J-on Hex to Binary Coded Decimal (BCD) Converter


<r:1sa{$eadce6ecosp:5.-dqp:o? DEod-E-6Edqil3 eq,rc6n:3rc@-e! hex
€Bah) rloGaq€r,:odil q,e:o? 4€qqo-,Eq,{."&e'8 e,""6 nscu code cfpSnS:@:eu
Q6,;I€3edG6€orrdn 431.0te3.6-%cD srjbroutine o16qc{o1,Giq6,ro93.3:od, 4
subroutine 3)al(AN544 - Utliiy N.4ath Rouiines) Application Notes (Z€ Hex lo Binary coded
Decimal (8CD) Converter c,treo: sulro:rire $6ci]:.)girr

{ subroutine efio?66.or€ato39" 16 bit hex ori{:.a BcD €aiQ:gp:f€ 3?ofuega,jl 3


oy,tes @6eor€e @o8:de o:6€:GB-d,, 43rell BBah 3)el oo2ss6 @6co:o2!rr : tytes c{
era:.6<ils,Soopca{€:
"36:co::opjrr
BCDvaItl : 00b
BCDVaIM : 29h
BcDvaIL = 96h

C " '91c:qo:q2p, ro/scl rsct


BcD qcr,:!rp:rl sub-oJlre cSeJq,J cooe
sJGscGoe:E:Gred LCD %€Q6oT€ir:<l€o-ji, sloqerdo%c8 BcDvarH ])a: saof;safq oon
G66q63r,6@.e.,De,.?c.x6ontL5rFc",R3."odn
oivision subroutine q6e :or8qld$:earool HexBCD subroutine c{ eo:c'5o1o{€,:,
eoTop$3:eocilo$rr

novf nrato!M, w

caII HeTBCD ; -> BCDvalH BCDvalM ECDvalL

HexBCD subroutine a)Ai NumbHi f3. Numblo 4!4€ Division subroutine


9co2!3€:eo:5.o2i 16 bit oqQ:€iD:.,i.io;0: subroutine nfo73.o:3S,qr:e.::sao1 eco

Jooe ees.$qdtio
-.{,. ''
n.[,{.) A]rai.c ic r !,12 cciles c,r : ., , , , :.:,i;,,(.,)

":..;: i,:,.--,,{":-S:
d).i,t:.jtr:oi BcDvsr!1 +:. ECDy:1i, d€.r,'! N rb e o,ii.j::r?
a^li-.r'rr:(l 's.r ...re :"li:. Gr:,['i':i']o5 ecG LCD cr3 .:',r.5i1..4':,
.*;dr)O..,i€rrc":q6"rJn :r. . i . ) 11{ a'o.3;:6rei:.3%;codr3:o:ir.rd i

s!q:pf :aDrillj/Ii ; :ciL !r..it.


a.CrN l) C!'
c.r Ll TcASa I
cil I l,CD.iaie
nolh ,. , C.cii;l point
call -CDdata
nori BCDvafM,li ; loIt roths
call ToASCIi
.all Lclrdata
:uaai falr.-:1 ,i, i '.ll: iri-.1:r

.:1, T.r:r::i l
.r:11 laD.i:ia
movi BCDVaIL,IJ ; 'ro!: 1!!o.hs
call ToXSC I I
caIL LcD.lara

3?o,o5d sv ogQ:coo3qP,eo: Q.3"r:qp:.4 o?3:o,c$qJ8 sa8soec,::. 3:o8q.s"r:.4


cl3.6#63, voliase dvider networt c{cop!q8:S: 6c?p.ql6o:qdledn {3!.EFA3alda;.1
-"€,,r$.-,?,D$.3rc8qld 1oko.4 cud,-d*€,oi,or:616 cQ-6c,)])dn

--;A-e6n;qp,.{ e"d,E,"s'"5 (0 - 5v) Dislat vottmeter oo8ooS: or2!eao:c3


6rr,€3 3'3i:Gtq6d DVM asm (source code) -Gd3'Q.4 63".o3%€coTEcqcSdltr
dn

Title "Diqital voLlneLer"


Iist P:16F876A
include "P16f 8?6A. inc"
confiq h '3ff1 '
erroreh'el -302
; CRYSTAT = 4MHz

; Rj\M DEFINITIONS

CBLOCK Cx20
so$:(?)AnaostoDieitalcof"ersron plcQ.,Sa{oa4@{Mo.i:qlooso6:qj}(9)
====:

BCDvalH
BCDvatM
BCDvaU,

shiftl,
ENDC

; Ital = LCD RS pin


;RA2= LCD E piD

LCD R'i PIN IS TIED TO GROUND

loilTB 0 -? =j,co rATr PI\s c 7

gin No. s!d5c1 Descriptlcr


:L Vss Groun.l
2 Vdd Lcgic supply
:l Vo Clr CONTRAST
T Diper of 5K pot
between 5V ancl
4 RS Register Selection FA1
5 RI,r Read/write
6 E Enable
DBO Data bit 0 RBO
I DB1 Data bir 1 RBL
9 DB2 Dara bi[ 2 RB2
i0 DB3 Daira bir 3 FB3
i1 DE4 DaLa bit 4 RB4
i2 DB5 Dala bit 5
DB6 Data bit 6 RB6
14 DB7 Data bit ? RB'
t5

ic.? fis e$r6lslo -* .s;l;Jl


-4,(r) Analo9 io Drgtal Conveision

iro Cornectioi

CODE START I-i.ID INITIALISE PORTS

; sra!t address = 0000h

..to SlrarL:

; CalitiRT llax llItsllE TO ,tjiaII a!rr,lAaTai

i.15clI :Lldr:!C1,,1.'
.. t.! N !'
i: ::" '2'
.:.,''],
:.'-
.::lii ' 6'
.ei1r 'r'
:::tr 'E'
re'-1rr ' 9'
ie]]lH 'l'
.e.lt 'l'
r.:1,1 'C'
.:ir" 'D'
::i1iir 'n'
i=i 1Li 'a'

; ! 3!!AI IJES:ACE5

; Ll:aa ir la5: p.slir.r :re-:!s ,-.. .f ...t


lriuTexl nrvillessPt,ii
ji'r,,:ss -Cdri PCi,, F
Da- " (0-5r/)tcLT l{ETli", 0saF
:r:ss Df "IOLTS ", r'r:f

PORTA = all loe


PORTB = all 1oa

Lsf srATU5,RP0
ORTA = all outputs except for qAO

PtRTg = al1 outpDts

J.ca e96 Girdt StN


,!g(?) Anaros ro D e,tal convers,on prc
Qo6.6%i@{M srt:floo5o6:qt (;)
.'=-:
NOVLTf TRT SB

ENABLE THE ANALOG TO DIGITA], CONVDRTER

Lrsinq RAo Pin lor the analog irpu


Analog data js rlght justified
novi! bt10001110,
novwr ADCON1
bcf STATUS,RP0 ; RAII Page 0

calt De1ay25 ; 25nS de1ay, LCD data sheet says 15nS

SEND INITIAT,TSATTON DATA TO DISP1AY

movlw bt00:110000I fdnction se! I bils


novlw br 0 01100 00 ' funciion set I bits
novlw bt00110000I function set I bits
movl w b'0011:1000r funciion set I bias. 2 tines.
novld b'00001100' disptay on, cursor off, blink
novlw b'000000011 clear the display ?

novlw b'00000110' increnent - no display shift


call LCDins

O aO,O, t"" VOI t lvll,laR MLS5A E ON L t\r, ;

novlN l-o (vHness) ; !(0 5v)vo]-T f4ETER"

DISPLAY THE VOLTS MESSAGE ON IINE 2 - CHAR 6

novlw 0xc6 d3ta starts Elr chara..er posn


call l,cDins
novld Loa (vTness)
cafl DoDisplay

ENABLE ANALOG MODUI,E

RC Mode CHo - ON

novlw b ' 110000 01 '

Joo? ee6 eE6dtqo -.t3


ro{d9) Anelos to Djsiral conieGion prc
{.te{ {@{(v, ocl:Eloo5N5:qp:(9)
novwf ADCON0

; DISPiAY REIDING 0N ],INE f2


i --------'
A2DIoop novlw 0xC0 ; dara sLarts ar chaiacrer posn 0
caII tcDins
i'------ - ------- -- ---- -
; TAKE A READING FROM AzD
; -------'
bsf ADCONo,Go DoNE ) enable anatog reading

; WAIT FOR READING TO COMPLETE


i --------
A2DHait btisc ADCOIJo,GO DON5
goto A2DHait
i ----
; MATH NEEDED TO CONVERT TO VOI,TAGE

; (Readioq x 5000) / 1023


novf ADRESfl,li
andlw 03h ; nask off unwanted data
nowf Nunalti
bsf STATUS.RPo ; RAM Page 1
novf ADRESI,w
bcf STATUS,RPo ; RAl, Page 0
nowf Nllnalo
nov]r, 0x13 ; 5000dec . 1388hex
novwf NunbHi
moYlw 0x88
novHf Nurnblo
caLl Multiply ; 32 blt lesult in NDrbni/Lo BslhaHi/Lo
, l4AxIMUu RESULT DOES NOT EXCEED 24 BIT
, RESULT / 1023

novf Nu]nbl.o, w
novwf nratolH
novf RsItaH-l.I,l
nov'rf nratolM
novf RsItaLo,tl
nowf nratorl
crrf denonH ; 102ldec = 0003FFhex
novLH 03h
novsf denonM
novlw oxFF
novr,'f denonl
call Division ; -> nlatotH nratorM nratorl

Joo? er8 s&"lqN -ctG- o3:@.,5011


AnaLog to DLgrta Conversion

RESUTT i\JIii tsN 16 BIT VA],US


CONVERI' 10 BCD

; > BCDval ll BCDvalM BCDvalL


RESULT i'iILL ONI,Y BE 4 DIGITS
DISILAY THEM IiIITH DECJMAI, POINT AETER ITIRST DIGIT
ssaPf BCDvafM, W

calI ToASCII
call LCDdata
; decimal point

rovf BCDvalM,It
calI ToASCII

BCDvalt, tl
0x0 F
ToASCII

BCDvalL,li
0!0F
cal I Tol,SCII

; I"]AI T 1/2 SECOND

; 2l ! 25{i a/2 i..

iecisz Count, I

; lre t n--xt rea.ling

; DISPIAY TEXT

I,ow (DispText) + 2

Jooq i95 c$jcllo.co Jr]


*l'(r) A""r"st" oig

DoDsloop caIID.isprext
aorlw oxFF
blfsc STATOS, Z
!eLu!n
xorlu oxFF
call LCDdata
incf Messpt. F
, goto DoDsloop

here goto here

OOTPUT 1 INSTRUCTION BYTE TO DISPLAY

LCDins novNf PORTB ; pDt instiuction on PORTB


catl Clock
bcf PoRlA,lcdRs ; trrlte "instluction"
call Clock
bsf PORTA,ICdE ; clock it in
call Clock
bcf PORTA,I cdE
;6mS detay betNeen insLluctlons
c]!f DelayL ; about a 6nS delay € 4MHz
novlR 8h
novHf DetayE
ctlp] decfsz Delayl, F
goto ct]pl
decfsz DelayH, F
goto c!Ip1
ieturn

; OUTPUT 1 oATA BYTE To DISPLAY

LCDdata Foverf PORTB


bsl PORTA,TCdRS ; Iilile "data'l
call Clock
bsf PORTA. tcdE ; clock it in
caII Crock
bcf PORTA,IcdE
call Clock
retDrn

J""? ?t6 cqr"l{N o3:oc,So3'


Jdr) Anaros to D,star conversion Prc Edaq%4@{M @i:qjod(.)6:q}(9)

cLOC(rNG DELAY_200uSG4MHz

decfsz DeIayL, F

25ns DEIAY 0 4MIrz

DeIaY25

clrf Delayl
!UPD decfsz Delayl, F
qoio PUPD
decfsz DelayH, F
qoto PUPD

16 x 16 MUI-TIPI-Y
ninna -> nunb rslta 16X16-> 32 bits
Mu l!tp.Iy 15 loops
nowrf l4count
novf NunibHi, w
novwf RsltbHr
novf Nunblo, w
novsf Rsllbl,o
cl!f NumbHl
cllf Nunblo
rrf Rsltbsl, F
rrf RsMLo, F
btfss STATUS,c

novf Nunalo,Vl
addwf NulibLo, F
blfsc STATUS,C
incf Nunblh. F
novf NunaHi. W
adduf NunbHi, E

rrf Nun cHi, F

3o.2 63 cgeol(o o3!o.3o€,


n.id., A.;ros rc o dir.r c.itveE.i Frc id.i.a;-_6.D :;ri:rroc;N;,q!,(r)
i.i F: l tr:i i ,l.
ri: R3l:aI.,l'
ce.t s: UC.Lrnr:?:_
9cto nu l.LiJ
.et ri
SUEROUTINE - 24 BIT OIVISION
nunerator: nraLorD nratorM Dratorl
denonanato!: Ccn.FH .lenonM denom1
nra:oril nratorlj nratorL
remainH remainM renainl,
novt nrator!.tt
novef shiftH
movt nralorM,w
nov$f shiftM
novf nra torl,.Il
novef shi arL
; 2'l brl Cirisjon l..p .o!nt3i
nov'r! frcouDL

cfrf nraLorH
clrf nralorM
cLrt nratorL
cl!f remainH
clrf lenainM
clrf renainl,
bcf STATUS, C
rlf shiftL, F
rlf shiltM, F
rlf shilttl/ F
!lf renainl, F
r1f renainM, F
r1f renainH/ |
novt denonH,IJ
subwf renain8,Id
tittss STATUS, Z

novf denonM/w
subwf renainM/ u
btfss STATlls I z

movf denonl-, vi
subaf renaint, W
lrtfss sTATUS, c

novf denoml,/ I,i


subwf remarnl-/ |
btiss 5TATU5,C

.looe ir6 cltolqN


decf renainM, E
novf renainM, tl
btfsc STATUS, Z
decf renainH, F
subwf renainM, E
bt fss STATUS, C
clecf renainH, F
suDwr rsarnH, t'
Itrsf STATUS,C

decEsz Mcount. E

to BCD conversion loutine


16 bit nuhber to coDvert js in NunbHi.
is set in ECDvaI HML

clrf BcDvalH
clrf BCDwaIM
c1r f BcDvall
bcf STATus, C
Ioop16 rlf Nunbl'o, F
r1f NunbHi, F
rlf BCDvalL, F
11f BCDVaIM, F
r1f BcDvalll, F

btfsc STATUS, Z

adjoEc novlw BcDvalL


novHf EsR
caII adjBcD
novlw BCDvalM

call adjBcD
novlh, BCDvalH
novwf PsR
ca.LI adjBcD

:,,ljECt)

J.or res G$rolqN -.3r-


-.1;(?) An:los to !iEri"l ..r.Ye'sio

r.l.i,J f iID!,',i
r.vHi'LerD
attsc Tenp,3
na /ri J liD!_
norilw -10n
addrif INarF,Ii
nov f Teup
blfsc Tcnp,l
novlri IliDir,
reiu.n

9.6qj.'5' o
c'fiq.i.28 P c16F876A @oal Plc16F877A ct@.i:Gpeg4qn8 LcD
o<oc6o1
nooule g3.;orS3c'5ard r,.3436p l.E1.U"Ecr,.{ 9{,"qg.6€:qld$: -8-3q.,"elr
.orr"u
"od"
c2Scopl: ri.t P - I5t871A; include 'P16f8?7A.i""" q$ e@8:otseo:
eloilrl2!'r

l".Q er6 aErolqo o8r-.t"3:


?-Gr PlC16F877 A-D Experiments wiih PicBasic
Pro
PicBasicPro .{-.i'BE, Plc16F877 G3. e o o5:o6ql.6qp:01q6$e.,ial€Gol€drr
.i(e-G)%€ LcD :oc6ogoSat.3c'9 coT$cor$: +(?-9)c6e 3?oe channer (1)1-"6a"5ncBc{
J$...'.jl-d' a-bit mode c{s:\:GG: Plc16F877A 9€. ao.3"3,-'5rnc ao€ channel
(r)tc-d*3,.$.6n""" e€f.Gcvr$.sD:qp:r{ LcD €.,Tqr€QcoTG{eQc'? 6or.oDdled"

pog qe3 -c9?-


"gqo1{o:
) Analcs to Disilar cofversion Prc q q1-{-
FOFJ -J. {]

Ijl]R"r- A l

' ' (qh:oc33gc6eq


Q(c-c) ceo8 crranner

LcD sdqp:q3e:ca3"d"6{ GrarcEdl",o?3:6%G€q€J3Jd,

LCD Pin Descriptions:

Pin#1 =Vss (LCD GND)


Pin#2 = Vdd (LCD +5V)
Pin # 3 = Vo (LCD contrasl adjust input)
P'n #4 = RS (LCD register select)
Pin # 5 = RA/Y (LCD read/wri1e input)
P'n#6 = E (LCD enable)
Pin # 7 = DBo (LCD data,input 0)
Pin#g = DB1 (LCDdatainputl)
Pin # 9 = DB2 (LCD data-inpui 2)
Pin #'10 = DB3 (LCD data-input 3)
Pin # 11 : DB4 (LCD data-inpui 4)
Pin # 12 = D85 (LCD data-input 5)
Pin # 13 = DB6 (LCD data npur6)
Pin # 14 = DB7 (LCD data nputT)

Jooe $5 @$rolqo
o.lt?) Analos lo Disital conveEion prc
{.5o6.e1@{M ori:qloa8N€.qlx(9)

IgiR^/F/rhv -.....-
tl^or N0 .+
RJ'\ITANI .+
llizaftz /r4. r+
RAln tiwFEr. .-
RA4/I0CX| € G
fi^&A'{49 +
iFo/FB^xt r_ 3 33

Rs18!EAf,J6 9
RE2IF'AN? .+

v5s + 29
OSCTCIKI{ .....- ,6
oscrrc!@uf + 11 21
FCAIIOSC'/t1CXr+ 2$
AC1'r16!CC!2 l_ 25
AC?rC4P! .+
*cascx/sc! 23
lor''sod *
FDIPSP1
-_ N
72

(i(?-o) PIc16F877 io5ep:3ryo@:Gi

:
!
t
r
tt
I
it
l0 pF
f
t
I fl es:66ecuo'-"o8cu6:s::oc,5:scseocqoc.a:@q
{(2

Joo? $3 a{roitEN -ecJ-


eo$:(a) Analos io Disital conversion

Q\9 Jo' ooc\ru:sl9D3?Q9

oo3o6,3"e3o93qEe%o3 ?3i,Gra:egffi386roca:oc3cu3:o{1::nor:e<-,Tno:p!$ s pin


ceramic resonator 93. crystat oi.;ocAqt:SQrf Q(9 e)%ecoTQcoo,E: oc6o,6:s@d3'{oi
Q(r-.d"a€ 6,iTGcor:,,Lrd, 4Q%3 s€r';c,,.GotQ.ra::(1){p 1x, y, z) o?..4 5K pot
(?h4.G6. cDdos€:cca:o13rd, oriE:o:6?a€:4 LCD cclT%e Q.orQ.ll"d' Q(r-".).ae
@do1' x, y, o'$Q:q?:4 o to zss 3"d cG.e:co:$36@o3:c%.636r6o6dn
'

t , t

Q(? 3t LcD 6,)T%3 -6{,cp=.1E+

.eG
.1."e 1e3 e$qdl{-
r) ,.{d?) Anaros to Digital conveBon
-{o o:1,qodo6,ep,(9)

er$Eecoo.roc8cu6:og8 derautt 3?c+G3. avtHz crystal c4 or8:o8 ooi:@poec;lo$r


r.rdd 4-"i,Gf"d{qg8 source code %€ DEFTNE osc
20 c{co$q€:eqoc:
6JGq6c$3'6o1],dr

source c.de 3rQegsQc{co.6o1o4€' 6 G€E€dle>d'r

. Picbasic Pro program to read pots on 16F877 ADC

Define LCD pins


Define LCD_DREG PORTD
Deflne LCD_DBIT 4
Define LCD_RSREG PORTE
DEfiNE LCD_RSBIT 0
DEfiNE LCD_EREG PORTE
DEfiNE LCD_EBIT 1
TRISA = o/o00001011
'Allocate variables
x var byte
y var byte
z var byte
ADCON1 = 4 ' Set PortA 0, 1, 3 to A/D inputs

LoW PORTE.2 ' tCD RAV line low (W)


Pause 100 ' Wait for LCD to start

Goto mainloop ' Sklp subroutines

SLrbrout ne to read a/d converter


9etad:
Pauseus 50 ' Wait for channel to setup

ADCONO.2 = 1 'Start conversion


Pauseus 50 ' Wait for conversion

Return

'Subroutrne to get pot x value


9etx:
ADCONo = ga1 'Set A/D to Fosc/8, Channel 0, On
Gosub getad
x = ADRESH
Return

Joog 66 €q{oilio -cc9


33!.&):I1:glo ois,r,r conuu,"ion
PC <o, ori,noo5oS:qp(e)
' s,ubroutrne to
gely: set pot yI
ADCONo = aro-
cosrru jetaj sel A/D.to Fosc/a, channet
t, on
Y = ADRESH
Return

' Subroutjne to gei pot


z value
ADCONo = 959
Gosub getad 'ScL A/D to Fosc/8, Channel
3, On
z = ADRESH
Return

malnloop:
Gosub getx ' Get x value
Gosub gety ' Get y vatue
Gosub getz ' Get z va lu -.
Lcdout gfe, 1. ,,x=,,
pause 100 ::tuo 'rcv-", #y, 'z= , #z ' scnd rn r.n
aDouL 10 - -'-
trmes a second
Goto malnloop ' Do it forever
End

9o5yr5r n

€:eoXqeoop!rr
[ricrDcode Studio tDE

o.rqSeqro::ogoEeoqi
o8oo${o1
a 16!:(0) Disassembrer etc {c6.{qQo{o oQ,qtoo5o6,qF(r)

oe$:(o)
Disassem bler

o-crr {s'1{r

Prc Qc6a{cS$co{c',rqp,.'? o{"q6q3:6p,?€ cQ:a3eo: hex r,re .{5r66oqqs"%o3


source r'le.'? compile ci.er,'7c6 assemote @1o735.qe@e: a3fi;@8,G66,,od'gF?a1:%3
o@i-ca$r-,S8. hex file c4 source file 39.06oJd6G;3:$eord disassembter software (J){L:
o€@.3'o? o:€Gol,rdl ocooo{1:co::9: Martin (aa674@freenet.carleton ca) gcacEeoTcoo:
])ei s4disasm exe(Version t t) s:e@:€:@6S:r loEcudl:sro::9c http:/ rww.hasi-online ors
€ Norbert ttagernann cqdaoTco.r:o$ elc-oisasm (Vercion 1s) oe@o€:@6.jlr2! r s,{g
aor:or6113:3ca€ 3,:r,flc3, €r:qd:atdqp,6"rclf lldrr @FE963)c8odrdl:o? 6e:q1cs
?,3i:Er$3dr])d,

o-jrr 84disasm.exe(Version 1.1 )

gi disassembler software ::{1:s:o::o:2! cggglq6cJDeoTcSdc.,ri€: Ptcl6c8a


aqro6 31Ec,r3"ai:GFlic-,Tqo6co.:63:G6o1$dll 4F$cod: prc16cs4 d.oi. 14-bir
opcode 4s?.t:GrcDr s:@::eo:prc qda{%Eco4cDqp:oqrc8c\rd: s!3i:Gi{€3rd,{
c:{Gt-r:ola>dr o€:q,3ca$.oc8qc6o:5?gr INHXBM aft:soa: hex file 4:r source fire
ol. 6Gb3:6,r:$E63,G6,',1odn

84disasm exe ci3eai:Gtqis?qrc6 ca:E:gr gl',e3t€.3?o7co2!"<.,:co:,er2! co 9


€4disasm zp oi Hard Disk 6oToAe extract q6cq<1.:1c2!rr cQeqoc6eepcA$cr::ear: Disasm exe
oouole c o26cQ.6q91e QG-r%€6(,,-GcD,:3ie! 84 Disasm window 6oTc.,.obd,
"i ict<

rooe a66 oirdqN -c:3-


Diszssembrer
'o6:(o)

windowQ
{(o-3) 84 Disasm
Q(o-o)

? open .{^click
drsassemble lqo?o

di\piclab-l
jEXPTlu HEX

EXPTllB.HEX

EXPIIb HEX
EXPTlCHEI
EXPT1D HEX
EXFTIE HEX

L.'r rres olrvod 9'"1- . .


l-.";i"i---l lerr"to 'i
-
ooen wintlowg hex nle 4cs:qlosQ
Q(o 1)

roor aa5 "$io'lqo


40000 85F 0x03-5
AOOO1 CLBF 0x06
a0002 ti ovLw 0x0l
a0003 I'i o\ /F 0x05
a0004 BcF 0x03.5
AOOO5 ELBF 0x06
AOOOG BTFSS 0r05-0
A0007 GoTo AOOOA
A0008 BsF 0i06.0
a0009 EoT0 A0006
AOOOA BCF 0 6_0
AOOOB GOTO 40006

Q(o-q) source file qcfeoTcr:oQ

Q(o-q)ce6e.1pco.,.,a9ool€r Source file cgcAe <.rTcu:e oe $rr o€: ca8 eo:8co(q)1


dlo8egdlo$r ocoeco?3o,rod,a,coress qp:c{eoTQ@: 1c8oeo$c.ro2! opcode
qp, c?eo18.,, o#oec'tro:o2i vatue {eol!Li1r:p! r

4 source rite 4
save orSqq3?%$ Fite>save As 4
cticke3cs.EqnS +G 9)%3
.oT@cor:ard3?o?e' save As wndow 6,rTo,6oed' 33 save eSqlSDd folder rr?6e:{cSg:
Frle name egcpcg€ sourc€ file c{ enension ( asm) @3. save ca3s1o1c2!n 4se.1 {G-C)
%S@colard.oo?€: oone c2r,1$e::: dralos box e<rTcu:@: oK .i
click e6cqo6$e,."r:G€.
disassemble oi06e: eSci:oiE::9:eoeo:r.c.:$rr

1oo9 193 o{,1o'l{o -cGc


lDII>PTlAFll'-
r-iF!:llir i{L:

.:!1r. H-=Y :l

lH*r.n"o :J

Q(o-9) .gcteoTca?6, Source riLe .{ extension( asm) e&J€:j save cp6Q

Q(o-g) sourcefile c{ sa* g*@c€.";f$Q

gl9$:@3. trex file c,? disassemble o76p:q$coreoc source file ogt heaoer qp'
dilrectives qpc lable qp:ie. comment ql":.{ eoT$co::@3:e$eorr eorO $. CALL instruclion
qp:oc6c,5 t-alte 6{.fJqle addre$ S€. e"TQtno:@€:ecaq6oe$r

Exptl hex
Q(o-G)o38 qo: 13. Expll asm 13. 4 disassemble q 3S: q$cule 9:c
Exptl asm o?.ci fiE:9l€l;TQ.":: ol cr$'

tr>3:4.o5doe9!,? @cf s<D':o?ft€:,,?i 6o>.o,@d@coc9o1::drr

r."e er6 aqr"rq- '"G.J-


File Edit Formit lieh HelF

;E(pt1. asnt recs Opcode Value


:Pr':iecti Tu.nino on a
'list_P LED
- ni.16Ea!-i BsF
include pi6F84a. irc A0000 0x03-5
coNFrG h lil l A00fi CLnF 0i06
A0002 I'lovLW 0101
A0003 I{OVWF 0105
ORG O A0004 BcF &03-5
serup BsF ol, 5 A0005 CLBF 0x06
CLRF 06 A0005 BTFSS 0x05.0
t4ovLv 01 AOOOZ GOTO AOOOA
t4ovwF 05 A00gB BsF 0x05-0
BCF 03,5 40009 Goro a0005
CLRF 06 A0004 8cF 0s05-o
40008 GoTo a0006
prai n ETFss 0 5,0 End
GOTO t4ai n2
EsF 06,0
GOTO lfa 1n
Main2 acF 06,0
GOTO Maln
END

Q(o-G) 9<o source Rte r{ disassemble q3@:e1$cuceo: Source fle t3.$L€:qi6oT0Q

o-?! PIC-Disasm (Version l-5)

sl disassembrer soflware ::{1:::':;:up! ootr63,4t:3ior,cod QQoa)nii$"{4€, *a,r


*,-d'
Pic-D,sam .{s3t:GLqls%c8 65r:€'s" gl.aq39e.3?o?.Da:eo:cD,:::p! co 9
Picdisasml0s zip o? Hard Disk e,rTca€ extract o76o7qc;1og!' {6f".6c{pa36o,cDr
PicDisasm.exe o? double click eSoidql]e
{G-2)q3".rS-",-pl Plc-Disasm v1 5
WindoweoTcu:eoc$r
oeoTe?:ce€ Main menu <l16E: cue'es"rd%€ shod cut toolbar oloS<j1cr$rr
o:i:Gt)d Qi6a{(ls$cD6ora3?qn:3?o':o? cS:qlosG3:qto6 short cut toolbar eci$ etc-rype
sc.orrba-s .43?ri,GG:e€:ql.S+e,i 3)S , 31.€,-?03 4€3Q shod cut c{
ctcr qSrfc6qi]3
Q(o ")%30cD.:a,d.r?. selecr a Plc rype tlst eoTo::e<-rep!r list 4
? Plc a'{|:3?o::.4
e6,ncS$€,Jler$rr 336s:qloscqd3rd erc s:{pooa:g€.oc8a:cA"u cancio.oc69,c{
e'<,cB text oox ca8eoT[co.::oplc{cDd, €%Get8o1a:d, oK 4
c]ick e3E: cs,qluSgc{
br5yS qdl €a!
'

Jooe ?r5 cftolqs -"6?-


ItFll]rl l2[E.iE ]:F:rri
laF:12 I2ta:4..! l:FED! l,tfra! I0:4f14
IrF2n4 I lc5!9 I2Ftil ! t2HV615 EEFEiti,i 64
rtF2a3 I2a5J!A l a:E03 t6Ht6l0
t,rr-2;0 12aEalB I tF6l5 ti.ltEt€ ADC
1rF127 1:aFsll 12F62r t9HV540
]EHV7F5
Tlma6/v"'DT ls! bllilN\!DT
Se,iill/!:
r2cE673 I2i6t3 I CCF/ECDP: .
l2cEE74 t6tr lrFB4
15[5tC
]EFE]
l6t5.qB ]EF8B
Tia6r laF:f:
liit.c2 IFa5!a
IiL-F::n I iiFln
1stit?B I IFE]S
16DiA I6F627A
I 6tr,-,r I 6F6?8

lrlcE5
16[654
I6F630
lD-"{l
o-?) P'c-Disasm window
] EF63l

Q
=El
I0F200 12C5M 1,1000
]2HV6DI
I2$,/615
16HV610
I CF220 t2EE5tS
I5HV540
124671

l2cE6/3
t2cE67l

9(" ') etc rvoe { e6:n.Sq

.Gs
,'+(o) Disassembrer qd.n"a+-n^"
"+,
",c
8Es?ri:Dt3)d ptc *{t
3?o.,.{e8,flas@:eqao8 oisassemure ceScg-a! hex nre ca
a'n,-'5qo1"e9r Main menu 9 Fite>open .4 cttct q6$e a*o2!:e o::e:r Shon cLrr Tootbar 9
open Hex-Frle c{ cticf ca3$".:5co3l:ecm€, olcure- Load Hex-File menu box 9 Look in:
64e,€e hex fire .i QG-e).a8@d.l'l
"s'flosqo]€dn

Q(o-g) uex fite c{ eg:q,:Sq

{ci..eg:ql,rs$, open r{ ctick q6c$rBeocs:a1 disassembte cr28$:oa: source fite


qriec'Tcu:Qc{- ,i(o ro)ao?€:c EEqcoa96pdr c\,€:.4 extension(.as;) GE
I,IPLAB IDE eal caSl€<ilo.>p!rr
%3
"?68 ""*
aQ-'"l13e-""fn: rlain menu o5gcoo5 eite: egqpq€ o4:Q1$pi ne at ca$6{9
f€.io€dc{ 6,i[Ecor:rrd" 4.-0e header directives qp:od: 6toEcu,;dca"%ESl8g;

!9re qp:.Aod: LADR_ox0Ooxx (Labre Address) qp:&6. 6"TEcor:rdo? 6 G€@qco


c33.e2j r

output nte cadp:ao:d9){1:cgo3@dq3o13,d, Nrain menu 9 view c{ crick q6c$c6


-
cge HexFile, D€bug, AsmFite, Hexdump o?!) eoTco:eoeglrr @6{l:33?c@'€:.1 €?rc6ql3
eoT$coc: o1 op! rr

HexFile:
Textrormat @€. Hexrite c{ eoT$cca:
@3:@6o1o2i rr

Debug:
P,c?:":T9 GoTo?o6oic3&: Prc @5 Prosram 6olr oroi:qp:.A 6oTG
co::@3:@6<;log! r PrcDisasmorai Prc E.6o{ ebusserc,4c8c,ieqln
PlcDisasm 65 [anslate-function
AsrhFit€:
4 E,-d$
HexFile r'? disassemble o76S,.qnc66l$cure], nsmrite r{eol!co::@€:@6o1o$rr
Hexdump:
Hexadecimal-Format
G3. HexFile c,icoT!cor:63:06t:1odn

Joog eT6 ei.1olqN -"Ga-


-.$d")

<p16F64!.,IUC>
CP OFT T PI;IRTE ON
'

Orqr LiroDlD

!5r 5',r \TLr5,lr,r

UOVLLI 0):D1
I{OVI'IF FoRT-q.

uau tt,otu=,
ctRr toRT! "oo
IADR OXD€!6
ETISS FORT.!..'
GOTO L,\D! OXDOOTI
BsF PORT9, -
GOTO L!I,R rlxooo 6
LARI 0x!04.{
Ld ecl polra, c
GOTO L.(}R OX]D!6

source file(AsmFile) 6l6c\rQ


Q(o-co) Disassemblecp6B:3r:

i(o-ot%S nexrire c{ eoT[co::clloplrr Q(o-c3) %3 Debus File 4 ""f0-,


,il$d!r Q(o-o?) ca€ Hexoumo e"Tl!co::dl r:plrr
"te "{

-:GG
Joo? ?16 eEroilqa
6ai:(o) Disassembrs Prc €.'So{%E@{(Dr -4,ql.d-3,sd9)

File. lt.\UsT fAs.emblyl\Plc tAB I fxPls\espll HtX


El g n H D E illl 1t PrcTvpe'
020000040000r
02 0000040000r-i.
10000tlo04316460 iDi?055crtE:1:660105 r ani2 ElrB
08001000n614062 B-r 610! E2E5C
02 400E!!f33r?E
!0000041! I'

Fe Edit View lnfo File: c-\UsI lAssenblyl\Plc tAB-l EXPTS\qptr.HEX


dEI g.E H H illl itHc.ryP.' i@F&;
Conf lguraEionBiEs: 0xlIf3

-.-ci: Dsla camin.l


0000 16s3 B5F 5']'ATU:,IIO
0001 01e 6 CLRT PORTE
00!2 3 !01 I{OVI!' Oxo1
ooo3 0085 IIOVLII trORT-..
0004 1263 lcf STATLiS. P.trr
0005 018 6 CLRF PORTE
0006 1c05 !Tr55 POFT,i.,0
000? 2eo-!- GOTO LADR OXoODA
000a 1406 NsF PORTD. D
!009 2EO6 GOTO L,I-DR ox0006
000-{ I0D6 BCI PORTB. N
000! 2e06 GOTO l.!.DR 0x0006

Q(o-cJ) Debus Fire Q

r..? ers oftciq- -"G.)


3.i:(o) oEassembrer "rc
{f3jd:!9e1349j!&I

tib Edr V_E,v li'o Fild ic:\usT { smbtyl\Plc LAB I ExPTs\exDr1 HEx

00000000 3a 30 32 3{] 30 30 30 :o 3rl 30 3d 30 :O2OOOOE40O00F-E,


00000010 0a !l. 3r :o 30 30 3n fo 30 .:lDOOOO0o031586
00000020 30 !l 30 31 33 30 39 ?5 50 31 32 3A 35 010130e5008312A6
00000030 30 31 30 35 31 43 30 41 32 :rs 41 ,1? 0D !-i- 3a ?0 01051COA28118. . :O
00000040 36 30 30 31 30 30 10 30 !6 31 l4:10 800100006140628O
0o0ooD50 36 31 3n 30 36 32 39 3s 43 30 32 34 30 61006235C.. r 0240
00000060 30 {5 30 30 4d 33 33 46 3? 45 0l! o! 0Eoot33r7E. ,:ooo
000000?0 30 30 30 30 31 46 ,i6 0D 0-!, 00001rF. .

HexdurnP File Q
Q(o-c?)

PIC-bisasilt",'
(c! 2@1 .2007 by Norberi Haqcmdnn

I PllD isasd@hiiionlhe oro


iD hro //wwPha,rioil ne.oro

Q(o-3t) About PIC-Disasm Text boxQ

Main menu > Aboul .4 crlct q6c$c6p: Q('-"E)q€0co,,.,ai""46: nlout


Inro
?
g€. web site {.c{:oc$qoS$:
PIC-D,sasm text box eoTcu:eoo$rr rD€,oe8olfiecr. e-mail
qcr6n:e<rT updated version.,ico$' tree
"3.$D2l*qj"6s<Dc8qp,.{ {o6,{3,;l-i!:r
oownroao <93o1$ 6@o1l'$ rr

Joog $3 ai6o16N -cGo


;

saEde) Hardwa,e rechn q*" f",lrc r\,r::""1:!T_____jrc_tco{qtlo{o o.i:qlodN6:qp:(r)

*4de)

Hardware Techniques for PIC Microcontrollers

e-3r {311:

pr c
Qc&{,?1@{.-ep:43?ri,GL3)d3?e1 rxscSo:o75pegee:co8:$&,d 3'6cD.c6
-.?q.ed, .8qo-qp'G3. 83:e.Dree.,"-3:+:e€. 3,.,it:3,d66pc3s3"6{:prc6rcDrsqp:
03c,rr6o6rE 43.3.ood, gl*"i,"a; ..s:D6c8c83cor:6]],ed:c,r6:qp:83. q6a4
ei-6-qp,4 86:6.013h@6,),3:{: f €. 3,oit:])d66pd?3'$4:G663?,€ 3"3i:Grq8a .i
or30o16d,

g-y aoSgc8qp:.{edo',r@3: (SAvlNG INPUT PINS)

Prc qo5aq%qco{.\,qp:.4ori:GtJ]dseil ::o39o5 linput piny qp:c{oc3$3o9


6 o,$3e13 od1,qp,o:la,elr .rt'laroc-ro-DtctrAL CONVERTER (ADc) qp:
prc ""q,",@€.
Jlo8ec-', Qdo{%$c"{oJ"qp:%3 a?o8eo5cap,ed,qp,c4 er,:c8cll:aSooiqp:3?4€:
or0.o3 3? r3: Gl3; .-,;l rre
g-g-crr oo8gc8o8lod,"ee .q"6Cp,8"4-6.!€s4:0G3:
(Multiple Switches on a Single lnput)

3?{16r,,3€e,el::cs8 3'oerc6or6?g aor;


(s$,lch) -6?",3.o€3'{:0t6c')iG,
=ir3q3,qp,%3?-, *.3r.3-{t%3 keypad slyle mu hptex,ng qa::ci3,n:EtE: muttipre
sv,rtches q,r:ol G3.d--dl-d, 3i...io,d, 3r{rca,3q"3:,ip:%3 3ro3t0506?o,d:%3
murtipre swilches qp:.{,ric8,qoi63:{ro)d:6o,o5,il3.d,

sled:o3€ eo3rc34 ?cD3?qd3aql3:G363, s6r16o..s.:.o""c{ saSeoeo::.ooco


3'G3ci. cG"3:orr{r:.{ Gras$ai3,6o13rdl, 4{ c0o3:dE,e.}, 36.x6o)csrJ.D,oG663,
q da{.aq-{o,3]d 3?€E cc,,.3?q,'sDqp:.4 4s:o,? Gr$3G,rc33.,,d,,

ANALOG TO DIGITAL CONVERTER (ADC)

ADc mo.iuie rjlo3e*: ptc qdoi,€$co6o'qp:%3 aoc :ao39c3o:61rp! Q(s-c)


%€Gco.:oJdo43: muliipre switches qp:oi o.65€3.@.3'€%qco6a:, 4Q%3 swltched
resistor netlvorK .43,tri'016@,3:6celq3c}eoopl, c'3'ca8 q'so,o-)1Q:qp:lri cs:EloS 3,ri:01
[3:$3. r,otrage crviuer o:QQ:c{ .0'3,oJ6o,$:6otrrdn qfic',e],Q.r,:oorcooi noc 9

Joo? ie8 o$qJqo ,00


$r{:(S) Hardv/are rec,,iqles ior Pic ftlicr..on1rcrre:s Prc
QdaiqqoiM ".?l|t:g.&]l
cs,i,ae:,:r soiv,are code '..D,d3;+:0io, tr)":43.paed? A.-,-64,"i
"i3,",$€19:,
Gs,fl .sd o?e,o,+e6,rGc,,.3rd,

+(e-c) Multipre switches wiih ADc

CO[J]PARATOR AND T][4iNG

comparator rio3eu prc qd.{,BE,:ofio,ce3 3'o3r":-;i-d,4


3'.i,0G'
murtipre swirches,ip,c4 -.3543,-$3e-dn qoEo,or6$:qp'.4- ?$('q63,36s,q1,,s
6():co.,od{e8 $.)3436pac!d6@,€.G6.0T-.- q.3,":r€.4c3d63,3 4363,ca3:6
3a8q:Q.3.,: (internat vortase rererence) oi {+a9co:$36o]JdL' oo5o6:.ir,id:ccsGGeta
83. 3'3i:qlqs])dEd:d,5:f 6.rcs6or,€.3o,,$e,i-d, .-.*d,s.
"or-G5.])d
s:co.3%3
caol8: comparator .? ADc a?Gsoli'oLg€6e:G6E:, ?cE,Did,9o Q(s-.1)"e€Q-,,-a.4.
oo5co8:.,f rap!.c,SQ|G8d -,"53.-"? et6053J3:$36e,G6,.,rt3,d,

(l(c-J) l'.'tu tipte Sw tcnes with Charse Timins


,i(e ,3:q qoso, n+ aqeca3 cnooSsoz c1 4or3€oec.,r:dr-d' 4{.GL"rsGs,
-d q.3;o:c{oi€'o,E€,".e":., ,'roosEo,cl .4 er3o6.8e:qi@.€a"re{gd o?3:o,6e,
G6oL,d, 43,i$-d ".+,qai, ,Gq"a$*- si6G6,ro1.dll d3lcqc84:qi3 qda{
oaqc"{o,:,,d 43,",H"GrF3.; .8.3.8.-".35.od, cs36f,.81,G4qrj€c$d, ..eo3:ao3qo5
qp:e43:D?,rp:]jd -56r"E6,J,8{3.e.c,c86.€dn qoe-",iQ,,r,,.{ es,x,,s]J"se.;

1.ca 1qB e$qil{-


sir,, H-.dw" ! rec.i.ques ro' prc Mso@nrrore,s
___j!ja{39lyjj3a.r^;* r

3Jd-.1 ,ls-i, oc1do,6Eql3,33?ce.; qel6o6e3.ff 4e,o,fi3rd .i6c,,.663Jr rE :e


(enoush sap) 61{o?""6,,f.,d' 3?.".5d Eq3:rrd GL3,? 3'a3cr 6arai G,multaneous swrch
process) Q,i{ir:oo?o5i.al3 qoso,rqp:o? e6:qc$"pca3 o4.::o:etc6qp:Bro6.l qBcSo?R.:cir
eo_r:.::p!r
comparator cao€qc3o31or2i:@3. swircn prccess,r?ccEDc6oiE:3)dool oo€tc8d
3'e.3ic33"G6.i. €0.€:dqQc93,3"1.Jdr tri.?3- -".sEo,e a3o6.,icec5"3,,,
c{cc6o,6@5 compararor sao€go5:a@63?ri:qE: ooo58or,,riqrl606o83:+36o"".35."d,
rn".SB-Q.3"r::>d comparator €i rhreshob q.D:f3i99lqlr:ea::oo'l comparator op!
state GG,3:.8.:6c'60.r.a)eir sorMare 3,$ 3:o39.3/:,cgd906 €Gi3:cifiGte3E:6q'.3
mocs8o,Q.3"r:e3. thr,"shord Q.s,:o?.a9q.8,,q1@"--{$4 4e!o,qdl ordn
DIGITAL THRESHOLDS AND TII\IING

36q6o,oSqd:od fe::t3..o3o?o1o2!' o.3c.:6:oplcud, i(a-J) -"?€'


comparator
o€ G6"il",d, s6q6orosqa:,'ei ,,'ocS6o,€rlq.3"r,o? ..-.':q6:6p%E comparator al
threshold q.s,?:.{ 3,ri:Gl6d.?.r: vrH thresho d .{3?3e:0tc.,,Jrrallr schmiti tasger input
<.,o6cu6,e,5 vrrr th,esho d f,ra! rrL inplt co.6orqi€ 8Cl@,"-"@9. 3-3q.3"r'e6oncson,i
c,?4€:or,$&,,$d, cl.6}5shd,%€ 3?c,g2!,qlde? 3,c,cs3"cDc6 3?€{.ec.,r.Q.o?,o?
crros sate e oT%€or3co?:qc]]r€@o€. et6E:6@3:D:*:fiQqp:o?rc6$@€:@6dloa!r '/,,r
threshord oiQ:xa9 ogd,-6?f€.o>6?co?d6f,,6@)3. cahbrarion qSqicft?66oc36.ea9r

g-1-1rr oo8qc6o:61or$:98 Keypad qp:4o,6.o3ori:Gfi3:


(Keypads to a Single lnput)

Q(g-q) axa Kevpao aesistor N'^iwork


i€. o,a',ip:oi cao,o-G6cod
o3o1d PoRrB ca3 Keypadsqp:.{ 3:
od s opl, xeypaos.ip'-d q7,&
crocoorrcrre,s P c €.Aaic6;@{M ori:qjodNS:qp(9)
riadware rechniqucs Io. Prc Nl
'aq:(e)
96.os o3:{.93.aoo313"5-.r,GLqq phs oJr'gc cg3,3oxa86@Jl o2!r eo:n,q:a:,@€. +xr
teypad a$1ca8 (8) I/o pin ois8oloa:n
i(g-?)%8 res,sto' network o:3qr.fcoTScoc:cilerplrr cr,3,::2! axa keypad o)Stc{
switchable resistor matrx sa@6 3?.+:Qlc'l,:Qd 6,lreco",G3'G5o13,dn Ke;, 4$3cio5o€
@EeoTco:eor -"fu.Aeit"Q ADc ai.6o?o6 capacitor charse timer .D read o?,5G:
g8cQo8o2i xey e3.{3eD: eald3"o>.3.{ 6oTeo36,r:dlrd,, s)qp!:c:p! o:3@6q13 tey
0,6?c4r,F.8ad @3.rE3:c?o33, 3?{:oLFEcilcJdl

e-?r LED oqpoQr:.{aai:GG8:


(DRIVING MULTIPLE LEDs)

Lisht Emittins Diode (LED) qp:3)d qdo{c8{co{co:qp,sacac; -.8Esri:o36a,


3'6coro63,o?0rosd:qp:G6@,.,LJd, Eosa{%4co6carqp:o\ 3}.8drc6qp:r,d LED qp:o8:
qQ:aq.6 cQcaSer-qq66:e@3,.{ ou:ncrF,::@€. Qc'5a$caico{o,€rl
"?"6".'$3@o3!'r
,?,3a,33!ri:Gt$36oa,d,
::csc;1o5o"6qoa3 LED 016c,r:.{ {.".J5-d, Q.3a{,Eico{c,rl
r.::ca3 ecs.69c3-".1o%.3e, .,,q.-c5flc3fi6iGe>r6@,€. =€drc,5-+2j,c,r5@3. reo
-cp,*&,.{ o:6"o€sacl: 0t$e€dqd:cD3::>{r<'i n6s6oTc?c8o,@ry1::drr Q"6"{
.€ico{.,,"ri caqc69.6saee1sacacA93.3r3i:@t$e6d LED s?66r3"%.6qp:c{ er,:c6ol"^oc:ca8
6orGcor:oL,dil

l/Ooins 1 3 5 6 6 s
LEOs 2 6 12 20 30 42 56

LED qp!$eg i€ec8qp'G6@63,.6@,3. q$S8:6@r€:.1 o,r:.no13"o6od:Dr E:


83.Q6"-d, Q(e 9)%€Gco',oo;.{. Qc6aqcd.D{ca.€rl s:cac;qdor61c63 LED e6e:.4
60.3:G1or6:o3oai:GGEeoc.2! sacar8q.Sol q.3".:q3.3?66%€
' ot
<u€:@: caqcAgo6ol
Q.oc:@t oe@q€ oz co€:eocE6pplrr

+(C-9) 2 LEDS oN 1 vo PrN

.lco? ir5 @ftolqN


Gi:(d Hadwa,e rechnrques ror Prc Mrcrccontrorers Prc €.no{.e1@i@ oi,qp.3o6,qP,(9)

q.,Sa{
%EcD{c',€,ts,€o5q o6(q)qo3€ reo (c) ii: or8.o€3"oi :GL$3Q4 Q(e -r) "a3
3,cgdeo6(r)e%6 LED (3J)cr: or3-33:3i,0rQc{ {(e-G) oe€6o1!.oe:D$
"AE-,G,
ool€:6%G3Re6,',a,dn

FlCmicao
DigllallO
ol
-03
\:
o5 06
oigital l/O i!
!!
o2
Digilal [rO
R3

q(o-J) 6 LEDS oN 3 uo PlNs

PlCmlcro
obital I/o
D1 o1t
i:
oig'ral uo
R2 D2 D5 ID7 D6
i:
Dlgital I/O
R3 0l o6 D10

Dqital l,o

Q(g-G) tz leos ot'l + uo etns

LED qp:c,fl o:6@6o3€ o6oQ:coo8emQcoS:eoc$


""con6uilQ(e-6)ql8-36o€co::m:;
qiteEdo?cu3:6eiLEDqp:c{ mulliplexins <93eo:o$-qc6 ogecv:cier: software timins r,?
o3i:Gfl1 cF"66,r],d,,
ococ8dl:aEoopcfl Dot matrix s€phics aisptay :a@6::4:@FIi pixel o:61eq9ca3
LED oJ6o?:.,? -.i,Gpd{ql€ LED 3,6q3?%c6tp:qp:o€:3rdt3.3"9t QeoTgsae"pSo$
$$.8J,eocE6pg!' el{.G6q83,?" rro o:6q:q13:c,f coe:e'qio%c8 33{qoicqq63l.@o€.
@6o$rr Dut.v q,cle $€. intensity {.r:gi eop.o13:;eoo$ r

rcoo 116 e5s"13,o -.9?-


oai:(d Hardware rechniques for Pic t,licrocontrollels Plc €o5.,i.3"i6{M m.e:

{..J--, cacorf ,-: -n3aoierj


"585%:
rED o:6.i:{r,oe,-oc:d ra.ri: r!
qt:{qe ,ntensity cld 6c!p.once.: E e:{L:
"@6eo.o.nq1n
oispray qp:.{ aive casqo2icBs{1:::d -eS-qsQEp3"@€,r9g,G5EcocE6"dr
LED or6c!:cD3:$3"%o8 s,"sd9c3561 active 06qq4€oa)d o,s?r,d active hish
G6G:
qj6or6?r,d active row @Sqeocs!, orqro5qp:4 cao€qo33"@6$o39o5qo:l"d' 4.9-
-lir"3qp,s qil3E,6@"e,+q63:ei$3".," "fl ,,
Leo qp:{orE@3ceE o,>6cQ:cooSoo,qcD€:cocqqlt ooEqcEqP:9€.o"c8d9c3qp:.4
ooicDcici re-conrjsure a66o:qdl€d, .i.93,EPo?N3r6d LED qp:3rpg @gc2 active @6
eqeoe$ r

g-1-crr Seven-segment Displays qp:gr.4ori:G$3:


(Driving Multiple Seven-segment Displays with I l/O Pins)

.BE:ocD{:€J,, Q"A$*aci seven sesmenr disprays qp:d -"i,DL.-.$


-"i,+'{
@o1o$,r xeypao q::d.:1.o3 seven'segment dispray qp:4 ca.,i,0.ri:.,c?c5 Q.;"{.aq-{
cacgdgdqt::BD,{ 3"+:QLqqcq3J6,r.,dr segment o6qq3:EocacB c,cg.A9c3o:6q
-.5
39€. common cathode(anode) 3?%c6 3,c31:3?S.69.3o,6?cEs"66o"rd I {(e r)e8 ocoi,
i8c\i:c{ ,i6o1E$3?%.3 .Do63acs?3,33,oec{ 6oTGco,:,)13)dr 3adl:o"8.6eoEa,d
common cathode 3?car'5 E..r?:G€.orqQ:c{ec36,r:€:r common anode:ao3c8
Q.-,{d.-iQ,
.4qo5c{,:qo13rd,, sa{6oc3cu6:9:ca€ 3,c8q:3?o8o5tc6,?E coqgoga,:aqdqp:a,6.D3.5@:9
oEl:6,.,:6c,,.6@dl 1)dn

B
c
D
.ll"
vlumrcro
E

G
.f r"

Diq(il

Note: Pin$ A - G 6rc oigilal t'O.

:(o-.) z DtGtTs ON 8 /o ptNs

Joo? $3 o{{olqo o€,o.'5o€,


@i:(d HadwrerechniqueslorPlcrvlicroconrrorers Prc{.3eicBE@{Motri,qloc6o5:rFG)

Nole: PrnsA -G urc Oigilall' .

Q(E-O) DIGIT EXPANSION USING AN OCTAL LATCH

3xDo6,il,i(e-o)%3Gcor:3)d.f,?. octal latch(such as 74F573) r'?ori:GE: ocDq:qp:.i


eg:g:S$QeoTeo: $E cil eo:o2!rr
octal latch .{saa?:EFp%3 €,cl6tt13?{.3qp:.{oc8@1eeoc8g.6qol€eqr

cr 9064 Q.-,Ges,,$,, sesmentqp: .A-G' 4 s:c$$eocQadl:e1e:a:€ setq8c;lr


LE
_jj'=tse. <B"G>=o G5al3 Disitl 3)ai enable @6eocEEp2],r
grrre gc6c{ {.-'iAs.,E', sesmentql': .A-G' 4 3?<'i6€a,Q6{rj6rera:3 set o?6dlr
<A-F>=1iE .c'=o G6q€ Di,oiil q6p%3 "0" GoTcurEocSS."d'
?, Q6(,T1463r,63,3 oico'o8ca, detay -{icor:eo: o1, digit0.6qocad 3mscloc:q13
digitqg6loo8d 21ms@6o2i:;c2r; flesh rale*ai aTHz G6),a:n
9r eaco.6c;l::8:aoiaoi€: aoc6cuoScpSeeo:Eo1rr

g-9,r oc8c39cE9:ol egc.::@3: (SAVING OUTPUT PINS)

Qo6a6%icDicD.€,5 sa<eo6ec6e:c{ o:3$€:>seelo.,G: ooil:66oe:qts3c:dfd,


cu6:s:ft.f aoc8coo8eoTSoil e2! rr

e-9-on LJsing Opto-isolators as Output Expansion


QoE.{ q$co$<.:co5 *"s"3q.5-ad="s.4.- 3?+:G0: LED 3,qp,3,G",.? c.lt,6o
$€c@oe: 3acoc6ca36olE:E:G5.ood, "ird,.ae,.6 Qc,6a{.89-fic-.\ 3?e.6q03
c:gg,ct:S.2e opto-isorator qD'4",6.089: .i-qp,-&,4 c6E:q136,,:ReGEe:
"%1
..-d,

Joo? ii6 6sici qo -!?!-


FIcqosa{oei@{Msq:rP'5N5:q':(ej
gl,!ry:fgqqaqPrcrr'iicro@nrrorrets

3o
?(e e) 12 DlGlr [,luLTlPLEX|NG wrH oPTo-rsoLATORS
-
o3:oc3o3'
.1oo9 1e6 olqo]{o *"
*+(0) Ha'dware Technrques ror plc t\,4icrocontro ers Prc 6d!{.e{@ 05o,6:EP:(el

=ir4
G:)t4
ffif,*fi,"ffii}""J3.::,T"'"Tf*9P;

g-9-1rr Using PlCmicro as Output Expansron

Dpd--, .o,%;6oTls
drive ot6 rr o€:0ca3
Ad.t _ "aqd-4, pruy co'otior
o%.3 3"3?: Grcor: dl opS n

P n3 A. G aE Dgnatt/O-

i(e-.") ptc r\,itcRo AS vo EXPANDER

e -c,r oo3/oecftc8ep:.{ oe6:"?qe3i:GG3: (MAxlMlzlNG PIN UsAGE)

.. Qo;o{zico{cu:erl o pin s:c{q6ci:oio,6?6m 3"oi:0rg€6d{et€ qp:E.3?c&g

Sharing l/O Pins with LCDS

- t:oottol^!tr: LCD modure rp:od €c66ieico{cDr\p:f€.o)oo53?4:Fjq?%S


r?.GJ-€tD€:o?.3?o?3e36$-%d
-
qa;"q.sq-6*,,i "uo,,"
"""g;.q,i:or:o?1.3$@oil1)dn
(c)r9 (rr)t3?d 3?ri:0r@6ro1 Dpln

Joor i$3 oliolqN -J2e- o6.o.i"r,


8f r"1oE-LNO3 c3l HllM SNrd O/l SNIUVHS (cc-0)'.4

-i
""'-l

LrSe'ssoos:cft:P6tr.x
gccalug.tego$cogoEoc."-e 3mrirFe.to,9aolfl aqeua ,@ee$
alqesLp ro uorrecrLdde '3{

u"o o"i 9- ;; $c 'F g""F


3 ,0,-S"8"e* '3$ :a,rracsue4 snq pod
",."'3j3.,t""'99*'pr3"*eeoeer$Epccceeg,:e$|5ooc631rr
olerco5!otoe.
"F"".:ttt'h*
Soeo€e:cJbsg.',:€ee
6:O:3* g l.c,hgheo uorrrsuer gs5o59:8ote$cc{e!b_ nnlq F.ocr u'
rFeo,seeAJ61,9 Aco .osolbs{
, F nFoco,3tro:F€' so&)€e@,t3seo:€er
Frcs5 r ,ecLooet" (qqq) $..oFco
5 (atqPua)l {s'".m pcc s31
elnpour
ai0c@3@e:$coro ccca:€eE k:c,b u,d o/l
hFo3$E:{ce,30cfgc!t5:eo,,Fs,LFcco,3t
6coAcL:db ua ni eoc Sco 63,.16ec.-r L
Hardwarc Techniques for PIC Mrcrocontro ers

e-Gn dloleflo:4gdnBo5{dr (PowER SAVING TRICKS)

Variable Frequency RC Osc llator

@3"9<n6ao€eo,eleu Rc osc,llaror cp,-d .q't6,{L-E' oci:qgca€ cgoS.?@


,jtod, riFr$ord: or3:o?,-d oqc3e6orSqt:od:.{c,r cao6eo:{3@olerdrli(s-c1)os€
6ollEco.'3Jd.ao?3: s'oi:c0L.dc8o5€fe>d r/o pin o:61ca3 G9.o6co3 qogs,o6oi:
:i cuTc8 rnor.'5Eo.::o:6oi:o? o,3.oe3e3i,Giedagq1€ o{c6€EoQ c$cGr3: (shifl) co:g€E:
mulli-speecr Rc oscilrator 3eGE ori:qq36,red. q16Er@e:r$:6'c8?e16qp:ocac6 ow
speed .43a:i:GG: qi6E:6@13:qp:6o,.Bg616qp:3?cAcB highspeed do.r:Qtq€eoeair

Q(g-.g) venl.rere seeED Rc osctllAroR

RC Watchdog Wake-up

+(e-c?) Low CURRENT \i/AKE-uP


watchdos timer o2)
3rd E8erl
E8€15 4-"a
cooe rrf o::ceaJipq€or$:6or.e:,
o:cce<'56pq€org:eor.3:
{c,5o{c8$co6coro?
r

SLEEP mode c G-dts,- (wake-up) cu:ego3 Eie6cpcaSord:6,',e: sacsgoci:,1og

Joo? itd "iedt{o) o3:ocio3:


ca{:fo) lrorrels Plc q.r.{%86{M Gci:qloo5N3:qp'(9)
Had'vare rechniques ror Prc Mic,oco

.€Jdn 3i..rr5od, G"ft.6r, 3"e:ql?qp,%8 o3:o:d ,-']o]or:ri:s 3,."sqqp,G':9c@'€:


.- ocit r:s,r
comparator cioEec>c Q.'5.{.e{,tro{c,r%e {"go-,cg3..4,-,,,$Eo-,"{.c8 compa'-ator
%€ or3.o3ooi:01@:,vake-up c{q6eo:3@d r:2! r Q(s-cq)cB€QcD',-&ao?€: qosc',
9€.rar.,o53c.r{.c{ comparator .5s:o3qo6qe o:6.03<r, lhreshold q.sr:.4 o{oqiS@Lo?3
S:e7:cr5 interrupt cfl enaute @6eo,jlo$rr {egcc$ .n,-,c63c.,rc[ q916o6cec3qgc3€"8:
SLEEP mode c!.c"po5co lrS,
ooo5Eo,-d threshotd q.@r:s?cSc6pdodo?€csDe q6'6Qi"at'.", interrupt 4
@6eoTeo@: ware-up 0i@6€o,jladrr *"ro5o13xo3..o€.e66:D,3qcAqp:c{ ecu.cu:cil
r nc
network c{ 968:e@€:3'rdrcc6r, {60&'r€ 3q€:<.?34€,,Lrdn

WAKE.IJP PROCEDURE

1 Set clmparator input to a digital oLtpul


2 \ Jrte a zero to blear the capacitor
3 Set ihe comparator input back lo a comparator rnput-
4 Read the comparator state Jlag to clear it.
5 Enabte the comparator interrupt
: 6 Set to SLEEP.

g-9r oq{oeoT":e,ieoc .il oll-6oc$€: (Transf ormerless Power S upply)

12l16/17 seies Plc qc6o{%$cD{curqp: Q963:eSo96qEe%.6 <.'1o1so8oc$8:9


qi6E:@c€: rom.r o$.orsaci:@p8sa3€o3rdrL 46@'3.Q€rofl.c{ eca396o6@3. <r:1ol e<-r:
c:d3:a1 6r,:ccs 6o1.o1:E: s,o?qaon ocErlard cDo6o6oTtl" eoleo: do',lcoSocQ€,
ocBNS: od6€€ao3Qci coTQd €d,
Q(g-c9)c?3@cD':.r$@o?€: cn,,'c66aro6o1: 9€. {ogo'rco:6o,i:{5fl o:i::oc8
:ocr5acSp, e:a8Q.oro3e1€:o:61 9€. :ocfq.rScoc:e:>sro1 rn<.:o53o:oerl .fi.Giq-d
(capacitive reaclance) oE! {ogaro5159co.6 p:go@:er:q€ {ogolrca€cB$:earqnEE:
e@r3:o$9@o66,6f e@3: eog.qeoc$n

V(F -r9/ KL @9::D.DocD(\)c!9

Joo? a+3 €iqolqN


$ldd Hardwarc rechniques ror Prc r,rrcroconrrorleE plc €.,56qoa$@{M Fi:noo5o6:qpd9)

4a168:G@.3:r:d moos6D€i -od8o:€.o,gQ:6,.rT,%srorplee@: Q.:;o:o3 1e: vr


r.dcDd: o.8.,5Q.3-, v2 @dqp:8.16:3)do? oi€";rod, 4-.1 e33:6@,3:ooo,o?
ca,do13"4€: %oSadF3GoDd,
Inus = V1 /Xc

or3:oa€ &
= 1/2nrc $d
,DocSSolsr\ cooc$8o,3.o>lQ:G6odr
ca<nc$$ vt= zeov93. t= soHz G6qg3-

lRMs = V1 /Xc = V1 x 2fiC


= 230 (2n x 50 c)
= 72257C
lFMs ^ /zmrultF l96DP I

ssorl$:o?q,{cqqie Q(e ois:ocso,6eqrs:c4 is3?c,sqp:


"r).?s".rE-.,-"d.r9.
o,o,jsEo-,qp:5E: co36GG3oi$3;r.rdn 4QcB3 3?6,)1e:8 3"":r€. 3?rLc3Q.3"r:o?. Ersc?
0-,dt3Jdn q.3?",cqe:o.6?q€,3e mqp:+:3ari:0t€36d er33:6@,€:oo.cD
"e"6"i{3{4
f,)e9 rbm,{FF .g.LgoDP'r
h

nn
-). +v

f",

Qte-r5l r,v q.3?r:o3q3:odcD6:+

c\rc6€% 3:3i: DLca)]s,al 8e"i€ec8qp,5d q.or:,r€ q3,4 ordE6h6.$,e Gte36o,.fi


ol3)dil i(e-3G)%e@doln

Joog ir6 ciroiiN o::od.3:


@lde) HErdware rechn'ques for Prc l,licrocontrclte,s ptc E
06. ioe4o8(D o:l;qpro5o3:qr(9)
+51V

5lv

Q(g-cC) -06."e.4, +/- 5 1v Q.sn:o€q€:oo5co6:Q

c{ fuse 5S: GltD(c) 9€.:oc63<.:E


::coc$<jloo6<u3:ca3 esaEE$:{.r,::<Q3:9 neuka (N)
co::odr{ root@1eoc$<tD$rr glei.aoatugc,5co":83,G€. 6oE.o.EeoSi p:og3:63: .,?
mc6cS$3e,.rog!rr
-qp:ea:S8. 12116/17 sedes prc qdoire$coficur4..{ oai:GtcJdool sflc8
q,cD:ci8:.'? erilQto$ oc$saEeorr Q(gca)oe8 oeo13:Q.r,r:c'f8:o:61o$'cao3o6 @1Q€-r'
cca oc6o6,c{ coTScoaol cc$r

{(g-cj) <D.'5eoa{' +s.iv Q.ocroS ep: oo6o6, {

Joo? i+6 cholqo


sq:(ro)Erecironic combinar on Lock with ptc prc
Q;r6.A1@{M ,)i:noo5N6:{ip:(r)

""e$("")
Electronic Combination Lock with PIC
co-cu {s1{,

web site. http//w\.!w jap hu/electronic/ c66eorcco:eo, Peie/s Electronic


saScrnqcA
Projects ejl€:oig
Peter JAKAB 6$3r.,6dl0cor:6r, Electronic Combination Lock with plc
e@.3:o? oreGdcdn

co-JF ocEavs!e€r3:6{'T$qa3 (Description}

gloo5cD6:c| orjl:qp:3,3o3/3eg3.QteE6p%3 3"ci,G6€dl


9 code qr: e:dn Keypad
4fi.6e€:E:e..6O{F"Ed:c.j@o6,3"al1retayc46e'g.49o:D6.o5a1:.,?
-s3./c"E.5 GFy3.'€3o1o$ r coae qp:.4cod: Ec3@Lc66Gr3,cs$6o1c:dn oo6c'r5:.4
sa{1::ao:: version (1){p i@,@,-3@-:,.llog'r
Version 2-023 f,)a: ptc16F843r db6olc)a9r
version 2-024 ])e:
ptc16F628 3,(?.3b6(',13,ain
version 2-0253)e: prc16F628o? seriat LcD 93.QocA 3"3i,GtoA3?%c6 b6o1-drl
oqP:o::@s. versron ra:q:c63 .adsr"3cp,s,i@8, 3?rd:ccsgj}r eeqr;$@
o1r.:2!'r

co-qn oo5o$:a<.26o76{ (Operation}

83.opi:s3:q$oo69o5c.,:63, code ql': 6o53!e:8, # oi Fsdt , ?.D"o6o:cor:


6:D' un-modrrred Hii lre oa,
1234#
::2!xcono crde qp:@6o1er2!r
1 2 3 4 c{{dg: # o?fic3codo?.6et6 retay
{e<,rc85.o2!rr
qco cooe c{Q€cQel3 O r{ :a:i'@16iolegr gcu coae o\egccf,ca6 () .{{"6.1rr e.o
code 9$9€ LED(code chanse indicato| cD3:cs:6oea9,,) G{-d code.4 $6@6
{oscod6ro:todn G3,ros.jteo(,.o?@ddl ll

1234r1998#1998#

{oJ t s s ee-,p! cooe a::6$6:g2:ooeeir


sr@::eur Keypad tayout' {oe:Qpe!{e8 source code ,%€ Keytabte 9
6r". 5,t1raoi6:6oT$co1,6::' bunon cr€rn.r.c.s.n:, 4 -.q$., .$ 0Fi.,,q.;.p1,

Joc? $6 e5r.lqN -3o? o3:ocio€:


,aE:(oo)Erectronic aombin?tion Lcck v?irh Prc Ptc {.,5a{%i6{M -.i,{oo5N5,qp,(9)

dt "456b"

o1"1"o6{,cq3,-d qi33:c@.€:3r+i:4: 200 mA ceoSco:$8@: q.3m:p 8 9 30 vorts


o@6rJ€.rd, 3i.6ec3 3?{:GrcDr:6.,q€N: -e6$€ca"r3 oiccDroscrd q$63=@.3:
,-,tnco .[qc8eo,$"- .n .D0"43,d'G66tdl€d'
BUzzER a:2j passive ceramrc piezo sounder 3a{t s,.o:G36ldl6dn lniernal (sound
generator) eleclronics d1:oo:: cl,eolc8 low-impedance speaker coils olo€eor BUZZER
3,41:s?o?:qp:o? -.i,Gr.d.q*'
co-9r Software
o3o6or:G3. software version ca:,c,i:o$ o73cQ:o$o2d@.1-d' 8E3a:i:Gpai
version e:ogri source code .{ 3?€orqc8,?€ Oowrloao o;3<1$€cilo$r version {6rc6t
source code :.cac8 asm nLe 6S. hex lire 4.oi glo-,3?3+€ 3,c2 co2ie<,,:cor:
",ai:o|{:xd
ctr CD "ch1o.zip"
g foldet %3 q,r,i3rtri:Gt$€,rilc:dlr
source code 4€:%E "coecqS:3,{to$ @L@ee @3,.;"q,-,:6€ea, ol epE-Ep:
oacgc8 ceRnition qp:olo€o1od egrcr6ol deRniton qp:.{e<,r.o'"dl r

Ithis value is used for delay calibration. Of course, the code will run with
- ldiiferent speed hardware bs well, but faster or slower than intended.
pulsewidth EQU this Value is used to set the delay of the output pulse To calculate the
.l?l150' _ delay in seconds, use pulsewidth'20 ms -
this value sels the length ofthe code. The length is elways fixed, and yo!
cal set il much higher. unti. yoJ have avarlable_R1yaI"
"ll_
nhz Eoo D'4' ())3:oe9 delay calibration s?%o606o1-dr

pulsewidth EQU 'D'.Iso' (])6:oe) outpLrl pulse 3?gri cetayc{ set q3e,{@Eolrpirr

cetayc{ og{.@€.cA"3n.tcqele pulsewidth'2oms rn""lqcilrlplrr

clen Eou 4 o3:a:2! code o:Q:s?e6l3A.3c4oo39c8cilopir chip (?e RA[4 6{qr6o1.


r:91 code o:o2:oeepacacr5cf oi:{oo69o3$3 <-r1o2!
'r

co-grr Hardware

cooe qp: r{
{rfcg€:epo3e Keypad .'?3:a,EFtc<.:ca!r 4x4 Keypad cr,6qo,p!n-.6
co,:rio? *,.A,jlQ(ro c)ca€ eoT@coc:,j1a:2ir1 ::.o3ol3.o'd6soc8@:e>r: ax4 Keypad ({rp
$oe1$3cllcn pustr lutton switcn(cG)1@€. 88c,3,o,d66or.3qoa$e,ic.,d,,

Joog ?+6 @iqdl qN


-a{:($) Eled.onic combinar,on Lock with Plc ptc q.te{.!Eco{M oi,qpc3o6:qa(9)

c
I-T-I

I $ D
t-T-l t-T-l I-T'1

{(co-c) +x+ XeypaO org!e:o: cDcoo:


Q

i-
'- Colo bor-r coi-lcor-s

Keypad oe8 code aegocc.::g:cf aacoc,5cileor::ooi8:ecA.GE$3;lcJdl

co-Grr ococt::{:o@3o1016o,8'"f..6o66.D:Elo3qpr(Power-up for the first time)

. u{oq6+3,c"",no. Qdo{c6$co{cucel€8c{ <.,o,5cu6:ca8cor6ao33 oldl6<-,:E:69.c8


ro5+o1c3(o)r8 vDD .{.Dc6acsE: qcco:S 6Qo6:trtr3@dqcjt€dr
. q€c\,:Q6foE q"ti"1.6('E) cae vDD ]Jd +5vDc
6 66o666o:qo:lee!,
doq6*E:cor:6r, EoSo{ 34 oo5c 3,%3or3.o€E:q.o3 o1olo?g€,
.'fc'5:,pi"e.1 ueep
oq3eo26eo:eoler,58eo:
@p!ar :6lcoce9r oFip@:qol- o{"qtu d?t6
?aqgo,c'54"366o:o1n
. Keypad gacto5qp:"? o]6qlo3$3o?e: ueep Ge!;o:5qo3;@,"r-,d'
4{.
o@r:e1o1cn Keypao 9 contact q,e:c{ 3?3:Eorr@3. o3€6D:o1r
c o.,6qlo8t3{€: beep 6a!:1,o'3q.3c"o6Qd@':6rqqi3 €:66
Keypad goo?o8qp:ofl
co,o,oq,?e84 {id*,.rA.d', source code oa€ mhz dennii,on c{.ot]..neo:$
G$c.d:6.',€:' deray .44:6.,r:d6D5.\,e9:6o,,e, GG€q,i-J'.

Joog $6 6irdlio '.oN-


ooq(.o) Ereclronic combination Lock with Plc Plc Q.66 {.61@{ @ Gtri: Xodo6:qP:(i)

version o:61q3:::e@:e:.4 €3;".3c;l-o?3'.,q5.,iqp'dd oreQco":o1-d,,

co-grr Combination Lock v2-023 for PlC16F84

schematic

+8-3@UDC
. 7eLO5 ol TAAa

E-f_
0sc2 p32

,\'.:.::".1,':.:":::::''"

code

details ot the source code internals

experimental source and HEX file modiied fort


(ON/OFF) relay operation
lexperimental source modified to accePl S dffer

to t"g"PJMo itu"rui" s. cr2d asm


se ourpurs
lpunzaran ,l?EIcI

cacoc6cilccuc:9 download o?61car:6rrec,:6cufi asm file 13, hex nte {.c{ 9lo:3?613.
oo7c"2ino,.o",.-'r cD ch1o zip forder 3 -2)ca€:ec,,corcilo2)rr
{

lcoe 1e6 eSol{- -roG


@4r(io)Eleclronrc combrnatjon Lock wth PIC e c Qo3e

part Iist
part number description
PlC16F84-10 or
tc1
. P1C16F84A - [/icroch]p microcontroLler pre-programmed

lc(min)=500 nA

any color LED or


3mm green LED

I 1 kohm 1/4W resislor

220 ohm 1/4W resistor


22 pF ceramic capacitor
C2 22 pF cerdr;c capac;loj
C3 1100 nF ceramic capacitor
c4 100 nF ceramic capactor
x1 10MHz or 4MHz crystal
celamic piezo sounder
BUZZER
(also called'piezo diaphragm','piezo audio transduceI.,'piezo
keypad 3x4 or 4x4 mat x keypad
K1 relay, see text for specifrcaiions
power supply wilh 8-30V DC output - sugge sted voltage is 12VDC
connectcrs forthe powersupply and the keypad
misc Prjni.d C rcLit Eoard (PCB) srip board or bread-board
lflexible rv res fo. connectrng rela! LED buzzer, po\.re. supp y
horsi J f- lhP'-'.ltorics

1oo9 996 o!9o1{o .3'-cDo3,


i:a1:(.o)Elecrronic Prc 6

Lock v2-024 for PlC16F628


schematic

inpuaPl65 of zso'

01

code

; description writte; by d;wntoad


source corle and HEX fite for ihe 16F627/g with defa;tt sennss peter .IAKA"
- *++j= f
c 2-024.he\

3rcodo:lcor:g download L?661.@.::6or6(r;o)d asm fite f€. hex fite o?,4 glore8f3.
eo?cDdco,co,:6o:: cD fi ch1 0 zp rotderqlS co2)cg3:eo,coc:o1op!

part list

any color LED or


3mm green LED
1 kohm 1/4W res sior

R2 220 ohrn
0h
c3 1100 nF ceram c capaciior

C4 100 nF ceram c caDacitor

Joor ?+E €6rclqN


4) '.4:1.o)Eectro.
eomb nat on Locr s rh P c Prc td,{.!io€or r1:qjodo6:qr,:(9i

cerrmic p ezo sounder


(a r. ca ed piezo d aphragnr', prezo au{lio transoucer piezo .,:!dio nd cator')
keypad 3x4 or 4x4 mair x keypad
Ki relay see terl for specifcalrons
power supp y with 8-30V DC output - suggested voliage is 12VDC
.conneciors for the power supply and lhe keypad
mjsc Prlnted Circuit Board (PCB), strip board or bread-board
flexible w res for connecting relay, LED, buzzer, power supply, keypad
housing for the eTectronics

co-grr Combination l-ock v2-025 for PlC16F628 with LCD

software

i
i thrs s the definiton ofwhai you see on the LCD instead oflhe dqits
HIDDEN CODE (default is asier sk) lf you de ete thrs I ne, the diglts are shown as eniered
I
ihis va ue contains the LCD positlon for messages By oefau t lt contains
the address oithe firsl LCD line (ciocunrented in the LCD daiasheet)
thrs value containsthe LCD posilion for code entry By defuutt it contatns
the address ofthe second LCD line (documented in the LCD datasheet)

schematic

*e-sovoc inp.,l9!99-g 7805

"I
6ND

BUZZEE
PIC16F62A ar
PICa6F62AA a.
P|C16F527 o.
prcL6F 5274

Jco? 66 oiecr qo .3,-d..:.


-.3;(tro)Ei3circnic ccmbineion Lcck riiin Plc Frc €Ja$.r4@E.s s.irerodN8

code )D?
13.oc5[

:a:gi
eco.3dleo,,g download L?€$co,:ca,oc,:3s$ asm file f€. hex fre o?.4 glaaqSl
3?o?cod6o'cca:o, cD 6 ch1 0 zip rotde, oAe ocdtrA3,6o:aa:o1 ])d,
pArt list

pre-pro9rammed

8C301 or similarrnpn btpolar transistor, lc(min)=500 mA


D1 1N4001, 1N4004 or 1N4007 diode
anv color LED or
LEDl
3mm oreen LED
R1 I kohm 1/4W resislor
R2 220 ohm 1/4W resistor
100 nF ceramrc capacitor

iserial LCD inledace: an HD4478o-compatibe 2x16 char LCD and some more
ielectronics

misc iPrinted Circuii Board (PCB), siflp boa.d or bread-board


'erib'e w:res for cornecll19 el€y. LtD buTzer, power suDpry, keypad
housrng for the electronics

too9 i
.loo? ?+6 aE+oi qo
I:(-) Eledronic combinaton Lock with PIC

seriar LcD interface oqoS@6r:E6coT$AcSqp:.{ g;laae6$3.s?.D$e<r:o*cor


) 9 ch1o.zjp rolder ce€codco:m3rd lcdif o?.mai cD6@r:€vi HTML document file .{
.."6@d'1'
Seial LCD interface c,? HD4478o-compatrbe 2x16 character rco 93. :oc6a3rr5
,i:&iq6d ,ro6oE:odecaa6Qc{ c-oc,5,i sacfl€
' "4Q€qcorl$l

DB7
DB6
n uB5
6
i ,-NC 5
DB4
DE]
DB2
DEI
l Crn
L, r, DEO
!N
RS

G}ID

b€..d 6 ln. i.la of I'rbt€ Mo


G.. hrp//w Girmcor^tr&cl hkn)

vcc
I
VL'CL
6
13 NC
n3? ( ---1r-ttA- 5
RB61 lcK
RB5 3
IO EN
2
I

_=-l

iderfacc conncctio! ro Fic GND


-------e

o6Qd3o)Elecll! ric comb nalion Lock with P C

oE,qE Qo:,1ooo81leoTeqq€ e,.-":c6o1 FAo(Frequently Asked Qnestions) .{i


oo5@d,jr ,

FAQ (Frequently Asked Quesfions)


Q: I don't want anyone to change lhe code What should I do?

A: replace the ''' key in the ke)'table to '#'

A: place lhe 3rci column of your keypad inside the box contarning the PCB and change
keylable so as onlythe 3rd column contains ihe key '''

Q: I lost the code for lhe lock What should I do?

A: Re-program the PIC chip wilh the latest HEX file you used The code will be reset to the vi
in the HEX file
A: read out the cont€nts of the PIC with a progranrrner You can find ihe actual code stored in
DATA EEPRON4 Depending onthe progranrner soflware, the code can be modifrec._ ',

Q: ls there a way to make thls design work as an on/off switch (toggle) inst, -d of a momeil
switch? ln detail, enter code to turn a sw(ch on, enter lhe code again to turn the swrtch off

A: yes- The modified 16F84 code i6 download.able here, name cl2b asm

Q: The combination lock seenrs to work (il beeps once for every keypress), but it doesn't ope
ihe relay!

A1: There can be a problem with operating your relay To check, disconnect resistot from pi
(R82) and touch t to the VDD (pin#14) lf it does not operate the relay, check your hansistor
the diode pola ty l\,4easure ihe output of pin#8 (RB2) when you eniered ihe co(ect codi
should change to +5VOC for the presettime interval then back to oVDC

A2: you possibly misconnecled some roMcolumn lines so incorrect keycodes are generated
if you swap colo and coll wires, and press the keys 1 2 3 4, it gets interpreted as 2 135

Q: I don'l have a 22pF capacitor- Can I use anolher value?

A: yes, any value between 1G25pF should work

You might also like