Está en la página 1de 44

-------------------------------------------------------------------------------------------------------------

T HC LP TRNH C
CHO PIC QUA V D.
Bin Son: Ch Phan Vinh Hiu.

Tp 1: Dnh cho ngi mi bt u

-------------------------------------------------------------------------------------------------------------

Li ni u:
Trn th gii, dng Vi iu khin Pic (Programmable Interlligent Controller)
ang c s dng ngy cng rng ri trong mi lnh vc ca i sng do cc tnh nng
vt tri ca n so vi cc dng VK khc. Do , nhu cu hc tp, nghin cu v ng
dng Vi iu Khin Pic trong gii sinh vin cc trng khi k thut cng nh ca cc
anh ch ang lm vic trong cc lnh vc in-in T-T ng Ha ngy cng cao.
Tuy nhin, ti liu Ting Vit ca VK Pic hin nay cha nhiu v cn nng tnh l
thuyt, hc thut m cha i su vo thc t ng dng nn cn gy nhiu kh khn cho
ngi hc. T l do , ti vit cun ny vi mong mun l em ti cho c gi mt
cch tip cn VK mi: d hiu, d lm, t tn thi gian v tit kim chi ph nht nhng
vn m bo lng kin thc cn thit cc bn c th t m rng, nng cao. Trong
cun sch ny chng ta tng bc hc cch lp trnh v s dng cc modul ca Pic qua
cc bi tp thc t, trc quang. Ti liu chc chn khng trnh khi thiu st, ti mong
nhn c kin ng gp chn thnh ca cc bn cc n bn sau c tt hn. Rt
cm n.
Mi th t, kin, ng gp v thc mc xin gi v a ch: hieuphanvinh@gmail.com
Handphone: 0983053941.

-------------------------------------------------------------------------------------------------------------

Mc lc
Phn 1: Cc bc chun b trc khi lm vic vi PIC.
1- Tng quan.
2- Gii thiu v hng dn ci t CCSC
3- Rp mch hot ng ca Pic.
4- Rp mch np ca Pic.
5- Gii thiu v s dng chng trnh Win Pic-800.
6- Kim tra mch np v mch test.
7- Gii thiu VK Pic-Pic 16f877a.
8- Cu trc c bn ca mt chng trnh C cho Pic.

Phn 2: Cc bi thc hnh.


Bi tp 1: Bt tt n Led.
Bi tp 2: DK dong co buoc.
Bi tp 3: iu khin tc ng c DC.
Bi tp 4: Giao tip vi bn phm.
Bi tp 5: Qut Led 7 on.
Bi tp 6: o - hin th nhit .

-------------------------------------------------------------------------------------------------------------

Phn 1: Cc bc chun b trc khi lm vic vi PIC.


1 Tng quan:
lm vic vi VK chng ta cn c 3 th c bn: Trnh bin dch (Compiler),
Mch-chng trnh np(Programmer) v Kit thc hnh .

V trnh bin dch : Chng ta s dng CCSC phin bn 4.0.11 cho php
chng ta dng ngn ng C lp trnh cho Pic, trnh bin dch ny cc
bn c th t ti trn mng hoc ly trong a CD nh km theo sch.

Mch np(Programmer) v Kit thc hnh: Ti c tng km theo sch 2


PCB: 1 PCB mch np loi JMD Programmer v 1 PCB kit thc hnh
kh n gin cc bn c th mua linh kin v t rp, trong a CD ti
c ghi danh sch linh kin cn mua v hng dn chi tit cch lp rp,
cc bn chu kh nghin cu. Ngoi ra, cc bn c th s dng bt k
loi mch np v kit test no m cc bn c min l c nguyn l phn
cng ging nh yu cu m ti m t mi bi tp.

Chng trnh np: Chng ta s dng chng trnh Winpic 800 phin bn
-----, trong a CD ti cng hng dn chi tit cch s dng.

Hng dn ci t v s dng CCSC:

Mt trong nhng kh khn vi ngi hc khi ln u tip cn vi VK l vic


lp trnh bng hp ng do s kh hiu v phc tp ca n. Do ti chn ng C gii
thiu vi cc bn nhm to s d chu cng nh rt ngn thi gian lm vic cho ngi
dng VK. Vi u th v s n gin, tin li, C dng nh l 1 gii php cho ngi
hc VK. Tuy nhin, nu c thi gian cc bn nn tm hiu thm v hp ng c nn
tng vng chc .

Phn mm CCSC l phn mm ph bin lp tri2ng C cho Pic. Ti s dng


phin bn 4.016 lm vic.
Hng dn ci t: B a CD vo a. Click vo file CCS_PCWH_4.016. Trong
c cha 3 file:

-------------------------------------------------------------------------------------------------------------

ci thnh cng trnh bin dch ny cc bn phi tun th theo 3 bc sau:


Bc th 1: Ci t chng trnh
Click vo tp tin pcwhupd ci t.

Click next.

Chn th mc ci t. Click next.

Click next. bt u qu trnh ci t.

-------------------------------------------------------------------------------------------------------------

Sau khi hoan tat my s hin ra thng bo i file ng k:

Nhn cancel. Ri nhn Finish.


Bc th 2: ng k
Sau bn chp file KeyfileGen t tp tin CCS_PCWH_4.016.
vo th mc ci t C:\Program Files\PICC ng k s dng
Click vo KeyfileGen lc s hin ln bng thng bo sau:

Click vo Tab Generar licencias.org s xut hin:

-------------------------------------------------------------------------------------------------------------

Bn tm ng dn n th mc ci t PICC

Sau click vo PICC ri nhn OK


Bc th 3: Cui cng l ci phn update cho chng trnh
. Bn click vo tp tin ideutilsupd trong th mc CCS_PCWH_4.016 a CD:

Tip tc Click next

------------------------------------------------------------------------------------------------------------Sau khi hon tt bn nhn finish ri khi ng li my.


Hng dn s dng CCSC.
Sau khi khi ng li my, trn mn hnh Desktop s xut hin Icon:

Click vo Icon ny ca s lm vic chnh s m ra.


Thanh Menu

Save

Trn thanh Menu c cc mc l: File, Project, Edit, Search, Compile, View, Tools,
Debug, Document, Users. Bn nhn vo tng mc xem cc chc nng c th.

