Sunteți pe pagina 1din 231

:,,.,' l.

::L:f:' ifigr*.irit

tI;,,.'

-1

il

-- ,,,,: . .: ,; .

;,ll;r r,;,i:i:il;l-'i'ri:,"Jj:: Y;,."iiiij',1;.j ":i,;


;r. :r. ii : ;::.
li i li .'. ;'rinl l"i:";ll,;* ij: :,
":i':;,i
'i
*?-::.i!':i:
-:',1'ii:
,'rri r',
irt:i a;::..:_-r'
:."r'!rt r,r, :.

i: i, :.;',

jaii::li
:

i:ji;ai.itji::

;i-:i;1r I ::. !

*l'i;ia:ii i;;iil.:.i,,:

,';i'.. i'i;

:..,.-:

iii

*..'Jl
tL' /

t'
z

MDA- WinPIC*2
11i,.1;.,:1'. .1 j,,:qr

,i.

::

1:.. .,

[.Jser's Manual

Ver 1.0

:
Midac
Emgineering
Co.o LtrI.

LZL9g?
ol"o8, [0.

fl*{irlas Engineering oo., ltd.


AilE Tenhnn-Tower

v#906 197-22

fiuro-Dong Kuro*Gu, Seoul, Ksrea"


Tel.

82-2-2'!tlg*$SfiS-7

Fax. BZ-Z*?"109*5968

www.ruir!aseng.com
f--rnfi

il" rnidas 1 @mldaseng.cern

Notice
@ CopyriEht 2007 Midas engineering

The Midas engineering will not repair an


MDA-WinPIC-2 kit that has been moclified and
when circuity has been added to user clesign
area may request that circuit be disconnected
prior to submitting the kit to the Midas
engineering

for

repair.

If, following assembly, you cannot get ycur


kit to operate satisfactory, the Midas
engineering

is

available

for

assistance. T'his

service is provided during the hours of 9AM


to 6PM(Korea rime), Monday trough Friday.

. Tel. 82-2-2709-5964-7
Fax. 82-2-2109-5969

. http

I lwww. midaseng. corn

" E_mail. midasl@midaseng.com

PART

a
a

MDA-WinPIC-2 USER'S MAI{UAL'


TABLB OF CONTENTS

1.

Introduction

1-1. Specificarions of the MDA_WinplC_Z kit ...........


l-2. The back view of the MDA_WinPIC-Z

2. Micom Programmer
2-1. Use rhe MDA-PROGRAMMER
2-2. Select Micom
2-3. Shortcut Button Function .............
2-4. Read FiIe.........
2-5. Automatic Write-Option Setup
2-6. Automatic Write
2-7. Blank Check
2-8. Manual Write - Erase
2-9. Manual Write - Write

2-t0. Manual Write -

Verify
2-71. Manual Write - Option
2-12. Edit Buffer Contents .."........"."
2-13. Save Buffer Contents..............
2-I4. Reload Fite.........
2-15. Data Communication.............
2-16. Setup Printer port.........
2-17. Inspect MDA-WinpIC-2

.....

............. 9
......... 12

13
.."... 13
.................. 14

.... 17
............."."" 18
.........2A
............"...27
.".. 23

......24
......25

...27
..................28

.........29
........ 30
.............31

.........33
.................. 36
................. 38

Serial Communication Experiment.

""""""'

" 124
'124

3-B-1. DS1302 (Digital Clock)


3-B-2. DS1620 (Digital Thcrmometer)

"""""""
3-B-3. Ii/rCP3202 (Serial A,{) converter) """"""'
3-B-4. AD7302 (DlA converter) """""'
Motor Experiment.

""""""'

motor

3-10. Dot Matrix Experiment. """"'


3-10-1. 5X7 dot matrix
3-lO-2.5X7 dot matrix animation
3-10-3. BX8 rlot matrix
3-10-4. SXB dot matrix animation

140

"""""""

146

""'160

"""""""""

160

matrix
32X16 dot matrix animation

"""""""""'163
""""""""'" 167
"""""""""'171
"'"""'""" 116
"""""""" i79

""""'

""'184

3-10-5. 32X16 dot


3-10-6.

t36

""""'146
"".-"""" 149
"""""'154

t-2 Phase step motor


3-9-2. Step motor control
3-9-1..

3-9-3. RC

131

3-11. Application Experirnent.


3-11-1. Graphic LCD """""
3-11-2. Graphic LCD animation
3-1 1-3. Ulrra sonic

"""""'"'

Infra-Red
3-11-5. Optical fiber """""'
3-11,-6. Wireless
3-71-4.

WinPIC-2 Schematic.

IAR Embedded Workbench.

"""""'iB4
"""'"" 190
""" 196
""""" 200
"""""" 203
"""""'2A6

l.

lrttlrlrlrrt'tion.

:::::::-:

1. ImtrductiEx,"s*
Thc I\4DA-WinPl('-f kit is

siro,,r

r] in

collrponents lrccr''ssirry t0 runik:r:;lltrrrl I'lL'

F'ig.
-c-

l-1

I,i!1.

I-

corrtlirr:;

all litc ltasic

6F,877 rn icrocrlllpLltcl'.

N4IIA-WinPtC-l Kii
lt'

rlrl,.ii;iillrr

r!g..r.or1r

1.

trntroduction.

@ Uanf : The universal


It provides the sensor
thermister) experiment.

@ A/D Converter :

asynchronous transmitter experrment.


(PYROELECTROTC,
humidity, CdS and

The analog

WinPIC-2 Trainer.

to digital converter is located to

the

usnr : The universar asynchronous is experiment.

@ DIA

Converter

WinPIC-2 Trainer.

: The digital to analog converter is located to the

@ I-pO : The LED

experiment.

@ RC Motor : To control RC motor


interface.

driver circuit

of RC motor

It

oc

Motor : It uses the D/A Converter the speed


of DC motor.
uses the photo interrupter to measure
the speed of DC motor.

@ srnp

Motor

the STEP motor.

: It

uses the step motor driver (sLA70z4M)

to

control

@ wireless Transmitter : The wireress

optical communication

communication experiment.

: 'rhe optical communication experiment.

i'

@ sz x 16 Dot Matrix : The 32 x 16 Dot matrix experiment.


@ urrna-soNlc : The ur,TRA-.soNIC
@ s x 7 Dot Matrix : The 5 x

sensor experimenr.

Dot matrix experiment.

@ eq x 16 Graphic LCD Display : Ir is 128 x 64


-10

rn.r.',

*!.I-^^--

dot graphic LCD.

l.

Intooduction.

1,-2. The back

view of the MDA,WinpIC-2.

(The Ilack view of the MDA-WinpIC-2)

Port Cable)

l2-

(AC Cable)

www.rnidaseng.c0!n

2. Nlicom

Pmgr:uruncr.

2-2. Select Micorm


If

MDA-PROGRAMMER

is

rhe MDA-WinPIC-}

operated when

is

with the printer port of a PC through the parallel cable (25P),


the following main screen is displayed.
If the MDA-winPlC-2 is not connccted with the printer port of a PC
through the Parallel cable (25P), "Verification Failure (Next Screen)" is
connected

displayed.

rylBl u'lu'lwlm,l
imll>l mlrci
:ulgj
ilel] *l$iul,.i.'i !s:J __,Jg.,$jg:l :st-l,'si
plandard HEX fileFlease load a standard HEX file

H,Wi

Bufler win... Dala communication win...

