Documente Academic
Documente Profesional
Documente Cultură
::L:f:' ifigr*.irit
tI;,,.'
-1
il
-- ,,,,: . .: ,; .
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.
v#906 197-22
82-2-2'!tlg*$SfiS-7
Fax. BZ-Z*?"109*5968
www.ruir!aseng.com
f--rnfi
Notice
@ CopyriEht 2007 Midas engineering
for
repair.
is
available
for
assistance. T'his
. Tel. 82-2-2709-5964-7
Fax. 82-2-2109-5969
. http
PART
a
a
1.
Introduction
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
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
""""""'
" 124
'124
"""""""
3-B-3. Ii/rCP3202 (Serial A,{) converter) """"""'
3-B-4. AD7302 (DlA converter) """""'
Motor Experiment.
""""""'
motor
140
"""""""
146
""'160
"""""""""
160
matrix
32X16 dot matrix animation
"""""""""'163
""""""""'" 167
"""""""""'171
"'"""'""" 116
"""""""" i79
""""'
""'184
t36
""""'146
"".-"""" 149
"""""'154
3-9-3. RC
131
"""""'"'
Infra-Red
3-11-5. Optical fiber """""'
3-11,-6. Wireless
3-71-4.
WinPIC-2 Schematic.
"""""'iB4
"""'"" 190
""" 196
""""" 200
"""""" 203
"""""'2A6
l.
lrttlrlrlrrt'tion.
:::::::-:
1. ImtrductiEx,"s*
Thc I\4DA-WinPl('-f kit is
siro,,r
r] in
F'ig.
-c-
l-1
I,i!1.
I-
corrtlirr:;
6F,877 rn icrocrlllpLltcl'.
N4IIA-WinPtC-l Kii
lt'
rlrl,.ii;iillrr
r!g..r.or1r
1.
trntroduction.
@ A/D Converter :
The analog
WinPIC-2 Trainer.
the
@ DIA
Converter
WinPIC-2 Trainer.
experiment.
driver circuit
of RC motor
It
oc
@ srnp
Motor
: It
to
control
optical communication
communication experiment.
i'
sensor experimenr.
rn.r.',
*!.I-^^--
l.
Intooduction.
Port Cable)
l2-
(AC Cable)
www.rnidaseng.c0!n
2. Nlicom
Pmgr:uruncr.
MDA-PROGRAMMER
is
rhe MDA-WinPIC-}
operated when
is
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
lndicati*rr,ofthe'srlerred Flle$lli,,,,,,
li rhe \{iriPIC-t is nor c0nr}e('leri u'irh rhe pe
j,
.:,:
t4
wwr,v"nridaseilg.com
2. N{icom i\*gnrmrner.
because the
properly.
%"*-.***--..,....
thefollowingthinqs[fiftbetlorreinrhi5.66;*'.
,i lf lVinPlC-2 is connecrerl with rl,e nrlniei -'
port of rhe PC rhrouqh rr'* pururi*i rabte ijlpi,
-
"
l6
wrv ry.
lr ri tlase ng, co
2. I\{icom
Programmer.
!P?!.j
<Fig. 2-5>.
The file to be written in the order suggested in <Fig. 2-5> is
read.
Exit.with,,a *ficlr;
-18-
www.midaseng.com
2. Micom [tugrammer.
ffii
Opt ionl
the
uP
f* ::' a
i p'0| 6F877
ii
-20
rvww.midaseng.com
the
it
is
2. i\{icom l\ogrirmmer:
Blnnk [.he,:k
i;li!
Fr,-rgtam *f,!
Verifi,::ati*n i:lt,!
l{iri{ r: i*'Crid*dno,.
Thc error message
shouid disappear.
22
www.rnidaseng.com
ended.
l--.
Bl.rnk
fkck
ank
Clicking
the shortcut
of MICOM
is displayed as
ffi$uflsr
ank
contents
it
possible
in <Fig. 2-10>.
,,
ilhrrk iliil
l/crificotian ONi
Confisutation Fuse Frogtanr Oli!
Blank Check En,rtl
Chin arjilres! I tli:l[]0 Vaiue I u[rli"t
MDA-WinPIC-2 MANUAL
-23
2. &liconr
Programmer.
2-8. kfanual
In
"Erase
case
Write Erase
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
24
*'ww,midaseng.com
done.
:-[
2-9. Manual
Write
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
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.
-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
Progranl
IS
"\'erifr"'.
MICOM correctly like <Fig. 2-14>. lt is so called
rificatic'n Dl(l
MICOM
FIC
I6FBI/
PrLrSranr"
MllA-WinPIC'2 MANUAL
'i
27
2. Micom Pmgnurrmen
2-\L" Manual
Write
OPtion
'the
the
not
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
,rrrisi r*tv1
utdou
#;;=-:l
'? Click and do
.l 6 i
"
ia't.ibln,rr{o1d'1irri.!e"
Configuration Word"
www.midaseng.com
up,
<lown,
the computer
of
thc
mouse'
"led1.hex".
: Blu:
i
i
$$$,
Ss'/e
! lq-nqqra
u'ls',Hlid"
elet*ir$tril1
x 3iry.*,
r'r
f:
!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.
; click
'
3F'--:.*--*
MI),d-14iiBPIC-2 MANTJAI
data'
-29
2. Micom
Frogrammer.
Save
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
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.
..
-30-
www.midaseng.com
done.
are
l-l{.
Reload IIlc
reloaded easily.
I
\
L"
,
MDA-WinPIC-2 MANUAL
3l-
2. Micom hogrammer,
:ii{,
_ii
i
i
l
,i
l
CIirk:'lYes{T}'i
HrcsM
i:il FlCI6Ffi77
.}r"
j'
.:r.
.
,.it..i..
'i
{:iY:
32
www.midaseng.com
=i;i:I,it
.s*.*,$i
pops up
communication.
MDA-WinPIC-2 MANUAL
33
2. I\'Iicom
Programmen
<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,,.
Inirialilati0n
".
I FICI$FT??
If
qial u,iu'lulln',Eresel_
,siffiloi
i${j>l
I
j
tsj-q:"
I
t
::.... .:|:..:.., ...::... .:
s!6nkl 'r,rilel-\'grtri
_B_1_3:,..1.-tU_,
Standard HEX
..:.
Sr
ite
C*u*t
wwlv.rnidaseng.com
Jrar
l*tc0M
il'
I PrCr6FS77
of the Serial
Port.
:
Inu 1$ir, ,il
I{ it
MICOM
to do
-"'l
cran d0 data conrmunication With th.
Cu
':
il:
l-14>.
iiilffil
qrr!fiillll3,
r'-'
t\{I}A-WinPIC-2 ['L{I{UAL
Ir)11.
35
2. Micom
Programmer.
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
*$, 5
s,[{}$t
.{ft e
;i}fl
d {,*!
r.$6"rl$i
u,{i1
. ptirsunat
*r**'4$1{.q:g
f 0nipUrtr
. ff1$$.$
fgin
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
If
{)rite
.
Count
3FFF
to
dr-r
it
aOartt.
] o'.'*u,
r^ig. 2-26 The Screen
in
case
the
prirtter port
MDA-WInPIC-2 NIANUAL
37-
2. Micom
Programmer,
re
Test
is
operating like
to
inspect
sure
to
acknowledge the
*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
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
38
www.mi.laseng"com
in <Fig. 2-28>.
\.N-\\N.N
ffilB1
save
oo31
lu'lrylu,. I lxri>1
Brnll t{ritelverilj erasel ]optiml
u,
-t
Eqt
q*_l
nutg,l
Slandard
{- coM t
Cancel
i
I
tvllCOM
...
::
Plcr 6F877
I
il
I
{
N{I}A-WinI{C-2 MANUAL
39
2. Micom Pmgrammer,
::-
fi'lw
Elanli tllr'lte
I9eril
Program
,ux,
Eiosli
{.r
at
Bpti
I r. _ 1;
$.e!'ng.writteal.ttt:lttie;,wiiiiF:rc;r....
i
-40-
www.midaseng.com
the
2- I
7.
In.spect
l\{lC(}1l-lptnl
and thc
*'itlt
Exit
r-"
a click
i,ary
I
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
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
{}
int i)
whi
le (i--);
/i
Shift Left
if(tenP == 0xff)
{ tenp = Oxfe.i
return, ).
etse
'
i
= (tene (( t)loxot;
(tenp
- 0xff) terp = Oxfe;
ienp
if
)
oe
ay
(0oooo)
i/
Shift
Risht
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
do{
PORTB
if
tenp;
(RAo) sHIrTL0;
else if (R l) sutrrnl;;
e lse terriP = Oxf f
;.
)while(t);
-45-
3.
Experiment
,,,
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
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
(i otorall' rr)
l" DelaY
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
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
-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*
#include (iot6ralz. n)
//
[tqrN
void main(void)
{
unsigned char
ADC0NI
ternp;
= 0x0f,
0xl7i //
TRISE
TRISB
= 0x00i
PSP mode
oo{
write
)while(l);
)
rs.'
i,J : .i'
.
."$
;:.
li'
www.midaseng.com
r:
circuit
Diagram
mg-ms lk
rR8-rBs 2SflAlS
TSEGHENT
*fr'
r]o
rfr,
q5 "L3.,,1..,
{#".,
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
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
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,
0xfe,
void
SES,IENT
(void)
P0ilTD
P0RTC
= SEc[ternp] ;
= DIGITlterp];
//
tenp++;
//
tenp
do{
bounce = P0RTB;
= 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-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
l"td"lt*
P",tD -l
Initialize PortB
Chatterin&/Bounce
Eruble i
Select the
first column
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
*!p
Program
//
"o
- F"
id
vo
SES4ENT (vo
id)
{
i
:!
PORTD
= SEGIdigir0];
P0RTC
0xfe;
// Segnent
// Dilit
//
nterrupt void
RB_tNT(void)
= PgPrU '
Bouncelchatter ing
doi
bounce =
P0RTB:
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
setting input
0xBB;
digit0 = 0x00;
do{
sEcMEM0;
'
P0RTB
asm
if
= 0xfe,
("SLefP");
//
Steep nnde
ll'0'
/l 'q'
MDA-WinPIC-2 I\,IANUAL
57
3. Experiment
else
else
if
if
ll
ll
'S'
a_"
.:::.
'C'
)while(1);
i;,:::
i.::t;
-58-
www.midaseng.com
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
Select segment
X4-X7
if
Delay
Counter
-60
www.midaseng.com
[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---
--:-
)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
,l_.-
P:- -6|,,n,"r=i,l--=
Retum
MDA-IVinPIC-2 MANUAL
-61
3.
Experiment
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)
#
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
,!&-
**.
COUNTI;
unsigned char
COUNT2;
unsigned char
TEMP;
unsigned char
STATE;
unsigned char
FUNCT,
unsigned char
ADDRO;
unsigned char
ADDRI;
unsigned char
EDATA,
//
Segrrcnt format
for '0'-'F'
lnternal
Code
for '0' -
F'
Delay
while(i--);
)
//
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
Oi
TEMP
))= l;
KEY++;
l//kFoR
KR0W
((=1;
KROW
l=6131'
if
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;
i++)1
.*i".f!
do{
scANl
0;
do{
SCANI
0;
:?'
CODEIKEY]:
void
HEXTSEG0
DtsP[o] = sEG[(noono
DISPII] =
DtsP[2] =
DrsP[3] =
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
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
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,
//
EER0M
data read
void READ(void)
{
//
EEPGD = 0;
//
RD = 1:
/l
EDATA = EEDATA; //
EEADR
= ADDRI;
/l
ltain
void main(void)
i
TRISD
TRISC
= 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
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
__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
finclude (iot0rglZ. n)
uns
i:,. ,i:i!j r
msgl
ll finerl
,,'
,1
interrupt
.):
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
256
www.midaseng.com
r:
!E
3-3.'fiurer ExperirnenL
ItlR0 = 0x00,
= l;
L_tNlr0;
T0lE
DtSPLAY0;
on_buf = 0x07;
sec
GIE
= 16;
= l;
Il256x256xl6xl[Ps] =
//
Enable al
sec.
unmasked interrupts.
ao{
flag = g'
ll
while(!flag); /
on_buf
CM,IAND (on_buf
ll
LCD 0N/0FF
lwhile(l);
MDA-WinPIC-2 MANUAL
-69-
3. Experiment
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
#inctude (iot0fgzz. h)
unsigned char pulse, flag;
"
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
OPT|ON
= 0xb8;
MDA-lYinl'IC-2 MAI{UAL
71
3. Experiment
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
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,,:..,,..'.,,,.,....,
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
#include (iot6razz. n)
unsigned char count, anlm, animc, flag;
[]=" Tirnerl
Const unsigned char msg2[]=" Animation ! !
const unsigned char
"
msgl
"
i
,
msg4[]="
const unsi gned char hangle[]= {0xl f, 0xl l, 0xl l, 0xl t, Oxl l,
Oxl l, Oxl
l, 0xl f,
0x0e,0xl I,Oxl
f,
l,0xl
1,0x1 1,0x00,0x00,0x1
);
const unsigned char formf]= {' o',
#include "1CI8.
h"
//
_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''
//
i++) CHnn_o(ox2o);
'
animation
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
CG
RAM
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.
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
t_
t --lryqiqyr, l
/
.\
-<_
Wait intemrpt
[-
upo.t.-cr,.r.
ui.prry
I
I
I
r-co
_
_-
J
.l
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
msgl[]=" Tinrerl
"
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++;
l/
10?
ll
6?
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 ;
..
l/
10?
j:
!l:l
:l
hour++,
l/
20-23
else{
//
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
circuit Diagram
BOO-ROS IK
IH0-IRS 2S8t8tS
as'fi;
--"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
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
//
//
= 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
Point = 0,
digit = 0xdf,
PEIE = GIE
=L
white(t);
lli4R20N
= l;
lirer2
MDA-WinPIC-2 MANUAL
83
3.
Experiment
3-4.
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
How to conliect
"s
.jurnper
PIC Port
n\
RCO
SPK
RC1
B'U
RC2
MEL
OSC1,2
4lltlh
-L
Program
"}p
$
# i nc
//
WinPIC-2
ude ( i ol 6f877. h)
ltain
void main(void)
{
unsigned char
TRISC
RCO
i,j;
//
//
= Oxfe;
=l,
// tirerl prescale
output
= 0,
TltlRlH=llvlRll=0;
TIC0N
CCPICON
T1,1RI0N
//
//
= 0x0b;
= l;
Ccrnpare nnde
Enable tinrerl
do{
i++){
I 4s,ol1t)12
ccPRlH
CCPRIL
for(.1=g'
CCP1
B;
I (Zq;
j++){
lF = 0;
l//
/
^=
0x0l;
a9ol{,l
zzolu,112
ccPRlH
))
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
= l;
ccPRrH
))
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
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
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
I
'iit,
unsigned
int
tenp2, tenpl;
msgl
[]="
!";
PR2:00"
ms$4[]={'
www.midaseng.com
'
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
//
count--',
//
count
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
//
tempZ-tenrpt
terp2= tenp2-tenpl
CcrNtrlapp
16*Or;
CHAR_0(ASCTst-[(te'rp2
CHAR_O(ASCTBLI(tenp2
)) a) a 0x000f]);
)) +) a 0x000f]);
CHAR_0(ASCTst_[(tenp2
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
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
I/
= 0i
ItlRlH=Tl'4RlL=0;
TIC0N
L_rNtT0;
fonl
(i=o;
for
i ( ao; i++){
Load
C0maax91'
CHAR_O(hangteIi]);
I
DTSPLAY0;
DrsP_ccPRlL0,
DtsP-PR20;
/
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
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
Fiow Chart
--__l
--=\
"X4"
----l
----...------''-r--..-----...-
'X5"
--a- -.-...-.-//
./ ,',=-'--{=
"x6* ?
?
[Stq
-<:-' --;tu=-=="X7" ?
r-g;u
rMRlrF
\-----'----l
Reurn
trom inienupt
lno
n.i
,,Y#
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
93
3.
Experinrent
Program
::t
'i3
c \trDAUi np
r
c2\exap I e\c\DC. C
t.'. A
finclude (iot0tazu. n)
fdefine
*define
DCS
RCz
SPD M4
//
//
ll
//
Enabte
bit
:1, ts
Direction
Pli/fi|
:;itr' -.
'. ,'.
Speed
"DC Motor
Control",
369 11r"'
'.
";
";
const char msg4[] =
"0123456789A8C0EF";
const char ASCTBL|I =
H Period
"Speed: 0000 rps
'l
.'!''
h1
ni ti at i ze LCD nndu
i++;1
do{
keV =
PgP"'
do{
keY =
P0RTB;
:0xf0)i
void
SPEED_DISP(void)
msd=lsd=0;
msd = speed/100;
tenp = speedlO0;
lsd = tffp/lO;
lsd ((= 4;
116 = ((tep%to) & oxor)
94
'.
-r*.
tsd;
www.midaseng.com
:..::l'
(0xd7)
C0,tvlAND
CHAR_o(((msd
)) 4) & 0x0f)+0x30);
CHAR_o(((rsd
)) 4) & ox0f)+ox:o);
COtui',1AND
I
/
lnlerrupt vecter
l/
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;
//
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)
{
= 0;
TRISB=TRISA=0xff;
TRISC
//
ll
= 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
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
'
= 0;
INTC0N
= 0;
Il,lRlON
= 0;
IIv1R20N
= 0,
else
DCE
if
= I;
INIC0N = 0xe0,
=
T}1R20N =
]},1RION
96
1i
1;
+vrvrv.mirlaseng.com
output
i
else
if
CCPRI
L++;
Itrv0;
)
if
else
)while(l);
MDA-WinPIC-2 MANUAL
-97
3. Experiment
\&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
cr5
F39
5tK
l9uF
cr3
R28
5tk
R?9
5ll
Lms$l
Sperconduct ivi
www.midaseng.corn
ty
Cbnverter ExpcrinrenL
Flow Chart
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
ANO
fiinclude "LCDBB.h"
// lnterrupt vector
ll
0.000[V]
tnitialize
LCD rnodu
le
//
_i
= (nonrsu (( B) |
f lag = l;
temp
ADRESL;
ADIF = 0;
)
void V0LT(void)
{
uns i gned
char
bcdh, bcd I ;
= temp )) to;
bcdh ((= 4'
bcdh
*=
10,
bcdh
l=
tenp
/l ta'' xl0
))
l0;
tenp 6= 0x03ff;
tenP *=
l0;
/l
))
bcdl = tenp
bcdl ((= 4'
tarP
xl0
to;
*=
l0;
bcdl l= tenp
//
tenp
I0
)) lO;
C0![4AND(0Xd7);
CHAR_0((bcdh
cHAR_o('
100
. ')
))
a)+oxgo)
www.rnidaseng.com
))
a)*ox:o)
(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;
//
f lag = 6'
te(!ftas);
volr0;
whi
DELAY(30000);
lwhile(t);
MDA-WinPIC-2 wIANUAL
- 101
3. Experiment
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
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
if
)
else
if
on_buf
if
(state == l){
(on_buf
))=
I) | OxgO;
else
PORTB
if
= 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
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
MDA-WinPIC-2 MANUAL
-105 -
3.
Experimenl
'
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:?
lno _---*---_.-
Synchronous mode
Enable Serial port
-106
ves
t-Bqt*--t
www.midaseng.com
Trarsmit
I'
ti
ti
t:
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
*include (iol6fB77. h)
//
Transmit routine
= l;
RC2
TXREG
TXEN
data;
//
Transmit
= li
whi te(!TRMT);
TXEN
RC2
= 0,
= 0,
//
Receive routine
RCO=l
RCO
= 0;
RCO
RCI
= 0;
RCIF
li
= 0,
=
TXEN =
SREN
l;
1,
//
//
//
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)
{
= 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
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
Scan Key
buffer.
Set Data
Setup cumor on "Address".
.J
t-!q!qiqqr4:-l
__t_
I s.trp SSPCON ]
't*ryqlryt*'_
I cq:\
(
-ilO
Return
wwrv,midaseng.com
)
),
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
Prograrn
ire#
...J
c : \trtDAUyinp ic2\exanp
le\c\spt. c
#inctude (iotOtgzz. n)
unsigned int ADDR:
unsigned char
uns
EEDT:
unsigned char
uns i gned cha
FLAG,
unsigned char
FUlrlCT ,
STATE;
/"',
//
h"
"KSCANI.
h"
"LCD8.
/l
/I
tnitiat ized
LCD Modute
ix
function x/
lnitial ize Spt
SPI
void S_tNtT(void)
{
RC2 =0:
SSPSTAT
SSPCON
0xC0;
0x20i
/
//
/
S,rP=|,
CKE=I
//
Standby
doi
= send;
)while(!er);
return (SSRnUr.) ;
SSPBUF
//
Transmi t
//
Read byte
void
EEREAD(void)
'
=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
=l;
RC2
temp2 = WAITBF(0x26):
temp2 =
/l
l#ATTBF(0x00);
RC2 =0;
//
Transmit address
RC2 =1;
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
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
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,
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
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
';
Flow
Chart
-_--:
Initialize pORT
:
f-G;**,"",,..r1
r!I.. )
(___m,r,*
::
:1
t,
on LCD.
--\
Cusor "Data ?
rt
nO
))>-)
addre^rs
buffer
Setup "Data"
tr
' ---- rl
I
ri
I
address buffer -
Setuo "Dara"
MDA-WinPIC-2 MANUAL
-Lt1
3.
Experiment
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
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
le\c\
2c. c
finclude (iotGtalz. n)
int
unsigned
ADDR;
unsigned char
EEDT;
unsigned char
KEY, KEY2,
unsigned char
FLAG;
STATE;
!!
";
h"
"KSCANI. h"
#include
/*
SPI Functions
"
'
ASCTBL[]="6123456789A8CDEF"
"LCDB.
f include
0000 00
*/
void S_lNlT(void)
{
SSPC0N
SSPSTAT
SSpADD
0x28; //
= 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
Transmi t
send)
{
SSPBUF
= send;
whi te(R);
if (ACKSTAT == t) s_rrurr(),
)
//
Receive
= 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)
{
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 =
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);
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
1;
www.midaseng.com
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
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
How to connect
umper
MDA-WinPIC-2 MANUAL
-125
prirncnt
3. Experiment
Program
^$
.J
c'
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
";
const unsigned char msgl[]=" Calendar/Clock
";
const unsigned char msg3ll=" 2000,00,00,SUN
* i nc I ude " LCD8. h"
unsigned char
RST
buffl,
'
1;
= 0,
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 );
)
-126
www.midaseng.com
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;
))=
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)
(0x88, MoNTH)
l{RtTE(0x8a, DAY);
[RtTE(0x8c, YEAR);
)
void DISP_CAL(void)
{
COf'tvtAND
(0x93)
))
C0Mv|AND(0x96)
))
+) a oxor) + 0x30)
& 0x0f) + 0x30);
CHAR_0(((M0NIH
CHAR_0((M0NTH
(0x99)
CC[,14AND
CHAR_0(((DATE
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
"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
//
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
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
#
fdef
ne l_0
RCO
#define CLK
fdefine RST
RCl
RC2
msgl[]=" Digital
uns
finclude
void
(-)
Tenp.
"',
!!
";
DSl620 ";
"
"LCD8. h"
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
TRISC
char
data, data I ;
i,
= 0x0t;
data = 0;
datal = I;
CLK
if(l_0
==
= I;
datal ((=
I ) data f= datat;
CLK
)
TRISC
= 0x00;
return data,
)
voi
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
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
= 0x00;
TRISC
RST
= 0;
CLK
= 0,
l_0 = l,
L_tNtT0,
DtSPLAY0;
for
CCInvqPl6uru
CHAR_0
oxao);
whi
le(l)
RST
= 0,
RST
= l;
SEND(0xac)
data = RECEIVE0;
RST
= 0,
SEND(0x03);
RST
= 0,
RST
-134
= l,
www.rnidaseng.com
= 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
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
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
AD-H, AD-L;
uns igned
const
char
msgl
[]="
l'1CP3202
msg3[]="
SPI
const
ADC
!!
"
rnode
0.000 [V]"
"LCD8. h"
fincIude
void S-lNlT(void)
{
RC2
= l;
SSPSTAT
//
//
0xC0;
= 0x20;
SSPC0N
SMP
=1,
CKE=I
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;
tenp
(AD_H
(( a) I nn-l;
= tenp
bcdh ((= 4;
bcdh
))
12;
-138
www.mi<lirseng.com
bcdh
l=
))
tenp
tz;
*= 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)
',);
))
+)+ox:o)
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
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
,Bs
{*iw
Flow Chart
f---:qsrl-l
I
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
*include (iot0ta;2. n)
ine
DtrYR
RC6
#define
DM
RC7
fdefine ADS
RC2
iidef
unsigned char
AD_H, AD_L;
-t42
AD7302 DAC
!!
";
wryw.midaseng.com
CHO
6"000 lV]";
CHO
I node,
9.000 [Vl";
ADS
=l;
SSPSTAT
SSPC0N
0xC0;
= 0x20;
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;
= tenrp ))
bcdh ((= 4
bcdh
tZ;
ternp g= Ox0fff,
tenP x= l0;
*=
0;
MDA-WinPIC-2 I{.ANUAL
- 1,13 -
3.
Experiment
))
bcdl = temp
bcdl ((= 4'
temp S=
t2;
Ox0fff;
CHAR_0('.')
))
a)+oxso)
))
+)+oxao)
'
CSrIrlaXp1g*.0;
)
unsigned
uns
int
temp;
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;
terP *= l0;
bcdh l= tenp ))
A;
terP *= l0;
bcdl = tetrp
bcdl ((= 4'
-114
))
g;
tid
www.midaseng.com
*=
1g'
l=
ternp
bcd
))
'
COlvtvl,tXP1O*.r,
CHAR_o((bcdh
cHAR_o(',. ',)
S;
))
q)*ox:o)
))
+)+oxso)
(0xe0)
//
tlain
void main(void)
{
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
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_
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
PHASED[8]
unsigned char
i;
= 0x00;
L_tNtT0;
TRISB
//
-l
B by clearing output
DISPLAY0;
do{
i++)1
PHASEDIi];
DELAY(6000);
I
lwhi
-r48
le(l);
wrvw"nridaseng.com
';t'r':
3-9. l\Iotor
Ex;rerinre nt
*#
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,.
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
-
_--
and Display
and Display
_l
C"+
it on LCt)
,o
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
Program
PHASED[B]
char
gned
PORTC
= 0x0f;
i++)1
do{
= PORTC;
)whi te((key & 0x0f) t= 0x0f);
keY
do{
keY =
PORTC'
= Oxff;
void LEFT45(void)
{
= pHASED[step];
l\{DA-WinPIC-2 MANUAL
- 151
3. Ilxperiment
tep--
)whi le(count2--);
)
void LEFT9O(void)
{
C0!la4PP16*oo;
(0xd0)
i++)
CHAR_0(SpACE_DIi]);
i++) CHAR_o(L_90M[i]),
step = 7;
do{
= pHASED[step];
step--;
P0RTB
)whi le(count2--):
)
void RlGHT45(void)
{
uns igned
C0uvlAND(oxdo);
i++)
CHAR_o(SpACE_DIi]);
cOm,lANp16roo;'
i++) CHAR_o(R_45M[i]);
count2 = 50i
step
=0;
do{
P0RTB
S
= pHASED[step];
l'l'j.{,..,
'i,i'
teP++;
t:f,
li**
)whi le(count2--):
)
vo
id
'']il;
$:
i!4
c0+,lAlo1gra,r
_l(,
'
www.midaseng.com
;++)
CHAR_o(spACE_DIi]):
C(M,IAND(0xd0);
count2
;++) cunn_0(R_gotvlIi]);
100;
cton:O'
do{
PORTB
s
= pHASED[step];
teP++,
)whi le(count2--);
)
//
lt'ain
void main(void)
{
TRISB
= 0x00;
// lnitialize port B by
clearing output
= 0x0f;
L_tNtT0;
TRISC
DtSPLAY0;
do{
SCAN0;
if
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
i
....-----__LnO
-.l..8..
n"" i Move RC lnotor needle
,.i
keur
;._;;."
1,,;.;fi
.- .'....--
..--.-=-.-==-----/"
- 154
wwrv.mitlinseng.com
RESET
-_l_-
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
"
"
Rennte Rontrol!,,;
const char
="
flag;
SPACE_DU
,,
,
gned
char
MDA-WinPIC-2 Ir{ANUAI.
- 155
3.
Experiment
= 0x8f,
P0RTC
i++)
do{
= P6O"'
)whi le((key & 0x0f) l= 0x0f);
keY
do{
keY = P6Pf''
= 0xff,
//
flag = 0xff,
il/R0 = 256-100;
T0lF = 0;
)
void
CENTER(void)
i
uns
c0rw{aND1g*,rr
'
156;
OPT|ON
= 0x08i
INTCON
= 0xa0;
count2 = 20;
do{
=0;
RC_M
=l
i++)1
=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)
{
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{
/
i++)1
=0;
=l'
while(!flas):
RC_M
=g'
RC_M
=0'
whl
i++)
le(!flas);
)whi le(count2--);
OPT|ON
= 0x28,
INTC0N
= 0,
l
void RlGHTS0(void)
{
(0xd0)
(0xd0)
i++) cHAR-o(SPACE-DIi]);
; i++) cHAR-o(R-90MIi]);
= 156, ll 256*100= 100[us]
MDA-WirPIC-2 MANUAL
-157
3.
Experinrent
OPTION
0x08;
INTC0N
0xa0,
count2 =
60;
do{
II
=0;
RC_M
=l'
i++)
i++)1
=0;
RC_M =0
t2--)
)
) wh
e (coun
=
INTCON =
OPTl0N
0x28;
0;
void
STEP(void)
i,count2,
CoauNP1sr,r,'
i++)
CHAR_o(SpACE_DIrl)
Cs,ilAND(0xd0);
Tl4R0
156,
=
INTCON =
OPTl0N
;++) CHAR_0(o_uscIi])
l/
256-100= 100[us]
0x08,
0xa0;
count2 = 60,
do{
"U" Pulse i.
I [ms]
i++)
flag
=0;
RC_M
=l
wnl
i
'l
le(!flag);
=0;
RC_M
=0'
whi
- 158
i++)1
le(!ftag);
;l
www.rnid:rseng.com
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
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
7lLSl5,t
5x7DOT|IATRIX
PICl6F87x
BESET
--_t_
*,osce,,ti'
z
Flow Chart
-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
i
whi
te(i--);
//
ttain
void main(void)
{
unsigned char
i;
P0RTA
= 0x00;
P0RTB
= 0x00;
doi
MDA-WinPIC-2 MANUAL
- 161
3. Experiment
CD
= 0,
i+*;1
= FONT57[|];
CK
= I'
CK
= 0'
CD
= I'
aelay(t00);
)
CD
= 0,
)while(l);
-162 -
www.midaseng.com
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
._
Prograni
'
#inctude (iotOt8zz. n)
CK RAO
fdef i ne CD RAI
#define
uns i gned
0x41, 0x43,0x46,
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;
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{
l0;
ld_cnt++)
load(ld_cnt);
display0;
)
SO; tO cnt++){
display0;
i
)while(l);
)
-166
wlyw.mi,Iaseng.com
il
i'
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
.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:
fdefine
D_G
RB2
//
FONT
whi
le(i--);
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
/I
RED
case 0:
= 0;
if(data & oxSo) D-R
D_R
CKR
= l;
CKR
= 0;
break,
//
GREEN
case
|:
D_G= 0;
= I'
CKG
= 0;
D_R
break,
//
AMBER
case
2:
0;
D_G
= 0;
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
i;
I
I
= 0x00;
=
state =
I
i
I
0x40;
l
!
.* -{
0,
j
s
do{
l]
if
(state == 3) state = 0;
)while(l);
-170 -
l:l
:lt
rvww.midaserig.com
.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_
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--..------>
.'*?#
.3
Progranr
C, \MDAUYinp
c2\exampte\c\D0Tl6_8_A.
#inctude (iot0tazz. n)
#define D_R RBO
*define EN RB6
*define RST RB7
unsigned char buffer[16]
lg)
whi
te(i--);
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 **;
//
RED
case 0:
= 0;
if(data s ox8o) D-R = l,
D_R
break
//
CKR
= l;
CKR
= 0;
GREEN
case
l:
D_G= 0;
D_G
= l,
MDA-WinPIC-? MANUAL
-173
3. Experiment
break;
//
AMBER
case
2:
D_R
= 0;
D_G
= 0,
li
t:
data
l
= 0,
oetay(t00);
EN
EN
= l,
C D = 0;
ts
bufferI i -j
= F9NT16[d-font0]
i
I
6;
d_font0--,
)
)
ll
uain
void main(void)
{
= 0x00;
P0RTB
= 0x40;
-t74
i,j;
www.rnidaseng.com
state = 0,
do{
i++){
LoAD(i);
for(1=0;
I ll
ror
for(i=0;
s
ta te++
if
(state==J) state=O;
)while(t);
MDA-WinPIC-2 MANUAI,
-175
3. Experiment
PICl6FBTx
0sc2
osc
I?^
fuol
Frliro
Flow
CLOCK
RESET
Chart
::::l Ivldn ,
lnirialize
:'
':,,,1
Ports.
)
]
r<
i
|
--..--.-.------.--=-__---l
-_t_
-176 -
clock
oumut
address ]
www.midaseng.com
Dot l\{aLrir
F,r'Prt
.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
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
//
FONT
constunsignedlongF0NT[16]={0x00000000,0x7ffc3ffc,0x00040004,0x00040004'
0x00040004, 0x00040004, 0x3ffc0004, 0x00047f
fc,
ll
uain
void main(void)
{
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
//
Latch
i++)i
i.
i.;l;
= 0i
le(t);
I
q1,i.Ua
-r78
www.midaseng.com
t
l
il
il'
rll
Circuit Diagram
PICl6F87x
0sc2
osc
"+2i
a=
x+
zi
F:
tl
tl
il
MDA-WinPIC-2 MANUAL
.1. Experiment
Flow Chart
[ .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
#define RED
RB4
fdefine
fdefine
GREEN
RB5
LATCH
RB6
#define
CL0CK
RB7
uns
ll
"^^" ront
0x0 I 800 I 80, 0x0 I 800 I 80, 0x0 I 800 I 80, 0x0 I 800 I 80)
vcid DISP(void)
{
for
(addr=0; addr
i,
( l6; addr++){
font = bufferfaddr];
if
i++){
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'
${
- 181
3. Experiment
= addr;
P0RTA
RB6
= l;
RB6
= 0;
il
il
iil
il.,r
= l;
RB7
= 0i
ii'
)
)
= 0;
P0RTA
)
void
char i)
LOAD( unsigned
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)
{
= 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
I // ror
s
-182
tate++
DtsP0;
www.midaseng.com
]t
:
I
I
MDA-WiuPIC-2 MANUAL
3.
Experiment
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+
3,
UY".
f"lt.
tc!-:8l
bytes font. ]
{.-' Orrprr 64r-'
s.c, )
LCl,".!r!g1r
!et.-J
fkl
qati-
-up!,
trqup-rcrfsGi
l--._
_
f -----R.t,*:--_l
-lves-,
_-__
C'-p**;lplllrlrr",fl
_t-_
Or".h U-tv rire-J
r
ffi
OrtpUlSqrrgld
--l
.l
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
":
[, -0.
0x00,
0xff,
0r'.. -, l3
0i0.i
_ , Lt3.
0rfc.
C,
0xC4,
ll.
0x00,
' -C.
0xff,
cons
uns i gned
char
lvll
[]
0xff,
0x00, 0x00,
0xff,
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;
TRISB
P0RTB
- 186
= 0x00,
= Oxff,
rvww.midaseng.com
3-ll.
Application
/'*
vo
LCD0 wr i
i
te
'*/
cdO_wr (uns
busy00;
P0RTB
= send;
PORTA
= 0xec;
//
CS2=0,
RW--0,
l=0
P0RTA
= 0xe0,
//
RW=0,
l=0
l=0
l=0
void
pase l= 0xb8;
I
cd0_wr (pase)
void
address l= 0x40;
lcd0_wr (address);
)
void
busyl (void)
uns
gned
TRISB
char
busy;
= 0xff;
do{
P0RTA
0xf6; l/
busY =
PgRTB;
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; //
P0RTA
= 0xe0,
//
MDA-WinPIC-2 MANUAL
-187
3. Experimenl
vo
id
cd I _page (uns
gne:
:-:
::
le,
page l= 0xb8;
I
cd I _wr (page)
l
vo
id
address l=
0x40;
I cd I _wr (address)
void
busyO0;
P0RTB
P0RTA
PORTA
= font,
= 0xed;
= 0xe0;
/l
l/
CSZ=0,
CSI=I, E=l,
RW=0,
Dl=l
D
l=0
vo
id
busyl 0
P0RTB
= fontl
= 0xf5,
/l
PoRTA = 0xe0; ll
P0RTA
RW=0, Dl=0
i
vo
id
uns
gned
char
i,
j;
cd0_pase (j )
cd0_address (OxOO)
;
i'
,q
font0(0x00);
"'
,-
)
)
vo
id
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
: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,
0xff,
0xff, 0x00,0x00,
MDA-WinPIC-2 N'IANIJAL
19r
3.
Experiment
[',3'. -,20.
2!.,
22.
0x2
0xff,
void
busy0(void)
unsigned
TRISB =
char
busy;
0xff;
do{
/l
P0RTA = 0xe0, /l
P0RTA
= 0xee;
CS?=|.
CS2=0.
= PSRTB;
whi le(busy & 0x80);
busY
TRISB = 0x00;
P0RTB
= 0xff;
/,,LCD0
write o/
void
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 l= 0xb8;
I
cd0_wr (page)
vo
id
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 =
P0RTB;
= 0xe0; // CS2=0,
whi le(busy & 0x80);
P0RTA
TRISB
= 0x00;
P0RTB
= 0xffi
/*
LCDI wr
void
te */
busyl 0
P0RTB
= send;
PORTA
P0RTA
= 0xe0,
0xf4, //
//
)
vo
id
page l= Oxb8;
lcdl_wr(page);
)
vo
id
address l= 0x40;
lcdl_wr (address)
i
vo
id
busy00;
P0RTB
= font,
Oxed, ll
PoRTA = 0xe0;
ll
P0RTA
CS2=0,
cS2=0,
CSI =0,
void
i
busyl 0
P0RTB
PORTA
PORTA
= font;
= 0xf5;
= 0xe0,
l/
//
MDA-\4/inPIC-2 MANUAL
-193
3. Experiment
)
vo
id
{
uns
gned
char i, j
lcd0_page(j);
cd0_address (OxOo)
font0(0x00);
)
)
vo
id
_c I ear (vo i d)
{
uns
gned char
lcdllage(j);
I
cdl_address
(OxOO)
void
clear(void)
-clear0;
*clear0:
)
void
display(unsigned char page, unsigned char address, const unsigned char *fnt)
cd0L:age (page)
lcdljage(page);
I
cd0_address (address)
i
i++)1
font = tntIi];
i f (address )= 6a) {
for(i=0;
(O+;
fontl (font);
)
else font0(font);
address++;
void
delay(unsigned int
www.midaseng.com
Application
while(i--);
)
void
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
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 - -.-....'-.._
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
finclude (lotGtall. n)
*def i ne TX RA3
fdef i ne RX RA4
unsigned
int
C0UNT;
"Distance Measure";
const char mss2[] =
"Distance
000cm":
//
-interrupt
{
CoUNT++; //
TMR0
= 256-29,
TO|F
= 0i
CCUNT
void
CONV(void)
unsigned char
C0UNT &=
BCDH
BCDH, BCDL;
0x03ff;
C0UNT/100;
- 198
www.rnidaseng.com
BCDL
C0UNT/10;
ECD|-((= 4'
tscDL
BCDL
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
= 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_
,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)
const unstg:ned
: ';
";
ASCTBL[]="6123456789A8CDEF"
i ie (! IRf'TI)
TXREG
= data;
(0x9e)
c0t'{\4p,iltD
CHAft_o(data);
C0lvh{AND
(0Xe0)
vo
itJ
RXD
(vo id)
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: ,
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
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
l-r1'pe-'-"-:
oone?-}
Enable Tarxmit
--__\_-_--l
message
I
<t
I
Ernlr
_\_/-^
no
Receive
Display on LCD
Trarsrnit routine
MDA-WinPIC-2 MANUAL
3. Experinred
,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
";
"LCDBB. h"
Transmi
ized
LCD modute
data;
.:
COUvlAlO(gxge)
CHAR_o(data)
CS[ranNP(gY.6;
)
//
Receive
void RXD(void)
{
-204
www.midaseng.com
3-ll.
Application flxpe
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++
)while(t);
)
MDA-WinPIC-2 MANUAI-,
-205
3. Experiment
3-1L-6.
Wtutu
r:iiiL;iiMii*;i:;i;i;:
6ffi;,il)
G=ilil;;il;f
F<qy> FXqT2
Display message
Error ? ->-Y99
{- ---=<6-
oi+lry
ryo ]
ffi}
on LCD
-206 -
Receive
www.midaseng.com
--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)
= dAtA;
cotvMAND
(0X9e)
CHAR-0(data);
cotvMAND
(0Xe0)
//
Receive
void
RXD(void)
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)
{
207; // mlbp6l(1tl+El)
= 0x20;
L_frilT0;
TXSTA
DtSPLAY0;
RCSTA
= 0x90,
count = 0;
do{
whi te(no4);
TXD (ASCTBL
[coun t] )
RXD0;
count++;
)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
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{
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-
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.
Be familiar
'
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
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\.
J'l
-"r#{t
:':". lif
Gprrrlrc srAR'rED
TuroRr,,rr,
clicl<
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
choose New... frorn the File nrenu to display the 1trllorving clialog box:
Select
22
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:
t3 Debus
i{J
rlJ
;.-.
,14
Exe
Lict
ilbi
23
Iuroxlal
GETTING STARTEr)
Chc,cise
tutor.
in the upper half of the dialog box, and choose Add to adcl thern to the
nerv project:
Dtivee:
Ie.,l,tlDos--=
Add lo Gro(.q].
f*..--l
I-dPS
n br6r-d
\Projects\COMM0N C
C:\Froiects\IUT0B.C
C
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
; tUl Xt
:l
,/,
Mai:n
Dal-I_count=r.r;
init-filc(},
white
call*court
< I,4AX_PIB
_t
tfz
I
1
ii
ii
Item
Highlisht
Keyword
Black bold
Text string
Blue
Preprocessor directives
Green
Numeric constants
Red/magenta/hlue
Comments
Other program
constructions
Black
information
see Colors
and
i'::,,
?-_;r
will
Workbench.
! ';'*-i
{.
:,}
"
TuroRrer.
changethe
Co*rprr,rNc THE
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.
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.,.
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
You can ciisplav any page by clicking the appropriate tab at the top of the
page.
ii
TUTORIAL
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
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.
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
b(
fi
bb ) to the correct
versiorr
Before linking the program you need to set up the linker options for the
project.
29
tvith
ol
C-SPY.
C Plu*lxol;r1.. ., ,,1-.
tr
'"i!iii,.rir.rt
riti:
Id*.L"rS lr.rtr,;ii
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:
3t)
lzz'2.s9
will
be