Mc Help

-------------------------------------------------------------------------------------------------------------

* Mc File :
To 1 chng trnh son tho mi.

FILE

M 1 chng trnh c sn.


ng 1 chng trnh ang m.
Lu ni dung chng trnh.
Lu ni dung chng trnh vi 1 tn khc.

* Mc Compile ( bin dch):


COMPILE
Nhn vo y (hoc nhn F9) dch ra file hex.

Xem m asm c dch t file C.

Xc nh ging Pic ang lp trnh.

* Mc Tool (cng c):


Dng hin th ni dung VK gi v PC qua cng RS232.
Dng dch ngc file .hex v file.asm hay .c

Dng chuyn i gi tr gia cc h


m(deca-binary-hexa 8 16 32).

-------------------------------------------------------------------------------------------------------------

* Mc Edit (Chnh sa):

* Mc Help (h tr, hng dn):


Nhn vo y (hoc F1) m Help.

Th vin tp lnh C.
Th vin tp lnh phn cng ca PIC.

9- Rp mch hot ng ca Pic.


10- Rp mch np ca Pic.

7 Gii thiu Pic16f877a:

-------------------------------------------------------------------------------------------------------------

Vi iu khin Pic c rt nhiu loi, nhiu dng nh: 12fxxx, 16fxxx, 18fxxx,
33fxxx, 32fxxx, dsPIC, rfPIC, PIC giao tip Usb . v . v.; ty theo nhu cu ng
dng ca ngi s dng m chng ta c s la chn cho thch hp. Trong khun kh
cun sch ny ti chn Pic16f877a gii thiu vi cc bn v n l con Pic thuc h 14
bit 40 chn mnh cho cc ng dng mc thng thng v tng i ph bin
th trng Vit Nam. Nu cc bn nm vng cu trc v cch lp ca Pic16f877a cc
bn c th d dng tip cn vi cc h Pic khc v chng c chung cc cu trc v tp
lnh cn bn.

AT89C51

Bng so snh c tnh gia AT89C51 v P16F877A:

------------------------------------------------------------------------------------------------------------AT89C51.
Atmel
(USA).
1982.
8 bit.
4 K.
128 Bytes.
Khng c.
4 Port(0,1,2,3), 32 I/O.
2.

PIC16F877A.
Hng sn xut:Microchip
(USA).
1995.
14 bit.
8 K.
368 Bytes.
256 Bytes.
5 Port (A, B, C, D, E), 33 I/O.
3.

Modul iu bin xung (CCP )

Khng c.

Modul bin i tng t - s (ADC)

Khng c.

Modul so sanh tung t


(Compartor).
Modul giam sat hot ng(WDT).
Cong song song (Parallel)
Cong noi tiep (RS232)
Chun giao tip SPI.
Chun giao tip I2C.
Che o tiet kiem nang lng (Sleep
Mode).
Nguon ngat (Interrupt).

Khng c

2.
phn gii: 10 bit.
1
phn gii: 10 bit, 8 knh.
2

c tnh.
Hng sn xut:
Nm ra i
di tp lnh
B nh Flash Rom
B nh Ram
B nh EEPROM.
S Port xut nhp
Bo nh thi (Timer)

Cong ghe che tao


S tap lenh hp ng.
Tan so hoat ong
Gi thnh

1.

1
1
1.

Khng c.

15

CMOS.
111
12 MHz.
15.000-25.000 VN

Nap trng trnh theo chun noi


tiep (ICSP)
CMOS.
35
Toi a 20 MHz.
55.000-70.000 VN

Khng c
Khng c.

Cng sut hat ng ti a ca cc cng I/O:


Dng ng ra cc i khi ng ra trng thi in p cao l 20 mA.
Dng ng ra cc i khi ng ra trng thi in p thp l 25 mA.
Dng in ca ng ra ln kch n Led trc tip m khng cn qua Buffer.

-------------------------------------------------------------------------------------------------------------

in p lm vic:
in p lm vic ti a l 5.5V.
in p lm vic ti thiu l 4.5V.
Mch Reset:
Pic s b reset nu a chn s 1(MCLR) xung GND .

Nguyn l mch reset: khi m ngun t C18 s ni chn 1 xung Mass Reset VK.
Khi in p n nh in tr R24 s ni chn 1 ln cao th 5V- a VK v trng thi
hot ng. Nt nhn s Reset mch mt cch bt buc. Diod d1 dng x dng int
t c18 v ngun m khng phi qua in tr r24 khi tt in ngun lm mch reset ngay
sau khi ta tt in.

Thch anh dao ng:


VK Pic hot ng 4 ch dao ng :
RC: Ch to dao ng bng in tr R- t in C.
LP: Ch to dao ng bng thch anh cng sut thp, tn s giao ng t:
32Khz-200Khz.
XT: Ch to dao ng bng thch anh tn s trung bnh, tn s giao ng t:
100Khz-4Mhz.
HS: Ch to dao ng bng thch anh tn s cao, tn s giao ng t: 4Mhz20Mhz.

-------------------------------------------------------------------------------------------------------------

Khi lp trnh cc bn phi khai bo ch dao ng tng ng vi gi tr thch anh m


cc bn s dng mt cch chnh xc nu khng chng trnh s khng chy. T lc nhiu
xung thch anh nm trong khong t 15-33pF.
V d:
Nu s dng thch anh 10Mhz cc bn phi khai bo ch dao ng l HS.
Nu s dng thch anh 1Mhz cc bn phi khai bo ch dao ng l XT.

8 Cu trc 1 chng trnh C c bn:


Mt chng trnh C v c bn gm 3 phn:
Phn th 1(Khng bt buc): Phn ch thch. Bt c mt chng trnh no, cng c
bt u bng vic gii thiu v chng trnh, tn chng trnh, ngi thc hin chng
trnh, lu phn cng, . v. v . . .Ni dung ca phn ny phi nm sau du //