lndicati*rr,ofthe'srlerred Flle$lli,,,,,,
li rhe \{iriPIC-t is nor c0nr}e('leri u'irh rhe pe

j,

'Veriliqation,:rFai lfre ( ri ext s c re e n ) " i s d iip lay*d,l* lr rf


the following things ran be done in ttris iase,
;i' lf lvinPlc-z is connecred wirh rhe prinrer

llIe0M sf,i'lieiin'ii'n' screen is doubte*s:iiik*6,,','.


PICl6fB77 is selecred a*tollatically

.:,:

Fig. 2-2 Screen with tlre IoIDA-WinPlC-2 Selected.

t4

wwr,v"nridaseilg.com

2. N{icom i\*gnrmrner.

In case that "verification Failure" occurs like <Fig. 2-4>

because the

is not recognizecl, try to do it again in the way


explained in .Fig. 2-4>. tf the MDA-winplc-z cannot be selectecl, set
up the PC printer and do it again. If the MDA-winplc-2 can't srill'be
selected, the printer port of the pc or the MICOM is not operating
MDA-winPrc-2

properly.

Euffer win... ] Data cnrnmunicstion win...


-.* *.

%"*-.***--..,....

lndication of the seIertrd MIC0M


-|:
ll the WinPl[-2 is nrrr ronnecred rvirh rhe pL,
"veri[ication Failure (*rxt screen]" is disprayed. and

thefollowingthinqs[fiftbetlorreinrhi5.66;*'.
,i lf lVinPlC-2 is connecrerl with rl,e nrlniei -'
port of rhe PC rhrouqh rr'* pururi*i rabte ijlpi,
-

"

ltre,gow,err*f,th**lnple *t'ii rurneU'ori.


:iX.'"Viiification'Fallurr {(Fiq, i'4X" at the bntrom rf
.$|!0M.=of.t.[i,malir$tre,enij"oI.*h.rl-ciiiru*,
,
l6Fff7?,ir'$$lee ted aurnnraf iiatly,, ' r''."
'PIe
"' " ,'

Fig. 2-4 Screen wirh rhe lr4DA-winprc-z not Selecred.

l6

wrv ry.

lr ri tlase ng, co

2. I\{icom

Programmer.

2-4. Read File

Bl clicking the shortcut

!P?!.j

button makes the screen displayed as iri

<Fig. 2-5>.
The file to be written in the order suggested in <Fig. 2-5> is

read.

Exit.with,,a *ficlr;

Fig. 2-5 "Read File" Screen.

-18-

www.midaseng.com

2. Micom [tugrammer.

2-5. Automatic Write-Option Setup

ffii

Opt ionl

Click the shortcut button with

the

mouse and set

uP

configuration word suitably to the system as in <Fig. 2-7>.


If the configuration is not properly set up for MDA-WinPlC-2,

not operated properly even though a program is written.

f* ::' a

i p'0| 6F877
ii

Fig. 2-7 The Screen to set up the Option'

-20

rvww.midaseng.com

the

it

is

2. i\{icom l\ogrirmmer:

When "Write Program" is enrir:d, <Fiu. 2-9> is displayed.


If "Error" is displayed, it shouki hr: written again

Blnnk [.he,:k

i;li!

Fr,-rgtam *f,!
Verifi,::ati*n i:lt,!

[on]'iguration Fuse Program ,]h.l

l{iri{ r: i*'Crid*dno,.
Thc error message
shouid disappear.

Fig. 2-9 T'ire Screen iiflcr "Write Program" is

22

www.rnidaseng.com

ended.

l--.

Bl.rnk

fkck

2-7. Blank Check


ma r
tol
U
I

ank

Clicking

the shortcut

to check whether the


<Fig. z-LO>. In case

of MICOM

is displayed as

ffi$uflsr
ank

contents

button with the mouse makes

it

possible

are completell' erascd as in

in <Fig. 2-10>.

fldn".' I 0ata comrnunicalion *rn

,,

ilhrrk iliil

l/crificotian ONi
Confisutation Fuse Frogtanr Oli!
Blank Check En,rtl
Chin arjilres! I tli:l[]0 Vaiue I u[rli"t

Ia,casg'lhat a Bl'nrJram has licen alreadY


tqri{ten,'1he errot:,fln es sflq e is tlisplayed,

Fig. 2-10 The Screen after the blank check is ended'

MDA-WinPIC-2 MANUAL

-23

2. &liconr

Programmer.

2-8. kfanual
In
"Erase

case

Write Erase

of the manual write, it

a Write a Verify a

Enl;i
rrl

should be written

in the order of

Option,'

I
I

{ Clicking the mouse with rhe shortcut button makes the contents
of MICoM completely erased. Namely, it is to have the value of ,'FF,,
Erase

Fig. 2-11 The Screen afltor ,'Erase program" is

24

*'ww,midaseng.com

done.

:-[

2-9. Manual

Write

t"1lX11g15s '*4 6.na

Write

m{
I0t'

$rritej Clicking the mouse with the shortcut Ltu.',,-:-, r1;r.:: :.he irera-file'
.rke
"led1.hex", in the "standard hexa-l'ile" written to \llLr,)1"1
<Fig. 2-t2>.

Siinf

*rl

5631i165:Wl',{1firr,'l

f1g

11'\,l,Ifi1'*'1

shortcut button

ffi*CHgt'lflf llf?Exr$LEt: i

ri

i 0ala communication wiru..

The rn*ssaqe arld artimation


rlurinq,ltWritB I'r:*qrs iit "
MICOU
PICI6FB77

Fig. 2-12 The Screen during "Write Prograln"

MDA-i{inPIC-2 MANUAL

25

2. Micom Pmgrammer,

.Fig. 2-13> is

If an "Error"

displayed

message

is

in

case

disPlaYed,

of the correct

Write.

Write should be done again.

Fig. 2-13 The Screen after "Program Write" is

-26-

www.midaseng.com

done.

2-10. I\Ianu-rl

2-10. Manual

written

to

Veilfy'

Write VerifY

fivl
:g.1f-YI

\\rite -

Clicking the

shortcut button verifies whether

Progranl

IS

"\'erifr"'.
MICOM correctly like <Fig. 2-14>. lt is so called

rificatic'n Dl(l

The mtssaqe :and, anirnatiort


durinrl'rVerify Prusram"

MICOM
FIC

Fig. 2-14 The Screen during "Verifi'

I6FBI/

PrLrSranr"

MllA-WinPIC'2 MANUAL

'i

27

2. Micom Pmgnurrmen

2-\L" Manual

Write

OPtion

Click the shortcut btrtton with the mouse and set up


configuration word suitably to the system as in <Fig. 2-1,5>. If
configuration is not properly set up for MDA-WinPlC-2, it is

'the

the

not

operated properly even though a program is written.

sul "t.crl
tl;l
tl

l! It.,& elte k
I
',
,I

,l

,l:,

i.l'Scr,up suitarrlY

'' lvinFlc-Z
,.

Lo

the

l1-1* adv,isrrl

to ust ilte ddf*ult stitlp rli'

,rrrisi r*tv1

utdou

#;;=-:l
'? Click and do
.l 6 i

2-15 The Screen to set up the

"

ia't.ibln,rr{o1d'1irri.!e"

Configuration Word"

www.midaseng.com

l-tl. i-l't IlulTer ('triltecio

2-\2. Edit Buffer Contents


as in <Fii
Clicking "Buffer-Window" with the mouse
<Fig. 2-16>"
'
L,,-r,', r ir ith
mo\'lng
after
Numbers"
with
"I{exadecimal
Write

up,

<lown,

left, or right key of

as ili <Fls' l-i6> or


<Fig. l-1t'> ls ihe contents

the computer

clicking a specific address with the

of

thc

mouse'

"led1.hex".

: Blu:
i
i
$$$,

Ss'/e

! lq-nqqra

u'ls',Hlid"

elet*ir$tril1

x 3iry.*,

r'r

f:

9[6Xggt tn lrBuffer trVindorr


fl(?{ExrtYlf.[] iiE'

!ll'r

rvin"'
*".." ffi
?::1::IT:*icationA:it' r''-':i lF l^
Ifffiffiffifr I t I rr I n I ril af{cr
{-*-1"iiil-Irl
;u*i*decirrlal
movttis
Numbers'
lviiir ouliiri
kty ol
ri{Jht
"{lursslr"r'rvith ttre'up, dolvtt' lell' or
Msniror

rr1-ousc'
a st)ecif ic addres-q y11tt t'B-t[.c
ei'
3i
t,l
i0
ni
rt'
ztl
r0
t',?r,i#ti,rir iiiri iu it nu
tt
i!
tr
68
q2
16
A0
F?
*i in 81 8?,ir1
!
E ffi=4ilr0
:: ,. ^" nt in r{ .n r^ fm irn 6- rn -t if Q3 i
"
ltas,
L*rrrc oi'iqirral lD'
w

.iiiriino
''

!i!!
ir

il

.i

I#cotl

'

Prc l0Fs?7

ff si trigt

[n

E? qE 8?

8[ sl

60

m.s'r

l.

iiiitreqn slaqrqe-( !o |QI'r !1


"
rr r,r :r'u trt rs ii il'lr [F 8fi F-fl 3{ tE fir I
gr $ tl l,t 95 cr l.) tlr Eli tir 8T
nL il,m r,r
gr'nu
rn w :r,zt,rE m ff fiD 13 !t !1 " "
ni:[i e0
rr;o E[ sI 6t liO
tro,nr ni ti
sl:sc
il
;u,;0
!! 11,:'
;n m si ir ts ra si tF Br t? 60 fio tF !1 q !1 ''t""
G gi

; click

'

3F'--:.*--*

Fig. 2-16 The Screen rnodifying the

MI),d-14iiBPIC-2 MANTJAI

data'

-29

2. Micom

Frogrammer.

2-13. Save Buffer Contents


ffi

Clicking the shortcut button with the mouse can make' it

Save

to store the buffer contents modified in <Fig. 2-17>. They


storcd in tlre order of <Fig. 2-lB>.
possible

isi,ltsrt{ ra .:.
l.l;tt,makC
a nerv [oldr.r"
,

*:i{lti,ilE:i

(} $e Ie{tr1h'*,:-f$lde.r', I rt,,.
tvh{ch thc filr.is stored.

my
documenl
.r;ri$
my
computer

ei.J
mv- Network
places

rvilituil

E*it !vitlr a tlick.

Fig. 2-1V The Screen for "Save Buffer Contents"

It is stored as "LED2.HEX" like <fiig. 2-18>.

file

rtarne

tcite,{l**nf
14 C0 ?J $l r?,f$:3t :f;Drffj{fli}f :ff.) I5 Sl lf $l r.#.'. !
l[ r0 l! 2n lr,8Et20 ffi i$,9!:Zl ffi]ztt E0 25jFr:.-.i.....,t
E4.E5,Fl EgiA8iE6:m,rSilo:r0:uii t{ f*'{F:il u$ ,., .,.

*0 36,8I,07'BI'f'?iAB:86iSDrm:rO
92 Al 3, 83,0?, E! r?, 58 j [0 1S[,{Xf , I 6
0F s3 c! B? ttE B? lz 97-0F 86 td ${ ts
[0 6F 69 83 9A 83 SS et,ge 8l trl 9? B9

.0,!-:se
g5-a

3F

EF SF, 3F. S2 : B?

ES'il

22 36 jrT
I

&

rt'tt
1S

:{11

Jrrr

..0 ..

:rT. 53 :. ., 8,,
.

i* tf st ....

6j gA fri
irE, S{ ;&[. f* r.i.

..

Fig. 2-18 The Screen after "Save Buffer Contents" is

-30-

www.midaseng.com

done.

are

l-l{.

Reload IIlc

2-14. Reload File


In

to avoid the annoyance such as "Open Frl.. iir casc of


reloading the file modified through the progr:ii'ir niodification,
ilouble-clicking the box portion of the "Standard Hcra-File" rvith the
mouse as in <Fig. 2-79> makes <Fig. 2-20> possibic. and it can be
order

reloaded easily.

f-Double-click tiris part


9rite i,-'..r'
J-F;F

Fig. 2-19 The Screen before reloading the modified file.

I
\

L"
,

MDA-WinPIC-2 MANUAL

3l-

2. Micom hogrammer,

Clicking "Yes(Y)" as in <Fig. 2-20> makes the "ledL.hex" file


reloaded.

:ii{,

_ii
i

i
l

,i
l

trad a standard llEX {ile ifite b{{{er!

CIirk:'lYes{T}'i

HrcsM

2*i;:':t ": :'


"

i:il FlCI6Ffi77
.}r"

Fig. 2-20 The Screen to reload the modified file.

j'

.:r.
.

,.it..i..

'i
{:iY:

32

www.midaseng.com

=i;i:I,it
.s*.*,$i

l-l -<. Data Lirmmunication

2-15. Data Communication


Clicking

pops up

"Data Communication Window" as in .Fig. 2-21>


the "Data Communication Window" screen to do data
the

communication.

the "Data Corn nt uri ir:atittt


Windorv" screen rtl rlo data
communicatittn.

2-21 The Screen Changed to "Data Communication Window"

MDA-WinPIC-2 MANUAL

33

2. I\'Iicom

Programmen

Click "Serial Initializaticln"

<Fig.

in

the

ln

2-22>

"Data

Communication Window".

miffii oi
u"lu'lwiu',i l${i>l mll
sltsi
ilrl i rp^;
"stgl F^j l"lrll.t:J:j:::1r.l'"gi - iq1::".1'i*l
.pe'r

n;.JiiJ,*n.siriut:r{iririr'iFno;,p,AUiTplLht'CiYLrr.llt1rx
Mnnitor wirr... I Bullor *1n,,.

Clicking thc right button with


the rnouse liointer plared on
lliis 1lart,makcs rhis i Sn!:trrnu"
dis*layed, anrl click "$erilri

Inirialilati0n

".

I FICI$FT??

Fig. 2-22 The Screen of "Data Communication Window"

the serial port is initialized as in <Fig. 2-23> to make an initial


setup of the serial port of a personal computer, it becomes the state to
do data communication as in <Fig. 2-24>.

If

qial u,iu'lulln',Eresel_
,siffiloi
i${j>l
I
j
tsj-q:"
I

t
::.... .:|:..:.., ...::... .:

s!6nkl 'r,rilel-\'grtri

jcer rerf,. Auto

_B_1_3:,..1.-tU_,

Standard HEX

..:.

Sr

ite

C*u*t

& e lick ::'Confirm


i

sel,t:i'r th e,.rti in m i1 {{;*.t :r11


'{}*,llt;,t hc ronrnrurticatiun
,,":i,p,*.i: tt, anr! tht:.tra;;1y liit
1"1

tsig. 2-23 The Screen to make an Initial Setup


-34

wwlv.rnidaseng.com

Jrar

l*tc0M

il'

I PrCr6FS77

of the Serial

Port.

:
Inu 1$ir, ,il

I{ it

becomr's the state

MICOM

to do

data e0ff.::". .-l-.., -

-"'l
cran d0 data conrmunication With th.

Cu

':

il:

l-14>.

iiilffil

qrr!fiillll3,

innlti ni cati (,il

r'-'

rsu r#in,.. i Butfer win...

Tht srre*n t* *t]:duli* {:utxtltlul:


'Ihe seriai p*rt *f the pers*nal cum:
should he canrected rvith the serr;,
*f tht: \'VinPI[*] throus]r the R5-l i- "
t'.rl:le(9 pin I : i ), and the tlata
t:rlnlnrurlicatii:tl proqranr sh*uld'0r
rir tht WrnPlC-2.

I;jg. 2-24 Tire Screen to do Da'

t\{I}A-WinPIC-2 ['L{I{UAL

Ir)11.

35

2. Micom

Programmer.

2-L6. Setup Printer Port


Clicking the shortcut button makes it possible to confirm itr.

printer port setup and whether the computer


MDA-WinPIC-2 correctly as in <Fig. 2-25>.

is

connected to

the

#ig*l li6t::e,l tr le i rr U
l$,6.nfir l,,:,, .-:'
P,'+!$$;iUt

t,g

g'$l+*'14

fi jit#;i

fdfi .*,'c.q r,I$$ii


t:'"s dliiltlL*.$$.e,'$
t Efl *r $,q rriffi
rt rr,c-$ * r.ti *, *o t** *, o'
dj,iB,,:

*$, 5

s,[{}$t

.{ft e

;i}fl

d {,*!

r.$6"rl$i

u,{i1

. ptirsunat
*r**'4$1{.q:g
f 0nipUrtr
. ff1$$.$
fgin

but it is disf la'lcil

dli-fli,,f
,{llf {$r.0$'il.tit'tt:11.i.,5',14i,Si*},{,1*i*H,',
:riiilr:L.r:i.. " I I,rt' i:!i !r:l,l { ft i :',:r'
:it
'1 li.X i

.i$

as
in (f+9,'?;]0)
*f'rt1*
*,ci,x,fli1l1
4:*.!.,p.;;ff$i$i1
f;is in r'asr-:
"1i

incorirg'rtflnlul{}cli0(}. ",'

Fig. 2-25 The Screen to verify the printer port setup and connection.

i
I

t,

l.

-36-

www.midaseng.com

.1-l(r. Setup llrinter PoIl

the printcr pori is not properly connected ri iih ihc li4DA-WitrPlC-2


as in .Fig. 2-26>. try to clo it again explained in <l'iq' 2-26>. if it is
correctly connected, the message of <fig. 2-26> is ntri ,1isp1ar ed,

If

{)rite
.

Count

3FFF

Eklt with a click, r'erifv nhslhcr


thc persona t contputta i$'ct:rl'rlctlY
cbnncctcd with the WirrFIC-l
ihroush tltt parallel rable. arrd tr]'

to

dr-r

it

aOartt.

] o'.'*u,
r^ig. 2-26 The Screen

in

case

of the irnproper connectton of

the

prirtter port

MDA-WInPIC-2 NIANUAL

37-

2. Micom

Programmer,

2-17. Inspect MDA-WinPIC-2

re
Test

Clicking the shortcut button makes it possible

whether the MDA-WinPlC-z

is

operating like

to

inspect

<Fig. 2-27>. Click

"Confirm" as in <Fig. 2-Zl>.

Click "Confirm" like <Fig. 2-27>. Be


precautions explained

sure

to

acknowledge the

in <Fig. 2-27> before clicking "Confirm".


terhedk itFI i?:

*h$-Et*Bt',bitttfi n,l

&?. ,ffi''l
Blmk (lr

iie

. , talrelad nf tirne
-An OpetatOn IeSt ( jIl r.in,rort rh. ,
ii$.f'6fiiitqi,i

=* f8t'e*ffii+?illir,iru tn* piliilter

rtstartsatest0t.p*,torMlC0Mthrouglr.the.FarallbleabIe.
- - -- - .t2.rCortrtect the serial
irort of the personal computer
All contents Elimir with rhe serial pbrt of tne WtnPlC;2 thipuqh I
wirr Ao s,3g7

I',

i;ffi$$.;2ilFra$Ei;t$* i i

Fig. 2-27 The Screen to check the operation of the MDA-WinPlC-2.

38

www.mi.laseng"com

2-17. lnspct NllC{}N1-lxrartl

Set up the serial port


suggersted

in <Fig. 2-28>.

\.N-\\N.N

ffilB1

save

of the computer with clicks in the order

oo31

lu'lrylu,. I lxri>1
Brnll t{ritelverilj erasel ]optiml
u,

-t
Eqt

q*_l

nutg,l

Slandard

Please set up communication Port!


Comm.. Port

{- coM t

[Ie.?'Y,? -, "*r1r set,,o,,1,,,,.,,,,, rntrrtit atir:n llttrt


(D

Cancel

i
I

# The se rial pcrt tesi'in starteel


as ilt (Fiq.2-19) wittl a clrck.

tvllCOM

...

::

Plcr 6F877

I
il

I
{

Fig. 2-2B"fhe Screen to set up the scrial port of the contputer.

N{I}A-WinI{C-2 MANUAL

39

2. Micom Pmgrammer,

Write "Data Communication


<Fig. 2-29>.

::-

fi'lw

Elanli tllr'lte

I9eril

Program

,ux,
Eiosli

" with MICOM as in

{.r

at
Bpti

I r. _ 1;

The message and animatioh'to indiratr


that "Datfl Cornmunicati6n Proq'ram" is

$.e!'ng.writteal.ttt:lttie;,wiiiiF:rc;r....
i

Fig. 2-29 The Screen to write the data Communication program to


MDA-WinPlC-2

-40-

www.midaseng.com

the

2- I

7.

In.spect

If the data communication between the personal computer

l\{lC(}1l-lptnl

and thc

MDA-WinPlC-z is working properly as in .Fig. 2--?0>. the message


such as "Success" is displayed, antl if the data cottttrttrnication is
not working, the message such as "Failure" is displavcd.

*'itlt

Exit
r-"

a click

i,ary
I

Il thc ciata cumntLulicilti0ll


is rvurking pruptr'ly, tht:

mcssaqc srrch as "Succcss"


is tlisplalr:tl, and il' tht tlata
curnill urlrcfl{rurt is ttt-tt
tvorkinq, the mess;t(,t sttch
'1.,i!irrr'' is displaytti
as
]FICI6F877

Fig. 2-30 The Screen after the data cotrtntutlication

IV[DA-WinFIC-2 I\{AI{UAL

chccL.

-41

3.

Experiment

3. Brperirnent
3-1-.

VO Port Experiment.

3-1-1. I_,Et)

ffi.,:

Circuit Diagram

5.6K'

PIC16F87x

rPIC16FBl/R

xa
rf

lxr

lq.

HT

*
RESET

91

-J--

FRin

R86
RB7

0sc2

0sct

XTRL

i.ir,

x+

);
,{7t

-42-

osco-rl-lX
:r .rl::1

1t

lS.!*{.i,lr

lvww.midaseng.com

tw
22p

l-1. V() Iloet fixlxrintcn{.

B,*
*W

Flow Chart

[Corfig,,.. atl

pins

I inout

G)
lno

---.<a'Xt
\ - Switch=l? -J*-[*aHrFrR

L---l

i.i

.,,f"HIl*",-*ii

SHIFTL

'-- --L__

ternp

5511
1

>i

l.

tempr

.-

0x7l

l
Y

\J,,*

tr{orv

to

connecl jurnper
PIC Port
T{AO

XU

TI.A1

x.l

Rt]0

YO

RI]1

Y1

Ii.Il_2

RI]3

Y2
t-)

RI]-4

Y-4

II.B5

Y5

RB6

Y6

L __iqr_

Y7

${DA-lYinF{Cl-2 MANUAI-

c3

3. Experirnent

=-

,Program

{}

c, \r,oe\ui np i c2\exanrp I e\c\LEDt. c


#include (iot6f877. h)
unsigned char ternp;

void delay (unsigned

int i)

whi

le (i--);

/i

Shift Left

void SHIFTL (void)


{

if(tenP == 0xff)
{ tenp = Oxfe.i
return, ).

etse

'

i
= (tene (( t)loxot;
(tenp
- 0xff) terp = Oxfe;

ienp

if
)
oe

ay

(0oooo)

i/

Shift

Risht

void SHIFTR (void)


{

if (tenP - 0xff)
{ temp = 0x,7f i
return,
)

etse{

)) t) lox8o;
if (tenP == [xff) temp = 9171'

terp = (tenp

oetay (6oooo);
/.'.'
)

/l

l,lain

void main(void)

{'
= 0x00;
TRISA = 0xff,
TRISB

ADC0NI

= 0x06;

tenp = Oxffi

-44-

www.midaseng.com

3-1. VO l'ort lixgxlirnenl.

do{
PORTB

if

tenp;

(RAo) sHIrTL0;

else if (R l) sutrrnl;;
e lse terriP = Oxf f
;.

)while(t);

MI)/r-11 irdonC"2 h'{AI{UAL

-45-

3.

Experiment

3-L-2. Traffic signal

,,,

Circuit Diagram
PICl6FB7x
PIC16F81/R

fln

RBG

0sc2

RB7

0$c1

il r-*

XTEL

au;t
--*i

I
I

oscr

x+-;"--;1

'rr3'i
J"iff
rtv [77 -" '--

'

xri
z:

rFt

/=

+
g

rffi
-46-

Gl -+ Y0, Yl *+ Yl, Rl
G2

-+ Y4,

Y2

'--+ Y2,

-+ Y5, R2 +

www.midaseng.com

Y6

]2

3-1. VCI Port lirlrcrirlrcrlt'

Flow Chart

L_

__

_--- -l

I nt ir oN antJ
4 tirnres
I

How to collnect

c;

,.*iF

blinking

r{A1

WinPIC-2 l(it
x0
x1

RI]O

Yt)

RI]1

Y1

ITAO

RB-2

RI]3
I{B4
RI}5
RB6
TII]7

I
l

Y2
Y3
Y4
Y5

Y6
Y7

Program

'i3

c: \moa\w

* i ncl utle
I

i.

.lumpcr

PIC Port

#,

CZ

i nP i

c2\exanP I e\c\TMFF I c' c

(i otorall' rr)

l" DelaY

void delaY (unsigned

int i)

{
wfii

te (i--);
47

MDA"lYinPlC'z MANUAI-

3. Experiment

!.

t,

ll

f;
n

ttain

void main(void)
{

unsigned char
TRISB

i;

+iirt

= 0x00;

oo{
P0RTB

= 0xbe,

for(i=o; i(4 ;

i++) {

oe t ay (6sooo) ; )

// Gl LED Nunber
tor ( i=o; i (+
P0RTB

For 0N/0FF
;

i++) {

= 0xbf;

tt
'i.

oetay(SZSoo);

+i

= 0xbe;

P0RTB

oe t ay (32500) ; )

IIYl,
P0RTB

R2 LED

::4

ON

= 0xbd;

oetay(6s0oo);
de I ay (6s0oo)

II

Rl,

PORTB

G2 LED

ON

Oxeb;

for ( i=0; i (4

i++) {

oe t ay (osooo) ; )

I GZ LED Nunber
for ( i=0; i (4

For 0N/0FF

P0RTB
oe t ay
P0RTB
oe t ay

= 0xfb;
(:zsoo)

i++) {
I

G2 OFF,

RI

ON

= 0xeb;
(:2soo)

I Y2, Rl LED

PORTB

ON

= 0xdb;

oetay(6sooo);
oetay(6sooo);
)whi

-48-

le(t);

www.midaseng.com

3-1. V0 Port lixprrirncnt.

3-1-3. I'arallel Slave Port


Circuit Diagram

PIC16FB7x

:
RB2

334
RDO/PSPO

RDI/PSPI

RDz/PSP2

RD3/PSP3

REO./HD

c6;

22p

nT[E

REl,/m

0scl

RE2leS

0sc2

"4Q:

t#-

rl-t

.R.?-

hst

cl

22p

Flow Chart
,,,:,'.

Miin

clearing output

MDA-l1 inPlC-2 NIA|{UAL

-49-

1#

:jr'

,+

3.

Experiment
.,i!. '

How to
*M
\wF.

connect jumper

RDO/PSPO

WinPIC-2 Kit
x0

RD1/PSP1

X1

RD2/PSP2

x2
x3
x4
x5
x6

PIC Port

RD3/",SP3
REO/RD

Retrwn
RE2/CS
"! RtsO

i:,.,

'.3

:.i{
''

ii

YO

.l

;si"$g;i*

,YL

RB1

RB2

i|:,. Y2

RB3

Y3

:"F,

Pto*tr*

c, \MDA\II inp ic2\exarnp te\c\PSP.

#include (iot6ralz. n)

//

[tqrN

void main(void)
{

unsigned char
ADC0NI

ternp;

= 0x0f,

0xl7i //

TRISE

TRISB

= 0x00i

PSP mode

oo{

if (lBf) tenP = P0RTD; // read


else if (0BF == 0) P0RTB = terp; l/

write

)while(l);
)

rs.'
i,J : .i'
.

."$

;:.

li'

www.midaseng.com

r:

3-2. lnterrupt Expcrinlcnl

3-2" Interrupt Experirnent.


3-2-1. External Interrupt

circuit

Diagram

mg-ms lk
rR8-rBs 2SflAlS

TSEGHENT

*fr'

r]o

rfr,

q5 "L3.,,1..,

Qq

{#".,

a3"F; nr"F,

qt

"ry",

rfr,
qo"l#",

PICi6F87x
ROB

B0t

ffi3

OSC

oscz

osco X
x_L- "' ll

x{,::.'.,.r,

fiD,

Ir

rq

R05
RD6

r.85!12

,::Zt\*,i

f${z

,.ffi'::

8D7
OSCI

rEg

+5u

Rfl

BESE T4
I

Rcs

+Ql

x4

**,

r f$s

RC,t

.',

_l_

l*,
I
g:o

RBo/rNI

I
L

&lIlA-1?lnPIC-2 MANIIAL

-5I-

3. Experinrent
;!e,
'@

Flow Chart

Initialize PORTD by clearing


output
Chattering/Bounce

Enable Intemrpt

oi;n,flo*

to

connect jumper

PIC Port

52-

RDO

WinPIC-2 Kit
A

RD1

RD2

RD3

RD4

RD5

RD6

RD7

RCO

QO

RC1

Q1

RC2

Q2

RC3

Q3

RC4

Q4

RC5

Q5

www.midaseng.com

3-2. Intenupt lixpcrirnenl.

Prograrn

'..3 c, \MDA\W

te\c\

inp ic2\exanrp

Nr"

#include iiol6f877. h)
unsigned clrar tenp;
const unsiEned char SEG[16]

// Segent a
0xdf,
// SeEent f
0xef,
// Segnent e
0xf7,0xf7, 0xf7,0xf7,0xf7,0xf7, // Segrent d
0xfb,
// Segnent f
Oxfdi;
// Segrent e
{0xfe, 0xfd,0xfb,0xf7,Oxef,0xdf, // Digit 0-5
Oxdf,
/l Dilir 5
0xdf,
ll aisit
Oxdf,Oxef,0xf7,0xfb,0xfd,0xfe, // Digi t 5-0
0xfe,
l/ Dieit 0
Oxfe);
l/ Disit}
{0xfe, 0xfe, 0xfe,0xfe, 0xfe,

const unsigned char DIGIT[16]

0xfe,

void

SES,IENT

(void)

P0ilTD
P0RTC

= SEc[ternp] ;
= DIGITlterp];

//

lnterrutp service routine


#pragna vector = 0x04
l/ Exlernal interrupt
_interrupt void EX*lM (void)
{

unsigned char bouncei

tenp++;

//

tenp

temp &= 0x0f,

do{
bounce = P0RTB;

)whi le((bounce & 0x0l)==g),


INTF

= 0,

/l

uain

void main(void)

{.
TRISD

= 0x00;

TIiISC = 0x00;
TRISB

= 0xff,
MDA-WinPIC-2 N{ANUAL

53

3. Experiment

OPT|ON
INTC0N

= 0x00;
= 0x90;

tenp = 0x00i
do{
sEo4ENT0;

("sLffP");
)whi le(t);
asm

54-

//

Steep nnde

www.midaseng.com

3-2. Inferrupt llxperinlent.

3-2-2. PORT

intcon change

Circuit Diagram

8QA-R85 rk
TBO-Tfts zSRTOIS

T=-nr"fi;

I(EY HRTRIX

"fi;n.-nr:ff
E- t,
?-t,

ill:'-n'irft

PICl6FB7x

m0
R8I
Rg?

RDo

R0t

:cl c0*

RD2
RD3

;zz,

FO.r

qicl
,-r-,

m6
RB7

_?_l_.1_l?

mi
RC2
BC3

RC{

l_?_

Bt5
03c2

mct

,!,

osco 'l'
l_j'
x_L
2:.,?xlltlz

dz ca

Lor
22e

'. fr'

^ 1r.0692
rtlz r^
+:

]l''t""'

32^

RESE T
I

{(L@'
Lo'

EiI

MIIA-WinPIC-2 MANUAT-

-55-

3. Experiment

@';" ' Flow chart

l"td"lt*

P",tD -l

Initialize PortB

Chatterin&/Bounce

Eruble i

Select the

first column

Check the pushed key.

How to connect iumper


RDO

WinPIC-2 Kit
A

RD1

RD2

RD3

RD4

RD5

RD6

RD7

RCO

QO

RC1

Q1

RC2

Q2

RC3

Q3

RC4

Q4

RC5

Q5

RBO

CO

RB1

C1

RB2

C2

RB3

C3

RB4

t0

PIC Port

-56-

RB5

L7

RB6
RB7

L2
L3

www.midaseng.com

3-2. fntenupt Expcdnrnl


n)*

*!p

Program

'5 c' \MDA\wi np

c2\exarp I e\c\RB_t Mr. c


#inctude (iot6razz. n)
i

unsigned char digi t0, key;

//

"o

- F"

const unsigned char SEGll6l = {0xc0, 0xf9,

0xa4, 0xb0, 0x99, 0x92, 0x82, 0xfB,

0x80, 0x90, 0x88, 0x83, 0xc6, 0xal, 0x86, 0x8e)

id

vo

SES4ENT (vo

id)

{
i

:!

PORTD

= SEGIdigir0];

P0RTC

0xfe;

// Segnent
// Dilit

//

lnlerrupl service routine

#pragra vector = 0x04


// I nterrupt*on-change

nterrupt void

RB_tNT(void)

unsigned char bounce.


keY
/

= PgPrU '
Bouncelchatter ing

doi
bounce =

P0RTB:

)whi le((bounce &

0xf0) != 0xf0);

RBIF = 0;
)

//

MAIN

void main(void)
{

TRISC

0x00; / / lnitial
= 0x00; l/ lnitial

TRISB

= 0xf0; //

TRISD

lNfC0N

ize

p0RTd

by ctearing output

ize

p0RTC

by ctearing output

tnitiatize

RB4, RB5, RB6 and RB7 by

setting input

0xBB;

digit0 = 0x00;
do{
sEcMEM0;

'

P0RTB

asm

if

= 0xfe,

("SLefP");

//

Steep nnde

(!(kev & 0x10)) disit0 = 0x00;


else if (! (kev & 0x20)) disit0 = 0x4;

ll'0'
/l 'q'

MDA-WinPIC-2 I\,IANUAL

57

3. Experiment

else
else

if
if

(!(key & 0x40)) digit0 = 0x8;


(!(kev & 0x80)) digit0 = 0x0C,

ll
ll

'S'

a_"

.:::.

'C'

)while(1);
i;,:::

i.::t;

-58-

www.midaseng.com

3-2. lnttnulit [ixptrirrtenl.

3-2-3. Completion of the write cycle

Circuit Diagrarn

ll-J" ss-scl

,,9.

"FlS1-aoi#

T'--',F"

PIC16F87x
ER2

330

ll.0592

-?"
r1-'

8ff2

rfiz -L

osco .t'
r-l'

frtuz,

w2
RESET

-re
L@_
LO',

ffi.ffi" H"ffi"ffi.ffi.
t,n
\ /
\,,

'00"

EEPROM

h{DA-trf

Address

TSEGMENT

EEPROM Data

inl'Ic-2 MANUAL

-59-

3. Experiment

@rl',Flgw

Chart

SCANI
Initialize the display pointer

if

any key is pushod save the


location code, and set flag.
Increase the code.

Select segment

Clear flag and buffer


Switch input

Initialize the kev buffer

X4-X7

if

any key is pushd save the


function key, and set flag.

Delay

Select segment, and update


pointer

Counter

the code and flag


Retum form SCAN1

-60

www.midaseng.com

3-2. Intcnulrt Iixpcrinrcnl.

[J,qs'i.eA.-pf;r

n.

q,o ]

I
I

lni,irli..
AtJtlrcss

rhe Dara

buifer.

arrd

i
]

l
Convefl Ad&ess and Data to
Segment format

[,

qirot"r

-l

7
I

d qitltl

,*rryq"-

-<q;";.;;
IEEPROM data

[
<1-

Cursor on Addres?

no
=1-r-

s"t

----*iI

.
c"***o_J I [Gp4q*:R,lto,
Adt-tress I
___t
vdsjI

t g!ryq-:Ll
|
RD<-l
I
-*qu'q ii-

L---

Adtlress r,. Lr"'


ScluP Duta

--:-

)l

^%:"l,li::
-___-J

tlt ]-t

Wdt.j---=

''

t, J--l
- Ll

cs.0?
o?
CS -.

)gs
):l

irc
-,
LpryBj-_aggEl
,LEI!4T4: !4,
l

'- EEg^rLJ t_ qq',o" 1 o l

,l_.-

P:- -6|,,n,"r=i,l--=

Retum

MDA-IVinPIC-2 MANUAL

-61

3.

Experiment

How to connect .lumper


PIC Port

WinPIC-2 Kit

RDO
.RD1

RD?:

RI3

RD4

RD5

RDt)

RI}7

RCO

QO

RC1

Q1

RC2

Q2

RC3

Q3

RC4

Q4

Rct

Q5

RBO

CO

RP1

C1

RI]2

c2_

,,,.....,,,.-,',,,,,,.:,'.'',

c-3

t0

;t'.,.,,,Etogram

li)
#

c, \uon\t[ i np i c2\exarpl e\c\EEPRff'l- c

inc lude ( iot 6tezz. rr)

unsigned char

KEY;

unsigned char

KEYI

unsigned char

KEY2;

unsigned char

FLAG;

unsigned char

ROW;

unsigned char

KR0W;

unsigned char

C0UNT;

-62-

'

www.midaseng.com

,!&-

**.

3-2. Intenupt llxpcrinrent.


unsigned char

COUNTI;

unsigned char

COUNT2;

unsigned char

TEMP;

unsigned char

STATE;

unsigned char

FUNCT,

unsigned char

ADDRO;

unsigned char

ADDRI;

unsigned char

EDATA,

unsigned char DISP[6];

//

Segrrcnt format

for '0'-'F'

const unsigned char SEG[16]

{0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xfB,


0x80, 0x90, 0x88, 0x83, 0xc6, Oxal, 0x86, 0x8e)

lnternal

Code

for '0' -

F'

const unsigned char C0DE[16] = {0x00, 0x04, 0x08,

0x0C, 0x01, 0x05, 0x09, 0x0d,

0x02,0x06, 0x0a, 0x0e,0x03, 0x07, 0x0b, 0x0f)


/

Delay

void delay(unsignecl char i)


{

while(i--);
)

//

Scan kev matrix and display segnnt.

void

SCANI

unsigned char

j, k;

= 0xdf,
KEY=KEY1=0;
ROW

= l;
FUNCT = 0xff;
FLAG

= 0xfe;
for (1=6' j (6; .;++; 1
FORTD = DISP[j];

KR0IY

= R0!V,
oetay(too);
P0RTC

PORTC

= Oxff,

PORTB

= (KRolY |

0xf0);

asm ("nop");
asm ("nop");

'

TEMP

P0RTB;

= (rrup )) +) I oxro;
for (k=0 ; k(4; t<++) i

TEMp

if

(!(TEMP &

oxot)){

MDA-\YinPIC-2 I\{ANUAL

63-

3.

Experiment

KEYI = KEY; FLAG =

Oi

TEMP

))= l;

KEY++;

l//kFoR
KR0W

((=1;

KROW

l=6131'

if

(!(KRow & oxlo)){


TEMP=PORTA

if

(!

(TEMP

FUNCT

FLAG

==

OXfO;

0xff)){

TEMP;

= 0;

)
)

))=1'
ROw l= 6*,0'

ROW

| //i tor

.:,.,,

KEY=KEYI&0x0f:

l,

void

SCAN0

unsigned char

i;

for (i=o; i(a;

i++)1

.*i".f!

do{
scANl

0;

)whi le(FLAG == 0);


)

do{
SCANI

0;

:?'

)whi le(! (rLRc == o));


KEY2

CODEIKEY]:

void

HEXTSEG0

DtsP[o] = sEG[(noono

DISPII] =
DtsP[2] =

SEGI ADDR0 &

DrsP[3] =

SEGI ADDRI &

DtsP[4] =

SEGI(EDATA

SEGI(ADDRT

DISPI5] = SEGI

if

STATE

-64-

EDATA

:rri,dfr

)) +) a 0x0f];

r:?.1,: :rt

0x0fl;

)) 4) & oxof];
ox0f];

)) 4) & 0x0f];
& 0x0f];

== 0){

www.midaseng.com

3-2. Intemrpt llxpedrnent.

0x7f, DISPIl]
D I sP[2] &= 0x7f; DISP[3]
D I sPiol

&=

8,= 0x?f,

&= 0x7f,

else

DrsP[4] &=

0x7f; DtsP[5]

&= 0x7fi

//

EER0,,|

data

wr i te

void WRITE(void)
{

whi le(WR ==
EEADR

EEDATA
EEPGD
WREN

l); // Wait for write to finish

EDATA,

= 0,

=L

EECON2

= 0x55,

EECON2

1;

WREN

llR

// Address to wr i te to
// Data to write to
I I Point to Data me{nory
I I Enable wr i tes

ADDRI;

Oxaa,

//
//

0,

Start write operation


Disable writes

//

EER0M

data read

void READ(void)
{

//
EEPGD = 0;
//
RD = 1:
/l
EDATA = EEDATA; //
EEADR

= ADDRI;

Write address to read from

Point to Data rne{rory


Start read operation
Read data

/l

ltain

void main(void)

i
TRISD
TRISC

ll tnitial ize PortD by clearing


// lnitial ize PortC by clearing

= 0x00;
= 0x00;

output
ouput

= 0x05:
TRISA = 0xffi
ADC0NI

TRISB
':

= 0xf0;

= 0xffi
'P0RTE = 0xff,
P0RTB

ADDRO

ADDRI

STATE

= 0;

EER0'1

data read

do{
READO

ll

MDA-WinPIC-2 MANUAL

65

3.

Experiment

loop:;
HEXTSEG0;

scAN0;

if

if (FUtlCT == 0xfd){
if( STATE == g) 51419 = 1;

I x4(AD) "L"
// xs(DA) "1"
/l STATE =

else WRITE0;

//

EER0M

//

xa(+1 "s"

(FUNCT

eIse

== 0xfe) STATE = 0;

data write

else

if

(FUNCT

== Oxfb){

ADDRI++; STATE

1,

else

if

(FUNCT

ADDRI--;

llxT(-)'L"

== 0xf7){

STATE

= I:

)
e

/l

lse{

if(

STATE

else

==

6) 4pppl

= (noonr

DataKey

(( 4) I KEY2;

EDATA

goto

= (ronrn (( 4)

KEY2:

loop;

)
)

lwhi

-66-

le(t);

o,r4ry1,.1pi

daseng.com

3-3. Tirner llxlrcdntent.

3-3. Timer Experiment.


3-3-1. Timer0 module timer
Circuit Diagram

PIC16F87x
PIC16FB4
RA0
RRI
RR2

RB3
RB2

R8l
886

nlff,

D7
D6
DS

D{
D3
D2

0sc2 0scl

DI

Flow Chart

(
Initialize timer mo<le

Initialize LCD module

I Internrpt service routine I ))

__l r-co
olrlgry__
I
Glry:d-rs,,y l
J

':"

t__
-1

.* ,- r'f'l_gT l

Wait interrupt ,

MDA.WiffIC.2 MANUAL

-67-

'1

3.

is-EFF:-q'r'r:$:ilg}!r,tq=.ffiiw{11:l'1fry,,-T::::fl::,ri

;'

:E:rFrr.^-/-{

"

Experiment

How to connect

jumper

PIC Port

WinPIC-2 Kit

RAO

RS

RA1

ti

RW

RA2

EE

RBO

D4

RB1

D5

RB2

D6

RB3

D]

OSC1,2

4Wb

W;',,,,Ptogram

,3

c, \MDA\I, inp ic2\exanp Ie\c\T [,tER0. c

finclude (iot0rglZ. n)
uns

gned char sec, on-buf, f I ag;

[] = " Tiner0 ';


const char msg2[] = " Tiner rode t! ",,'.'
":
const char msg3[] = " Exercise |
const char msg4[] = " Isec 0N/0FF. :'";
// RBO-RB3 : DAIA, RAO=RS, RAI=RW, RA2=E
*include "LCDA.h"
ll lnitiat ized LCD routine
// lnterrupt service routine
const char

i:,. ,i:i!j r

msgl

fpragrna vector = 0x04

ll finerl

,,'

,1

interrupt

_i nterrupt void ON_0FF(void)


{

.):

sec--;

/l

sec

if(sec == 0){
sec = 16;
f lag = 1'
)
Tlr4RO

= 0,

TO|F

= 0;

ll

uain

void main(void)
{
OPT|ON

-68-

= 0x87i

/l

Tiner mode, Prescale rate 1

256

www.midaseng.com

r:

!E

3-3.'fiurer ExperirnenL
ItlR0 = 0x00,

// Enable tiner0 interrupt


II tnitiaIize the LCD nodule

= l;
L_tNlr0;
T0lE

DtSPLAY0;

on_buf = 0x07;
sec
GIE

= 16;
= l;

Il256x256xl6xl[Ps] =

//

Enable al

sec.

unmasked interrupts.

ao{

flag = g'

ll

Clear interrupt flag.

while(!flag); /
on_buf

= ((on_buf ^ 0x07) & 0x07) ! oxoo;

CM,IAND (on_buf

ll

LCD 0N/0FF

lwhile(l);

MDA-WinPIC-2 MANUAL

-69-

3. Experiment

3-3-2. TimerO module counter


Circuit Diagram
PIC16F87x

PICl6FBl

RR8
RRI
RR2

RR,',/TOCKI
BB3
RB2

R
UDO

RBI
RBO

W
USS

trcLR

oscz oscr

IINL

i.,
tlt

i^-,

,i I-

-.-t

-*-

0sc0
x-Li, ' , ,.,

ur,L I
;a-J"

z l, 29rsl:

"tss
\$$ir''

Flow Chart

fu{Elq

re.l"--l
Display the pulse on LCD

@t
[.

-70-

,Clear

flae

www-nridaseng.com

biIgf.

'it
h

3-3.'Iirner Ex;xrintcnt

;l:

,li
I l.l

How to

tr

connect junrper

fr
&

PIC

Porl

WinPIC-2

RAO

RS

RA1

RW

RA2
RI]O

I]E
D4

RB1

D5

RB2

D6

RB3

D7

RA4/TOC-KI

x4

OSC1,2

ri

l,llb.

Program

c , \MDA\H i np i c2\examp I e\c\C0uNTER0.

#inctude (iot0fgzz. h)
unsigned char pulse, flag;

const unsigned char msgl[]=" TimerO


const unsigned char msg2l]=" Counter nrode !
const unsigned char msg3l]=" Exercise

"

const unsigned char msg []="lnput pulse : 0 "


#include "LCD4,.h"
// tnitiatized LCD routrne
Itpragma vector = 0x04
// lnlerrupt service routine

_interrupt void C0UNT(void)


{

pulse++;

//

pulse +

pulse &=0x0f;

if(Pulse

S) pulse = 0;

l/ Bounce/chattering
flag = 1'
/i Set interrupt flag.
TtlR0 = 0xff;
// lnitialize TlvtR0 register
T0lF = 0,
// Ctear ftag bit T0tF
whi te(!na4)

//

tiain

void main(void)
{

//
//

Counter npde

increnent on high-to*low transition on T0CKI pin.

OPT|ON

= 0xb8;

MDA-lYinl'IC-2 MAI{UAL

71

3. Experiment

0xff, // TIft0 = 255


ll Enable tirer0 interruPt
T0lE = l;

TMR0

r-_tNlT0;
DISPLAY0;

pulse = 0i
GIE

l/

Enable al

unmasked interrupts

doi
f lag = g'
wni

le(! flag)

CottYtAND(0xde)

CHAR-0(pulse + 0x30)

| ll

convert to ASCII

ffi

code

)white(l);

;]ffi
;1,

ii!:l ';'ri''1i

ffi

,;ffi

iffi

iffi

",1

www.midaseng.com

'ir'E

3-3. firner Experinrent.

3-3-3. Timerl module timer


Circuit Diagram

PiC16F87x

n:EE

0sc2 osct

RD7
RD6
BD5

D7
D6
D5

UDO

BD{

D{

r0

RD3
RD2

D3

D2

RDI

DI

USS
K

RDO

XTRL

i{l
ittk:

RESET

rf
-ae
L@Lat -

ca: ^
rl=ctzzpl
+.

l0k

ll.rf,ru
mrz

22p

F,,:..,,..'.,,,.,....,

;lrW, Flow chart

lnitialize timer mode

hitialize LCD Module


on LCD
I

[,oad font fiom CG ram,


Save address

lruriuliuTMRl register, I
I c!*
I
1T r{]q.
)

to buffer

MDA-WinPIC-2 MANUAL

-73-

3.

Experiment

How to connect

.u$-,,

c,

jumper

PTC Port

WinPIC-2 Kit

REO

RS

RE1

RW

RE2

EE

RDO

DO

RDl

D1

RD2
RD3
RD4
RD5
RD6
RD7

D'Z

D'7

OSC1,2

4\frh

D3
D4
D5
D6

Program

\MDA\Wi npi c2\examp I e\c\TtMERI. C

#include (iot6razz. n)
unsigned char count, anlm, animc, flag;

[]=" Tirnerl
Const unsigned char msg2[]=" Animation ! !
const unsigned char

"

msgl

"

i
,

const unsigned char msg3[]="prnnle Display !",


"
const unsigned char

msg4[]="

const unsi gned char hangle[]= {0xl f, 0xl l, 0xl l, 0xl t, Oxl l,

Oxl l, Oxl

l, 0xl f,

0x08, 0x08, 0x08,0x0e, 0x08, 0x08, 0x08, 0x08,

0x0e,0xl I,Oxl

l,0xl I,Oxl l,Oxl l,Oxt t,0x0e,

0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,

0xl f, 0x10, 0x10, 0x10, 0xt0, 0x10, 0x10, 0xl f,


0x04, 0x0a, 0xl
0x

f,

l,0xl

1,0x1 1,0x00,0x00,0x1

0x0 I , 0x0 I , 0x I f ,0x02,0x04, 0x08, 0x I 0,

0xl f,0xl0, 0xle, 0xl0,0xl f,0x00,0x00,0x1

);
const unsigned char formf]= {' o',
#include "1CI8.

0x00, 0x01, 0x02, 0x03, 0x04, 0x01, 0x05,

' ',0x06,0x03,0x07, , . ,' .'l:


l/ tnitial ized LCD routine

h"

#pragna vector = 0x04

//

lnterrupt service routine

_interrupt void

TIMERI

(void)

74

f,

www.midaseng.com

3-3.'limer

//
//

= 0;

TIvlRlON

t-if(count == 0) {

ccun

count =
f lag

ExJrcrir*cnt

Stop t iner I
count

B;

1'

// lnitialize

Tlr4RlH

and TlvlRlt

TlvlRlH=Ili4RlL=0,

0i
= li

ll
//

TlvlRllF =
I
I

IvlRl0N

Ctear ftag

bit

I],lRilF

Enable tinrerl

)
:i

void

HAN_DISP(void)

i
uns i gned

//

char

Erase I ine

c0M'/laxp13roo''

for ( i=0; i (16;


COl't'tR[1P1un,r,

//

i++) CHnn_o(ox2o);

'

animation

for (i=0 ; i ( aninc,


(0x60)

C0i,il4AND

i++) CHAR_o(form[i]);

l/

ltain

void marn(void)
{

unsigned char

//

tiner

npoe

TIC0N

= 0;

Tlr4RlH

= 0;

TlvlRIL

= 0;

Tl4RllE

i,

l;

//

tinerl interrupt

Enable

L_tNtT0;
DtSPLAY0;
/
i

load font frcxn

CG

RAM

for (i=0; i ( o4; i++)1


CtltWnlqpl; I OxaO) ;

ll

Point

CG RAM

address

to

read f rorn.

CHAR_0(hangleIi]);
)

//

65536

count =

x l[us] x 8 = 0.5

B;

MDA-1VinPIC-2 MANUAL

-75

3. Experiment
';
*.'i

anim = 0xdf,

anirE = 0;

= Ii

PEIE = GIE
Ilr4Rl0N

1;

//

Enable

tirBrl

f lag = 6'

lil

,.,i1

i.,

.,sJ

i
;

i'

le(!flag);

i:

HAN_DrSP0;

an

= ((anim-t)

nntr

& 0x0f)

Liik=,:i,;r

OxOO;

if ( anim :

16) anirrc =

l;

lwhile(l);

-76

'

i.

.,,.

:\

anim

i,

'i.'l

llEnable interrupt

do{

whi

www.midaseng.com

ri,
t

-1-J.'lirncr fkplimenl.

3-3-4. Timerl module counter


Circuit Diagram

PIC16FB7x

HCo./Il0s0
RCl./Tl0sl

R07

BD6

UM

805

RESET

--r_

nE

BD{

u0

RD3
RD2

uss

RDI
K

RDO

0sc2 oscl
XTSL

rr,l
a

,*,

f;1
s zzrf
I

rfiz

ITI

.ff

Flow

Charr

__l
kritialize counter

Initiulir. LCD

'

mocle I

lr{odule

Display message on LCD

t_

t --lryqiqyr, l
/
.\

-<_

Wait intemrpt

[-

upo.t.-cr,.r.

ui.prry
I

I
I

r-co
_

_-

J
.l

tni,iutir" 11\1Rl regisrcr,

t rg{g

-r-MR

l1t

rrF

--_--

IIIDA-WinPIC-2 MANUAL

77-

3. Experiment

;,r,,,How

to

connect jumPer
:.i

PIC Port

WinPIC-2 Kit

REO

RS

RE1

RW-

RDO

DO

RD1

D1

RD2

D2.

RD3

-,'_-- '--

D3
D4

-- -

RD4
RD5
RD6
RD7

D6
D'7

osc1.2

4MIlz

RCO/T1OSO

CKO
CKI

i:.::i?{

Program

c,\uoa\tl inp ic2\exarp le\c\C0uNTERl. C


#include (iot0tazr. n)
unsigned char hour,min, sec, flag;

const unsigned char

msgl[]=" Tinrerl

"

const unsigned char msg2[J=" Counter nrode ! ";


const unsigned char msg3[]=" Hour Min. Sec. ";
const unsigned char ms$4[]=" 00 : 00 : 00 ";

finclude "LCD8.h"
#pragna vector = 0x04
// lnterrupt service routine
interrupt void CLOCK(void)

l/

tnitrat ized

LCD

routine

{
Tlt4Rl0N

f lag

= 0;

// Stop tirnerl

= l;

sec++;

if((sec & 0x0f)==16;1

l/

10?

ll

6?

sec &= 0xf0i

sec=sec+0x10;
if((sec & 0xf0)==gx6;1
sec = 0;
min+t;

78

t
r:: r.

www.midaseng.c0m

::

itt
.:...k:,:
,l"r:.ir]l:.
{t "I',.

::,.
: :,.
::

,i.

:.1 , i.iilii;,::,

. -i

-, ..:1fi

D5

RCIiTlOSI

,''i''

EE

RE2

,.,'1..

'

,{iS ;

..

3-3. Timer llxpefimenl

if((min & 0x0f)==19;

l/

10?

min &= 0xf0,


min = min + 0x!0;

j:

!l:l

if((min & 0xf0)==9x60'){ // Al


min = 0;

:l

hour++,

if((hour & 0xf0) I= 0x20) {


if((hour & 0x0f) == l0){

l/

20-23

hour &= 0xf0,


hour += 0x10,
)
)

else{

if((hour & 0xf0) == 4; hour = 0;


)
)

//

TMRIL:lI4RlH = 32768, (t/gZ.zOe[kl],])

Tl,lRlH
Ttr4RiL

= ((0SSs0-azzoe) a oxrroo) ))

(OSSS0-:ZZ0a)

lF = 0;
]}I4R10N = l;

ll
//

].tlRl

3276S

= l[sec]

g;

a oxoorr;
Ctear f tag
Enable

bit

TllRt tF

tinerl

void CLK_DISP(void)
{

//

Houre

C0l,tr,fiXg1grar;

'

CHAR_0((nour

)) 4) * oxso);

CHAR_0((hour &

//

Minute

CCtivUn5lP

'

1O*Or,

CHAR_0((min

)) a) + 0x30);

CHAR_O((m|n &

//

0x0f) + 0x30);

0x0f) + 0x30);

Second

Co\ti,lAND

(0xdc)

CHAR_0((sec

)) a) * 0x30);

CHAR--0((sec &

0x0f) + 0x30) ;

ll uain
MDA-WinPIC-2 MANUAL

79

3. Experiment

void main(void)

i
TIC0N =

0x0a;

//

Counter node

//

tt'mtL:n'nlH = 32768
ll (t/32.768[kk]) x 32768 = l[sec]
Tl,4RlH = ((0SSA0-:Zr0A) a OxrrOO) )) e;
IlvtRtL = (oss:0-rzr0a) a oxoott;
Ilr4RllE

li

//

Enable

tiner interrupt

L_tNtT0;
DrsPLnY0;

hOUr=min=SeC=0;
PEIE = GIE
TMRI0N

= l;

//

Enable t inerl

do{

f lag = 0;
whi

le(!flag);

cLx_DlsP0;

)while(l);

80-

www.midaseng.com

J-3. Tinrer Iixlx'dnreni.

3-3-5. Timer2 module

circuit Diagram

BOO-ROS IK

IH0-IRS 2S8t8tS

as'fi;

,,,F; N'"F' *,#=, nr"F,

--"H';

RSo-8S7
17

RS8

PICl6FB7x

IPffi

[:i
iil

XTfl-

tB;

ilm

RB6
RB7

RESET
I

oo-@
:10'

M,,,

.", . r

.*l

lB3

fttH

0sc2

a ,t-l

1., ,rl

rtI

OSCI
x_L.
,

.05t?

3nts

zzpl

oscl

Flow Chart

I\_

Display 7 segtnent

It_"Ct"r. flae bit TMR2IF.

enaUt" {Iag bit TMR2IE.

t*[,,*:r. )

MDA-WinPIC-2 MANUAL

-81

-E

3.

Experimenfi

.,

How to connect

jumper

PIC Port
RBO

WinPIC-2 Kit
A

RB1

RB2

RB3

RB4

RB5

RB6

RB7

RAO

QO

. RAl

Q1

RA2
RA3
RA4
RA5

a?

-,
-_ *

_-

Q3

Q4
Q5

OSC1,2

4Wh

Frpgram

'5

c r \MDA\II i np ic2\exanp

te\c\T

MER2.

#include (iotStatZ. n)
unsigned char point, digi t;
const unsigned char seg[]= {0x89,0x86,0xc7,0x8c, Oxcl,0x92}
fpragma vector =
lnterrupt vector

0x04

//

//

lnterrupt service routine


_interrupt void TIMER2(void)
{

= 0;
P0RTB = seglpoint];
TIr4R20N

P0RTA
po

//

Stop tiner2

/l

poinl +

= digi t;

nt++;

disit ))= 1;
digit l= 6169'
if(point == 6){
point = 0i

digit = 0xdfi
)

IlvR2lF

0;

TtvR2ON =

t;

-82

Enable tiner?

www.midaseng.com

J-3.'lirner

//

llxlrcrimrcnt.

uain

void main(void)
{

T2C0N
llr4R2

= 0;

= 0;

TMR2IE
PR2

= l;

//

Enable

ll

tnitial ize

l/

Enable

tiner2 interrupt

0x80:

TRISB=TRISA=0;

PORTA

and P0RTB by clearing output.

Point = 0,

digit = 0xdf,
PEIE = GIE

=L
white(t);
lli4R20N

= l;

lirer2

MDA-WinPIC-2 MANUAL

83

3.

Experiment

3-4.

CCP Module Experiment.

3-4-1 Compare mode


A*t
\&ry

Circuit Diagram

PIC16FB7x

R22

5.6K
R23

RC0

5.6K
RCI

freG oscz

oscr

xl-:
_

osc

-f,'

ilJ

iil.69t:

l0k

r-l H

rh tt

,S$

Flow Chart

yes

L t*u.n'r"i@

-84-

www.midaseng.com

22p

3-4. CCP Nlodule Ex;rcrinrcul

How to conliect

"s

.jurnper

PIC Port

n\

RCO

SPK

RC1

B'U

RC2

MEL

OSC1,2

4lltlh

-L

Program

"}p
$

c, \MDA\Hi npi c2\exampte\c\PHoNEl.

# i nc

//

WinPIC-2

ude ( i ol 6f877. h)

ltain

void main(void)
{

unsigned char
TRISC
RCO

i,j;
//
//

= Oxfe;

=l,

// tirerl prescale

lnitial ize RCO by clearing


Speaker off
rate l:l

output

= 0,
TltlRlH=llvlRll=0;
TIC0N

CCPICON
T1,1RI0N

//
//

= 0x0b;

= l;

Ccrnpare nnde

Enable tinrerl

do{

for (i=0; i <20;


/

i++){

I 4s,ol1t)12

ccPRlH

= (1042 & 0xff00) ))

CCPRIL

for(.1=g'
CCP1

B;

lA42 & 0x00ff;

I (Zq;

j++){

lF = 0;

whi te(!ccPl tF);


P0RTC

l//
/

^=

0x0l;

a9ol{,l
zzolu,112

ccPRlH

(1563 & 0xff00)

))

B;

CCPRIL=1563&0x00ff;

'

for (j =O;
CCPI

j ( t0 ; .;++;

lF = 0;

while(ICCPIlF);
P0RTC

^= 0x0l;

N{DA-!YinPIC-2 MANUAL

-85

3. Experirned

lll
//

ll

3nf{zl

zo

Speaker

RCO

off for 2 seconds.

= l;

ccPRrH

(20000 & 0xff00)

))

B;

CCPRIL=20000&0x00ff;

for(i=g'j(100;j++){
CCPI

lF = 0;

whire(!ccPr rF);
)

)while(t);

-86-

www.midaseDg.com

r-J. Cf

i'

Llodule Experinrenl

3-4-2 Capture rnrrde


Ai*
.i*Y

Circuit Diagram

PIC16FB7x
REA

BEI
RE2

RD7
RD6
RDs

fs{

RD3
RD2

RDI
BDO

x6

RC2,/CCPI

RB2

RB6

RCl,/CCPz
R

osc2

rl7

ror

CLOCK

-zzo BESET

887

oscr

F-low Chart

I{RT, -IIMERI,
frlnitializeCCPI,

["IN4ER2,

and CCP2

------\

-s-_----=-\"x7-?
-/'/

--'->

CCPRIL=CCPRIL+2

MIIA-1Y!nPIL:-2 NIANUhL

87

3. Experiment

_t

[cr.ar

Hgw to connect

nrg ur, ccpznl

iumper

PIC Port

WinPIC-2 Kit

REO

RS

RE1

RW

RE2

EE

RDO

DO

RD1

D1

RD2
RD3
RD4
RD5
RD6
RD7
RB4

D:Z

D3
D4
D5

D6
D-7

X4

RB6

x5
x6

RB7

X7

RB5

@r*

'.

RC2/CCP1

RC1/CCP2

RC1/CCP2

RC2/CC-P-1-

OSC1,2

4\frb,

" Program

\mn\H i np i c2\exanp I e\c\CAPTURE. C


*include (iot0tazz. n)
c

I
'iit,

unsigned char count;

unsigned

int

tenp2, tenpl;

const unsigned char

msgl

[]="

CCPI P'rilyl Mode

const unsigned char msg2[]="66pRlL:00

!";

PR2:00"

const unsigned char msg3[]={' ','C','C',


' ,0x08, 0x09)

const unsigned char


-88-

ms$4[]={'

www.midaseng.com

3-4. CCP Il{otlule Experimenl

,' t' ,'u' , 's' ,'t' t:

'

const unsigned char hangle[]= {oxtr,oxil,0xll,0xlf,0x00,0x04,0x04,0xlf,


0xl f,0xt0, 0x10, 0xt0, 0xt f, 0x00,0x00,0xt f,

0x1f,0x04,0x1t,0x11,0x00,0xtf,0x04,0x04,

0x00,

0xtf,

0x01, 0x01,0x02,0x04,

0x0g,0xt0,

//

0x0B,0x0B,0x0B,0x0B,0x0g,0x0B,0x0g,0x0g / /

);
const unsi gned char ASCTBL[]=

"0t234567B9ABCDEF"

#include"LCDB.h"
/ I lnlerrupt vector

/l

#pragra vector =

lntitiatizedLCDnpdule

0x04

//

lnterrupt service routine


_i nterrupt void CApTURE(void)
{

count--',

//

count

if(count == 0) tenp2 = (CCnR2H (( A1


etse templ = (ccRn2H (( s) | CCpR2L;
CCP2|F

0;

l/

1 CCnR2L;

bit

Ctear ftag

void

RUN(void)

tenp2=templ=0:
count = 2;
PEIE = GIE

l:

//

Enable interrupt

Tlv1R20N = l,
//.Enable tinerl and tiner2
le(! (count - 0));

llvlRl0N =
whi

0; //
PEIE = GIE = 0;
//

TMRlON

TlvlR20N

Stop

tinerl

and tiner2

Disable interrupt

TtlRlH = II,1R1L = Tl4R2 = 0,

//

tempZ-tenrpt

terp2= tenp2-tenpl
CcrNtrlapp

16*Or;

CHAR_0(ASCTst-[(te'rp2

)) rz; & 0x000f]);

CHAR_O(ASCTBLI(tenp2

)) a) a 0x000f]);
)) +) a 0x000f]);

CHAR_0(ASCTst_[(tenp2

CHAR_0(ASCTBL[tenp2 & 0x000f])

CC}vt4AM(0xe0);

.while(!RB4): /l

Bounce/chattering

void DISP_PR2(void)
{

MDA-WinPIC-2 MANUAL

89

3. Experiment

CS,tr44N91gr..i

'

)) a) a 0x0f]);

CHAR-0(ASCTBLI(PR2
CHAR_0(ASCTBLIPR2

C0m'lR6p10,,.r,

& ox0f])

'

l
void

DISP_CCPRIL(vo id)

C0'naaXD10(.r; '
CHAR_0(ASCTBLI(CCPR|L

& 0x0f])

CHAR_0(ASCTBLICCPRIL
CC[r|'4AND

(0xe0)

)) a) a 0x0f]);
i

ilr:
;

'i.l

llPRZ+2
voio Ph2_u!C(void)

i
PR2 += 2:

//PRz+2

DISP-PR20;
wni te(!nB5);

// Bounce/chattering

llPRz-2
void

PR2_DEC(void)

PRZ

-=

2:

/lPRz-2

DtSP_PR20;

white(!RB6);

/l

Bouncelchattering

// PR|L + 2
void PRIL_ll,lC(void)
{

CCPRIL += 2;

//CCPRIL+2
I

DtsP_ccPRlL0;
whi te(!RBz);

l/

Bouncelchattering

//
//

tnitialize

/l

Main

void main(void)
{

unsigned

char i;

TRISC

= 0xfb;

TRISB

= 0Xff;

PRZ

= 201:

-m-

P0RTB

by setting input

PW Period = 300[Hz]

www.midaseng.com

J-{. C'('l' l\ludulc lixlxlirrrenl.

l;
// Enable capture irrterrupt
CCPRIL = 0x7f;
/l "H" putse period SO[2"]
CCPIC0N = 0x3c I/ CCPIX=CCPIY=0, PMvl nrode
CCP2C0N = 0x05; 1/ Capture node
CCPZIE

CCPR2H=CCPR2L=0;
I
I

// liner? lnternal clock, Prescale rate l:16


= 0x02,
Ilv1R2 = 0,
T2C0N

I/

Tinerl lnternaI clock, Prescale rate I:I

= 0i
ItlRlH=Tl'4RlL=0;
TIC0N

L_rNtT0;

fonl
(i=o;
for
i ( ao; i++){

Load

C0maax91'

Ox+O), llset GC RAlvl address

CHAR_O(hangteIi]);

I
DTSPLAY0;

DrsP_ccPRlL0,

DtsP-PR20;
/

Scan swi tches

doi
if(RB4 == O) RUNQ ,

else if(RBs
else if(RB6
else if(RB7
lwhile(t);

//

RB4=0?

0) PR2_INCO ,
== 0) FR2_DEC0;
== 0) PRIL_INC0 ,
==

/l
//
//

RB5=0?

RB6=0?

RBl=o?

MDA-!YinPIC-2 MANUAL

-91

3. Experiment

3-4-3 PWM mode

circuit

Diagram
PIC16F87x
Bf0

RB.r ffil
R85

RD7

D7

R06

RD,S

DS

nDl

D{

RD3

D3
D2

FO2
BDI

DI

GC2

rc0
RCI

rc2/t

Rf,{

Pt

osct
MTR

U32A

Asz

7{LSt{
PHOTO

7+LSI2SR

tB
frx.
38
t8

lc
3C

rc

c23

9. luF

l,2Elr
3,,tEN

NOTOR

rro, mD|DCN
D/RCoI'UERTEE I
ll l_+ o
-{-o
L"-l
oot-{ocz
'h?e--1
ocr )-r

.^, -

92-

www.midaseng.com

3-.1. CLIP N{orhrle lixlxrinr*rrt.

Fiow Chart

I r,ir-ur" PORT A. B,and

Initialize Tirner and CCPI


Enable intem-rpt

--__l
--=\

"X4"

----l

----...------''-r--..-----...-

'X5"
--a- -.-...-.-//
./ ,',=-'--{=
"x6* ?
?

[Stq

-<:-' --;tu=-=="X7" ?

r-g;u

rMRlrF

\-----'----l

Reurn

trom inienupt

lno

n.i

,,Y#

How to connect .jurnper


PIC Port

WinPIC-2 Kit

REO

RS

RE1

RW

RE2

EE

13DO

DO

RD1

D1

f.D2

D'2

RD3
RD4
RD5

D3

RD6
RD7

D6_

Rrl4

x4

RBI

X5

RB6
RB7

x6_

RCO

DC.E

RC1

DCR

ilc2

D-CS.

RC3

SPD

OSC1,2

4tfrb.

D4
D5
D-7

X7

l!fD.4- WinPIC-2 MANLTAL

93

3.

Experinrent

Program
::t

'i3

c \trDAUi np
r

c2\exap I e\c\DC. C

t.'. A

finclude (iot0tazu. n)

#define DCE RCO


#define DCR RCI

fdefine
*define

DCS

RCz

SPD M4

const char msgl[] =


const char msS2[] =

//
//
ll
//

Enabte

bit

:1, ts

Direction
Pli/fi|
:;itr' -.

'. ,'.

Speed

"DC Motor

Control",

" Period '

const char msg3[] = "

369 11r"'

'.

";
";
const char msg4[] =
"0123456789A8C0EF";
const char ASCTBL|I =
H Period
"Speed: 0000 rps

'l

.'!''

unsigned char sec_buf, speed;


* i nc I ude "LCD8.

h1

ni ti at i ze LCD nndu

unsigned char SCAN(void)


{

unsigned char i,key;

for (i=0; i(+;

i++;1

do{
keV =

PgP"'

)white((key & 0xf0) != 0xf0);


)

do{
keY =

P0RTB;

)while((key & 0xf0)


return key,

:0xf0)i

void

SPEED_DISP(void)

unsigned char msd, lsd, tarp;

msd=lsd=0;
msd = speed/100;

tenp = speedlO0;

lsd = tffp/lO;
lsd ((= 4;
116 = ((tep%to) & oxor)

94

'.

-r*.

tsd;

www.midaseng.com

:..::l'

3-4. CC-P Module Exjrcrirncnl-

(0xd7)

C0,tvlAND

CHAR_o(((msd

)) 4) & 0x0f)+0x30);

CHAR_0((msd & 0x0f)+0x30)

CHAR_o(((rsd

)) 4) & ox0f)+ox:o);

CHAR_0((lsd & 0x0f)+Oxgo)


(0xe0)

COtui',1AND

I
/

lnlerrupt vecter

#pragna vector = 0x04

l/

lnterrupt service routine


_interrupt void PULSE(void)
{

if(TorF){
sPeed++;
TMRO

= 256-14;

T0lF = 0,
)

else

if(TMRI tF)

I // t

sec.?

Il,1Rl0N = 0;

sec_buf--

i f (sec-buf == 0)

SPEED_DISP0;

sec_buf

10.

sPeed = 0;

l/lus(lt(awz/a) x 12500 x l0 = I sec.


IvlRtH = ((65536-l2s0O) )) S) & 0x00ff;
llvlRlL = (0ss:0-tzsoo) a oxoott;
llr4Rl0N
TtlRl

l;

//

Enabte

tinerl

iF = 0;

void DUTY(void)
{

C0IMAND(0x9d)
CHAR_0(ASCTBLI(CCPRIL

"

CHAR_O(ASCTBLICCPRIL

C0l,ttnPP1O*.0,

)) a) a 0x0f]);

& 0x0f]);

'

// uain
MDA-\ltnPIC-2 MANUAL

95

3.

Experiment

void main(void)
{

unsigned char key,

= 0;
TRISB=TRISA=0xff;
TRISC

//
ll

lnttial ize PORTC by clearing output


lnrtial ize P0RTA and PORTB by setting

= 0x06:

ADC0NI
DCE

= 0,

DCR

1:

L_tNtT0;
DTSPLAY0;

OPT|ON
Tl4R0

= 0xbf;

= 256-14;

0x30i //

rate l:B
I I lus(lt(Nuztq) x 12500 x l0 = I sec
TtvlRlH = ((0SSe0-rzsoo) )) g) & 0x00ff;
T1C0N

Iti4RlL

= (0SSS0-t2500) & 0x00ff


=

sec_buf

Prescale

10;

,
I / PIM per od 300 [Hzl
CCPRIL = 0x7f; /l Duty rate 501%l
CCPIC0N = 0x3c; // Pf$V node
T2C0N = 0x03; // lnternal clock. Prescale rate 1:16
PR2

207

= 0,
DUn ();
TMR2

speed = 0,

PlRl = 0;
PlEl = 0x0l;
do{
keV = 560*,r

if

'

(! (key & 0xl0)){


DCE

= 0;

INTC0N

= 0;

Il,lRlON

= 0;

IIv1R20N

= 0,

else
DCE

if

(! (key & 0x20)){

= I;

INIC0N = 0xe0,

=
T}1R20N =
]},1RION

96

1i
1;

+vrvrv.mirlaseng.com

output

3-4. CCP Module Experimenl

i
else

if

CCPRI

(!(key & 0xa0)){

L++;

Itrv0;
)

if

(!(key & 0x80)){


CCPRI L--;
ourv0;

else

)while(l);

MDA-WinPIC-2 MANUAL

-97

3. Experiment

3-5. A/D Converter Experiment.


3-5-1. A/D Converter
r\

\&s

Circuit Diagram

clB

PICl6FB7x

e-

ffii,fri ffi

(-

cHl

883/RN3
b7

RD7
RD6

1t

D6
D5
D,t

BD5

Ser

RD.I
RD3
RD2

D3
D2

R0l

DI

RDO

THERI1 I STOR.

xrnl
{;l

Ht

,*rr,

o"I

t'',:'ifft
ln

HUNIDITY

x-!

oscr X
:)

fi2

1t.692i
?ilH21
rh

CLOCK

rhc i2e

osco 'l'
l)
x_L

RESET

-_l-

z,aeis

,{l''" ';" ""'^'t


R1D CONUERTEB

cr5
F39

5tK

l9uF

cr3

R28

5tk
R?9

5ll

Lms$l

Sperconduct ivi

www.midaseng.corn

ty

Cbnverter ExpcrinrenL

Flow Chart

Read 1y'D ctnverted value

tljr*'",l_ 1

t*U^ O*O**.**.

pe\ay 22[us)

: -r*qlqlr]
-L<--._=_/-\nol
.-.---\-----l

ft6P How to

connect .iumper

RI]O

RI]1
RI]2
RDO

RD1

RD2
RD3
RD4
RD5
RD6
RDZ

849/ANo
RA_I/AN1-

B4?/AN2
RA3/AN3
RA5/AN4

osc1,2

MDA-WinPIC-2 MANUAL

la

-99

3. Experiment

Program

'3 c, \MDA\II inp ic2\exanp le\c\ADCo. c


finclude (iototazz. n)
unsigned int tefip, flag,
const unsigned char msgll]=" A/D Converter
qglst unsigned char msg2[]=" Volt neter !!
const unsigned char msg3[]="yrs1+:5V, Vref-: a";
const unsigned char msg4[]="

ANO

fiinclude "LCDBB.h"
// lnterrupt vector

ll

0.000[V]

tnitialize

LCD rnodu

le

*pragma vector = 0x04

//
_i

lnterrupt service vector


nterrupt void AD_lNT(voici)

= (nonrsu (( B) |
f lag = l;
temp

ADRESL;

ADIF = 0;
)

void V0LT(void)
{

uns i gned

char

bcdh, bcd I ;

tenp &= 0x03ff;


tenP *= 5;

= temp )) to;
bcdh ((= 4'

bcdh

tenp &= 0x03ff;


tenP

*=

10,

bcdh

l=

tenp

/l ta'' xl0
))

l0;

tenp 6= 0x03ff;
tenP *=

l0;

/l
))

bcdl = tenp
bcdl ((= 4'

tarP

xl0

to;

tenp &= 0x03ff'


temP

*=

l0;

bcdl l= tenp

//

tenp

I0

)) lO;

C0![4AND(0Xd7);

CHAR_0((bcdh
cHAR_o('

100

. ')

))

a)+oxgo)

www.rnidaseng.com

.}-5. A/D C-onverter Experiment


CHAR_o((bcdh & 0x0f)+oxso)
CHAR_o((bcdr

))

a)*ox:o)

CHAR_O((bcdt & 0x0f)+0x30)


CCttvtvtAND

(OXeO)

)
/

vo

l,lain

id

nra i n

(vo id)

//

nignt justified

ADC0NI

ADIE

= 0xge;
1,

L_tNtT0;
DTSPLAY0;
ADCONO

0x0t: //

PEIE = GIE

Channet

0,

Fosc/2

= l;

ADIF = 0,

DELAY(500):

//

Z3lpsl

do{
G0

l;

//

Start A/D converting

f lag = 6'

te(!ftas);
volr0;
whi

DELAY(30000);

lwhile(t);

MDA-WinPIC-2 wIANUAL

- 101

3. Experiment

3-6. USART Experiment.


3-6-1. UART Interrupt
Circuit Diagram

PICl6FB7x
BB0

nn+ 11

BC7/M

RBI
RB2
RB3

RBl
nB5
BB6
RB7

frm

tlsc2

0scr

IIE!

l!{z

oscr
-F

1il.692

i.,
h zzprt? fil-Z)
c0=
I

*{

r&

R2

zl

t?{r

F'

ttv

22o

Flow Chart

Receive routinc

no ----'
<-- RCIF=I?

t-lle!rylqtE
I

Setup BAUD rate

T r.,

I
"ir-uu.
L

ltContinuom Receive-)

l:ryry

-l

L qryqerryq

t.__

-102

\-------

i,ye!

___

I nryryt
v

f__@_l
Interrupt serrice
mutfure

ww'rv"midaseng.coln

Receive

$
3-6. USART Experinrcul

How to collnect

.jumper

PIC Porl

WinPIC-2 Kit
Yq
)-1

Y2
Y3
Y4
Y5
Y6
Y7
RX

IX
t1.\sgzMtv

Program
,13 c, \MDA\I{i np i c2\examp I e\c\UART- C
#include (iot6teZz. fr)
unsigned char data, state, on_buf, sec;

//

lnterrupt vector
#pragma vector = 0x04
/ / lnlerrupl serv i ce rout i ne

_interrupt void

0N_0FF(void)

//

sec

if(sec == 0){
sec = 42;

if

(state == 0){

= (on_buf ((= t) | OxOt;


(on_buf == 0xff) on_buf = 0xfe,

on_buf

if
)

else

if

on_buf

if

(state == l){

(on_buf

))=

I) | OxgO;

(on_buf == Oxff) on_buf = 0x7f;

else
PORTB

if

(state == 2) on_buf = on buf;

= on buf:

)
Tl,1R0 =

0;

T0lF

0;

MDA-WinI'IC-2 I\{ANUAL

-103

?nL

3. Experiment

//

Transmi

void

TXD(void)

whi te(!TRMI);

= data;

TXREG
)

//

Receive

void

RXD(void)

whi te(!RCtF);
i

//

(FERR) {

Framing error

= 0;
CREN = L
CREN

else if(oERR){
CREN

= 0;

CREN

= l;

/ )verrun error

i
data =

RCREG;

Vlain

void main(void)
{

= 0;
OPT|ON = 0x87;
TRISB

Il'4R0

l/
//

tnitial ize

P0RTB

by ctearing output

lnlernal clock, Prescate I :

256

= 0x00i

SpBRG

TXSTA

= 0x24;

71

9600[bps] (t t. 0sgzri,)

= 0x90;
on buf = 0xfei
RCSTA

P0RTB

= on_buf,

sec =

42;

l/

256 x 256

x 42 x 0.36lusl =

sec.

state = 0;
T0lE = l;
GIE = li
do{

RXD0; I / Receive
TXD$ ;
// Transmi t
if (data -- 'L') state=O;
else it (data =='R') state = l,
-104 -

ryww,midaseng.com

3-6. USART Experiment

else if (data == 'S') state = 2;


)whi le(t) :

MDA-WinPIC-2 MANUAL

-105 -

3.

Experimenl

3-6-2. USRT lnterrupt

'

Circuit Diagram
LEUEL

u30

PICtGFSTx

^ r-r

22O

RRl1

RC6/CK
Rno
RC2

SERIN
SHFT.LD

RC0

A
B

RCI

rem
BC74T

oscl
OSCI

Frfin
Flow Chart

1;::;.:.= :

aTffii,;ttt,;)

--;l--

[Vl3ln::;:;]:;:aint{r:iYi!:

,_<-T:?

Set BAUD rate

lno _---*---_.-

Synchronous mode
Enable Serial port

-106

ves

t-Bqt*--t

www.midaseng.com

Trarsmit

I'
ti

ti
t:

3-6. USARI' Expcrinrcnt.

li
ll

How to

i:

connect .jumper

ir'
t;

i.

PIC Port
RAq

WinPIC-2 Kit

RCO

RC77DT

UDL
UDE
UDI]
UCK
UDT

OSC1,2

4WIz

l
It
i
i

x4

RC1
ITC2

Il.c_6/cK

D*

Program

{&,ssP

'5

c, \HDA\U i np i c2\examp t e\c\USRT_MS.

*include (iol6fB77. h)

//

Transmit routine

void TXD(unsigned char data)


{

= l;

RC2

TXREG

TXEN

data;

//

Transmit

= li

whi te(!TRMT);
TXEN

RC2

= 0,

= 0,

//

Receive routine

unsigned char RXD(void)


{

unsigned char data;

RCO=l
RCO

= 0;

RCO

RCI

= 0;

RCIF

li

= 0,

=
TXEN =
SREN

l;
1,

//
//

Single Receive Enabled

//

Disable Transmit

bit

Enable Transmit

whi te(!RctF);

data =
RCI

RCREG;

1,

= 0;
return(data);

TXEN

MDA-WInPIC-2 MANUAL

-107

3.

Experiment

//

M,ain

void main(void)
{

unsigned char data;

= 103;
TXSTA = 0x90;
TRISC = Oxf8;
TRISA = Oxff;
SPBRG

ADC0NI

// e6o0[bps] (4tl*ll)
// Synchronous rnode

= 0x06;

= Oxfa;
RCSTA = 0x80,
PORTC

ll

Enable

ll

Bounce/Chattering

serial port

do{

wnile(M0);
data =

RXDO;

TXD(data);

wnite(!nRo);

)while(t);
)

-108 -

www.mid;seng.com

3-7. MI\{SP Expcrimenl

3-7. MSSP Experiment.


3-7-1. SPI mode
Circuit Diagram
KEY IlRTRIX

BEO

EI

E2
807

m6
D5
BO,
BD3

D2
R0t
RDO

XIfl-

t[

:fi, I+osct
i,,,1 g-.ilr.-"1_

R83
RC5/S00

t'H

^{ll.-6t2.^

,;'il_,sio;J
2t,,'nrw
tf,.,.,,,.,.,

MDA-WinPIC-2 MANUAL

-109

3. Experiment

Flow

Chart

[llqqlic l_-rgBr--l
I
I

Oisptay rnessagc on LCD.

L,itlalize SPI mode

Scan Key

buffer.

Set Data
Setup cumor on "Address".

.J

t-!q!qiqqr4:-l
__t_
I s.trp SSPCON ]

t!rytt-*,* r[-ITTT[ * *" I


[

't*ryqlryt*'_

I cq:\
(

-ilO

Return

wwrv,midaseng.com

)
),

3-7. I\'IMSI) Expcrirncn'r

cs_:_!

-. __._ l_ ,_
LTryryL_o,o orn. ]
L

r-r=q+tqr-l

I cs-r-_

3;;.*;;1
l"i, -]
f[Erq:]Ylrs qellqj
t_ (5[ms])
i1@-t-,,-*
___L_

I cs-s

i--

!-,

[ --qL-i
_l

__

Enable Start

liilhtp
.wjite
lErase
f

Trarsmit OP code

_]

bit

."r.?
Enablel

_J

r-,.*trryfryf

_t

| 9!_-* r-_

----J--'---- no
a--_ Veriiy
Y
--_xzl
->t- Ern.n

MDA-WinPIC-2 MANIIAL

-111

3.

Experiment

,,,,

How to connect

.iuniper

PIC Porl

WinPIC-2 Kil

REO

RS

RE1

RW_

RE2

EE

RDO

DO

RD1
RD2

D,2

RD3

Di

RD4

D4

RD5

D5

RD6

D6

RD7

D7

RBO

CO

RIJl

C1

RB?

C2

RU3

C3

RI]4

LJI

RB:5

L1

RB6
RB7

L3

RAO

-112

D1

L2

x4
x5

RA1
RA2
RA?
RC2
RC3-/sc5
RC4/SDI
RCI/SPC)

SDO

OSC1,2

4tfrb

xF-

X7
SCS

SCK
S-DI

www.midaseng.com

3-7. N{[.ISP Expedrrreut.


DJ}

Prograrn

ire#

...J

c : \trtDAUyinp ic2\exanp

le\c\spt. c

#inctude (iotOtgzz. n)
unsigned int ADDR:
unsigned char
uns

EEDT:

i gned char KEy, KEy2;

unsigned char
uns i gned cha

FLAG,

unsigned char

FUlrlCT ,

STATE;

const unsigned char msgl[]=" Microwire ,,,


const unsigned char msg2[]=" Spt rpde(93C66)";
const unsigned char msg3[]=" Address
Data ,,:
const unsigned char msg4[]=" 0000
00 ,,:
const uns i gned char ASCTBLII="6123456789A8CDEF"
#include
f i nc I ude

/"',

//

h"
"KSCANI.
h"
"LCD8.

/l
/I

tnitiat ized

LCD Modute

Scan key matr

ix

function x/
lnitial ize Spt
SPI

void S_tNtT(void)
{
RC2 =0:
SSPSTAT
SSPCON

0xC0;

0x20i

/
//
/

S,rP=|,

CKE=I

SSPEN=1, CKp=0. CL0CK=Fosc/4

//

Standby

unsigned char WAITBF(unsigned char send)


{

doi

= send;
)while(!er);
return (SSRnUr.) ;
SSPBUF

//

Transmi t

//

Read byte

void

EEREAD(void)

'

unsigned char tenpl, terrp2;

=l;
tenpl = ((noon ))a) a 0x0001)
terp2 = WAtTBf (tenpt);
RC2

tenp2 =

oxoooc;

//

SSPBUF

READ

ADDRH

IVATTBF(ADDR);

MDA-14/inPIC-2 MAI-{UAL

- 113

ts

3. Expriment

temp2=0;

= \{AITBF(tenp2);

EEDT

RC2 =0;

//

Write byte
void EEWRITE(void)
{

uns igned

char tarpl, tenp2;

=l;

RC2

temp2 = WAITBF(0x26):
temp2 =

/l

Enabte erase anrl write

l#ATTBF(0x00);

RC2 =0;

//

Transmit address

RC2 =1;

tenpl = ((ADDR))B) &0xoo07)

0x0a;

//
//

tenp2 = \{AITBF(tenpt);
tenp2 =

l{ATTBF(ADDR);

tarp2 = I,vAtTBF(EEDT)

SSPBUF

Transnit

//Trarrsnit

ADDRH

ADDRL

Dala

RC2 =0;

/i

DELAY(s000);

De

lay 5 [nisl

=l;
tenpl = lflAlTBF(0x20):

RC2

RC2 =0,
/

Verify

RC2 =1,

tenpr

((ADDR))B) & oxooot)

0x0c;

// SSPBUF = ADDRII
// Transmi t ADDRL

terp2 = WAITBF(tempt);
temp2 = I{ATTBF(ADDR);

templ = I{AITBF(0x00);
RC2 =0,

if

(tenpz !=

EEDT) S_tNlT0

//

Main

void main(void)
{

= 0xd0;
TRISA = 0xff;
TRISC

ADCONI

= 0x06;

//
//

tnitia|ize Port
Configure

all

A try

setting input

pins as digitat inputs

TRISB = 0xf0;
P0RTB
P0RTA

-111

= 0xff;
= 0xff:

tl'lvw,rnirkrseng.com

til
3-7. MMSP Experinrent

Iil

Ii

L_tNtT0;
DTSPLAY0;

//
lii

tnitialize

SPI node

S_tNtT0;
ADDR=EEDT=STATE=0i
do{

i'I

EEREAD0;

loop:;
CSa'UNP16*Or,

)) 12) & 0x000f]);

CHAR_0(ASCTBLI(ADDR

CHAR_0(ASCTBLI(ADDR

))
))

CHAR_0(ASCTBLI ADDR

& 0x000f]);

0HAR_0(ASCTBLI(ADDR

A) a 0x000f]);

4) & 0x000f]);

cointAND(0xdb);

))

+) a 0x0f]);
cHAR_o(ASCTBLI EEDT & oxof]);
if (STATE == 0) C0[tlANo(oxU) , ll Cursor on Address?
else C0kI"1ANO(OxOO) ;
l/ Cursor on Data?

CHAR_0(ASCTBLI(EEDT

scAN0;

if

(FUNCT

else

if

== Oxfe) STATE =

(FUMT == 0xfd)

if(STATE ==

else

g)

0;

5141P

// [|(AD)="L"?
// X5(DA)="1"?

1;

EEWRITE0;

l // else if
else if (FUNCT == 0xfb){
ADDR+r; STATE

xa(+)="1"t

//

xt(-)="1"t

= l;

else

if

(FUNCT

== 0xf7){

ADDR--, STATE

= l;

i
else{

if(

=- o)

STATE

else

ADDR

(ADDR

(( 4) I KEYz;

EEDT

(EEDT

(( 4) | KEYZ;

goto loop;
)
)

)while(l);

MDA-WInPIC-2 MANUAL

-115

3.

Experiment

3-7-2. I2C mode


Circuit Diagram
X{

KEY I1RTB

-_J_

_r-

r.Do

r[
uss

R87

R80
R8t
8R2

ltt3
8t3/SCL

:cl
l2b

cr

tt

8C{,/SD8

oscr 'fl
l_l
xl
^ ll,692,^
4nLJ_

2liltz

,F'

-l16

www"rnidaseng.com

;llfl

osco

x-L

';

3-7. MMSP Expa

Flow

Chart

-_--:

Initialize pORT
:

f-G;**,"",,..r1
r!I.. )

(___m,r,*

::
:1

t,

Display Address and Data

on LCD.

--\

Cusor "Data ?

rt

nO

))>-)

addre^rs

buffer

Setup "Data"

tr
' ---- rl
I

ri
I

address buffer -

Setuo "Dara"

Set Address buffer.


Setup cursor on "Address,,

Set Data buffer.


Setup cursor on "Address,,.

MDA-WinPIC-2 MANUAL

-Lt1

3.

Experiment

-,ll:ll :-=, '' .. ACK? --->I Enable Srln , i| ..]L_

q w.it.avrr, ) I
I Condition ,

r
'r*nsmit

l:r'rror

wrire
[I t:olnrirantl
II I
I

|
I
\[Error--.] __I
| Tran'mit ,pr*i I I
I atHress bYe l I
ACK? - I
ryL- --'l-----=
Pf*""'I

ACK?
Ye.s

I
lJes --]
t [rrhl; Sro;
I c;,"d,,,,;-

..r

-.l

t-D.rry-[ .s(rru)

-l
I Erurnlc

t stan CorrditionJ
t r*o.riiL w.i[-)
t.o,r*ond )

fn.;l . Ir---i"'-.
l, V .
lowerl

-ot*t_--l-t'

l[Enrrr)
, yes
. |
| rr.ilr\mtr upper
|
I a,l.lr.:.s lxne
-)
no
'; '1
A('K?
i yes | ,
[r:..n'.]
Transmir
Dara
I
r ys .
I
I l [n.r-,,.
r:i,.*,,,i -r.*"r]
lTrarsrnit

i.*,

I sr..

) I

li

l-

[,{{n^*s

l'Yq )

@Ei
I Enable Start I
I Condirion )
__]-_ _.__ __
I Transmit Write
l. co**rrd
)

_!..

l- Yes
l
I- address brtr'. 'll
l'

Transmit upper

118

www.rnidaseng.com

3-7. MMSP Experirncnt.

How to connect

.jumper

rya_Iq(

WinPIC-2 Kit

REO.

RS

RE1

RW

RE2

EE

RDO

DO

RD1

D1

RD2

D2

RD3

D3

RD4

D4

RD5

D5

RD6
RD7

D6

RBO

CO

RB1

C1

RI]2

CZ

RB3

c_3

RI]4
RI]5
RI]6
RB7

LO

\+9

x4

RA1

X5
x6-

84?

D,l

LI
L2
L3_

RC3/S.CL,

K7
SCL

RC4ISDA

S.DA,

OSC1,2

4\ilh.

RA3

I\{DA-WinPIC-2 MANIIAL

119

3. Experiment

Program

'.J

c \MDA\II inp ic2\examp


'

le\c\

2c. c

finclude (iotGtalz. n)

int

unsigned

ADDR;

unsigned char

EEDT;

unsigned char

KEY, KEY2,

unsigned char

FLAG;

unsigned char FU|IT;


unsigned char

STATE;

const unsigned char msglU=" SSP l2C(241C32)";


const unsigned char msg2i]=" Master nnde

!!

";

const unsigned char msg3[]=" Address Data ":


const unsignerl char msg4[]="
const unsi gned char

h"
"KSCANI. h"

#include

/*

SPI Functions

"

'

ASCTBL[]="6123456789A8CDEF"

/l lnilial ized LCD tiicdule


// Scan Key matrix

"LCDB.

f include

0000 00

*/

void S_lNlT(void)
{
SSPC0N

SSPSTAT
SSpADD

0x28; //

lZC Master nnde

= 0;

2;

//

ZZZlkHzl = 4[pg2]/(4.(2+t))

//

RepeateO

void

Start condition

R_ST*C0N(void)

{
RSEN

= l,

whi le(RSEN):

//

Start Condition
void SC0N(void)
{
SEN

= l;

wni le(Sru);
)

//

Stop Condition

void ST0P-C0N(void)
{
PEN

= l;

whi le(Prru);

-120

www.nddaseng.com

3-7. I\'IltSP Iixpefi nicnl

Transmi t

void TX_BYTE(unsigned char

send)

{
SSPBUF

= send;

whi te(R);

if (ACKSTAT == t) s_rrurr(),
)

//

Receive

unsigned char RX_ByTE0


{
RCEN

= l,

whi te(RCEN);

= l;
ACKEN = l;
ACKDT

whi te(ACKEN);

return (ssnaur)

//

Read Btye

void

EEREAD(void)

scoN0;
TX_BYTE(0xa0);
TX_BYTE(ADDR

))S):

TX_BYTE(ADDR);

R_sr_coN

TX*BYTE(Oxat);
EEDT

RX_BYTE0;

sroP_coN0;
)

l/

Write Byte
void EEWRITE(void)
{

unsigned char tenpl;

scoN0;
TX_BYTE(0xa0);
. TX*BYTE (ADDR

))A)

TX_BriE(ADDR);
TX_BYTE(EEDT);

sroP_coN0;
DELAY(5000);

MDA-WinPIC-2 MANUAL

-lzt

3. Experiment

scoN0;
TX_BYTE(0xa0);

))8);

TX-BYTE(ADDR

TX_BYTE(ADDR);

R_sT*coN0;

TX*BYTE(0xal);

templ = RX_BYTE0;

if

(te{rpl l=

EEDT) S_tNtT0,

sToP_coN0;
)

lfiain

void main(void)
{

0xff; l/
ADC0NI = 0x06; //
TRISA =

tnitial ize Port A by setting


Configure

all

pins as

input

digital

inputs

TRISB = 0xf0;
P0RTB

= 0xff;

PORTA

= Oxff;

L_tNtT0;
DTSPLAY0;

S INIT0;
ADDR=EEDT=STATE=0;
do{
EEREAD0;

loop:;
C${MAND(0xcl3);
CHAR*0(ASCTBLI(ADDR

))

CHAR_0(ASCTBL[(ADDR
CHAR_0(ASCTBLI(ADDR

)) S) a 0x000f]);
)) 4) & ox000fl);

CHAR_0(ASCTBLI ADDR

a 0x000fl);

rz) & 0x000f]);

c0tuua1616roo; '

))

+) a oxOfl):
CHAR_0(ASCTBLI EEDT & 0x0f]);
if (STATE == 6) 66p1441r10(oxot);
CHAR_0(ASCTBLI(EEDT

se

C0dr4AND

(0xdd)

scAN0;

if
eI

(FUNCT

se

== oxfe) STATE =

(FUNCT

==

|f(STATE ==

-122

0x f

6)

d)

0;

51tr16

ll

X4(AD)xey=";"'t

// X5 (DA) key=" L" r


=

1;

www.midaseng.com

3-7. l\{MSP F)xgrcrirncnl


else

EEWRtTE0;

) // else if
else if (FUNCT == Oxfb){
ADDR++; STATE

\6(+)xey="1"t

//

x7(-)key="L"?

= I;

else

if

(FUIICT

== 0xf7){

ADDR--; STATE

= t;

else{

if(

STATE

etse

==

g) 4ppp =

(ADDR

(( 4) |

KEY2;

EEDT

(EEDT

(( 4)

KEY2;

goto loop,
)

Iwhile(l);

MDA-WinPIC-2 MANUAL

-t23

3.

Experirnent

3-8. Serial Communication Experiment.


3-B-1. DS1302 (Digital Clock)
Circuit Diagram

PICl6FB7x
REO

REI
RE2

R
UDD

RD7
RD6

FD5
RD{

UO

RD3
RD2

uss

RDI

ROO

xI{
l,/o

GSCI

ucc
ucc

Gls

I 4 .l'

.!-

CS:

,r,
xl

osca 1lX'
,), x--L
2i 2Amtr

fi:

ff-r-n

;ffi

osc

^.1r.692
lllz

osc2

SCLK

RSI

xJ_

t*lz

Flow Chart

@D

',,',-. -

- \
fr ryrEftlllgJ

Gnqi:qlrqi
____I___-__

ni'ptuy m9!yg. J

l
trl'#
s"adrrcr,"tl
I

L l$:L
i___

c"*

,i

Ylt:

Dl,

I rryr -lDSI]9LJ
_\
I

r;"r6ffiftt.i

rvnre Cornrnana

Rcturn

RST

1.

wlE rery*q

1a-,
input

[clearing

f-O=gg',

I Reset DSt_.302 J
a\
Setup RCo uy
I

l.settrng

output

-124

__l

wwn'.midaseng.com

Return

3-8. Serial C-ommunication Ex

How to connect

umper

MDA-WinPIC-2 MANUAL

-125

prirncnt

3. Experiment

Program

^$
.J

c'

lude ( iol6rAf z. fr)

nc

#def

le\c\DSl 302. c

\MDA\Wi np i c2\exanp

ne l_0

RCO

*define SCLK
{define RST
uns igned

char

RC1

RC2

YEAR, I'/ONTH, DATE, DAY, HR, MlN, SEC;

";
const unsigned char msgl[]=" Calendar/Clock
";
const unsigned char msg3ll=" 2000,00,00,SUN
* i nc I ude " LCD8. h"

unsignecl char READ(unsigned char address )


{

unsigned char
RST

buffl,

'

1;

for( i =0; i (a; i++)1


SCLK

= 0,

if(address & 0x01) t-0 = l;

else l_0 =
SCLK = I'
address

0;

))= t;

TRISC

= 0x0l '

buffl = 0'

for(i=o; i(B;
SCLK

i++){

= 0;

buffl ))= I
if(l 0) buffl l= g16s'
else buffl &= 0x7F'
SCLK = L
;

)
SCLK

= 0;

= 0;
TRISC = 0x00'
RST

return ( outtl );
)

void t{RITE(unsigned char address, unsignei char data)


{

-126

www.midaseng.com

3-8. Serial (lorrnrurnication llx1rcrirncnl.

unsigned char L
RST

= l;

for( i =0, ( B; i
i

++

){

=
if(address & 0x0l) I 0 = t;
else l_0 = 0;
SCLK

0;

SCLK

= I;

arjdress

))=

for(i=0;i(e;i++){
SCLK

= 0;

if(data & oxol) t_o = l,


else l_0 = 0;
SCLK = l;
data

))=

1'

SCLK
RST

= 0,

= 0;

void

READ_CAL(void)

DATE =
DATE

READ(OXB7)

&= 0x3f,

lr40NTH

lvl0NTH

&=

READ(0X89)
0x

DAY = READ(OXBb)
DAY &= 0x07,

YEAR =

READ(OX8d)

void

READ_CLOCK(void)

SEC = READ(OXBI)
SEC

&= 0x7f;

MIN = READ(0X83);
MIN &= 0x7fi

HR

= nrRo(ox85):

HR &= 0x3f,

I
voi

Wt ITE_CL0CK(vo

d)

{
lryRtTE(0x80, sEC);

MDA-!VinPIC-2 MANUAL

-127

3. Experiment

lvRtTE(0x82, MtN)
t{R tTE (0x84, HR)

tilR tTE (0xs6, DATE) ;


wR I TE

(0x88, MoNTH)

l{RtTE(0x8a, DAY);

[RtTE(0x8c, YEAR);
)

void DISP_CAL(void)
{
COf'tvtAND

(0x93)

))

+) & 0x0f) + 0x30)


CHAR*0((YEAR & 0x0f) + 0x30);
cHAR__0(((yEAn

C0Mv|AND(0x96)

))

+) a oxor) + 0x30)
& 0x0f) + 0x30);

CHAR_0(((M0NIH
CHAR_0((M0NTH

(0x99)

CC[,14AND

)) 4) & 0x0f) + 0x30);

CHAR_0(((DATE

& oxof) + 0x30);

CHAR_0((DATE
COI'f4AND (OXgC)

//

"sut't"

if

(DAY

==

t){

CHAR_0(',S',)

CHAR_0('U',)

CHAR_0(',N',)

//

"wN"

else

if

(DAY ==

CHAR_0('M',

Z)l

CHAR_0(',o',);
CHAR*0(',N',)

II

//

"TUE"

if

else

(DAY ==

CHAR_0(',T',)

CHAR_0(',u',)

CHAR_0('E',)

3){

/l

"wED"

else

if

(DAY ==

4){

cHAn_o(',w');
CHAR_0(',E',)

-128 -

rywu,,.nritlaseng. com

3-8. Serial Cbrnmunication Experinrenl


CHAR_0(',D',)

"THU"

else

if

5){

(DAY ==

CHAR_0(',T',)

CHAR_0(',H',)

cHAR_o(',U',)

l/

"FRt"

else

if

(DAY ==

CHAR_0(',F',)

cHAR_o(',R',)

6){

t',);

cHAR_o(',

//

"sAT"

else

if

(DAY ==

CHAR_0(',S',)

CHAR_0(',A',)

CHAR_0(',T',)

7){

)
C0!I1AND

(0x60)

void

DISP_CL0CK(void)

{
Cot'{\4AND

(0xd2)

)) a) a oxOf) + 0x30);

CHAR_0(((HR

CHAR_0((HR &

0x0f) + 0x30);

C0l't'mXP16rOr,

'

CHAR_o((MIN

))

+) a oxof) + ox3o);
& 0x0f) + 0x30) ;

CHAR_0(((M|N

CO'/MAND(OXdC).

CHAR_o(((SEC

)) 4) & oxof) + ox3o);

& 0x0f) + 0x30)


coiouNpi6*uor '
CHAR_O((SEC

//

Main

void main(void)

{'
TRISC

= 0x00;

= 0;
SCLK = 0;
RST

//

Reset DSl302

MDA-WinPIC-2 MANtl,AL

-129

3. Experiment

l_0=L
L_tNtT0;
DTSPLAY0;

ivRrTE(0x8E,0);
lYRtTE(0x8o,
YEAR

o);

= 0x02,

ICINTH

0x0B,

= 0x05;
DATE = 0x08;

DAY

= 0x06;

HR

MIN

= 0x30,

SEC= 0x00;

[RrTE CL0CK0;
do{
READ_CLCTK

READ*CAL0;

DrsP*cLocK0;
DrsP_cAL0;
)whi

-rJo

le(l);

wwlv.midaseng.com

3-8. Serial (irrntnunication lixprfirnent.

3-8-2. DS16Z0 (Digital Thermometer)


A,:

s$

Circuit Diagram

PIC16FB7x

DQ
CLK
RST

uss

lDO

I (HI
T
T

803

RO2

RDI

(LO)

BDO

(cfri,
BCS

Rtr

BC2

0SCt

osc2

??p

BESET
I

'

Flow Chart

Crqqrea=)
v

tr"gi":,.rys{r,;l]
I__
'l
it
eositive.
I 2's comnlement
[
.J

t-q*-&*",a

/-\

r=-'r r

l.

/
(

traflsnilt

,hrr.

)
-

L_ __
RetuI _.
-)

____-

t1-rsr\rq;l
'

Retum

MDA-W|nPIC-2 MAN[IAL

-I3l

I
3.

Experimenl

How to conncct

iumper

PIC Port

WinPIC-2 Kit

RE0

RS

REl

RW

RE2

EE

RD0

DO

RDl

D1

RD2

D2

RD3

D3

ItD4

D4

RD5

D5

RD6

D(r

RD7

D'7

RCli

DT1

RC1

CK1

RC2

THR

OSC1,2

41,frh

Program

.3
#

c : \MDA\lti np i c2\exanp te\c\Dst620. c

inc lude ( iotGraZZ. fr)

fdef

ne l_0

RCO

#define CLK
fdefine RST

RCl
RC2

const unsrgned char

msgl[]=" Digital

const unsigned char msg2[]=" Thernrcnpter


const unsigned char msg3[]=" PtC
const unsigned char msg4[]="
cons

uns

finclude

void

gned char degree []

(-)

Tenp.

"',

!!

";

DSl620 ";
"

{0x02, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}

"LCD8. h"

SEND(unsigned char data)

unsigned char

i;

for(i = 0; i(A;

i++){

= 0,
l_0 = data & 0x01;

CLK

CLK

= l;

data

);=

1'

-132

wwvy.mirltseng.com

: II

'

r.ll

Ii

tl

.:ll

ri

3-8. Serial f,-onrnrunication Expedlnenl


)

unsigned char RECETVE(void)


{
uns i gned

TRISC

char

data, data I ;

i,

= 0x0t;

data = 0;
datal = I;

for(i=0; i(8; i++){


= 0;

CLK

if(l_0

==

= I;
datal ((=

I ) data f= datat;

CLK

)
TRISC

= 0x00;
return data,

)
voi

DISP_LCD(uns i gned char

t0,

uns

gned char t)

i
unsigned char

t3 =

il,

t2, t3;

& 0x0l;

t ))= t;

if(

t0 == 0x0t ){
C0i,n4AND

cilAR_o(

(0xd7)

'

',

):

t = -t;

l,

+=

c0tvMAND(0xd8);
,1

il
lt

t!

Ii
tl

BCD Convers ion

tZ = il100;
if( tz != 0x00 ){
t2 += 0x30,
cHAR_o(t2)

il$

t2 =
tt =

Dt

iI

tl

tT"l00,

t2lfi:

+= 0x30;

else{
'iI

il

t2 = t%100i
tl = tZ/trA:

illl

if( tl

i,]

it
tt
ti

== 0x00

) il

rt

II

li
li
ti

MDA-WinPIC-2 MANUAL

-133

3. Experiment

else

tl

+= 0x30,

CHAR_0(

tl
tl

il

);

t2%10;

+= 0x30;

cHAR_o(

il

);

cHAR_o('.');

if(
e

t3 & oxor

se

CHAR_0

cHnn_o('o');

(' 5' )

CHAR_0(oxoo);

CHAR_0('C');
CHAR_0(ox2o);

(0xe0)

Co"{\4AND

//

ttain

void main(void)
{

uns

gned char data, datal

= 0x00;

TRISC
RST

= 0;

CLK

= 0,

l_0 = l,
L_tNtT0,
DtSPLAY0;

for

(data=0, data(B; data++){

CCInvqPl6uru
CHAR_0

oxao);

(degree [oa ta] )

whi

le(l)

RST

= 0,

RST

= l;

SEND(0xac)

data = RECEIVE0;
RST

= 0,

if((data & oxo3 ) != oxffi ){


RST=L
SEND(0x0c)

SEND(0x03);
RST

= 0,

RST

-134

= l,
www.rnidaseng.com

3-8. Serial tlonrnrunication flxpxrinrenL


SEND(0x22);
RST

= 0:

RST

= l;

SEND(Oxee);
RST

= 0;

do{
RST

= l;

SEND(0xac);

data =

RECE|VE0;

= 0,
)whi te((oata & 0xB0) != 0x80);
RST

RST

= l;

SEND(0xaa);

data =

RECEtVE0;

datal = RECEtVE();
RST = 0;
Dl SP_LCD

(daral, data)

MDA-WInPIC-2 MANUAL

-135 -

3. Expcriment

3-8-3. MCP3202 (Serial A/D converter)


Circuit Diagram

PICl6FB7x
RAO/RNO

RRI/Sil
RR2/S|2
RAVRll3
RRS/S|{

D?
D6
D5

RD7
RD6

BD5
RD{

D1

RD3
RD2

D3
D2

RDI

D1

FDO

XTAL

|'l!t

osc

x_Lrr.0592l

lffitr
;:.:

:CI

S
^

{./sD

CO:

zzoI

osct

i.,sc*

R2

CLOCK

2tHz3

0sc2

HUNIDITY toox

l ll -i'

l.ttt
osCa .tr

cl5

RESET
I

,ll
"-l2,?3filtr

,f ''

frCtE

rh cs 22p

LO

''

R,/D

iil

CONUERTER

.rj
:il

ct7

838

.j

R3{

828

5lk

Ln358H
a

R29

Sperconduct

5lk

-136

rvww.ntidtrsertg.com

ivity

3-8. Serial Conrmunication llxpcrirnent.

Flow Chart

fi-*ffi---t)
__=r__

LUq{ge eonrc

LCD Di

[rl4g* r.ry*.

,-- ------)lLrI r:

Il\-*_ I
I

-lransmrt-----r., I

Irl I
a3

I To*,rit
]

Rcturn )

1311_outu

Chonn"l)

ro*rt

t-c.t;r*. AD-aqlt

r_=-__L_.\

oisplay AD vatue
| | onLCD
| [\_.-:l
i
I r_,_r-\
Delav

\,, ..\3
.'n6W

Lpp[rg-l-

How to connect

I
I

iumper

,i

fi

il
fi
ti
fi

il
H

fl
1l
1:

it
E}

it
fl

lj
I

il

MDA-WiIrPIC-2 MANIIAL

-137

3.

Experinrent

Prograrn

'.J

c, \MDA\tl inp ic2\examp le\c\t{CP3202*include (iol6fB77. h)


unsigned char

AD-H, AD-L;

uns igned

const

char

msgl

[]="

l'1CP3202

const unsigned char msg2[]=" Serial


const unsigned char

msg3[]="

SPI

unsigned char msg4[l=" CHO :

const

ADC

!!

"

rnode

0.000 [V]"

"LCD8. h"

fincIude
void S-lNlT(void)
{

RC2

= l;

SSPSTAT

//
//

0xC0;

= 0x20;

SSPC0N

SMP

=1,

CKE=I

SSPEN=1, CKP=O, CL0CK=Fosc/4

unsi gned char WAITBF(unsigned char send)


{

rio {
SSPBI.JF

)whi

= send;

te(!sr);

return(SSPBur);

i
void

CONVERT(unsigned

char form)

RC2 =0;

AD-H = WAITBF(OXOI);
AD-H = WAITBF(form);
AD_L
RC2

'ilAITBF(OXOO);

=l,

void V0LT(void)
{

unsigned
uns

int

tenp;

gned char bcdh, bcd I ;

tenp

(AD_H

(( a) I nn-l;

tenp &= Ox0fff;


tenP *= 5;

= tenp
bcdh ((= 4;

bcdh

))

12;

tenp &= Ox0fff;

-138

www.mi<lirseng.com

3-8. Srrilrl (-irlnltnrnictliorr I,)x;x'rinlrnl.


temP o= 16'

bcdh

l=

))

tenp

tz;

tenp &= OxOfff;

*= l0'
bcdt = renp ))
bcdl ((= 4'
teinp

tZ:

temp 6= Ox0fff;

*= l0;

tenP

bcdt l= tenp

))

colilvlAND (0Xd7)

CHAR_o((bcdn
CHAR_O('.

))

tZ;

q)+ox:o)

',);

CHAR_o((bcdh & oxof)+sx39)


CHAR_o((bcdr

))

+)+ox:o)

CHAR_o((bcdt & 0x0r)+ox:O)


C0lt[UnXp

19r.O;

//

MAIN

void main(void)
{

= 0xd0,
L_tNtT0;
TRISC

Dt SPLAY0

s_tNtT0;
AD_H=AD_L=0,
do{
C0NVERT(0xa0),

voLT0;
DELAY(3oo0o);

)whi

le(t);

il
!t
ft

Ii
il

tl

ii
il
ji
it

ii
E
ri

it

ii
li
['
ti
t1

MDA-WiIrPIC-2 MANUAL

-139

3.

Experiment

3-B-4. AI]rrcAz (D/A converter)


Circuit Diagram

PIC16F87x
Rm./Bi'B ^^^

BFiznNr X:Y

ffiiffi3 ;Ei

1.7
R25

RAs/8N{

B0l8N5

rsu

U2O

ucc
cl{t

cs,/sl{DN
DtH

BC2

RD7
BD6
RD5
RD.t
RD3
RD2

RC3/SCK BDI
RDO

CHI

DOI,IT

RC{/SDI

CLK

RCS/sDO

GI.D

.t'
osc r
x_r!t.692 .!

RR{

0sc2
RC0

tcr co:

RCI

zzr,$

^
rh-L
x-l
2

il;'
u11

osca

7{LS

D./A

6{

CONUERTEB

rfi

Cg 2?o

CLOCK

BESET
I

lJ

' a6igz j

..:

..i

u19
RHI

rruTR

ti Hi;
Dl

F{}

.X'

u18
D7 UDD

P9

a2

^
fHr -r--

LEDIS
LEDS

RROJ

LEDT
LED6

IIODE

LEDS

SIN
..
x]
-

D0 ;i
PD

D6HD'363
CLR

LEDg

ROUT

BLO

.c

LEUEL *sU

LED{
LED3
LED2
LEDI

Ln3915N

DC NOTOB
R53

l5
Br0
2SCr8r
TPt?

ti

11

r(1TOR

88

140

rvwrv.rnidluseng.com

3-8. Serial lbnrnlrnicalion lixgrcrintenL

,Bs
{*iw

Flow Chart

f---:qsrl-l
I

[- Trursnrit .9art bit. ]

fu;;'*;a
fonrat
\I

Transmit

and Data

Return

Lursseaar-y;lyt

( lcn Disptav )
_]--

I Tr*.urit ]
I\1)durnnrv clara

BCD Conversi,,n

l_l

Dirylysl4q:l
(

Retum

[g-a-"]ryd4iir,ri

(* isrqry )

ti

fl!1

{iI
ll
ili
H

MDA-W!nPIC-2 MAtitlAL

-t4t

3.

Experiment

-s

How to connecf

.jumper

PIC Porl
RBO

RB1

RB2

RD!
RD1

RD2
RD3
RD4
RD5
RD6
RD7

849/ANo
RA1/AN

RAz/AN2
RA3/AN3
IIA5/AN4
REO/AN5
RC2

RC3/SCK
RC4/Sr)l
RC5/SDO

RA4
RC('
RC1

RC6
RC7

osc1,2

,D&
.w'

,3

Program

c \MDA\II inp ic2\exanp te\c\AD7302. c


'

*include (iot0ta;2. n)

#define DCP RCO


#define DAB RCI

ine

DtrYR

RC6

#define

DM

RC7

fdefine ADS

RC2

iidef

unsigned char

AD_H, AD_L;

const unsigned char msgl[]="

-t42

AD7302 DAC

!!

";

wryw.midaseng.com

3-8. SeriaI (-ilnrnnurication IIx;xrilnelrt.


const unsigned char msg2U="
cons

CHO

6"000 lV]";

uns i gned char- msg3 [] ="1y,6p3202-Sp

const unsigned char msg4[]="


#include "LCD8B. h"
void S_lNlT(void)

CHO

I node,

9.000 [Vl";

ADS

=l;

SSPSTAT
SSPC0N

0xC0;

= 0x20;

unsigned char WAITBF(unsigned char send)


{

do{

= send;
)whi te(!Br);
SSPBUF

return(sSneUn);
)

void

CONVERT(unsigned

char form)

ADS =0;
AD_H

IryATTBF(0x01);

AD_H

WATTBF(form);

AD_L

WATTBF(0x00);

ADS =1,
)

void VOLT(void)
{

unsigned

int

uns i gned

char

ternp

tenp;
bcdh, bcd I

= (AD_H (( S) |

AD*L;

tenp &= Ox0fffi


temP n= 5

= tenrp ))
bcdh ((= 4
bcdh

tZ;

ternp g= Ox0fff,

tenP x= l0;

bcdh != ternp )) tZ;


tenp &= OxOfff;
ternP

*=

0;

MDA-WinPIC-2 I{.ANUAL

- 1,13 -

3.

Experiment

))

bcdl = temp
bcdl ((= 4'
temp S=

t2;

Ox0fff;

terP 't= l0;


bcdl != tenp )) t2;
ccrM',laxg19y,r;
CHAR_0((bcdh

CHAR_0('.')

))

a)+oxso)

CHAR_0((bcdh & 0x0f)+0x30)


CHAR_0((bcdt

))

+)+oxao)

CHAR_o((bcdt & 0x0f)+ox3o)

'

CSrIrlaXp1g*.0;
)

void DA-0UT(unsigned char data)


{

unsigned
uns

int

temp;

gned char bcdh, bcd I , i ,

ternp-data"5;
DAA

0;

//

for (i=o; i ( 8;
it((data & 0x80)
else
DCP

DAB

Channel

i++)1
== 0x80) DAB =

l,

= 0;

= l;

= 0;
data ((=
DCP

1'

)
DWR

Oi

= l:
bcdh = (turp
bcdh ((= 4'
DWR

)) g) a oxooou;

tenp &= 0x00ff;

terP *= l0;
bcdh l= tenp ))

A;

tenp &= 0x00ff;

terP *= l0;

bcdl = tetrp
bcdl ((= 4'

-114

))

g;

tid

www.midaseng.com

J-8. Serial Cirnrluunication lixpe rinrent.


temp 6= 0x00ff;
temP

*=

1g'

l=

ternp

bcd

))
'

COlvtvl,tXP1O*.r,

CHAR_o((bcdh
cHAR_o(',. ',)

S;

))

q)*ox:o)

CHAR_0((bcdh & 0x0f)+ox:o)


CHAR_0((bcdr

))

+)+oxso)

CHAR_0((bcdt & 0x0f)+[x]Q)


C0i,IvlAND

(0xe0)

//

tlain
void main(void)
{

unsigned char daci


TRISC = 0xl0;

DCP=DAB=DM=0;
DWR

= l,

L_tNtT0,
DtSPLAY0;

s_tNtr()

AD_H=AD_L=0;
dac = 0;
do{
DA_0UT(dac);
C0NVERT(0xa0)

voLT0;
DELAY(20000);
dac++;

)while(t);

MDA-WinPIC-2 MANUAL

-145

3. Experiment

3-9. Motor Experiment.


3-9-1. Phase step motor
Circuit Diagram

PICl6F87x
RC{

BEO

REI
RE2

RD7

r6;
Bc3
BC?

RD3

B?

07

D6
DS

UDD

Dt

UO

D3
D?

USS

DI

RDO

XTfl.

osc

a .1'
:

x-l

lltz

m+

;cl c0;
tttI ?2ol
ttl

r 'll 'l'

t.0592:

tr{z i_3_

.l'
lJ

osco

x_!

z, m{{ri:

.rl-'
u23

''l.t-

'" 't""

Rffi 3:B

tffil

+l2U

ffi

lN/81

tNn2

RsR
*Bn

Bt-r E

i,r? ;

REFR
R'FB

HIE
UJIE
flJTE

BsB Im
GE

68

sLR702{il
HOTOB

l{t5 -

c20:

nwr

R5l
czt

.r7r(

=I nopr

rh rh

www.midaseng.com

STEP

RESET

_J_

3-9. N{okrr Er;rcfinrcnl

Flow Chart

Delay

I q"tl;;** -l
connect jumper
PIC Port
II.EO

RS

RE1

RW

RE2

EE

ITDO

D0

ItDl

D1

II.D2

D_2

RD3

D3

I1D4

D4

I{D5

D5

ItD6

D{

BD7

D7
''",,'

RCO

LO

RC1

,.',

i"

RC2
RC3-

L2
L3

RC4

C3

RI]4

PA

11IJ5

PB

I{I]6
IUlT

PIA
P/B

OSC1,2

4l\ilh

'.'

t{

it

rt

il
ii
tr

li
li

MDA-WinPIC-2 I\{ANUAL

-147

3. Experiment

Program

c. \lrlDA\tI

np i c2\exarp

e\c\STEPl.

f include (iot0rgzz. n)
const char msgl [] = " STEP Motor ! ! ";
const char msg2[] = " Phase Control ";
const char msg3[] = "Driver SLA7024M ";
const char msg4[] =

const char

" Now l-2 Phase !";

PHASED[8]

{0x10,0x30,0x20, 0x60, 0x40,0xc0,0x80, 0x90}

*include "LCD8. h"


/l l{ain
void main(void)
{

unsigned char

i;

= 0x00;
L_tNtT0;

TRISB

//

-l

lnitial ize port

B by clearing output

DISPLAY0;

do{

for (i=0; i(B ;


PORTB

i++)1

PHASEDIi];

DELAY(6000);

I
lwhi

-r48

le(l);

wrvw"nridaseng.com

';t'r':

3-9. l\Iotor

Ex;rerinre nt

3-9-2. Step motor control

*#

PICl6F87x
BEO

BEI
8E2

RD7
RD6

nor

D5

D,

nor I

noa

R
IDD

nos I
noz I

D3
D?

UO

DI

SS

*l

XTfl.

ri

tf&:

l;;1
I znl
trt

*r,-osc'l,#
n,0592
ff

,!^

t*tz

ttl

u23
us8
us8

IN/Tll

lwqz
IN/31
lH/A2

o
o
o
o
o
o

OJIR

BSfI
RFR

RfFB

flJrF
&,IB
flJIE
T06

ES8

ID8

G8
G8

sLR782ail

110T0B

Circuit Diagram

msl

c2o; I czr
I I tzoor
mm

aTeoE

MDA-WinPIC-2 I,IANUAL

- 149

I
3. Experiment

1$

Flow Chart

'.

message

on LCD.

.: ""i,.

Rotate right 45 degree,

and Display

it on LCD

Rotate left 90 degree,


and Display it on LCD

How to connect

.jumper

PIC Port

WinPIC-2 Kit

REO

RS

RW
EE-

DO

D1
D'Z

D3
D-4

D5

D6
D7

t
L1

L2
L3
C3

PA
PB

Pl^
PIB
4\frh

-I50

':8.

www.midaseng.com

--

3. Experiment

F-low Chart

i.r
_--L...

"3"

k9v?

_l

no

"7" key?

ro I

'-.. -"-l
-

_--

Rotate right 45 degre.e,


it on LCD

and Display

Rotate left 90 degree,


and Display it on LCD
Rotate right 90 degree,

and Display

_l
C"+

it on LCt)

,o

How to connect jumper


PIC Port

WinPIC-2

RE1

,L.l

It.E2

IIDO
I

RDl
RD2
RD3

RD4
RD5

RD6
RD7
RCO
,t

RC1

RC2
I{C3
RC4

RB4

RI]5
RB6
RB7
OSC1,2,

-150 -

www.midaseilg.com

3-9. l\{otor llxlrcrilnenl

Program

C, \MDA\W i np i c2\examp I e\c\STEp2. C

#i nc I ude (totOtAzu. tr)

const char msglf] = " STEp Motor !l ";


const char msS2U = "Degree Control !";
const char msg3[] = "Driver SM7024M ";
const char msg4[] = " Press 3,7,8,F !";

const char L_45t'1ll = " Lef t 45 degree!",


const char R_45M[] = "Right 45 degree!,,;
const char L_90[,][] = " Left 90 degree!";
const char R_90M[] = "Right 90 degree!";
,,:
const char SPACE_D|I = "
const char

PHASED[B]

{0x10, 0x30, 0x20, 0x60, 0x40, 0xc0, 0x80, 0x90}

unsigned char key;

#include "LCDB. h"


void SCAN(void)
{
uns

char

gned

PORTC

= 0x0f;

for (i=0; i(a;

i++)1

do{

= PORTC;
)whi te((key & 0x0f) t= 0x0f);
keY

do{
keY =

PORTC'

iwhi le((key & 0x0f) == 0x0f);


PORTC

= Oxff;

void LEFT45(void)
{

unsigned char step, i,count2,


cOtfi4AND(0xd0);

for (i=0; i(16 , i++) CHAR_o(SpACE_Dtil);


CS,nflND(0xd0);

for (i=0; i(to ; i++) cHAR_o(L_45Mlil);


'count2 = 50,
steP = 7'
do{
P0RTB

= pHASED[step];

l\{DA-WinPIC-2 MANUAL

- 151

3. Ilxperiment
tep--

step &= 0x07,


DELAY(6000);

)whi le(count2--);
)

void LEFT9O(void)
{

unsigned char step, i,count2,


'

C0!la4PP16*oo;

for (i=0; i(r0 ;


coI,t'{AND

(0xd0)

i++)

CHAR_0(SpACE_DIi]);

for (i=0; i(16


count2 = 100i

i++) CHAR_o(L_90M[i]),

step = 7;
do{

= pHASED[step];
step--;

P0RTB

step &= 0x07;


DELAY(6000);

)whi le(count2--):
)

void RlGHT45(void)
{

uns igned

char i, step, count2;

C0uvlAND(oxdo);

for (i=0; i(16 ;

i++)

CHAR_o(SpACE_DIi]);

cOm,lANp16roo;'

for (i=0; i(to;

i++) CHAR_o(R_45M[i]);

count2 = 50i

step

=0;

do{
P0RTB
S

= pHASED[step];

l'l'j.{,..,

'i,i'

teP++;

t:f,

li**

step &= 0x07;


DELAY(6000);

)whi le(count2--):
)
vo

id

lGiT90 (vo id)

'']il;

$:

i!4

uns i gned char i, step, count2i

c0+,lAlo1gra,r

_l(,

'

www.midaseng.com

3-9. l\Iokrr Iixpcrirrxl

for (i=0; i(16

;++)

CHAR_o(spACE_DIi]):

C(M,IAND(0xd0);

for (i=0; i(16 ;


=

count2

;++) cunn_0(R_gotvlIi]);

100;

cton:O'
do{
PORTB
s

= pHASED[step];

teP++,

step &= 0x07,


DELAY(6000);

)whi le(count2--);
)

//

lt'ain

void main(void)
{

TRISB

= 0x00;

// lnitialize port B by

clearing output

= 0x0f;
L_tNtT0;
TRISC

DtSPLAY0;

do{
SCAN0;

if

(!(key & 0x0t)) LEFT450;


etse if (!(kell & 0xt]2)) RtGHT4s0;
etse if (! (key & 0x0a)) LEFTso0;
etse if (t(key & 0x08)) R|GHT900;
lwhi

le(t);

// "3" Rey?
// "7" key?
// "8" key?
// 'F" key?

td
at

li

ri

ii
llli
ti

It

il

MDA-WinFIC-2 MANUAL

- 153

3.

Experiment

3-9-3. RC motor

g$

circuit

Diagram

PIC16F87x

RD7
RD6
FD5

D7
D6

BD{

D{

RD3

D3

RD2

02
DI

D5

RDI
RDO

XTfl,

osc

I 1)ti'

x_Lu.a5s2
^
+ ilz -icoi
ifl
osco .fi'
ttlz

"

, "' ,.tr,
")

,f

$$

Flow

z,

la
rhc 1zo
R2

20il1, iS

'''"7

Chart

-:------;\
(L:--g4ir*:*r,,.
lt"tLL:,]
Lft'g,4
_ __-__J_,. . -

LP[&Gselr
- .->l <:

---

LCtr]

-*:*r"
..3"

kev,l

=-=-/

-y".

RC motor needle
i toN{nu.
center.
I

Mnn. RC motor needlc


,.*
- -- I
t,r -90 degree.
i

i
....-----__LnO
-.l..8..
n"" i Move RC lnotor needle
,.i
keur
;._;;."
1,,;.;fi
.- .'....--

..--.-=-.-==-----/"

- 154

wwrv.mitlinseng.com

RESET

-_l_-

3-9. fuIofurr [ixJ>-rlinrenl.

FIow to collnect

junrper

PIC

Port

Winl'}lC-2 Kir

REI)

RS

I{E]

RW

I{82
ItD0

EE
Dt)

RD1

DI

RD2

D2

RD3

D3

I{D4

D4

RD5

D5

RD6

D6

RD7

D7

RCO

LO

RCl

L1

RC-2

L2

I{C3

L3

RC4

C3

I].C7

ItCM

()sc1.2

4tilth

Program

c' \MDA\Hi np i c2\examp te\c\RCl. c


fiinctude (iotOtgzz. n)
*def ine RC_tr4 RC7

const char msgl[] =


const char msg2[] =

"

"

Rennte Rontrol!,,;

Servo Motor !!,.;


const char msg3l] = "Degree Control 1,,;
const char msg4f] = " press 3,7,8,F l";

" RC Motor Center,,,


" RC lvlotor _90 !!";
const char R_90M[] = " RC Motor +90 l!";
const char D_MSG[] = " RC Motor -45 !!";
const char C_MSGU =
const char L_90t'4[] =

const char

="
flag;

SPACE_DU

unsigned char key,

,,
,

#include "LCDB. h"


void SCAN(void)
{
uns

gned

char

MDA-WinPIC-2 Ir{ANUAI.

- 155

3.

Experiment

= 0x8f,

P0RTC

for (i=0, i(4;

i++)

do{

= P6O"'
)whi le((key & 0x0f) l= 0x0f);
keY

do{
keY = P6Pf''

)whi le((key & 0x0f) == 0x0f),


PORTC

= 0xff,

//

lnterrupt service vector


#pragna vector = 0x04
// lnterrupt service routine
_i nterrupt voi d FULSE(void)
{

flag = 0xff,
il/R0 = 256-100;
T0lF = 0;
)

void

CENTER(void)

i
uns

gned char i, count2;

c0rw{aND1g*,rr

'

for (i=0; i(to ; i++) cHAR_o(SpACE*oIi]);


C0lvtr6XP 16*oO;

for (i=0; i(16 ; i++) CHAR_0(c MSc[il);


Ilr4RO

156;

OPT|ON

= 0x08i

INTCON

= 0xa0;

count2 = 20;
do{

for (i=0; i(tS;


flag

=0;

RC_M

=l

whi te(! ftag)

i++)1

for (i=0; i(too;


flag

=0i

RC_M

=0'

whi

156

i++)1

te(!flag);

www.midaseng.com

r=!F
3-9. N{oior llxprrinrcnl

)
) wh

i I e (coun

t2--)

OPTl0N

= 0x28;

INTC0N

= 0;

void LEFT9O(void)
{

unsigned char i, count2,


c0\ttAND(0xd0);

for (i=0; i(to ;


co/t{AND (0xd0)

for (i=0, i(t6 ;


TIr4RO

t++) cHAR_o(SPACE_DIi]);tf

i++) cHAR_o(L_90M[i]);

156; /l

OPTlON

= 0x08,

INTCON

= 0xa0,

256-100= 100[ps]

count2 = 60;
do{
/

"U" PuIse 0.7[ms]

for (i=0; i(7;


flag

i++)1

=0;

=l'
while(!flas):
RC_M

for (i=o; i(loo;


flag

=g'

RC_M

=0'

whl

i++)

le(!flas);

)whi le(count2--);
OPT|ON

= 0x28,

INTC0N

= 0,

l
void RlGHTS0(void)
{

unsigned char i, count2,


cottvLAND
I

(0xd0)

for (i=0; i(16 ;


coivi,tAND

(0xd0)

i++) cHAR-o(SPACE-DIi]);

; i++) cHAR-o(R-90MIi]);
= 156, ll 256*100= 100[us]

for (i=0; i(to


1lv1R0

MDA-WirPIC-2 MANUAL

-157

3.

Experinrent

OPTION

0x08;

INTC0N

0xa0,

count2 =

60;

do{

II

"U" Pulse 2.3[ms]

for (i=0; i(ZS;


flag

=0;

RC_M

=l'

whi le(! ftag)

i++)

for (i=0; i(lOO;


flag

i++)1

=0;

RC_M =0

whi te(! ftas)

t2--)

)
) wh

e (coun

=
INTCON =

OPTl0N

0x28;
0;

void

STEP(void)

uns igned char

i,count2,

CoauNP1sr,r,'

tor (i=o; i(t6 ;

i++)

CHAR_o(SpACE_DIrl)

Cs,ilAND(0xd0);

for (i=o; i(t6 ;


=

Tl4R0

156,

=
INTCON =

OPTl0N

;++) CHAR_0(o_uscIi])

l/

256-100= 100[us]

0x08,
0xa0;

count2 = 60,
do{

"U" Pulse i.

I [ms]

for (i=0; i(l l;

i++)

flag

=0;

RC_M

=l

wnl

i
'l

le(!flag);

for (i=o; i(too;


flag

=0;

RC_M

=0'

whi

- 158

i++)1

le(!ftag);

;l

www.rnid:rseng.com

3-9. l\{olor Iixpefi rrrenl

i
)whi le(count2--);
OPTl0N

= 0x28'

INTCON

= 0;

l/

ttain

void main(void)
{

TRISC

= 0x0f;

L_lMT();
DISPLAY0;

do{

0;
if (l(ke}/ & oxol)) CENTER0;
else it (l(kev & oxo2)) LEFTgo0;

scAN

else
else

if
it

(l(keY & oxOa)) RIGHT900;


(l(keY & oxo8))

STEPO;

)while(1);

rl
II

.lIt

,i
I

I
I
I

ii

il
il

il
il
it
ittl

t?

l{
EI

ill

li

MDA-WinPIC-2 N{ANUAL

l5J

3. Experiment

3-L0. Dot Matrix Experiment.


3-10-1. 5X7 dot matrix
Circuit Diagram

7lLSl5,t

5x7DOT|IATRIX

PICl6F87x

BESET

--_t_

:cl cr: - in.8592


3 nt,
mI zzoI
mm'

*,osce,,ti'
z

Flow Chart

Output font to PORTB

-160

i'ellE

1di-..;.-.""*-.:ti

www.midaseng.com

th

ca

22D

3-I0. Dot

How to

connecl .jumper
WinPIC-2 Kit
RB9

l{t)

RI]1

RI

RI]2
RI]3
RB4

lit2
R3
R4

RB5

R5

RB6

I(6

RAO

CK

RA1

CD

OSC1,2

|'Ith.

Program

'J

c,

\MDA\W i np i c2\examp

e\c\D0T5_7.

#inctude (totorgzz. h)

#define CK
#define CD
/ / font

RAO

RAI

const unsigned char F0NT57ll =

{0x00, 0x27,0x25,0x25, 0x19,


0x00, 0x06, 0x0t, 0x0t, 0x3f,
0x00, 0x47, 0x69, 0x49, 0x49,
0x00, 0x57, 0x55, 0x55, 0x55)

void delay(unsigned char i)

i
whi

te(i--);

//

ttain

void main(void)
{

unsigned char

i;

0x00; ll tntial ize port B by ctearing output


TRISA = 0x00, l/ tntial ize port A by ctearing output
ADC0NI = 0x06; // Configure all pins as digitat inputs
TRISB

P0RTA

= 0x00;

P0RTB

= 0x00;

doi

MDA-WinPIC-2 MANUAL

- 161

3. Experiment

CD

= 0,

for (i=o; i ( 2o;


PORTB

i+*;1

= FONT57[|];

CK

= I'

CK

= 0'

CD

= I'

aelay(t00);
)

CD

= 0,

)while(l);

-162 -

www.midaseng.com

3-10. Drlt Matrix ErgrcrinrerL

3-10-2. SX7 dot matrix animation

Circu

it

Diagrarn

Il
t2
13

ol
02
03

i;D3;

7rLsr6{

5xTDOTNRTBIX

PICl6FBTx

MDA-WInPIC-2 MANUAL

- 163

3. Experirnent

FIow Chart

LOAD

FONT )

[",i.iiiebqir!ip,,$
_

(
How to connect

Vr:s

8.t,,*

.jumper

PIC Port

WinPIC-2 Kit

RBO

RO

RB1

R1

RB2

R2

RB3

R3

RB4

R4

RB5

R5

RB6

R6

RAO

CK

RA1

C-D

OSC1,2

4tfrh

www.midrueng.com

__1_
,,dra. !!!qr

._

Dot l\{atrix llxperi

Prograni

'

\MDA\|{ i np i c2\exanp I e\c\D0T5_7_A.

#inctude (iotOt8zz. n)

CK RAO
fdef i ne CD RAI
#define

uns i gned

char buffer [20]


const unsigned char F0NT57[] = {0x40, 0x40,
;

0x41, 0x43,0x46,

0x4c, 0x58, 0x70, 0x60, 0x40,


0x01, 0x01, 0x41, 0x6t, 0x3t,
0x I g, 0x0d, 0x07, 0x03, 0x0l )

void delay(unsigned char i)


{

whi

te(i--);

void display(void)
{

i.j:
j ( 5O; ;++;1

unsigned char

for
CD

(1=g'
= 0;

for (i=0; i (
p0RTB

2O; i++)1

= bufferIi];

CK

= l;

CK

= 0,

CD

= l;

detay(r0o);
)
)
CD

= 0;

void load(unsigned char i)


{

uns i gned

char j , d fon t0

d_font0 = 9;

for

(.1=6'

j(20;

.1++)

for(j=0;j(=i'j**)
'

bufferi.yl= 6;
{

bufferIi-j] = F0N157[d_font0];
buffer I i -j+10] = F0NT57[d_fonto+t0]
d_fon

t0--,

hIDA-WinPIC-2 MANIjAL

- 165

3.

Experiment

)
I

Nlain

void main(void)

uns

gned

char I d_cnt;

TRISB

= 0x00;

TRISA

= 0x00;

ADC0NI
P0RTA
P0RTB

,11

= 0x06;

= 0x00i
= 0x00i

oo{

for (ld*cnt=0; ld cnt

l0;

ld_cnt++)

load(ld_cnt);

display0;
)

for (ld*cnt=0; ld cnt (

SO; tO cnt++){

display0;
i

)while(l);
)

-166

wlyw.mi,Iaseng.com

il

3-I0. Dot Mahir ExpcrinrenL

i'

3-10-3. BXB dot matrix

Circuit Diagrarn

Dr16_1

DT16-2

+t.

+-

-H-

-DF

+-

+F

Trlst6t r-rus
GloB nrg
'---'
rhR2t
rcc)-J

+*
;fi
R3l

u7

16x16x2
DOT hRTRlx

ur3
IXI

il

R8l

s.6r

-->

rrcc

PICl6FB7x

IHI
tN2
lH3
INT
Ilrs
tH6
IN7
lxt,
oo

OI

tN2
02
Ir3
03
lHr
ot
INs
05
IH6
06
tH7
07
lN8
0a
GilD Cfi

Tnr

25lgl

+-

7{LSr6t

xIa-

kt

x-t

osco

riu

d'

Zglt12

,F)

Bx

.d##

Flow Chart

Prsr'-mv
-t

-*-j

tn;riuli.. cqllryt
I ---;--=>l

r
|-| [ ourprt roNr to PoR lpJ

It

AMBER

Ci*r--

|l.-l--; c.r,;"rc_or lo J
tr--5c.ii1!;-_=

f;
E

MDA-WinPIC-2 IUIANUAL

OI
02
03
OT

0s
06
07

08
con

3. Experirnent

IIow l.tl connect

.jumper

WinPIC-2 Kit

PIC Port
RI]O

R82

CnR
D-G

RB3

CKG,

RI]4
RI]5

C-D

RU1

RB6

CKC
EN

RB7,

CLR

osc1,2

41,11h

Program
'..-]

\MDA\Hinpic2\exaunple\c\D0Tl6 8. C
finclude (iotGtazz. n)
C:

#define D_R RBO


#define CKR RBl

fdefine

D_G

RB2

#define CKG R83

fdefine C_D RB4


fdefine CKC RB5
*define EN RB6
#define RST RB7

//

FONT

const unsigned char FONTl6[l = {0x8f, 0x89,0x89,

0xe9, 0x89, 0x89, Ox8g, 0x00,

0x9f, 0x95, 0x95, 0x95, 0x95, 0x95, 0x91, 0x80I

void delay(unsigned char i)


{

whi

le(i--);

vold display(unsigned char statel)


{

unsigned

char i, j, data;

= li
C D = l;
RST = l;
for (i=0;
EN

CKC

168

i(

10; i++)1

= l;
www.nridaseng.com

= 0,
data = FONTI6[i];
CKC

for

(j =0,

swi

j ( B; .1++1

tch(statel & 0x03) {

/I

RED

case 0:

= 0;
if(data & oxSo) D-R

D_R

CKR

= l;

CKR

= 0;

break,

//

GREEN

case

|:

D_G= 0;

if(data & oxSo) o_c = ,.


CKG

= I'

CKG

= 0;

D_R

break,

//

AMBER

case

2:

0;

D_G

= 0;

if(data & oxao) {

I'
D_G= I'
D_R

I
I

CKR

= I'

CKR

= 0;

CKG

CKG

= 0,

break

1,

data

((= l;

i
= 0,
delay(loo);

EN

EN

= l;

CD=0;
i
C_D

RST

= 0;

1,

ll

uain
void main(void)
MDA-WinPIC-2 MANUAL

-t69

3.

Experimenl

unsigned char state,


TRISB
P0RTB

i;

I
I

= 0x00;
=

state =

I
i
I

0x40;

l
!

.* -{

0,

j
s

do{

l]

for (i=0; i(tSO; i++) disptay(state);


s ta te++

if

(state == 3) state = 0;
)while(l);

-170 -

l:l

:lt

rvww.midaserig.com

3-10. Dot Nlatrix Ex1x

3-10-4. 8X8 dot matrix animation

.N

Circuit Diagrarn

UI

DTl6_1

lr
12
13m

r;>sl

.*c!

t4'l+us

6_2

02

16s
17
7.LSt6{

DT

0t

+t+t+t+t-

+t_

07

6|DPr

'-tiffiT-

+F
+t+F

Rlg

rrR2l

16x16x2
ffi
R3l DoT rlRTR x
I

u7
R0{

TRI

5.6r

2S8t0t5

u13
IHI
IH2
IN3
lHl
lNs
Ix6
lH7
lH8
GilD

ucc

PICl6FB7x
7{LSt6,

INI
IN2
tN3
lNa
Iils
116
Il.l7
IM
Glo

OI

02
03

0{
05
06
07
08
CtrI

7rLSl6.

OI

02
03

0{
05

06
07
08

cofl

XIf,

i't
I tfi,

l''3'i

"orct,J -+ osco;f'
2i Alr,L
,F'

MDA-WinPtC-2 MANUAL

.17

ft2

t0{

29

-171

3. Experiment

Flow Chart

Initialize PortB
Initialize buffer pointer

I
lounter -

I J

--,1 .no
l"------..(rnr.,

Update color

r--2I

I
|

L-qu,ru,

Fonr

ro PonB

___L_

IL_croc[-."]

I I
l-j-)
lno
-

| -/

-\s

cD=o -*
-.--.-.....-

-__L_

[:st column ? >


v
ves
r

ir:,

How to

Retum

connect .iumper
PIC Port

WinPIC-2 Kit

RBO

D=R.

RBl
RB2

CKR
D_G

RB3

C-KG

RB4

C_D-

RB5

CKC-

RB6
RB7

EN
CLR

OSC1,2

4WIz

www.midaseng.com

= oi--..------>

[]ot Nlatrix Erpr

.'*?#
.3

Progranr

C, \MDAUYinp

c2\exampte\c\D0Tl6_8_A.

#inctude (iot0tazz. n)
#define D_R RBO

#define CKR RBt


#define D_c RB2

fdefine CKG RB3


#define C*D RB4
#define CKC RB5

*define EN RB6
*define RST RB7
unsigned char buffer[16]

const unsigned char F0NII6[]

{0x18, 0xlB, 0x18, 0x18, 0xlB, 0xlB, 0x18, 0x99,


0xdb, 0x7e, 0x3c, 0x99, 0xdb, 0x7e, 0x3c, 0x

void delay(unsigned char i)

lg)

whi

te(i--);

void di splay(uns i gned char statel)


{

unsigned char i,

EN=L
C_D = l;
RST = l;
for (i=0;
CKC = l,
CKC

data;

tO;

i++)1

= 0i

data =

for

i(

j,

bufferIi];

(.1=0,

j ( A; l **;

switch(starel & 0x03){

//

RED

case 0:

= 0;
if(data s ox8o) D-R = l,

D_R

break

//

CKR

= l;

CKR

= 0;

GREEN

case

l:

D_G= 0;

if(data & oxe0)

D_G

= l,

MDA-WinPIC-? MANUAL

-173

3. Experiment

break;

//

AMBER

case

2:

D_R

= 0;

D_G

= 0,

if(data & 0x80){


D_R=L
D_G

li

t:

data

l
= 0,
oetay(t00);
EN

EN

= l,

C D = 0;

void L0AD( unsigned char

ts

char j,d font0;


d_font0 = 15;
for (i=6' j(t6; .1++; buffer[i]=
for(.1 =0; .1 1= i' j++) {
unsigned

bufferI i -j

= F9NT16[d-font0]

i
I

6;

d_font0--,
)
)

ll

uain

void main(void)
{

unsigned char state,


TRISB

= 0x00;

P0RTB

= 0x40;

-t74

i,j;

www.rnidaseng.com

3-10. I)ot lVlatrix Expt

state = 0,
do{

for (i=0; i( to;

i++){

LoAD(i);

for(1=0;

I ll

ror

for(i=0;
s

ta te++

if

j ( 2O; 1++) disptay(state);


i ( 200; ;++) disptay(state);

(state==J) state=O;

)while(t);

MDA-WinPIC-2 MANUAI,

-175

3. Experiment

3-10-5. 32X16 dot matrix


Circuit Diagram

PICl6FBTx

0sc2

osc

I?^

fuol

Frliro

Flow

CLOCK
RESET

Chart

::::l Ivldn ,
lnirialize

:'

':,,,1

Ports.

)
]

r<

i
|

--..--.-.------.--=-__---l

Shift Font bir

-_t_

-176 -

clock
oumut

address ]

www.midaseng.com

Dot l\{aLrir

F,r'Prt

How to connecl .jumper

.cs

WinPlC-2 l(it

PIC Port

RAO

AO

RAI

NI

naz
nn:
Riil

RT}5
I{I]O

r{B,
osc

r,2

I
I
i

A2

a:
ne,p

GREEN

LNTCH

t'r-ocr
il.ose2[1lL

Program

'3

c. \MDA\I{i

np i c2\examp

f inc lude ( iot6tezl.

e\c\D0T32-l 6. c

rr)

: address
#def i ne RED RB4

//

RA0-RA3

fdefine
*def i ne
#def i ne

GREEN RB5

uns i gned

char font_c:

LATCH

RB6

CL0CK

RB7

unsigned long font;

//

FONT

constunsignedlongF0NT[16]={0x00000000,0x7ffc3ffc,0x00040004,0x00040004'
0x00040004, 0x00040004, 0x3ffc0004, 0x00047f

fc,

0x00040000, 0x00040 I 00, 0x00040 I 00' 0x7 f f c0 I 00,


0x00000 1 00, 0x00000 I 00, 0x7ffe7 f fe, 0x00000000)

ll

uain

void main(void)
{

char i, j, addr, state;


TRISB = 0x00, / I tnitial ize port B by clearing output
TRISA = 0x00, ll tnitialize port A by cleaning output
ADC0NI = 0x06, // Configure all pins as digital output

uns i gned

P0RTB

= 0,

P0RTA

= 0,

state = 0;
do{

MDA-WinPIC-2 I\{ANUAL

-177

3.

Experiment

for (j = 0, j (

200; j++){

font_c = 0,

( t6; addr++) {
font = F0NT[addr]
for (i=0, i ( sz; i++)1

for

(addr=0; addr

(state == 0)

RB4=l;

._,

'l.
:.

RB5=0i

| // if
else if (state -

t){

RB4=0; RB5=l;

) //
lse

else

RB4=r

) //
I l/
etse

if
,,1

RB5

=l;

else

i'f

0;
I // else
RB7=l',

// OFF

RB4=0i RB5 =

= 0,
font ))=

:
.,'i

"

RB7

P0RTA

= addr;

l;

RB6

RB6

= 0i

for (i=0, i ( too;


RB7 = l,
RB7

//

Latch

i++)i

i.

i.;l;

= 0i

state++; // Uptae color


if (state == 3) state =0;
)whi

le(t);

I
q1,i.Ua

-r78

www.midaseng.com

t
l

il

3-10. Dot lVlatrix

il'

rll

3-10-6. 32X16 dot matrix animation


,A$

Circuit Diagram

PICl6F87x

0sc2

osc

"+2i

a=

x+
zi

F:

tl
tl

il

MDA-WinPIC-2 MANUAL

.1. Experiment

Flow Chart

I-----Un frrg _n"",__]


|

[ .u,1111.i

-I

no

------'-4....-.........cclunter = 0?

J----'.---.

(--

----.....-

--

Yes

.n.**

t--!p@Ir-el- ]

t"
I

II
I

[!e4qrq* l
t r,sr,iqr;rts lrU I
f--d*;;

rl
'uffi

FIow

to

connect .jumper
WinPIC-2 Kit
AO

A1

NZ
A3
RED
GREEN

LATCH
CLO-CK
11.0592|ifih,

180

w'ww.nddaseng.com

3-10. ilot

Prograrrr

',3

c, \MDA\|I inp ic2\exanp le\c\DoT3z I6 A,C


f inctude (iot0rAzZ. n)

#define RED

RB4

fdefine
fdefine

GREEN

RB5

LATCH

RB6

#define

CL0CK

RB7

uns

gned char fon t_c:

unsigned char d_font0;


unsigned char state;

unsigned long font,


unsigned tong bufferIt6]

ll

"^^" ront

const unsigned tong F0NT[16] = {0x01900180,0x03c003c0,0x07e007e0,0x0db00db0,


0x I 998 I 998, 0x3l 8c3 I 8c, 0x6t 866 I 86, Oxc I B3c I 83,
0xB I 8 I B I B l, 0x0t 800 I 80, 0x0 I 800 I 80, 0x0 I 800 I 80,

0x0 I 800 I 80, 0x0 I 800 I 80, 0x0 I 800 I 80, 0x0 I 800 I 80)

vcid DISP(void)
{

unsigned char addr,

for

(addr=0; addr

i,

( l6; addr++){

font = bufferfaddr];

for (i-0; i ( gz;

if

i++){

(font & 0x00000001){


if (state == 0) {
RB4=1;

RBS=O;

I // it
else if (state == l){

I/

RED

//

GREEN

//

AMBER

RB4=0; RB5=l;

l //
else

else

R84=l

j /l
l // i'f
else

RB5 =1,

etse

RB4=0; RB5

I //
1,1

li

lii!
I;r1

il

if

= 0;

//

orr

else

RB7=l
= 0;
font ))=

RB7

1'

${

I\{DA-WinPIC-2 iVIAI\ UAL

- 181

3. Experiment

= addr;

P0RTA

RB6

= l;

RB6

= 0;

il
il

iil

il.,r

for (i=o; i ( zo; i++;1


RB7

= l;

RB7

= 0i

ii'

)
)

= 0;

P0RTA
)

void

char i)

LOAD( unsigned

uns i gned char

n-|.
l-

i,

k;

i++;

d_font0 = 0i

for (j=g'.j1,,'

ror(;i)o;
buffer

1++) Ouffer[j]=

i-- )

O;

5-k] = FONT[d_font0++];

k--;
)

//

ttlain

void main(void)
{

unsigned char ld_cnt, count2i


TRISB

= 0x00;

TRISA

= 0x00,

ADC0NI
P0RTB

= 0x06,
= 0x00,

P0RTA

= 0x00i

state = 0;
do{

for (ld_cnt=0;

t_d_cnt

t6; ld_cnt++) {

LOAD(td_cnt);

for(count2=O; count2

50; count2*+)

for(count2=0; count2

200; coun t2++) DISP0

I // ror
s

-182

tate++

DtsP0;

www.midaseng.com

]t
:

I
I

MDA-WiuPIC-2 MANUAL

3.

Experiment

3-1L. Application Experiment.


3-11-1. Graphic LCD

q$

Circuit Diagram

P IC

6F87x

I*-T
11
{}.l
'1CLR
0sc2 oscl

BESET
I

-184 -

6,1

tTl

Il.6

UOUI

x_L

l+lz

6{

USS

LO

r28 x

"xTAL

I i"l'i I
,T,#
xa

UO

lcNa

L+r

BBI

UDD

,r

2:

www.midaseng.com

Application ExPri

Flow Chart

Set Pagq

Orrnrt

t"--

O+

C ct".r, u*v n;- )


-:-r:::lr---:
[-s"trr o".ts ^ i,r*" I
--t -zq-q
"1 BIil" l

3,

UY".

f"lt.

tc!-:8l

bytes font. ]
{.-' Orrprr 64r-'

s.c, )

LCl,".!r!g1r

!et.-J

fkl

qati-

-up!,

ur.y flag =o? ,;=


--_.
.-_____/

trqup-rcrfsGi
l--._
_

f -----R.t,*:--_l
-lves-,
_-__

C'-p**;lplllrlrr",fl
_t-_
Or".h U-tv rire-J

r
ffi

OrtpUlSqrrgld

Fcsz. csr,l-LBw, p-]

--l

.l

How to connect iumper


PIC Port

WinPIC-2 Kit

RAO

DI

RA1

R:W

RA2

LCE

841

CS1

ItA4

CS2

RBO

L.CO

RB:l

LC^1

RI]2
RI]3
RB4

-l'C2

RB5

LC5

RI]6-

LC-6

RB7

LC7

osc1.2

Atilth

LC3

LC4

MDA-WinPIC-2 MANUAL

-185

3.

Experiment

Program
'.,3 c, \MDA\|Yi

c2\exaip r e\c\G_LCDt. c
fi i nc I ude (iot0razz. tr)
np

const unsigned char Mil=r


0,
C

'c, [ , ;4, 0x04,

":

[, -0.

0x00,

0x04, 0x04, 0x04, 0x04, 0x04,

0xff,

0x80, 0x80, 0x00, 0x00,

0r'.. -, l3

0x04, 0x02, 0x02, 0x02, 0x02, 0x02,

0i0.i

_ , Lt3.

0xf0, 0x00, 0x00, 0xff, 0x00, 0x00,

0rfc.

C,

0xC4,

ll.

0x04, 0x04, 0x04, 0x04, 0x04, 0x04,

0x00,
' -C.

0xff,

0x80, 0xgO, 0x00, 0x00,

0x00 l,rCi 0x00, 0x80, 0x40, 0x20, 0x10, 0x0c,


0x10. 0i2J. 0x40, 0x80, 0x00, 0x00, 0x00, 0x00)

cons

uns i gned

char

lvll

[]

0x3f. Cr20, 0x20. 0x20, 0x20, 0x20, 0x20, 0x20,


0x3f. 0r00, 0x00. 0xff, 0x00, 0100, 0x00, 0x00,
0x0f, 0r I 0, 0x20" 0x40, 0x40, 0x40, 0x40, 0x40,
0x20, 0x I 0, 0x0f, 0x00, 0x00,

0xff,

0x00, 0x00,

0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,


0x20, 0x00, 0x00,

0xff,

0x00, 0x00, 0x00, 0x00,

0x24,0x22,0x21, 0x20, 0x20, 0x20, 0x20,0x20,


0x20, 0x20, 0x20, 0x20, Ax?l , 0x22,0x24, 0x00)

vo

id

busy0 (vo i d)

unsigned
TRISB

char

busy;

= 0xff;

do{
P0RTA

= 0xee;

P0RTA

= 0xe0,

ll
l/

l=0

CSZ=O,

CSI

E=1,

R!Y=l

CSZ=O,

CSI =0,

E=0,

RW-0, Dl=0

=l

busY = P6RTB;

whi le(busy & 0xB0);

TRISB
P0RTB

- 186

= 0x00,
= Oxff,

rvww.midaseng.com

3-ll.

Application

/'*
vo

LCD0 wr i
i

te

'*/

cdO_wr (uns

gned char send)

busy00;
P0RTB

= send;

PORTA

= 0xec;

//

CS2=0,

RW--0,

l=0

P0RTA

= 0xe0,

//

CS2=0, CSI=O, E=0,

RW=0,

l=0

CS2=1, CSI=O, E=1, RW=|,

l=0

l=0

void

lcd0_page(unsigned char page)

page &= 0x07;

pase l= 0xb8;
I

cd0_wr (pase)

void

lcd0_address(unsigned char address)

address &= 0x3f,

address l= 0x40;
lcd0_wr (address);
)

void

busyl (void)

uns

gned

TRISB

char

busy;

= 0xff;

do{
P0RTA

0xf6; l/

busY =

PgRTB;

= 0xe0; // CS2=0, CSl=0, E=0, RW=0,


whi le(busy & 0x80);
P0RTA

TRISB

rl
rl

iI

PORTB

/*

LCDI wr i te o/

void
iI
I

= 0x00;
= 0xff,

lcdl*wr(unsigned char

busyl 0

.
ri

i,

il

t,

send)

PORTB

sertd;

P0RTA

0xf4; //

CS2=1, CSI=0, E=1, RW=O, Dl=0

P0RTA

= 0xe0,

//

CS2=0, CSI=0, E=0, RW=0. Dl=0

MDA-WinPIC-2 MANUAL

-187

3. Experimenl

vo

id

cd I _page (uns

gne:

:-:

::

le,

page &= 0x07;

page l= 0xb8;
I

cd I _wr (page)

cdl_address (uns I -c:ei :har address)

l
vo

id

address &= 0x3f,

address l=

0x40;

I cd I _wr (address)

void

font0(unsigned char font)

busyO0;
P0RTB
P0RTA
PORTA

= font,
= 0xed;
= 0xe0;

/l
l/

CSZ=0,

CSI=I, E=l,

RW=0,

CS2=0, CSI=O, E=0, Rff=O,

Dl=l
D

l=0

vo

id

fontl (unsigned char font)

busyl 0
P0RTB

= fontl
= 0xf5,

/l
PoRTA = 0xe0; ll
P0RTA

CSZ=|, CSI=O, E=1, RW=0, Dl=l


CS2=0, CSI=O, E=0,

RW=0, Dl=0

i
vo

id

cd0_c I ear (vo i d)

uns

gned

char

i,

j;

for (.1=g' j (8; j ++) i


I

cd0_pase (j )

cd0_address (OxOO)

;
i'

,q

for(i=0; i(64; i++)

font0(0x00);

"'

,-

)
)
vo

id

cdl _c I ear (vo i d)

unsigned char

for(1=6' j(S;

i,j'

.;++;1

lcdl-.pageU);
I

- r88

cd I _address (OxOO)

wrvw.niidaseng.com

i.

ri

..,- | *i

'i1.1l"rli

ii

Application [,r
ror

( i =0;

fontt

(oxOo);

i
vo

id

clear(void)

_clear0;
_clear0;
display(unsigned char page, unsigned
char address, const unsigned char,*fnt)
unsigned char i, font,

lcd0jage (page)

lcdtjage(page);
I

cd0_address (address)

for(i=0, i (6+;

i++){

= fntIi];

font
i

(address
I

)=

6a) {

cd I _address (address_64)

font I (font)

etse font0(font);
address++;
)
)

void

main( void )

TRISA

= 0x00;

TRISB

= 0x00,

PORTA

0xe0; //

=
= 0xff,
tcd0_wr(Ox:r);

ADCONI

CS2=CS|=E=0

0x06,

P0RTB

lcdt_wr(Oxfr);
clear0;

//
//

LCD0 0N

LCD1 0N

disptay(0x03, 32, M);


disptay(OxOA,

:2, ut);

whire(l);

MDA-WinPIC-2 MANUAL

-189

3.

Experiment

3-1'/.,-2. Graphic

LCD animation

Circuit Diagram

PIC16FB7x

csl
D?
D6
D5

l*ffiT
11

D{
D3

m-_n
0sc2 oscl

-190 -

RBI

R
UDD

{}.,

U(

UO

LcNa
128 x 6{

t"

www,midaseng.com

6{

.J

UOUT

USS
K

.#

-FIow

to

conncct jumper
PIC Porl
RA0

WinPIC-2
D-I

RA1

R_W

RA2
RA3

LCts
CS1

It,A4

CS2

I{BO

LCO

IIBl

LC1

I].B2

-hCZ

RU3

LC-3

ITI]4

ItBT

LC4
LC5
LC6
LC1

OSC1,2

4uth

RI]5
RB6

...R
$

c,

program

\MDA\W i np i c2\examp

e\c\G_LCD2.

finctude (iot0rgzz. h)
const unsigned char M[]={
0xfc, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0xfc, 0x00, 0x00, 0xff, 0xg0, 0xgO, 0x00, 0x00,
0xf0, 0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02,
0x04, 0x08, 0xf0, 0x00, 0x00,

0xff,

0x00, 0x00,

0xfc, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,


0x04, 0x00, 0x00,

0xff,

0x80, 0x80, 0x00, 0x00,

0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x0c,


0x I 0, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00)

const unsigned char Mlfl=1


0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x3f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x0f, 0x10, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40,
0x20, 0x10, 0x0f,0x00, 0x00,

0xff, 0x00,0x00,

MDA-WinPIC-2 N'IANIJAL

19r

3.

Experiment

[',3'. -,20.

0x20, 0x20, 0x20, 0x20, 0x20, 0x20,

C,20. Lr,!0. 0x00,

2!.,

22.

0x2

0xff,

0x00, 0x00, 0x00, 0x00,

l, 0x20, 0x20, 0x20, 0x20, 0x20,

0r20. 0:20. 0x20, 0x20, 0x21.0x22,0x24,0x001

void

busy0(void)

unsigned
TRISB =

char

busy;

0xff;

do{

/l
P0RTA = 0xe0, /l
P0RTA

= 0xee;

CS?=|.

CSI=1, E=1, RW=1, Dl=0

CS2=0.

CSI=0, E=0, RW=0, Dl=0

= PSRTB;
whi le(busy & 0x80);
busY

TRISB = 0x00;
P0RTB

= 0xff;

/,,LCD0

write o/

void

lcd0_wr(unsigned char send)

busy00;
P0RTB

= send;

//
PORTA = 0xe0; //
PORTA

= 0xec;

CS2=0, CSI=I,

E=1,

R!Y=0, Dl=0

CS2=0, CSI=O,

E=0,

RIY=0, Dl=0

)
vo

id

lcd0jage

(uns igned

char

page)

page &= 0x07,

page l= 0xb8;
I

cd0_wr (page)

cd0_address (uns i gned char address)

vo

id

address &= 0x3f;

address l= 0x40;
I

cd0_wr (address)

)
vo

id

busyl (void)

unsigned
TRISB

char

busy;

= Oxff;

www.midaseng.com

3-1I. Application

do{
P0RTA

0xf6; //

busy =

CSZ=|, CSI=0, E=1, RW=1, Dl=0

P0RTB;

= 0xe0; // CS2=0,
whi le(busy & 0x80);
P0RTA

TRISB

= 0x00;

P0RTB

= 0xffi

CSI=0, E=0, RW=0, Dl=0

/*

LCDI wr

void

te */

lcdl_wr(unsigned char send)

busyl 0

P0RTB

= send;

PORTA

P0RTA

= 0xe0,

0xf4, //

CS2=1, CSI=0, E=l, RW=0, Dl=0

//

CS2=0, CSI=0. E=0, RW=0, Dl=0

)
vo

id

lcdl_paEe(uns i gned char page)

page &= 0x07;

page l= Oxb8;
lcdl_wr(page);
)
vo

id

lcdl-address(uns i gned char address)

address &= 0x3f,

address l= 0x40;
lcdl_wr (address)

i
vo

id

fontO(uns i gned char font)

busy00;
P0RTB

= font,

Oxed, ll
PoRTA = 0xe0;
ll

P0RTA

CS2=0,

CSI=1, E=1, RW=0, Dl=l

cS2=0,

CSI =0,

E=0, RW=O, Dl=0

void

fontl (unsigned char font)

i
busyl 0
P0RTB
PORTA
PORTA

= font;
= 0xf5;
= 0xe0,

l/
//

CS2=1, CSI=0, E=1, RW=O, Dl=l


CS2=0, CSI=0, E=0, RW=O, Dl=0

MDA-\4/inPIC-2 MANUAL

-193

3. Experiment

)
vo

id

cdO_c I ear (vo i d)

{
uns

gned

char i, j

for (j =0; j (S; .i++;

lcd0_page(j);
cd0_address (OxOo)

for(i=0; i(64; i++)

font0(0x00);

)
)
vo

id

_c I ear (vo i d)

{
uns

gned char

for (j =0; j (B; .;++; 1

lcdllage(j);
I

cdl_address

(OxOO)

for(i=0; i(64; i++) fonil (0x00);


)

void

clear(void)

-clear0;
*clear0:
)

void

display(unsigned char page, unsigned char address, const unsigned char *fnt)

unsigned char i, font;


I

cd0L:age (page)

lcdljage(page);
I

cd0_address (address)

i
i++)1
font = tntIi];
i f (address )= 6a) {

for(i=0;

(O+;

cdl _address (address-64)

fontl (font);
)

else font0(font);
address++;

void

delay(unsigned int

www.midaseng.com

Application

while(i--);
)

void

anim(unsigned char scrol l)

clear0;

l,

display(scrol

display(7-scrol

32, M);

l,

32, Ml)

vo

main( void )

id

unsigned char

i;

= 0x00;
TRISB = 0x00i
TRISA

P0RTA

0xe0; //

=
= 0xff;
I cd0_wr (ox:r)

ADC0NI

cs2=csl=E=O

0x06,

P0RTB

lcdl_wr (Oxai)

; //
; //

LCD0 0N

LCDI 0l'l

clear0;

for(i=0; i(4;

l++)1

anim(i);
oe t ay (4oooo)

while(l);

MDA-WinPIC-2 MANUAL

195

3. Experiment

3-11-3. Ultra sonic

Circuit Diagram
PIC16FB7x
Rno

RffI

882

m3

BR{

.;;i:
F83

n82
R8l

D6

R80

D1
D3
D2

D5

ffi*r*,

'i'

-196

.;l!

DI

c0:

22p

x+

x_L

2"

,r

www.midaseng.com

3-11. Application Ex

f,

8o

trn0
CxT
RXT

UR3

IK

tn{

cr8r5

{7K

firr.rn s.66ru

lr

M<

Flow Chart

ffi
message
I - -.-....'-.._

ftransmit ultra sonic

Enable Timer0

MDA-WinPIC-2 I\{ANUAL

-197 -

3. Experiment

How to connect

iumPer

PIC Port

WinPIC-2 Kit

RAO

RS

RA1

RW

RA2

EE-

RI]O

D4

RB1

D5

RI]2

D6

RB3

D'7

RA3
R.A-1

UTX
URX

osc1.2

4trfiz

Program

lC- c

c, \l,lDA\lI inp ic2\exarp I e\c\Sotl

finclude (lotGtall. n)
*def i ne TX RA3
fdef i ne RX RA4
unsigned

int

C0UNT;

const char msgl[] =

" Ultra Sonrc !! ";

"Distance Measure";
const char mss2[] =

const char msg3[] =

" I cm - 999 cm ";

const char msg4[] =

"Distance

000cm":

*include "LCD4A. h"


// lnterrupt service vector
#pragna vector = 0x04

//

nterrupt serv i ce rout i ne


void ULTRA(void)

-interrupt
{

CoUNT++; //
TMR0

= 256-29,

TO|F

= 0i

CCUNT

void

CONV(void)

unsigned char
C0UNT &=
BCDH

BCDH, BCDL;

0x03ff;

C0UNT/100;

CflJt{I 7.= 100;

- 198

www.rnidaseng.com

3-l 1. Application Experi

BCDL

C0UNT/10;

ECD|-((= 4'
tscDL

BCDL

((CAnrZ"rO) & 0x000f);


'

corruaxe16*oo;

& 0x0f)+0x30)

CHAR_o((BCDH

)) 4) & 0x0f)+0xao);

CHAR_0(((BCDL
CHAR_0( (BCDL

(0xe0)

C0lf'1AND

& 0x0f)+0x30)

i/

ltain
void main(void)
{

r_trurT0;
DtSPLAY0;
TX

= l;

//

Measure

do{
TX

=0;

TX

=l;

OPT|ON

//

Transmit

0x00; /l Tiner} lnternal clock,

Prescale rale 1:2

= 256-29i
TO|F = 0,
T0lE = l;
GIE = l;
I]'4R0

while(!RX);
OPT|ON

= 0x08;

T0lE = 0,
GIE = 0,
coNV

DELAY

(60000)

)white(t);
)

MDA-WInPIC-2 MANUAL

-199 -

[:rperiment

3-11-1. Infra-Red
3,J

,l,t
i

Circuit Dirg:.,:.

i
"l

Il1r-.F87x
R88

nnz X{

F8t

330-

R82

R8{

rc.?,nx

RD7
FC

Rt5

D5

RC6/TX

RDI

D{

RD3
RD2
RDI
PO

D3

6C2 oscl

D7

n,
D1

XTfl{i

nrz:
OSC I

xa

xl_

:cr c0- _ 11.663?


r*tz
mI znlrfirtlI

,r
2

IR5

lrDfl

IRI
6.8K

osco#

sr
IBL

ELIL

IR2

IBt

l0K
IR3

l0K

icl
0.001 uF

I
J

li
l

Flow' Chart
l

DirlLo orrt,r-t,.J

:ri':{r*-")
Receive routine

-200

www.nddaseng.com

:t

3-ll.

[{ow to

connect .jumper
PIC Port

WinPIC-2 Kit

RBO

RS

RI]1

RW

RI]2

EE

RDO

DO

RD1

D1

i;i

RD2
RD3
RD4

D3

RDi

D5

RD6
RD7
RB4

D6

D_4

D'7

x4
ITX

RC6/'fX
RC7/RX

JRX

OSC1,2

.#
.3

Application Ilx;rerin

4l,frh

Prcgram
c, \MDA\ll inp ic2\examp le\c\

tRDA. C

#incIude (iot0teZ;. h)

msgl[]=" lnfra-red !! ";


char msg2[]=" TxD -) RxD ";

const uttsigned char

const unstg:ned

const unsrgned char msg3[]=" Transmitter


const unsigned char msg4[]=" Receiver .
con:;t unsi gned char

: ';
";

ASCTBL[]="6123456789A8CDEF"

#include "LCDBB. h"


vcid TXii(unsigned char data)
{
wh

i ie (! IRf'TI)

TXREG

= data;
(0x9e)

c0t'{\4p,iltD

CHAft_o(data);
C0lvh{AND

(0Xe0)

vo

itJ

RXD

(vo id)

unsigned cnar data;


\'lhi te(!RCtF);

MDA-WinI'IC-2 MANUAL

-201

3. Experiment

(FERR) {
CREN

= 0;

CREN

1;

else

f(0ERR) {

CREN

= 0i

CREN

= l;

data =

:,i.

RCREG;

C0i,UnfrP16Y0., '

'_.ril::

CHAR_0(data);

.:r*1, '
,..tt:j,rj,

C0,14AND(0Xe0);

.ar:I.!j

'.:;|.; :i

).,
/l tlain

'

'

-"!.i,"i
:tEt.

..;,.:,"r'L, -:'r .
i.! $
-!,,- | , a.: :
,:f.:i
.r;,
!:11 ;ii,
..
.r: ,

unsigned char count,

207; //

::..."1

300[bps](+tt*tl)

= 0x20;
L_tNtT0,
TXSTA

D tsPl_AY

= 0x90i

count = 0;
do{
wrri te(Ra+);

TxD(AscTBllcountl)

RXD0;

count#;
count &= 0x0f,
t{hi te(!RB4);

)while(l);

-202 -

,-. i,i
i:

:,

RCSTA

t",i

rt
t.,:.

void main(void)

SPBRG

.ltiir;Sr

;ii'j'Er;
.:;:,
:.,

www.midaseng.com

3-11-5. Optical fiber


Circuit Diagram

IC I 6FB7x
RBo

naz X'l

Ral

33o-rt-

BA2

BD7
RD6
RDg

BC7./8X

RC6/Tx

FD{
FD3
FD2

FDt

frCEH

oscz osc,

Flow Chart

it.,:

(EGG]ffi]

Mriin':t . .::it);|]
,

______>l

lno

Set BATID rate

l-r1'pe-'-"-:
oone?-}

Enable Tarxmit

--__\_-_--l

message
I

Enable Con. receive

<t
I

Ernlr

_\_/-^

no

Receive

Display on LCD
Trarsrnit routine

MDA-WinPIC-2 MANUAL

3. Experinred

How to o0-4'cl irmper

,J

PIC Port

WinPIC-2 Kit

$q

RS

RBl

RW

RB2

EE

Bp9

D0_

RD1

D1

RD2

D2

RD3

RD4

D3
D4

BP-5

D5

RD6

D6

897

D7

RB4

x4

t
I

;.d

t.

inl

i1i
,,1;

B9q4x

OTX

RC7/RX

oRx

osc1.2

4Wh

Program

'$

c, \toA\tIi

np i c2\exarp

Ie\c\0pT IcAL. c

#inctude (iot0tazz. n)
const unsigned char msgl[]=' Optical fiber! ";
const unsigned char msg2[]=' TxD -) RxD ':
const unsigned char msg3[]=" Transnitter
const unsigned char msg4[]=" Receiver

..

const

uns

#include

//

l/

lnitial

":

Jr
1

";

gned char ASCTBL[]="0| 23456789A8CDEF"

"LCDBB. h"

Transmi

ized

LCD modute

void TXD(unsigned char data)


{
whi te(!TRMr);
TXREG

data;

.:

COUvlAlO(gxge)

CHAR_o(data)

CS[ranNP(gY.6;
)

//

Receive

void RXD(void)
{

-204

www.midaseng.com

3-ll.

Application flxpe

unsigned char data,

white(!RCtF);
i

(FERR) {
CREN

= 0;

CREN

= l;

else

if(oERR){

CREN

= 0,

CREN

= I;

i
data =

RCREG;

cotrfvraxp

1gya.;

CHAR_0(data);
ctr04AND(0Xe0);
I
'!

Main

void main(void)
{

uns i gned
SPtsRG

char count,

207; //

300[bps] (+[utlr1;

= 0x20;
L_tNtr0;
TXSTA

DtSPLAY0;
RCSTA

= 0x90,

count = 0;
do{
whi te(Re4);
TXD(ASCTBL[count]);

nxD0;
coun t++

count &= 0x0f,


whi re(!RB4);

)while(t);
)

MDA-WinPIC-2 MANUAI-,

-205

3. Experiment

3-1L-6.

Wtutu

,::. Circuit Diqgrn


PIClGFSTx

ffi,..,,' Flow Chart


r:

r:iiiL;iiMii*;i:;i;i;:

Set BAUD rare


Enable Tarsmit

6ffi;,il)

G=ilil;;il;f

F<qy> FXqT2

Display message

Error ? ->-Y99
{- ---=<6-

Enable Con. receive

oi+lry

ryo ]

ffi}

on LCD

-206 -

Receive

www.midaseng.com

3-1t. ApPlication ExPri

--S How to

connect iumPer
WinPIC-2
RS

RW
EE-

DO

D1
D2_
D_3

D4
D5

D6
D1

x4
IYTX
WRX
4MIlz

'3

c,

Program
\MDA\IY inp ic2\exarnp

le\c\w

IRELESS-

#include (iotorazl. h)

const unsi gned char ASCTBL[]="6123456789A8CDEF"


// Transmi t
void TXD(unsigned char data)
tt
wnile(ITRMT);
TXREG

= dAtA;

cotvMAND

(0X9e)

CHAR-0(data);
cotvMAND

(0Xe0)

//

Receive

void

RXD(void)

unsigned char data;

MDA-!\1nPIC'2 MANUAL

-207

--

3. Experirreil

whi re(!RCrF);
i

(FERR)

CREN

= 0;

CREN

l;

else

f(oERR) {

CREN

= 0;

CREN

= l;

data =

RCREG;

CS,!\4AI\p(6xdc)

CHAR_0(data);
Colvtr4aXg

16X.r;

ll

uain

void main(void)
{

unsigned char count:


SPBRG

207; // mlbp6l(1tl+El)

= 0x20;
L_frilT0;
TXSTA

DtSPLAY0;
RCSTA

= 0x90,

count = 0;
do{
whi te(no4);
TXD (ASCTBL

[coun t] )

RXD0;

count++;

count &= 0x0f;


wni te(!RB4);

)while(l);

-208

www.midaseng.com

Eii

X mrinPIC-Z Schematic

lI
trJ
f
(J
o-

:l

z
I

(r

o
E

x
cF

(E

=
a

UJ

J
F
F

U
F

U
U
c

=
G

Y
U
o
J

cF
(5

Cf

coU
U

f,
cl
6

c
c
U
a

c
U
N
N

=
m
U

o
0
e

o
G
C)

oc

8s
{F_t

I
{ts*

E$-

o
l

o
c
U

q
o:

t o-l
E o
(n

lrl

(J
o_

=
I

CE

a
E

Lrl

J
F
F

E
(,

U
N

ffi$
Erf*tffh

TU o
N
o: N

o. 6
o
f
N

OJ

.{

L
OJ

c
C]

UI

ao,

LLI

CJ
o_

z
=
I

Cf

o
E

u
F

t
U
z.

O
O
a
c

u
F
u
>

Z,

cl

O
G

(f

";q
c

m
6

OJ

<n

CC

LrJ

CJ

Z oe
z4
=
(E
o_

a
E

J
F
F

l-

ES

f;(

TJ

=
o

+
s

rr
o
F

o-

U
ts
ld t'l

f;

a'(

I-e

tRne

lfl 8q
lJ 9c

"rie Jd;
_-.&sl

\pfl

_iH

(U

L!

T.

o
(!

o o
6
3

o
N

q
a.

t!

:)

(-i
o_

z
f
G
I

cc

O
F

o
U
z
z
o
O

ooooo oo ooo oo ooooooooo oooooo ooo

oo

cc

l-J-l

oooooooooooooooooooooooooooo

-J
F
F

co

c
f

C)

,a
r\
X
@

cc

O
F
O

z.
c)
O

a
c(f,
o
oo
,a
(E

U
G

oooooooooooooooooooooooooooooooo
oooooooooooooooooooooooooooooooo

:tlI
JBI

OJ

{d{

6S868 i8E 6 It-

cg
t

(U

= ;99r9

iEc
:== 6c

E.

lq

trj
O
o

lJr t

o_

88868 r86

o
3

fi9

"

;i

a
O

=!9r9

BBsS$.

s;ssrxcr 6UffI.

(l'll

U
J
=
o
o
E

o:

F
(E
E
ts

O
a
N
X

I
r

c
F

=
F
O
a

+ + ++

x
o
N

;FEE

ofl

fJ*$=l
6u868888
g

=1"t-d

6ts888

-uo^.

u{

Eq.;h
l.

z z

Y'

68889U 86

6
N

J
F

=6

Et

=[ -..---.-

trJ

lc
.==e 6c

(U

.c.

+++ +

]4

a
E

88.

.L

,a

ac

l'

'8ti 8IJ bE iE

;l:
f"

5aa8E r8&

arI
tl

OJ

o_

ffi
\l

6l
<l
rrl

(J

LL

o. o
l G

o
c!

o
4

Q':

fftr+
68888 r88

sl|6tffie6$t
4
---.--^I

t:-----*-.

OJ

.6

(9

LJ

of
I

CJ

o-

z
3
I

(E

a
E
I]l
-J
F
F

TRT

c
U
F
F
U
E

C
U

cGz.

U
O
U
f

F
I

U
J
U

c
=

pc

U
J
U

g$

c
=

BB g*o

t*"
36

iF+

z.
o

L-r

ES

F
c
O

z.

=
=
=
o

E{
&s

s
dEld
)o

-m
-

9@

r$

i--i*
aE!

a
J
G
O
F
C
O

El
-l

ll

!l

d1

N
a

o_

lz.
lH
ll

o o
f

t:

Ir

l:

E; 4;

E8

ts

aa*e+
0eB3i

z.
I

U
C

o
z.t
-Uj
o a'---v
CL

|<--1r-+*

Hllff
oooooo
$l
O-

IAB F-rnbedded Workbench.

i:'.

'

TuroRrAL

ri

t'

tl.

This tutorial illustrates how you might use the Embedded Workbench to
develop a simple C program, compile it, and run it using the C-SPY
debu$gier.

Have installed the Embedded workbench software, as described in


the QuickStart Card or the chapter Installation and documentation.

Be familiar

'

with the architecture and instruction set of the

PlCmicro'" microcontrollers.

USING C-SPY
This tutorial assumes that you are using the C-Spy debugger with the
Embedded Workbench, and describes how to use C-Spy to run the
programs you are developing. If your installation does not include c-spy,
you can use the Embedded workbench editor to examine the listing files.

GBrrrNc

STARTED

The

fi1es you are working on in the Embedded workbench are orga,,.ized..


into projects.

We recommend that you create a directory where you keep the project
In this tutorial we assume that there is a directory called pro j ects

fi1es.

on the

c:

drive.

Copy the files tutor . c, tutor. h, common . c, and common . h that are
provided in the i a r\ewnn\pi cmi cro\i ccpi c\tutor directory to
c: \projects\.

The first step in using the Embedded Workbench is to create a new


project, to specify which target processor you are working on, and to
include a list of the fi1es contained in the project.

J'l

-"r#{t
:':". lif

Gprrrlrc srAR'rED

TuroRr,,rr,

RUNNING TTIE EMBEDDED WORKBENCH


click the start button in the taskbar, tiren

clicl<

progranrs ancl IAI{

Embedded Workbench.
r.el Access*bs

t,\
,,.J

Ld

Qewwns

:
ryd, lottings

'$

a
rr:,

eppf*q"

l'fHGEmmEEmmil g
fid

ran c.ser

Mk o$dtlooh

{3 sr"itup

::

. ffi

Ms.oos noms

. liif

Windows Exphrer

Ewr...

qp

Then click the IAR Ernbedded Workbe,ch pro{ralu ico,, aud


Embedded Worl<bench window will be displayed.

CRBATING A NBU/ PROJECT


Create a project for the tutorial as follows.

choose New... frorn the File nrenu to display the 1trllorving clialog box:

Select

22

Project and choose OK to display the Nerv Project dialog box.

Gnmruc

STARTED

Enter Demo irr the Project Filename box, and set the Targiet CPU
Family to PIC:

l,ocate thr: r.lilectory rvhere you want to store your project. In this exampie
lve choosc c: \projects. Tl'ren choosc OK tcl create the newproject.

The Project u,inrlow willbe displayed. Nlake sure that Debugi is selected
frorn the 'fargcts clrop-clo'"vn list box:

A directory structure is created in the project direclory, with separate


directories for executable files, list files, and object fiies:

t3 Debus
i{J
rlJ
;.-.
,14

Exe
Lict

ilbi

23

Iuroxlal

GETTING STARTEr)

Chc,cise

Files... {roin the Project nrenu to displal,the Pro.ject liiles

dialogbox. Locate the files

tutor.

c and cornmon . c irr the file selectiorr list

in the upper half of the dialog box, and choose Add to adcl thern to the
nerv project:

Lis{ Fibt d Type:


l-lCsourceFres['.c) _]

Dtivee:

Ie.,l,tlDos--=

Add lo Gro(.q].

f*..--l
I-dPS

n br6r-d

\Projects\COMM0N C
C:\Froiects\IUT0B.C
C

Then click Done to close the Project Files dialog box.


Click the E] s.ymbol to display the files in the Project v,,irldow tree display:
il
i

I
;

Since rve did not create any group in our project the Embeddecl
\\/orkbench created the default group Cornrnon Sources.

You can add fiies to a project at a later date, or relnove files, using the
Files... crlmrnand on the Project menu.

24

..1

GBmrNc STARTED

EDITING A FILB
To edit one of the fiIes in a project you simply double-click its name in the
Project window. For example, double-click the frle tutor. c. The file is

displayed in an editor window:


lFtttt,tr

; tUl Xt
:l

,/,

progru tor tutorT.


Pyints the Fibohacci nubers,

Mai:n

void main (void)


{

Dal-I_count=r.r;

init-filc(},
white

call*court

< I,4AX_PIB

_t

tfz

I
1

Note that the Embedded Workbench editor provides a number of useful


features to help you enter programs correctly, and to provide immediate
syntax checking as you type.

ii

For example, the following components of a program are identified:

ii

Item

Highlisht

Keyword

Black bold

Text string

Blue

Preprocessor directives

Green

Numeric constants

Red/magenta/hlue

Comments

Dark blue italics

Other program
constructions

Black

You can configure these.settings; for more


Fonts,page 71.

information

see Colors

and

i'::,,
?-_;r

will

erior into the program so that we


can see the error handling features provided by the Embedded
We

use the editor to introduce an

Workbench.

! ';'*-i

{.

:,}

"

Couprr,txc rHE rRoJECT

TuroRrer.

changethe

put fib( fib ) online zzto put--fib( fibb ) a,cl sa'e

the file by choosing Save front the File menu.

Co*rprr,rNc THE

SETTING COMPILER OPTIONS

PROJECT

The Embedded workbench allows you to set options for the q,hole target,
for a group of files, or for a single source file.

will set options for the whole Debug target,as rve do


not need individual optio,s for the groups or files in the target.
For this tutorial we

select the Debug folder icon in the project window, to specify which
options are to be set, and choose options... frorn the project nre1lu.
.,-Qflicri,,;,
'.:a*-:*-''':;

i,,,:goroih,

'1
,i

Maks

i' . BuddAl

I,

.9-t;;i,l'.t

'',,

1,.i

'

Alternatively, click the right mouse button on trre Debug folder ancl
Options... from the pop-up menu.

choose

'1'

'

'

laveAs Iert.,.

The options dialog box is displayed. Then seiect General i, the


categlory list and click the Target tab to display the target options for the
Ernbedded Workbench tools:

Set the Processor setup file to 1-704l by selecting the fi1e 17c43. i 39
in the . . . \setup\ directory. Then select the Higih-end (16 bit)
processor.

26

,-i

C0MPILING THE PROJECT

Next select ICCPIC in the Cate$ory list to display the pages of


C compiler options:

You can ciisplav any page by clicking the appropriate tab at the top of the
page.

ii

TUTORIAL

Couprr,Ixc rHE PRo.IEcr

Click Output to display the C compiler options and che ck tltat Generate
debug information is selected, to create an outpttt filc fbr debu$$in$

with

C-SPY:

Choose

OK to save the options you have specified.

COMPILING A FILE
To compile a source fi1e you are editirtg choose Compile from the Project
menu, or click the Compile button in the toolbar.
You can also compile a source fi1e by selecting
and choosing Compile.

it in the Project windon'

LIruxruc rHE rRoJECT

The progress, and any error messages, rvill be displayed in the Messages
rr,indow:

e,aa I n

a in

re*

l,

i.od 0ue"r I

Compiling lrle TUTOB C...


TU TOR-C

c:\poiects\tu(or.c {22} : Erorl100l: Undeclared identrlier:'fibb'


Total number ol erors: 1
Total rumber of warnings: 0

Here there is one error corresponding to the bug we inserted.


Double-ciick the error message in the Messagies window. The crrrsor will
in the progiram anrl you can
simply correct the error.
be rnoved directly to tlie appropriate line

For exar.nple, in this case change put_f i

put fib( fib ).

b(

fi

bb ) to the correct

versiorr

Then recorrrpile as clescrihed earlier. It should compile this time without


an error, and you can then close the tutor. c source file by choosing
Close from the File rnenu.
Compile the file common

c in the same way.

The object files are created in the project's debug\obj subdirectory.

Before linking the program you need to set up the linker options for the

project.

SETTING THE LINKER OPTIONS


select the Debug folder in the Project window. Then choose options...
from the Project menu, and select XLrNK in the categlory list to display
the linker option pages.

29

LrrLrsc l'IiE rR.oJECT


I'L,.t'onta l.

View the options


set to Debug

tvith

ol

the Output page. Check that the For.nrat option is


to gt:nerate a {ile lix.tlebugfling

info with terminal I/A,

C-SPY.

C Plu*lxol;r1.. ., ,,1-.

tr

0eh4 irfo iqiih termltl l,O


: ::' :
g*wia,',: '''

'"i!iii,.rir.rt

riti:

Id*.L"rS lr.rtr,;ii

'I'lte. r;liorsc oK to close thc irralog


box a,rr s..l\/c yollr-settirrgs.

LINKINGTHE FIT,ES
To link the project choose Link from the project
ill.,nu. The filc-s rvill
thcn bc linked, a,d the .vlessagies window u'iil sho*, pr.ogress
clrrririg

linking:

Providing ther.e ."1,'ere no err-ors, the output file demo.


d39
gieuerated for usi: rvith tlrc C-SI-'y Sirrrulalor.

3t)

lzz'2.s9

will

be

S-ar putea să vă placă și