//================================================= =======
// Ten chuong trinh : Chuong trnh chop tat den led.
// Nguoi thuc hien
:XXX
// Ngay thuc hien
: 19/06/2008
// Phien ban
: 1.0
// Mo ta Chu thich : Dung PIC16F877A - thach anh 20MHz
//
//
//
//================================================= =======
S lng chng trnh cc bn vit s ngy cng nhiu v cng phc tp, a dng. Vic
ghi ch thch r rng u mi chng trnh s gip cc bn qun l nm bt v s dng
cc chng trnh mnh vit tt hn, ngn np hn.

------------------------------------------------------------------------------------------------------------Phn th hai(Bt buc): Phn khi to PIC. Phn ny l phn bt buc theo sau phn
ghi ch, bi v chng trnh dch cn phi hiu bn ang lm vic vi con PIC no, lm
vic vi n nh th no v thit lp phn cng cho n ra sao.
#include<16f877A.h>
#fuses HS,NOLVP,NOWDT,NOPUT, NOPROTECT
#use delay (clock=20000000)
Gii thch:
T kha #include<x x x > dng khai bo bn ang vit chng trnh cho con
Pic no.
T kha#use delay (clock=20000000) dng khai bo tc thch anh m bn
ang s dng cho Pic.
T kha #fuses dng thit lp cu hnh hot ng cho Pic :
1. Khai tc thch anh: HS, XT, LP hay RC.
2. C s dng b gim st hot ng WDT hay khng.
3. C bo v code hay khng.
4. Timer 0 c s dng khi m ngung ln hay khng.
Phn cn li l chng trnh chnh (Bt buc):

void main()
{

//Ni dung chng trnh chnh c vit ti y.

Lu : Trnh bin dch khng dch nhng ni dung nm sau du // v nhng ni


dung c hiu l ch thch.

n y cc bn c y nhng phng tin v kin thc c bn bt tay vo


phn th 2: lm cc bi thc hnh.

-------------------------------------------------------------------------------------------------------------

Phn 2: Cc bi thc hnh.


Bi 1:

Xut Gi Tr.

I _ L thuyt:
Pic 16f877a c 5 Port I/O bao gm:

Port A(RA0- RA5): c 6 I/O.


Port B(RB0- RB7): c 8 I/O.
Port C(RC0- RC7): c 8 I/O.
Port D(RD0- RD7): c 8 I/O.
Port E(RE0- RE2): c 3 I/O.

Khc vi AT89C51 hot ng xut nhp ca tng Port c thc hin ch bi 1


thanh ghi l thanh ghi Port(P0, P1, P2, P3) th Pic s dng 2 thanh ghi l thanh ghi
Port(PortA,PortB,PortC) v thanh ghi Tris (TrisA, TrisB, TrisC..).
Thanh ghi Tris c dng quy nh tng chn ring r ca Port hay c Port l
xut hay nhp. Sau d liu s c xut hay c nhp thng qua vic ghi vo hay
c ra t thanh ghi Port.

V d: Khi ta ghi vo thanh ghi Tris B gi tr 00001111 th ngha lcc chn t RB0-RB3
l nhp cn t RB4-RB7 l xut.
H m trong C:
S nh phn c vit di dng: 0Bxxxxxxxx. V d: 0b11111111.
S Hexa c vit di dng: 0Xxx. V d: 0XFF.
S Deca c vit di dng: xxx. V d: 255.

------------------------------------------------------------------------------------------------------------II _ Thc hnh:


Bi 1 A:
By gi chng ta bt u bi thc hnh u tin: S dng Port B bt tt n Led:
Bc th 1: Vit chng trnh.
Bn m chng trnh CCSC, vo File ->New -> Source file.

Bn t tn v lu project vo 1 th mc no do bn ch nh.V d: baitap1.c


Sau bn nh on m sau vo.
//================================================= =======
// Ten chuong trinh : Chuong trnh xuat gia tri thay doi trang thai Port B..
// Nguoi thuc hien : Phan Vinh Hieu.
// Ngay thuc hien
: 19/08/2008
// Phien ban
: 1.0
// Mo ta Chu thich : Dung PIC16F877A - thach anh 20MHz
//Port B c quy nh l Port xuat va noi voi 8 led de kiem tra trang thai.
//================================================= =======
#include<16f877A.h>
#fuses HS,NOWDT,PUT
#use delay(clock=20000000) // Su dung thanh anh 20MHz.
main()
Lu : Kt thc lnh phi c du ;
{
Set_tris_B (0B 00000000);//Quy nh trng thi xut nhp ca Port.
Output_B(0B 11111111);//Xut gi tr ra Port B.
}
By gi, chng ta cng tm hiu ngha ca tng ging lnh:
Ti phn khai bao phn cng: #fuses HS,NOWDT,PUT.

------------------------------------------------------------------------------------------------------------- Khai bo HS: S dng thch anh tc cao(20MHz).


- Khai bo NOWDT:Khng s dng b nh thi gim st.
- Khai bo PUT: Khng s dng Timer0.
Trong thn chng trnh chnh:
- Lnh Set_Tris_B(0B 00000000) s a gi tr 0B 00000000 vo

thanh ghi TRIS_B nhm quy nh ton b Port B l xut.


- Lnh Output_B(0B 11111111) s a gi tr 0B 11111111 vo thanh ghi
PortB a trng thi ng ra ca tt c cc chn ca Port B ln cao .
(*Lu : Tham kho Help ca CCSC phn Build in function nm r hn v cc tp
lnh.)
Sau khi hon tt, cc bn n nt save lu chng trnh li ri nhn Compile
(hoc F9) dch ra tp tin .Hex . Lc chng trnh s hin ra bn thng bo sau :
Tn ng dn ca project c dch.

Thng bo xem c li hay


khng.
Thng bo dung lng Ram - Rom
si ht.

Bc 2: Tip theo ta np chng trnh cho Pic bng phn mm Win Pic 800.
- u tin bn m tp tin WinPic800-356d-All nm trong a CD.
- Click chut phi vo Icon.

-To mt shortcut ri chp ra desktop.

-------------------------------------------------------------------------------------------------------------

Click vo Shortcut ny m chng trnh np.


Chn ngn ng.
Thit lp cu hnh mch np.

Xa ni dung IC.
c ngc t IC
T ng tm m IC c np.
Bt u np IC.

Ti file Hex.

Kim tra kt ni gia kit np


vi my tnh.

u tin bn cn khai bo v thit lp phn cng cho mch np: Vo Setting ->
Hardware:
Lc chn loi Kit np

Khai bo cng com


m bn cm mch
np vo.

Ti mc Selection Hardware bn chn loi kit np JMD Programmer. Sau xc dnh


a ch cng Com ca my ri nhn Apply edits thot.
Sau khi set up xong, bn cm IC vo mch np(Lu : Ch cm IC vo sau khi set up
phn cng xong.).Bn nhn vo biu tng:
Ti file Hex cn np.
Tip theo nhn:

-------------------------------------------------------------------------------------------------------------

np.
Sau khi np bn rt IC ra khi mch v cm IC vo mch test.
Bc 3: Cm Buss ni gia Port B vi modul 8 n Led theo s sau:

VDD
VDD

U6

32
11

5V

J10
1
2
3
4
5
6
7
8

BUS 8 SOI

33
34
35
36
37
38
39
40

RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6/PGC
RB7/PGD

RC0/T1OSI/T1CLK
RC1/CCP2/T1OSO
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT

HEADER 8x2/SM
2
3
4
5
6
7

8
7
6
5
4
3
2
1

JUMPER 8

RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

RA0/AN0
RA1/AN1
RA2/AN2
RA3/AN3
RA4/T0CLK
RA5/AN4/SS

RE0/AN5/RD
RE1/AN6/WR
RE2/AN6/CS

R10

R11

R12

R13

330

330

330

330

330

330

330

330

MCLR/VPP

OSC2/CLKOUT
GND

R9

OSC1/CLK

19
20
21
22
27
28
29
30
8
9
10
14

13

33
2
33

31

R8

12

R7

GND

1
R6

15
16
17
18
23
24
25
26

PIC16F877A
LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7
5V

RESET
1

R24

1k
C18

104pF

Sau bn cp ngun cho Kit thc hnh , ta thy ton b Led Port B sng. Nu trng thi
Led khng thay i bn lm li tht cn thn v chnh xc tng bc trn.
By gi cc bn lm li bi tp trn vi cc port A, C, D, E ()v xut ra cc gi tr khc
nhau ri quan st trng thi ca cc n Led.
Ngoi lnh Output_B() tc ng ln c Port ta cn lnh tc ng ln tng chn ca Port
nh:
output_bit( PIN_B0, 0); Lnh ny iu khing trng thi 1 chn ca Port,
output_high(PIN_A0); Lnh ny iu khing trng thi 1 chn ca Port

------------------------------------------------------------------------------------------------------------output_low (PIN_A0);
output_toggle(PIN_B4); Lnh ny o trng thi ng ra
Bi 1 B:
By gi s c trng thi ng vo: Vic c trng thi ng vo ca VK nha

5V
R8
1K

B8

c trng thi PortB v xut ra PortD:


#include<16f877A.h>
#fuses HS
#use delay(clock=20000000) // defind crystal = 20MHz
main()
{
Set_tris_B (0B 11111111);
Set_tris_D (0B 00000000);
Output_D(Input_B());
}

-------------------------------------------------------------------------------------------------------------

- Lnh SET_TRIS_B(0B 11111111) s a gi tr 0B


11111111 vo thanh ghi TRIS_B nhm quy nh ton b
Port B l nhp.
- Lnh SET_TRIS_D(0B 00000000) s a gi tr 0B
00000000 vo thanh ghi TRIS_D nhm quy nh ton b
Port D l xut.
- Input_B() s c trng thi cc chn ca PortB.
-

Output_D(Input_B()); s xut cc trng thi ra cc led ca Port D

VDD
VDD

U6

32
11

5V

J10
1
2
3
4
5
6
7
8

BUS 8 SOI

33
34
35
36
37
38
39
40

RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6/PGC
RB7/PGD

RC0/T1OSI/T1CLK
RC1/CCP2/T1OSO
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT

HEADER 8x2/SM
2
3
4
5
6
7

8
7
6
5
4
3
2
1

JUMPER 8

RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

RA0/AN0
RA1/AN1
RA2/AN2
RA3/AN3
RA4/T0CLK
RA5/AN4/SS

RE0/AN5/RD
RE1/AN6/WR
RE2/AN6/CS
1

330

330

R11

330

R12

330

8
9
10
14

8
7
6
5
4
3
2
1

BUS 8 SOI
JUMPER 8

33pF

JUMPER 8

R13

330

8
7
6
5
4
3
2
1

R10

330

GND

330

R9

12

330

R8

GND

R7

OSC2/CLKOUT

19
20
21
22
27
28
29
30

OSC1/CLK

13

20Mhz
33pF

31

R6

MCLR/VPP

15
16
17
18
23
24
25
26

PIC16F877A
LED0

LED1

LED2

LED3

LED4

LED5

LED6

5V

LED7
5V

5V
R8

1K

RESET
1

5V
R8

5V
R8

1K

5V
R8

1K

5V
R8

1K

5V
R8

1K

5V
R8

1K

R8

1K

1K

R24

1k
C18

B1 3

104pF

B2

B3 3

B4

B5

B6

B7

B8

-------------------------------------------------------------------------------------------------------------

Bi 2:

S DNG HM DELAY V LNH GOTO.

I _ L thuyt:
a-hm delay:
Khi lp trnh bng hp ng iu khin n Led chp tt ta phi vit 1 chng trnh
con c tn l Delay vi mc ch l lm chm hot ng ca VK i 1 khong thi gian
bng cch tun t gim gi tr ca cc thanh ghi. i vi C ta khng cn phi lm cng
vic ny na v C h tr cho ta 3 hm Delay nh sau:
-

delay_cycles (time):Lm chm chng trnh i (time) ln chu k


my, gi tr ca (time) thay i trong khong t 0-255.
delay_ms (time): Lm chm chng trnh i (time) mili giy, gi
tr ca (time) thay i trong khong t 0- 65535.
delay_us (time): Lm chm chng trnh i (time) micro giy, gi
tr ca (time) thay i trong khong t 0- 65535.

Vi d: Nu bn mun chng trnh chy chm i 1 giy bn s dng hm Delay nh sau:


delay_ms (1000);//1 giy bng 1000 mili giy.
a-Lnh Goto:
Khi cc bn mun chng trnh ca cc bn r nhnh n 1 v tr, 1 on chng
tri2ng khc th cc bn dng lnh nhy, trong 89c51 ta dng lnh LJMP NHAN. Cn
trong PIC ta dng lnh GOTO NHAN.
V d:

II _ Thc hnh:
By gio chng ta s s dng hm delay v lnh goto vit mt chng
trnh chp tt n led
//Chuong trinh chp tt n Led ung dng hm delay v lnh goto
#include<16f877A.h>
#fuses HS

------------------------------------------------------------------------------------------------------------#use delay(clock=20000000) // defind crystal = 20MHz


main()
{
SET_TRIS_B (0b00000000);
LOOP:
OUTPUT_B(0b00000000);
DELAY_MS(1000);
OUTPUT_B(0b11111111);
DELAY_MS(1000);
GOTO LOOP;
}

Gii thch:
u tin bng lnh
SET_TRIS_B (0b00000000);

chng ta thit lp ton b Port B l xut. Sau lenh ny ta gn mt nhn tn l


LOOP:
Sau nhan LOOP ta dng lnh
OUTPUT_B(0b00000000);
tt ton b Port B. Tip theo ta dung hm delay
DELAY_MS(1000);
delay 1 giy ri bt sng ton b Port B bng lnh:

------------------------------------------------------------------------------------------------------------OUTPUT_B(0b11111111);
Chng ta delay tiep 1 giy
DELAY_MS(1000);
Nh vy n Led chp tt 1 ln sau 1 giy v chng ta mun qu trnh ny lp i lp
li nn s nhy v thc hin li t u bng lnh GOTO
GOTO LOOP;

-------------------------------------------------------------------------------------------------------------

Bi 3:

KHAI BO V S DNG CC BIN (VARIABLE).

I _ L thuyt:
Bin l ni ct tm cc gi tr, kt qu m chng trnh sinh ra hay thu thp c
trong qu trnh hot ng.
Cc gi tr v kt qu c nhiu loi khc nhau nn bin cng c nhiu loi
bin khc nhau
Bin c kiu Interger : l cc bin ch cha c cc gi tr, cc kt qu l s
nguyn t nh: 0,1,2,3,4,5,6,. v . v . Ty theo kch c ca cc bin m ngi ta chia tip
bin c kiu Interger ra lm nhiu loi nh sau:
bin c kiu Interger 1 bit cha cc s 0-1.
bin c kiu Interger 8 bit cha cc s nguyn nm trong khong t 0-255
bin c kiu Interger 16 bit cha cc s nguyn nm trong khong t 0-65535
bin c kiu Interger 32 bit cha cc s nguyn nm trong khong t 04294967295
Bin c kiu Float : : l cc bin cha c cc gi tr, cc kt qu l s thc nh:
3.14, 24/100, . v . v ..
Bin c kiu char ky t 8 bit
II _ Thc hnh:
By gi chng ta s hc cch s dng bin.
#include<16f877A.h>
#fuses HS
#use delay(clock=20000000) // defind crystal = 20MHz
Int8 a;
main()
{
Set_tris_B (0B 11111111);
Set_tris_D (0B 00000000);
a=Input_B();
Output_D(a);
}
*Gii thch:
Sau phn khai bo mc nh thit lp phn cng l ti phn khai bo bin cho chng
trnh. Dng lnh :
Int8 a;

------------------------------------------------------------------------------------------------------------Khai bo chng ta s dng 1 bin c tn l a, kiu bin l s nguyn vi di l 8 bit.


Tip theo sau l phn chng trnh chnh vi hai ging lnh u:
Set_tris_B (0B 11111111);
Set_tris_D (0B 00000000);
Nhm khai bo Port B l nhp cn Port D l xut.
Lnh
a=Input_B();
s c gi tr ca Port B ri lu vo bin a.
sau lnh:
Output_D(a);
S xut gi tr ca bin a ra Port D. Ta thy y bin a ng vai tr cha gi tr trung
gian, ty theo yu cu lp trnh m gi tr trung gian ny c x l nh kim tra, so
snh, cng tr nhn chia, lu vo b nh.. v .. v ..Trc khi xut ra Port D.

-------------------------------------------------------------------------------------------------------------

Bi 2:

S DNG VNG LP FOR V WHILE.

Bi ton tip theo ti yu cu l cc bn lp trnh cho n Led ca Port B chp tt ng


10 ln ri ngh. Nu dng hp ng cc bn phi gn 1 gi tr vo thanh ghi, mi ln chp
tt n Led cc bn phi gim gi tr ny i 1 n v, ti khi no n bng 0 th ngng.
Cng tng t, trong C cc bn s lm nh sau:
//Chuong trinh chp tt n Led dng 10 ln dng vng lp For.
#include<16f877A.h>
#fuses HS
#use delay(clock=20000000) // S dng thch anh 20 Mhz.
Int8 I;
main()
{
SET_TRIS_B (0b00000000);
FOR (I=1;I<=10;++I)
{
OUTPUT_B(0b00000000);
DELAY_MS(1000);
OUTPUT_B(0b11111111);
DELAY_MS(1000);
}
}
Gii thch: Sau on khai bo phn cng ta khai bo 1 bin tn: I , kiu Interger
c di l 8 bit nh sau :
Int8 I;

------------------------------------------------------------------------------------------------------------Bin I ny s c dng lm bin m.


u tin, lnh SET_TRIS_B (0b00000000); s quy nh c Port B l Port
xut.
Tip theo ta thy cu lnh:
FOR (I=1;I<=10;++I)
{

OUTPUT_B(0b00000000);
DELAY_MS(1000);
OUTPUT_B(0b11111111);
DELAY_MS(1000);
}
Cu lnh ny s thc thi on chng trnh nm trong du {-----------------} ng 10 ln
nh sau:
Bc 1: u tin n gn bin I=1;
Bc 2: sau n kim tra xem liu I c nh hn hoc bng 10 hay khng
nu tha (ngha l i<=10) th n thc hin cng vic trong {-----------------} 1
ln,
Bc 3: thc hin xong n t ng tng gi tr trong bin I ln 1 n v .
Bc 4: Sau n ly gi tr va tng trong I so snh vi 10 xem c nh
hn hay khng, nu tha th nhy v Bc 2, nu khng tha th thot khi
vng lp.Dng cng vic.
Chng ta xem lu khi sau hiu r hn:

-------------------------------------------------------------------------------------------------------------

Gan I=0

Sai

Kiem tra
I<10 ?

ung
Thc hien

Tang I len 1

{Cng vic;}

Ket thuc

C php tng qut:


for (I=1;I<=N;++I)
{Cng vic;}

N: l s ln m bn mun lp li {cng vic.}

------------------------------------------------------------------------------------------------------------Khi lp trnh iu khin chng ta thng gp trng hp l phi thc hin 1 cng
vic lp i lp li 1 s ln nht nh hay phi tha 1 iu kin no . Trong ngn ng C
c 2 lnh l FOR v WHILE gii quyt yu cu .
a-Lnh For:

Gii thch :
for (i=1;i<=10;++i)
u tin ta t ra 1 bin I u chng trnh; sau ta gn
bin I c gi tr ban u l 1, tip theo ta so snh bin I ny vi gi tr

Cng vic m bn cn lp li c t nm trong du { }:


{Lnh }
Tr

-------------------------------------------------------------------------------------------------------------

Bi 2:

MODUL BIN I ANALOG DIGITAL (ADC).

I Gii thiu:
Modul ADC c dng bin i cc tn hiu t dng in p (Analog) sang
dng s (Digital) cc thit b s (MCU, PLC, PC) c th hiu, ghi nhn, x l c v
iu khin c. Cc loi ADC ph bin trn th trng l ADC0809, ADC0804,.v.v.
01
11
11
10
00
10
10
11

Mch x l.

Cm bin.

Thit b s.

ADC.

V d: Mt b iu khin hin th nhit dng Vi iu Khin lm vic theo nguyn l


sau: Cm bin nhit ( LM35, RTH, THERMOCOUPLE) bin i nhit sang in
p, gi tr in p ny sau khi qua modul ADC s thnh 1 gi tr nh phn xc nh, VK
s c gi tr nh phn ny v suy ngc li gi tr nhit tng ng u vo ri hin th
ra LCD hay Led 7 on.

II L thuyt:
Vi iu khin Pic16f877 c tch hp 1 b ADC c cu hnh nh sau:
- S knh Analog ng vo ti a: 8. Cho php chng ta c th tun t ly mu analog ti
a 8 knh.
- phn gii: Gii thch: Khi cp in p ng vo thay i t Vref- >>> Vref+ (thng
th ly trong mc t 0>>5V) th gi tr s ng ra thay i t 0 -1023(10 bit.) hay 0 -255(8
bit.).
- Tn s ly mu ti a: Chu k my chia 2 (Fosc/2) . Gii thch: V d bn s dng thch
anh 4Mhz th tn s my l suy ra tn s chuyn i ca ADC l:.
(La chn knh ng vo)

(Cc ng vo Analog)

Modul
ADC

(in p ng vo)

in p tham chiu

-------------------------------------------------------------------------------------------------------------

II _ Thc hnh:
Cm Buss ni gia Port B vi modul 8 n Led theo s sau:

5V

U3

J8

PORTA
PORTE

7
8
9
10
11
12

1
2
3
4
5
6

2
3
4
5
6
7

5V

RA0
RA1
RA2
RA3
RA4/T0CLK
RA5/SS

J11

R25

9
10
11
12
13
14
15
16

50K

1
2
3
4
5
6
7
8

33
34
35
36
37
38
39
40

5V

33pF
OSC1-877
4Mhz

5V

19
20
21
22
27
28
29
30

1
2
3
4
5
6
7
8

8
9
10

1
2
3

9
10
11
12
13 PORTC
14
15
16

RE0/RD
RE1/WR
RE2/CS

J15

9
10
11
12
13
14
15
16

PORTD

J5
4
5 PORTE
6

HEADER 8x2/SM

5V

2
D13
DIODE

1
2
3
4
5
6
7
8

VDD
VDD
GND

33pF
SW2

11
32

15
16
17
18
23
24
25
26

J12
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

HEADER 8x2/SM
OSC1-87713
OSC2-87714 OSC1/CLK
OSC2/CLKOUT
reset-877
1
MCLR/VPP

OSC2-877

RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6/PGC
RB7/PGD

J9
RC0/T1OSI/T1CLK
RC1/T1OSO
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT

9
10
11
12
13
14
15
16

LM35
J17
4
5
6

1
2
3
4
5
6
7
8

1
2
3

R24

GND

20K

31

R26

12

PIC16F877A

R6
330

R7
330

R8
330

R9
330

R10
330

R11
330

R12
330

D5
LED

D6
LED

D7
LED

D8
LED

D9
LED

D10
LED

D11
LED

R13
330

1k
reset-877

C9
104

By gi chng ta s s dng modul ADC c gi tr in p t bin tr, sau gi tr


bin i s c xut ra Port B.
#include<16f877A.h>
#device ADC=10 // Khai bao s dng ADC v nh phn gii 10 bit

D12
LED

------------------------------------------------------------------------------------------------------------#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000) // Thch anh s dng 20Mhz.
Int8 adc;
//=============================================================
Main( )
{

Set_tris_b( 0x00); // Quy nh PortB l xut.


Setup_ADC ( ADC_CLOCK_DIV_32 ) ;// nh tn s ly mu cho ADC
Setup_adc_ports( ALL_ANALOG

);//Cu hnh s knh Analog ng vo

Set_ADC_channel ( 2 ) ;
Delay_us (10 );
nhan:
adc = read_adc ( ) ;
Output_B ( adc ) ; // xuat ra port B gia tri bien adc
goto nhan;
}
*Gii thch:
Trng khi bo u tin ta thy c dng lnh:
#device ADC=10 Ging lnh ny nh phn gii 10 bit cho ng ra ADC ca Pic. Nu
mun phn gii thp hn ta lm nh sau #device ADC=8 ccccccccccc
Setup_ADC ( ADC_CLOCK_DIV_32 ) ; Ging lnh ny nh tn s ly mu cho ADC
bng tn s chu k my chia cho 32, ngoi ra ta cn nh c cc tn s khc nh:
ADC_OFF : tat hoat ong ADC ( tiet kiem ien , danh chan cho hoat ong khac )
ADC_CLOCK_INTERNAL : thi gian lay mau bang xung clock ni ( mat 2-6 us
chung cho cac chip .

------------------------------------------------------------------------------------------------------------ADC_CLOCK_DIV_2 : thi gian lay mau bang xung clock / 2 ( mat 0.4 us nu dng
thch anh 20MHz )
ADC_CLOCK_DIV_4( 0.8 us )
ADC_CLOCK_DIV_8 ( 1.6 us )
ADC_CLOCK_DIV_16 ( 3.2 us )
ADC_CLOCK_DIV_32 ( 6.4 us )
ADC_CLOCK_DIV_64 ( 12.8 us )
V d: Nu mun tang tn s ly mu ln ta lm nh sau:
Setup_ADC( ADC_CLOCK_DIV_2)
Setup_adc_ports( ALL_ANALOG
); Giong lnh ny thit lp s knh ng vo
Analog cho module ADC l 8 v s dng in p tham chiu Vref l 0-5v (in p ngun
cp cho Pic).
Sau ay la cac gia tr khac cho lnh Setup_adc_ports() :
ALL_ANALOGS : dung tat ca chan sau lam analog : A0 A1 A2 A3 A5 E0 E1 E2
(Vref=Vdd)
NO_ANALOG : khong dung analog , cac chan o se la chan I /O .
AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF : Cc chn Analog l A0 A1 A2
A5 E0 E1 E2 in p tham chiu Vrefh ly t chn A3
AN0_AN1_AN2_AN3_AN4 : A0 A1 A2 A3 A5
( ten th giong nhau cho tat ca thiet b nhng 16F877 ch co portA co 5 chan nen A0 ,
A1 , A2 , A5 c dung , A6 , A7 khong co )
AN0_AN1_AN3 : A0 A1 A3 , Vref = Vdd
AN0_AN1_VSS_VREF : A0 A1 VRefh = A3
AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF : A0 A1 A5 E0 E1 E2 VRefh=A3 ,
VRefl=A2 .
AN0_AN1_AN2_AN3_AN4_AN5 : A0 A1 A2 A3 A5 E0
AN0_AN1_AN2_AN4_AN5_VSS_VREF : A0 A1 A2 A5 E0 VRefh=A3
AN0_AN1_AN4_AN5_VREF_VREF : A0 A1 A5 E0 VRefh=A3 VRefl=A2
AN0_AN1_AN4_VREF_VREF : A0 A1 A5 VRefh=A3 VRefl=A2
AN0_AN1_VREF_VREF : A0 A1 VRefh=A3 VRefl=A2
AN0 : A0
AN0_VREF_VREF : A0 VRefh=A3 VRefl=A2

------------------------------------------------------------------------------------------------------------Bng tm tt:

Set_ADC_channel ( 2 ) ;Giong lnh ny s quyt nh knh no trong cc knh


c khai bo trn c ly mu d liu.

Delay_us (10 );
adc = read_adc ( ) ;giong lnh ny c kt qu chuyn i v gn vo bin adc.
Output_B ( adc ) ; xuat kt qu bin i ra port B e quan sat

Sau khi rp mch nh7 hng dn ta np chng trnh cho IC v


chy th ta thy. Khi tng dn in p ng vo gi tr nh phn ng ra
Port B tng dn.

-------------------------------------------------------------------------------------------------------------

Bi 2:

QUT LED 7 AN.

II L thuyt:
Led 7 on l 1 thit b hin th c s dng rt ph bin v gi thnh r , bn
cao v s dng d dng. Vic s dng PIC hin th Led 7 on c phn d dng hn so
vi 89 do h tr khai bo bin v cc php ton s hc trong C.
Trc khi bt tay vo vic lp trnh hin th cho Led 7 oan chng ta tim hiu s
qua phn cng v nguyn l qu1t lu nh ca led 7 on:

Cu to led 7 on:
Led 7 on gm 7 led n c sp xp theo hnh s 8 v 1 led lm du1 chm. 8
chn Anot ca c ni chung v ni ra ngoi theo chn s 3 v chn s 8. ln lt cc
chn cn li c a ra ring r qua cc chn 1-a,2-b.v.v.. Mun kch sng cnh
no th a chn ca cnh xung mass.Vic kch sng cc led ny s cho ta cc s t
0-9 v cc ch nhu A, b,C,d,E,F,.v.v..
VCC
3-8
DP G

10 9

Bng m led 7 on:


Gi s ta ni port D vo cc chn tn hiu ca Led by on. Nu mun led hin th s 3
ta phi xut ra PortD gi tr 0xB0 ch khng phi gi tr 0x03.Do ta phi xy dng
bn m led i t gi tr BCD ra m led by on.

M s
0
1
2
3
4
5
6
7
8

PORT
CHN
LED
0xC0

D7
DP

D6
G

D5
F

D4
E

D3
D

D2
C

D1
B

D0
A

0xF9
0xA4
0XB0
0x99
0x92
0x82
0xF8
0x80

1
1
1
1
1
1
1
1

1
0
0
0
0
0
1
0

1
1
1
0
0
0
1
0

1
0
1
1
1
0
1
0

1
0
0
1
0
0
1
0

0
1
0
0
0
0
0
0

0
0
0
0
1
1
0
0

1
0
0
1
0
0
0
0

------------------------------------------------------------------------------------------------------------0x90

By gi ta vit mt chng trnh xut gi tr ra led n v tng dn gi tr ny t 0 n


9
#include<16f877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000) // defind crystal = 20MHz
int8 MALED[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,};
//==============================================================
// y l dng khai bo bng tra m Led. C nghia nh sau: khai bo 1 bin c 10
phn // t, mi phn t l 1 s nguyn 8 bit c th t t 0-9, cc gi tr cho cc phn t
ny //c gn trong du{}. V d khi ta gn a=MALED[2] TH BIN a s c gi tr l
0xa4 l m led ca s 2.
//================= main program =========================//
void main()
{

SET_TRIS_C(0x00 );
SET_TRIS_D(0x00 );
output_low(PIN_C2);// a chn C2 xung 0 nhm cp ngun cho led hin th.
nhan:
output_d(MAP[2]);//Tra v xut m led ca s 2 ra Port D.
goto nhan;

}
Bi tp: Lp trnh xut ra Led cc gi tr tng dn t 0 ln 10. Thi gian tng tng gi
tr l 0.5 giy(500mS).
Gi : Dng vng lp FOR c bin I tng t 0 n 9, sau dng bin I n2y tra bng
m led.

p n:

------------------------------------------------------------------------------------------------------------#include<16f877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000) // defind crystal = 20MHz
int8 MALED[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,};
int8 i;
//================= main program =========================//
void main()
{

SET_TRIS_C(0x00 );
SET_TRIS_D(0x00 );
Output_low(PIN_C2);

Nhan:
FOR(I=0;I<=9;I++)
{ Output_d(MAP[I]);
Delay_ms(500); }
Goto Nhan;
}

K thut qut lu nh:


kch c nhiu led ng thi vi s chn kch ti thiu ta ni ca1a Led theo s
di y:

-------------------------------------------------------------------------------------------------------------

5V
O0
O1
1K

1K

1K

1K

O1

Q1
A1015

A
B
C
D
E
F
G
DP

U2
7
B 6
C 4
D 2
E 1
F 9
G10

A
B
C
D
E
F
G

T
L

220Ohm
1
2
3
4
5
6
7
8

O0

Q2
A1015

3
8

PORT CHON LED

8
DP

5 DP

A
B
C
D
E
F
G

LED7.1

U3
7
6
4
2
1
9
10

3
8

5V

A
B
C
D
E
F
G

T
L

1
2
3
4

5V

8
DP

5DP

LED7.0

PORT KICH MA LED

Tt c chn kch ca cc led c ni chung li vi nhau. Cc chn kch ngun c ni


ring. Nguyn tc qut Led nh sau: Gi s ta mun 2 Led trn hin th gi tr 23. u
tin ta hin th th a chn kch ngun O0 xung 0 v chn O1 ln 1 la chn led 0,
sau p gi tr MALED s 3 ra PORT KICH MA LED, ta cho gia tri nay hin th 1
khon thi gian khong 1mS sau a chn kch ngun O0 ln 1 v chn O1 xung 0
la chn led 1, sau p gi tr MALED s 2 ra PORT KICH MA LED, ta cho gia tri
nay hin th 1 khon thi gian khong 1mS, ta lp li nh trn. Vi cch kich nh trn
nu ta mun tng s led th ch cn tng thm chn kch ngun.
II _ Thc hnh:
Sau y ta s vit mt chng trnh hin th gi tr ca mt bin ra 2 Led 7 on
dng nguyn tc qut lu nh:
#include<16f877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000) // defind crystal = 20MHz
int8 MALED[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,};
int8 count,donvi,chuc;
void main()
{

SET_TRIS_C(0x00 );
SET_TRIS_D(0x00 );
count=68;

// Gn gi tr 68 vo bin count

------------------------------------------------------------------------------------------------------------nhan:
output_low(PIN_C1);

//Cp ngun led 2.

output_high(PIN_C0);

//Tt led 1.

Chuc= count/10;

//Chia ly s hng chc v gn vo bin Chc.

output_d(MAP[Chuc]);

//Tra m led ca s hng chc.

delay_ms(1);

//Hin th gi tr ny trong 1ms

output_high(PIN_C1);

//Tt led 2.

output_low(PIN_C0);

//Cp ngun led 1.

Donvi= count%10;

//Chia ly s hng n v v gn vo bin Donvi

output_d(MAP[Donvi]);

//Tra m led ca s hng n v.

delay_ms(1);

// Hin th gi tr ny trong 1ms

goto nhan;

//Quay tr li t u

}
Bi tp: Vit chng trnh hin th ra 2 led 7 on gi tr tng dn t 0->99.
Vit chng trnh xut ra 3 Led 7 on gi tr 321.

-------------------------------------------------------------------------------------------------------------

Bi 2:

IU KHIN NG C DC.

I L thut:
ng c DC c s dng rng ri trong cng nghip do tnh cht d iu khin hn so
vi ng c AC, mometn ln cu to n gin. xe p in.

-------------------------------------------------------------------------------------------------------------

Bi 2:

IU KHIN NG C BC.
(STEPPER MOTOR)

I L thut:
ng c bc thng c s dng trong cc ng dng yu cu chnh xc cao
nh iu khin robot, cc qu trnh t ng, iu khin v tr. Cu to c bn ca dng c
bc:
Day ngun
Stator

--A
N

Rotor

Day kch

--B

Stator ca ng c bc gm 4 cun nam chm in A, -A, B, -B c u ni vi s


dy nh trn hnh v,.
Rotor l mt nam chm vnh cu quay quanh mt trc c nh

Nguyn l hot ng ca ng c bc: ng c bc hot ng gia vo xung


in. u tin ta cp ngun vo 2 chn ngun ca 4 cun dy
Bc 1: Ta a chn kch ca cun dy A xung Mass trong mt khong thi gian T, lc
lc t sinh ra s ht Rotor hng vo cun A.
Bc 2: Ta a chn kch ca cun dy A ln cao th v a chn kch cun dy B
xung mass trong 1 khong thi gian T. lc lc t sinh ra s ht Rotor hng vo
cun B. Vy rotor quay 1 gc l 90 (ta ni ng c bc c phn gii l 90 ).
Bc 3-4. Lm tng t nh vy cho cun A v B..
Bc 5: Quay li bc 1.

------------------------------------------------------------------------------------------------------------+
ON
--

-- ON +

+ ON --

-ON
+

Nh vy vi th t kch xung :A B A --B ta thy ng c quay trn theo chiu kim


ng h, mun i chiu quay ta kch theo th t A B A B. Tc quay ph thuc vo
thi gian T. Nu mun quay chm ta tng T, quay nhanh ta gim T.
Trong thc t cc cun dy stator c sp sp sao cho ng c c d phn gii rt thp,
khong 1.8 /bc.
Cch xc nh dy ca ng c 6 si ra. Cch nhanh nht xc nh l xc nh
gi tr in tr gia cc dy bng VOM hay DMM.
15Ohm

15Ohm

--A

30 Ohm

--B