You are on page 1of 172

Vi s tien bo cua khoa hoc ky thuat, viec thu thap va chia se thong

tin ang c quan tam, cai tien lien tuc. Giai phap tot nhat cho cong viec
tren la s dung mang. Ngay nay rat co nhieu loai mang khac nhau: mang
truyen d lieu noi tiep dung chuan RS-485, mang LAN, WAN, mang
Ethernet, mang Internet Hien nay, mang Internet la mang tien tien
nhat, chung chia se mot lng thong tin vo cung ln. Trong noi dung e tai
nay toi ch gii thieu mang truyen d lieu noi tiep dung chuan RS-485
1. Nhiem vu e tai:
Mang thu thap va x ly d lieu t cac thiet b sau:
oc ma vach: dung vao viec quan ly thi gian nhan vien ra vao
cong ty
Thermocouple: Thu thap va ieu khien nhiet o cua lo nhiet,
do khong co lo nhiet, va s ap ng cham cua nhiet o. Do thi gian bao
ve luan van khong nhieu, nen khong ieu khien thc te ma ch thong qua
mo phong, chng trnh mo phong c thc hien tren phan mem Visual
Basic
Quang Bao:Dung e thong bao tin tc cua cong ty, ch tren
bang thong bao thay oi c.
2. Thc Hien:
Thiet ke 3 kit AT89C51:
Kit thu thap va ieu khien nhiet o:
- ieu khien lo nhiet, dung ieu kien on-off, thong qua logic
m
- Dung cam bien: Thermocouple
- Hoat ong cua lo nhiet: ban t ong
Kit oc ma vach:
- Do khong co thiet b oc ma vach, dung phm thay the
- Muc ch: Kiem tra thi gian nhan vien ra, vao cong ty lam
viec
Kit quang bao:
- Dung hien th thong bao, thong bao tin tc
Thiet ke chng trnh ieu khien tren kit va PC



uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 1









































uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 2









I. S lc ve mang:
1) Mang (NetWork):.
He truyen thong va trao oi d lieu c xay dng bang s ghep noi
vat l hai hoac nhieu may tnh. Cac mang may tnh ca nhan khac nhau tuy
theo quy mo bao quat cua chung. Mang nho nhat, goi la mang cuc bo (
LAN), co the ch noi hai hoac ba may tnh vi mot thiet b ngoai vi at tien,
nh may in laser chang han, ln hn mot t co the noi en 75 may tnh hoac
nhieu hn na. Cac mang ln hn, goi la mang dien rong ( WAN), dung cac
ng day ien thoai hoac cac phng tien lien lac khac e lien ket lac khac
e lien ket cac may tnh vi nhau trong pham vi t vai chuc en vai ngan
dam. Thanh phan c ban cua mang la may tnh ca nhan hoac tram cong tac
co lap card giao dien va eu c noi bang day cap vi may dch vu tep
cha bo lu tr ln trung tam. Tat ca cac thanh phan o tng tac vi nhau
bang phan mem he ieu hanh mang ( NOS). May dch vu tep trung tam
khong c s dung trong cac mang bnh ang ( peer-to-peer). Khac vi cac
he thong nhieu ngi s dung, ma trong o moi thanh vien c trang b mot
terminal cam khong co kha nang x ly, trong mang may tnh moi thanh vie n
co mot tram cong tac cha cac mach x ly rieng cua mnh. Cac mang may
tnh ca nhan cung c phan biet theo cau truc lien ket, tc la theo dang hnh
hoc cua mang topo mac noi chung. Cac cau truc lien ket pho bie n hien nay
gom cac to po hnh sao, trong o cac may c noi vi mot may dch vu tep
trung tam, va to po buyt, trong o may c noi vi mot day cap xng song
duy nhat. ong thi, cung co hai phng phap truyen thong tin thong qua day
cap cua mang: bang tan c s, va bang tan rong. Co mot so tieu chuan ang
canh tranh nhau trong viec chi phoi cac tieu chuan truyen thong ma theo o
cac d lieu se c trao oi trong mang
1.1) Mang LAN ( Local Area NetWork )
Cac may tnh ca nhan va cac may tnh khac trong pham vi mot khu
vc han che c noi vi nhau bang cac day cap chat lng tot, sao cho
nhng ngi s dung co the trao oi thong tin, dung chung cac thiet b ngoai
vi, va s dung cac chng trnh cung nh cac d lieu a c lu tr trong
mot may tnh danh rieng goi la may dch vu tep. Khac nhau khac nhieu ve
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 3
quy mo va mc o phc tap, mang cuc bo co the ch lien ket vai ba may tnh
ca nhan va mot thiet b ngoai vi dung chung at tien, nh may in laser chang
han. Cac he thong phc tap hn th co cac may tnh trung tam (may dch vu
tep) va cho phep nhng ngi dung tien hanh thong tin vi nhau thong qua
th ien t e phan phoi cac chng trnh nhieu ngi s dung, va e tham
nhap vao cac c s d lieu dung chung.
1.2) Ethernet:
Ethernet la cong nghe c s dung rong rai nhat trong cac mang
cuc bo ( mang LAN ). Ban than rieng Ethernet khong the lam thanh mot
mang; no can en vai thu tuc khac nh TCP/IP, e cho cac nut thc hien
viec truyen thong tin . Ethernet trong dang chuan cua no a khong am
ng c viec luan chuyen mo t lng thong tin ln, nhng van co nhieu
u iem, cu the la:
Cac mang Ethernet de thiet ke va co chi ph thap trong viec cai
at.
Cac thanh phan cua mang co gia thanh re va c ho tr tot.
Cong nghe a c th thach qua thc te va to ra la kha hap
dan cung nh ang tin cay.
n gian trong viec bo sung them hoac bt i cac may tnh tren
mang.
c a so cac phan mem va phan cng ho tr.
Mot van e chnh con ton tai vi Ethernet la: bi v cac may tnh
eu tranh ua e truy cap len mang nen khong co g am bao la mot may
tnh cu the nao ay se truy cap c mot thi iem cho trc. Cuoc tranh
gianh se xay ra cac van e khi 2 may tnh eu co gang truyen thong tin
cung mot luc; e roi ca 2 eu phai lui ra khoi cuoc tranh ua va khong co
d lieu nao co the c truyen.
Phan cng, nh c, va tieu chuan ghep noi cua mot loai mang
cuc bo, do hang Xerox Corporation a ra au tien, co kha nang lien ket
en 1024 nut trong mot mang buyt. Do s dung toc o cao trong k thuat
truyen tin dai tan c ban (kenh n). Ethernet cho phep truyen d lieu dang
day vi toc o 10 megabit moi giay, vi thong lng thc te t 2 en 3
megabit moi giay. Ethernet dung ky thuat tham nhap nhieu moi bang cam
nhan song mang co do xung ot ( CSMA/CD) e e phong truc trac cho
mang khi co hai thiet b ong thi cung co tham nhap vao mang. Chu y:
Co mot so hang, nh 3 Com va Novell chang han, cung san xuat phan cng
mang cuc bo cung theo nh c Ethernet, nhng san pham cua hang nay
thng khong tng thch vi san pham cua hang kia.
BO TRUYEN NHAN ETHERNET:
Ethernet khong oi hoi phc tap phan cng. Cac day cap c
s dung e noi vi no hoac la cap hai si xoan khong boc kim (UTP) hoac
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 4
la cap ong truc. Cac day cap nay phai c cat oan e o dai tng ng
vi tr khang phu hp vi tr khang at trng cho chung, cu the la 50O oi
vi cap ong truc va 100O oi vi day cap UTP
Moi nut eu co phan cng truyen va nhan e ieu khien qua
trnh truy nhap ti day cap va ong thi giam sat s lu thong cua d lieu
tren mang. Phan cng thc hien chc nang truyen nhan goi la bo truyen
nhan va mot bo kiem tra bat au va ket thuc khung.
Bo truyen nhan Ethernet truyen theo mot Ether (cac nut giam sat
bus) n. Khi khong co nut nao truyen th ap tren ng dan bang +0,7V.
ien ap nay cung cap mot tn hieu nhay vi song mang cho tat ca cac nut
tren mang; ien ap nay con goi la nhp tim ( heartbeat). Neu mot nut phat
hien ra dien ap nay th no biet rang mang ang hoat ong va khong co nut
nao ang truyen.
Nh vay khi mot nut muon truyen mot thong iep th no phai ch
en mot thi iem khong ban. Khi o neu 2 hay nhieu bo truyen ang hoat
ong cung thi iem o th se xay ra xung ot. Khi chung phat hien thay
tn hieu, mot nut truyen i mot tn hieu bao tac nghen. Cac nut b lam vao
tnh trang xung ot luc o se ch mot khoang thi gian ngau nhien ( trong
khoang 10 en 90ms) trc khi co gang truyen lan na. Moi nut tren mot
mang eu ch mot lan truyen lai. Nh vay, hien tng xung ot lam anh
hng en hieu qua truyen d lieu tren mang. Thong thng, cac bo truyen
nhan phat hien ra xung ot bang viec giam sat ien ap mot chieu (DC)
hoac ien ap trung bnh tren ng truyen.
Khi truyen d lieu, mot n v truyen nhan phan m au bang 1s
va 0s lien tiep. Ma c s dung la ma Manchester, ma nay dien ta bang
so 0 khi co bc nhay ien ap HIGH xuong LOW va 1 khi co bc nhay
ien ap t LOW len HIGH. ien ap thap bang +0,7V. Nh vay khi phan
m au c truyen th iep ap se thay oi gia 0,7V va +0,7V
0,1microsec
1 1 1 0 0
+0,7V
-0,7V
Nhan roi
(Idle)
Nhan roi
(Idle)
Phan m au

Tn hieu digital Ethernet
Neu sau khi truyen pham m au ma khong phat hien thay xung
ot th phan con lai cua khung truyen se c truyen tiep

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 5
1.3) Internet:
Mot he thong gom cac mang may tnh c lien ket vi nhau tren
pham vi toan the gii, tao ieu kien thuan li cho cac dch vu truyen thong
d lieu, nh ang nhap t xa, truyen cac tep tin, th tn ien t, va cac
nhom thong tin. Internet la mot phng phap ghep noi cac mang may tnh
hien hanh, phat trien mot cach rong rai tam hoat ong cua tng he thong
thanh vien. Nguon goc au tien cua Internet la he thong may tnh cua Bo
Quoc Phong My, goi la mang ARPAnet, mot mang th nghiem c thiet
ke t nam 1969 e tao ieu kien thuan li cho viec hp tac khoa hoc trong
cac cong trnh nghien cu quoc phong. ARPAnet a neu cao triet ly truyen
thong bnh ang ( peer-to-peer), trong o moi may tnh cua he thong eu
co kha nang "noi chuyen" vi bat ky may tnh thanh vien nao khac. Bat ky
mang may tnh nao da tren c s thiet ke cua ARPAnet eu c mo ta
nh mot tap hp cac trung tam ien toan t quan, mang tnh a phng va
t ieu hanh, chung c lien ket di dang "vo chnh phu nhng co ieu
tiet" . S phat trien thiet ke cua mang ARPAnet n thuan ch do nhng
yeu cau ve quan s: Mang nay phai co kha nang chong lai mot cuoc tan
cong co the vo hieu hoa mot so ln cac tram thanh vien cua no. T tng
nay a c chng minh la ung khi My va cac ong minh tham gia vao
cuoc chien tranh vung Vnh. S ch huy va mang kiem soat cua Irak, c
to chc mo phong theo cong nghe ARPAnet, a chong lai mot cach thanh
cong oi vi cac no lc cua lc lng ong minh nham tieu diet no. o la
ly do tai sao cong nghe co nguon goc t ARPAnet hien nay ang c xuat
cang mot cach rong rai. Mang Internet nguyen thu c thiet ke nham muc
ch phuc vu viec cung cap thong tin cho gii khoa hoc, nen cong nghe cua
no cho phep moi he thong eu co the lien ket vi no thong qua mot cong
ien t. Theo cach o, co hang ngan he may tnh hp tac, cung nh nhieu
he thong dch vu th ien t co thu ph, nh MCI va Compuserve chang
han, a tr nen thanh vien cua Internet. Vi hn hai trieu may chu phuc vu
chng 20 trieu ngi dung, mang Internet ang phat trien vi toc o bung
no, moi thang co them khoang mot trieu ngi tham gia mi. Li khuyen:
Hau het moi ngi eu co the tham gia vao Internet. Nhieu to chc loai ln
va va co cac he thong th ien t eu co cong noi vao Internet. Cao hn
mot mc, cac dch vu th ien t co thu ph (nh) Compuserve va MCI deu
co cac cong noi vao Internet; mot so he ba ng bulletin a phng cung vay.
2) Bus
ng dan ien noi bo ma theo o cac tn hieu c truyen t bo
phan nay en bo phan khac trong may tnh. May tnh ca nhan co thiet ke
bus cua bo vi x l theo ba loai ng dan: - Bus d lieu truyen d lieu
xuoi ngc gia bo nh va bo vi x ly. - Bus a ch xac nh v tr nh nao
se c a vao hoat ong. - Bus ieu khien truyen cac tn hieu cua cac bo
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 6
phan ieu khien. Ngi ta se phat trien bus d lieu cua may bang cach noi
bo x l vi mot hoac nhieu khe cam m rong, va goi la bus m rong (
expansion bus). bus d lieu, bus a ch, va bus m rong eu c mac noi
theo nhng hang day dan song song, cho nen tat ca cac bt can gi i se
c truyen cung mot luc ong thi, giong nh 16 hoac 32 chiec o to dan
hang ngang cung chay ve mot hng tren xa lo cao toc. Co ba loai cau truc
bus thng gap pho bien trong th trng ma y tnh IBM PC va tng thch
PC. - Bus ISA ( Industry Standard Architecture). ay la bus 16 bit, au tien
c xay dng e dung cho cac may tnh AT ( Advanced Technology). Bus
nay bao gom nhng khe cam m rong 8 bit e tng thch vi cac bo ieu
hp cu, va khe cam 16 bit dung cho nhng bo ieu hp kieu AT. - Bus
MCA ( Micro Chanel Architecture). Loai bus 32 bit s hu rieng c dung
trong cac may tnh IBM PS/ 2 cao cap. - Bus EISA ( Enhanced Industry
Standard Architecture). Loai bus 32 bit, nhng khac vi bus MCA la co the
tng thch ngc vi cac bo ieu hp ISA. Tnh chat rong rai cua 32 bit
ch c s dung mot phan. Mac du cac ng dan trong bus noi bo cua bo
x l hoat ong toc o cao phu hp vi bo x l cua ban, nhng bus m
rong th hoat ong vi toc o thap hn nhieu - EISA 8. 33 MHZ va MCA
10 MHZ. bus Local (la mot loai ng dan toc o cao lien ket bo x l
cua may tnh vi vai ba khe cam m rong) a c xay dng e tang toc
o cho viec hien hnh video trong cac chng trnh dung nhieu o hoa nh
Microsoft Windows chang han.
3) BaseBand ( Bang c s )
Trong cac mang cuc bo, ay la mot phng phap truyen thong, trong
o tn hieu mang thong tin c a trc tiep vao cap trong dang so khong
ieu bien. Cac tn hieu may tnh co the c truyen qua cap bang hai cach:
tn hieu tng t va tn hieu so. Mang truyen thong tng t c goi la
mang bang rong ( broadband network). Cac mang truyen thong so c goi
la mang bang c s. V cac tn hieu cua may tnh la tn hieu so, cho nen so
lng mach can thiet cho mot mang bang c s e truyen dan tn hieu nay
ra vao may tnh la rat t. Hn na, nhieu mang bang c s co the s dung
day cap hai si xoan (day ien thoai bnh (thng)), cho nen lap at chung
gia re hn vi mang bang rong oi hoi phai co cap ong truc. Tuy nhien,
he bang c s b han che ve c ly truyen dan va ch cho phep thc hien
mot kenh truyen thong trong mot luc. Hau het cac mang may tnh cuc bo
eu la mang bang c s.
4) BoardBand (Bang rong)
Trong cac mang cuc bo, ay la mot phng phap truyen thong tn
hieu tng t c at trng bi dai tan rong. Tn hieu nay thng c
tach chia ra hoac truyen don ( multiplex) e cung cap cho cac ng truyen
thong a kenh. V cac tn hieu cua may tnh la loai tn hieu so, nen chung
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 7
phai c chuyen oi bang mot qua trnh goi la bien ieu ( modulation)
trc khi chung c truyen qua mang tn hieu tng t. Mot modem se
thc hien nhiem vu o. He thong dai rong dung phng phap truyen tng
t. V may tnh la thiet b so, nen yeu cau phai co cac thiet b giong nh
modem ca hai au cap truyen e chuyen oi tn hieu t so thanh tng t
hoac ngc lai. Truyen thong dai rong co the m rong c ly kha xa va hoat
ong toc o rat cao. Mang dai rong cung giong nh mang truyen hnh
cap, co the truyen hai hoac nhieu kenh cung mot luc (cac kenh khac nhau
ve tan so). Do o mang truyen thong dai rong co the thc hien truyen ca
d lieu lan tieng.
II. RS-485:
1. Gii thieu:
Khi he thong can truyen mot khoi thong tin nho khoang cach xa,
thong thng ngi ta chon RS-485
Mang s dung chuan RS-485 rat a dang: ta co the giao tiep gia PC
vi nhau, hoac gia PC vi Vi X Ly , hoac bat ky thiet b nao truyen
thong noi tiep bat ong bo. Khi so sanh vi Ethernet va nhng giao dien
truyen thong theo nhng chuan khac th giao dien RS-485 n gian va gia
thanh thap hn nhieu.
Theo nhan nh cua toi ( oi vi truyen khoi d lieu nho ) th chuan
RS-485 rat linh ong. Ta co the chon so lng bo ieu khien ( Master ),
bo nhan ( Slave ), chieu dai cap, toc o truyen, so node can giao tiep, va
rat tiet kiem nang lng
2. Mot so at iem cua RS-485:
Gia thanh thap:
Cac bo ieu khien ( Driver ) va bo nhan ( Receiver ) khong at
va ch yeu cau cung cap nguon n +5V e ta o ra mc ien ap vi sai toi
thieu 1.5V ngo ra vi sai.
Kha nang ve mang:
RS-485 la mot giao dien a iem ( multi-drop ), no co the co
nhieu Driver va Receiver, so Receiver co the len en 256 neu ngo vao cua
cac Receiver co tr khang vao cao
Kha nang ket noi:
RS-485 co the truyen xa 1200m, toc o len en 10Mbps. Nhng 2
thong so nay khong xay ra cung luc. Khi toc o truyen tang th toc o baud
giam xuong.
V du: khi toc o la 90Kbps th khoang cach la 1200m,
1Mbps th khoang cach la 120m, con vi toc o 10Mbps th
khoang cach ch con 15m.
3. Giai thch mot so ac tnh RS-485 :
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 8
Cac ng truyen can bang va khong can bang:
S d RS-485 co the truyen tren mot khoang cach ln la do chung s
dung ng truyen can bang. Moi mot tn hieu se truyen tren mot cap day,
vi mc ien ap tren mot day la am hoac ien ap bu tren day kia. Receiver
se ap ng phan hieu gia cac mc ien ap, c minh hoa hnh di:


VA
GND
o o
VB
A
B


Hnh 1.1: ng truyen can bang

Vi n
GND


Hnh 1.2: ng truyen khong can bang
Mot thuan li ln cua RS-485 la kha nang chong nhieu tot. Mo t thuat
ng khac cua ng truyen tn hieu dang nay la vi sai tn hieu.
TIA/EIA 485 ch nh hai ng vi sai la A va B. Tai bo ieu khien (
Driver ) neu V
A
> V
B
th mc logic au vao la cao, nguc lai V
A
< V
B
th
mc logic au vao la thap. Tai bo nhan ( Receiver ) neu V
A
> V
B
th mc
logic au ra la cao va ngc lai
oi vi cac Receiver au vao phai nam trong tam 7V + 12 V. Mc
ap vi sai au vao toi a - 6V s V
A
V
B
s +6V
Tai sao dung ng truyen can bang co li :
ng truyen can bang co u iem bi hai ng tn hieu mang dong
gan bang nhau nhng ngc dau. ieu nay giup giam nhieu tren ung
truyen bi hau het cac ien ap nhieu ieu tang hay gian ieu nhau tren ca
hai ng truyen. Bat k mot ien ap nhieu nao tac ong len mot day ieu
b triet tieu bi ien ap bu tren day kia. ng nhiei co the la cac day
khac trong cap hoac ben ngoai. Mot bo nhan can bang ch nhan tn hieu
can truyen, loai bo tn hieu nhieu hoac giam i rat nhieu tn hieu nhieu.
Ngc lai, trong giao tiep khong can bang, bo nhan phat mc ien ap
gia day tn hieu va at. Khi co nhieu chung se tac ong en mach, khi
gap moi trng co nhieu ln chung se gay sai lech mc logic mach hoat
ong sai.
Mot u iem khac cua ng truyen can bang la no co the triet tieu
c phan ien ap tiem tang gia bo phat va bo nhan. Trong ket noi
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 9
khoang cach ln, ien the cac Driver va Reciver co the khac nhau nhieu
von.
mot ng truyen khong can bang, ien the at khac nhau co the
lam cho Receiver khong oc c au vao. Con ng truyen can bang
th chung khong quan tam en ien the at v no ch oc phan ien the
hieu gia hai day truyen tn hieu.
Trong thc te, cac thanh phan RS-485 ch phu hp vi s chenh lech
the at nhat nh. Mot cach e triet tieu hoac giam bt van e nay la co
lap mang.
4. Nguyen tac hoat ong cua RS-485 :
a) Mc ap yeu cau:
Giao tiep RS 485 ien hnh s dung nguon cung cap n +5V nhng
mc logic tai au phat va au thu khong phai la mc TTL hay mc CMOS,
e co mc ra thch hp th V
A
V
B
> 1.5V
ien ap gia moi au ra va at khong xac nh bang viec tr ma
mode ien ap chung phai nam trong tam 7V. Neu nh giao tiep can bang
mot cach hoan hao th cac au ra offset bang mot na vi nguon cung cap.
Bat c s can bang nao cung lam tang hay giam mc offset.
Hnh ben di ch ap ra A va B cua mot bo ieu khien RS-485. Bien
o au ra gan 3V thay oi t +1 +4V hoac 1V -4V so vi at. Nguon
cung cap cho bo ieu khien la +5V
A
B

Hnh 1.3: Ngo ra cua bo phat RS-485

Hnh ben di ch mc ien ap vi sai gia day A va B au ra cua
Driver. Bien o nh nh cua ap ra la 6V gap hai lan bien o nh nh cua
ien ap tren moi ng day.




Hnh 1.4: Ngo ra vi phan cua bo phat RS-485
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 10

Neu nh mot au ra ong m trc mot au ra khac th ien ap au ra
vi sai ong m cham hn va ieu nay gii han toc o truyen cua mang.
Thi gian lech ( Skew ) la khoang thi gian ong m chenh lech gia 2
au ra. Cac Driver cua RS-485 c thiet ke sao cho toi thieu thi gian
lech.
Tai Receiver, ien ap 2 au vao A va B ch can 200mV. Neu V
A
- V
B

> 0.2V th au thu se oc la mc logic 1, ngc lai la mc logic 0. neu nh
ien ap vi sainay < 0,2V th mc logic khong xac nh
S khac nhau gia ien ap Driver va Receiver la gii han nhieu cho
phep 1,3V. ien ap vi sai co the yeu i hoac b nhieu k sinh khoang 1,3 V
th au thu van nhan c mc logic ung.
Trong hau het cac mang, ien ap au ra bo phat ln hn 1,5V. Do o
gii han nhieu ln hn. Mot bo Driver can cap nguon 3V cung co the co ap
ra vi sai gia 2 au ra la 1,5 V
TIA/EIA 485 nh ngha : B > A mc 1; A > B mc 0 . S dung
nh ngha nay cac chip giao tiep RS-485 th lam ngc lai.
b) Dong yeu cau:
Dong tong trong RS-485 thay oi theo tr khang vao cua thanh phan
trong mang gom: cac bo phat, cac au thu, cap va cac thanh phan au cuoi.
Tr khang ra cua bo phat thap va tr khang cua cap thap cho phep
viec ong m c nhanh hn va bao am bo thu se nhan c tn hieu vi
toc o cao nhat co the. Neu tr khang cua au thu cao th no se lam giam
dong trong mang va keo dai tuoi tho cua bo nguon.
Viec s dung thanh phan au cuoi se co li oi vi dong trong mang.
Khi khong co cac thanh phan au cuoi th tr khang vao cua cac bo thu se
anh hng ln oi vi ien tr tong noi tiep. Tong tr khang vao thay oi
theo cac bo thu va tr khang va o cua chung.
Mot bo phat RS-485 co the lai en 32 n v tai. TIA/EIA 485 xac
nh mot n v tai di dang dong yeu cau. Mot bo thu tng ng mot
n v tai, ma tai nay khong keo nhieu hn mot lng dong xac mh tai
au vao va ien ap c xac nh theo tieu chuan. Khi ap tai au thu la
12V th mot n v tai Bo thu se khong keo nhieu hn 1mA. e at c
yeu cau nay th mot bo thu phai co mot ien tr au vau t nhat la 12 KO,
mac gia moi au vi sai vi V
cc
hay GND tuy thuoc vao chieu dong ien.
Neu them mot bo thu th ien tr tng la 6000 O. Neu co 32 n v tai th
R tng ng la 375O
5. Chuyen oi sang TTL:
a) Song cong ( Full-Duplex ):
RS-485 c thiet ke e dung cho he thong nhieu node ( multi-drop).
Hau het mang RS-485 la ban song cong s dung nhieu bo phat va bo thu,
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 11
cung chia se mot ng truyen tn hieu. Nhng chung ta cung co the s
dung RS-485 dang song cong, o moi hng se co ng truyen tn
hieu rieng cua no. Viec chuyen oi mang RS-232 sang RS-485 song cong
de dang thc hien bang phan mem.
Vi mang loai nay ta co the s dung SN75179B hai au bo phat va
bo thu. Mang nay gom 1 bo phat dung chuyen oi 5V TTL sang RS-485 va
mot bo thu dung chuyen RS-485 sang 5V TTL
ay la mot giai phap n gian khi ta muon tao mot mang song cong,
khoang cach xa gia cac vi ieu khien. Cac chip giao tie p RS-485 nho hn,
n gian va re hn trong viec chuyen oi sang RS-232
O
O
NODE 0 NODE 1 NODE 2
NODE 3
O
O
O
O
O
O

Hnh 1.5: Ket noi song cong nhieu node

Trong mot mang gom co chu va t, o node chu dung e ieu khien
mang va cho phep viec thu phat cua thanh phan khac. Mot cap day dung
e noi bo phat cua con chu vi bo thu cua cac con t, con mot cap day
khac noi bo phat cua cac con t vi bo thu cua con chu
Tat ca cac con t phai c thong tin t con chu e biet con nao c
cho phep. Viec nh a ch cua con t c xac nh bang cap day oi lap.
Thuan li cua phng phap nay la tiet kiem thi gian cho cac con t bi v
chung khong oc thong tin tra li cua cac con t khac. Neu tat ca cac node
cung chia se mot ng d lieu th cac con t phai oc tat ca moi thong tin
lu thong tren ng mang e lay thong tin t con chu gi ti.
b) Ban song cong:
Rat nhieu mang dung ket noi 485 la ban song cong vi nhieu bo phat
va thu cung chia se mot ng tn hieu.
Khi mot mang co 3 hay nhieu node th tai mot thi iem ch co mot
node c thu hay phat. Viec s dung 2 ng truyen tn hieu la thuan li
khi ch co 2 thiet b ( mot chu, mot t ) v moi node co the thu phat bat k
luc nao ma khong s co s xung ot. Nhng neu co nhieu hn mot bo phat
tren cung mot cap day th khong co s am bao rang ng truyen tn hieu
la rong(free) khi bo phat can truyen
Tren cac vi ieu khien cho phep xay dng cac bit port nh la au vao
hay au ra, chung ta co the gi hay nhan mot bit n , tai tao lai bit khi can
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 12
thiet. Chung ta cung co the lam ieu nay e s dung t nhat so bit port co
the hoac s dung ban song cong e tiet kiem day
120. CONTROL OUT
SERIAL IN
CONTROL OUT
75176BP
1
2
3
4
5
6
7
8
RO
RE
DE
DI
G
N
D
A
B
+VCC
SERIAL IN
120
SERIAL IN
+5V
75176BP
1
2
3
4
5
6
7
8
RO
RE
DE
DI
G
N
D
A
B
+VCC
CONTROL OUT
+5V
SERIAL OUT
SERIAL OUT
+5V
SERIAL OUT
75176BP
1
2
3
4
5
6
7
8
RO
RE
DE
DI
G
N
D
A
B
+VCC

Hnh 1.6: Ket noi ban song cong

Chip bao gom mot bo phat dung oi mc logic TTL sang RS-485 va
mot bo thu dung chuyen RS-485 sang mc TTL va moi chip eu co mot
au vao cho phep. Khong giong nh SN75179B chip nay ch co mot cap
chan RS-485 va chan cho phep vao, dung xac nh lieu bo phat hay bo tu la
tch cc
Khi au vao cho phep cua bo pha t mc thap th ngo ra cua bo phat
tranh thai tong tr cao. Khi au vao cho phep cua bo thu mc cao th au
ra cua bo thu trang thai tong tr cao
6. Ket noi mang va phng thc truyen:
ac iem cua mang dung chuan RS-485 la phai chung mass, mc ien
ap chung: -7 +12v.
a. Dang ket noi tong quat:
Hnh ben di mo ta cach ket noi tong quat, moi node co chip thu phat
SN75176B ( tng t Max485, LTC485, DS3695 )
Mach co ien tr 120 O noi song song vi ngo vao, ra vi sai ( chan 6-7
), va hai dien tr 560 O keo len
Vi cach ket noi nh vay th e truyen data t bo ieu (Master) en
cac thiet b chap hanh ( Slave ) ta phai set chan 2-3 len mc cao, tng t
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 13
khi cac Slave gi Message ve Master, chan 2-3 cung phai len mc cao.
Con khi nhan Message th ta phai set chan 2-3 xuong thap





Hnh 1.7: Dang ket noi tong quat cua mang dung chuan RS-485
b. Ket noi t ong :
Van e: khi thiet ke mang dung chuan RS-485, do tat ca cac node
cung chia se mot ng data, nhng tai mot thi iem ch co mot bo ieu
khien hoat ong. Tc la trc khi node nay phat th node khac khong c
phat.
Hnh di ay cho ta cach ket noi t ong khong can phai set chan 2-3
moi khi phat.



Hnh 1.8: Ket noi t ong
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 14
Vi mach hnh tren th khi ta viet chng trnh ieu khien, ta khong
can phai chot bo ieu khien, v dung 75176B ket hp vi 555, se cho ta thi
gian delay u e bo ieu nay hoat ong ( Enable ) th bo ieu khien khac
khong hoat ong ( Disable ). Giai thch cu the nguyen ly hoat ong cua
mach tren, se c e cap trong phan thiet ke mach.
7. Viec cho phep bo ieu khien ( Driver ):
Mot viec quan trong trong s dung mang ban song cong la viec ieu
khien cho phep cac bo ieu khien ( bo phat ). Khi mot bo phat ang chuyen
th no van con c cho phep cho en khi no thc hien xong viec chuyen
data. Sau o no khong c cho phep trc khi cac node khac thc hien
viec phat.
Hnh 1.9: Tn hieu cho phep cua bo phat va 1 byte data c phat

Moi quan he gia mot byte d lieu phat va tn hieu cho phep bo phat
Co 3 cach e ieu khien chan cho phep cua 485:
Hnh tren 1 bit se ieu khien ca bo thu va bo phat tren moi
chip, v chan cho phep bo phat tch cc mc cao, trong khi o chan cho
phep bo thu tch cc mc thap. Do o ch co mot chan c cho phep tai
mot thi iem.
Trong nhieu mang, au ra bo thu luc nao cung c tch cc do
o no co the c noi vi at. Bit ieu khien ch noi vi chan Enable cua
bo phat. Viec bo chan Enable cua bo thu cung cap mot cach n gian cho
1 node e phat hien khi nao th mot chuyen oi hoan thanh, bang cach
oc d lieu truyen tr lai
e linh hoat hn ta co the s dung cac bit rieng re e ieu
khien cac chan Enable cua bo phat va bo thu.





uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 15







I. Gii Thieu:
Co hai tieu chuan chnh yeu ap dung cho qua trnh truyen d lieu noi
tiep la vong dong ien 20mA va RS-232. Vong dong ien 20mA s dung
tn hieu dong ien e mang d lieu, con chuan RS-232 s dung cac mc
ien ap.
cac nc phat trien khai niem vong dong ien a quen thuoc vi
nhieu ngi lam viec trong lnh vc o lng, ieu khien va t ong hoa
trong cac c s san xuat cong nghiep. Khai niem vong dong ien con mi
me va t c trnh bay trong cac giao trnh. Di ay toi gii thieu vai net
ve nguon goc, cac chuan vong dong ien va nguyen tac hoat ong, ng
dung cua chung:
II. Vong dong ien:
1) NGUON GOC:
Mo hnh cua he thong truyen d lieu bang vong dong ien bat
nguon t phng phap tieu chuan a s dung tren cac may ien bao in ch.
Cac may anh ien bao kieu c ien a c dung kha rong rai vao cuoi
nhng nam 1930 vi thiet b t cac cong ty nh Kleinschnitt va The
Teletype Corporation ( My )
2) TRUYEN D LIEU BANG VONG DONG IEN:
Thay cho viec dung mc ien ap, viec truyen d lieu con co the
c tien hanh nh s chuyen mc dong ien, hay noi khac i la thay oi
gia tr dong ien. Giao dien noi tiep cung gii thieu 2 kha nang, e tuy
chon mot trong hai phng phap truyen
Giao dien dong 20mA ra i trc RS-232 c xem nh mot tieu
chuan. Giao dien nay con c goi la giao dien TTY hoac thng goi la
vong dong ien, mo ta trang thai logic qua tac ong cho hoac khong cho
dong ien 20mA i qua. Giao dien dong 20mA c chia ra lam hai phan:
chu ong ( co nguon dong khong oi 20mA rieng ) va b ong ( dong ien
20mA c tao ra t thiet b ghep noi ). Nh vay, th bao gi cung co mot
thanh vien giao tiep goi la chu ong con thanh vien kia goi la b ong.
giao dien dong 20mA co nhng tn hieu sau:
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 16
- TxD ( + ) d lieu gi ( ng dan i )
- TxD ( - ) d lieu gi ( ng dan ve )
- RxD ( + ) d lieu nhan ( ng dan i )
- RxD ( - ) d lieu nhan ( ng dan ve )
Thong thng th giao dien dong 20mA khong co tn hieu bat tay
khi thiet lap ng truyen. Vi giao dien nay, viec truyen d lieu tren
1.000 m et la hoan toan co the thc hien c. Nhieu sinh ra tren ng
truyen anh hng cam ng len ca ng dan tn hieu i va en, do o
nhieu b loai tr. Muon the ng dan i va ng dan ve ( con c goi la
ng ao va khong ao ) phai at sat nhau, sao cho khi mot tn hieu nhie u
xuat hien th cung anh hng ca len hai ng tn hieu, xoan hai day vi
nhau lam ng truyen. Tat nhien vi giao tiep nay khong the co c toc
o truyen cao
Co 2 chuan vong ien khac nhau: 60mA va 20mA trong o chuan
60mA a loi thi. Ly do e vong dong ien tr nen pho bien oi vi cac
may ien bao in ch la tnh hieu qua cua phng phap. Cu the moi ch in
ra nh viec s dung cac vong dong ien, trong o moi ch tng ng vi
mot nhom la chon t 5 en 7 cuon day co loi sat, kch hoat cac thanh gat
ben trong may. Cac cuon day nay c ni thanh cac day vi so lng cac
cuon day khac nhau, tuy thuoc vao k t can c truyen. Thc te cho thay
trong trng hp nay viec truyen ien ap khong hieu qua bang viec truyen
dong ien
Co t nhat la 3 kieu thiet b vong dong ien khac nhau:
- Ch co may in
- Ch co ban phm
- Co ca ban phm va may in ket hp vi nhau
Co 3 kieu truyen thong c s dung vi cac he thong vong dong ien o
la: n cong, ban song cong va song cong

He thong n cong: cho phep truyen thong tin theo mot hng. Nh
vay mot bo nhan se luon nhan thong tin, con bo truyen se luon truyen
thong tin va khong bao gi xay ra viec thay oi vai tro; luong d lieu luon
i theo mot hng.
He thong ban song cong va song cong: cho phep cac thong tin theo hai
chieu, nhng ch theo mot hng tng thi iem. Cac vong dong ien n
cong va ban song cong ch can mot cap ng truyen, trong khi vong song
cong can hai cap ng truyen, moi cap cho mot hng. Tuy nhien hoat
ong song cong van co the thc hien tren mot cap day xoan n gian neu
nh cac mc d lieu trc het c bien oi thanh tn hieu am thanh, cu
the hn la thanh tn hieu co tan so nam trong vung tai nghe c ( audio
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 17
tone ). Trong trng hp ay, he thong se s dung cac cap khac nhau cua tn
hieu e dien ta mc logic 0 va 1, moi cap cho mot hng.

a)VONG DONG IEN 60mA:
Vong dong ien 60mA bay gi a loi thi va ch tm thay trong cac
thiet b cu. He thong 60mA c mo ta tren hnh cho thay mot trong cac
may ien bao in ch co the c noi vi cong loi ra noi tiep tng thch
TTL. Trong nhieu trng hp, mot bit cua mot cong song song se c cau
hnh nh cong noi tiep thong qua hoac la phan mem hoac la bo sung phan
cng. Tren hnh 4.2, bit co t y ngha nhat (LSB) cua cong song song c
ch nh nh au ra noi tiep
R1
220
R2
2
1
NGUON NUOI
130V DC
D5 T1
MJE340
Cong loi ra TTL, LBS
May i en bao
60 WPM
Baudot

Vong dong ien loai 60mA
Mc TTL t cong ra noi tiep tren hnh 4.2 ieu khien cc B cua
TST cong suat, chu ien ap cao. Hai cc C, E cua TST c au noi tiep
vi dong ien 60mA va nh vay no hoat ong nh mot chuyen mach (cong
tac). Khi mc TTl la High, TST T1 m va dong ien chay trong vong.
Ngc lai, khi bit TTL la LOW, TST chuyen sang trang thai cam va se
khong co cong ien i qua mach Do o TST cung cap mot mc logic 1, khi
bit TTL la High, va mc logic 0 khi la Low
Vong dong ien c nuoi t nguon mot chieu 120 en 140 V, co
mot bien tr ieu chnh c mac noi tiep (R2), c s dung e at gan
ung mc dong ien
Mc dong ien trong vong dong ien 60mA c ieu chnh bang
cach ngat vong va chen vao mach mot mili ampe ke vi thang o 0 en
100mA
Phm se c nhan tren ban phm, hoac trong trng hp cua hnh
4.2, mot mc HIGH phai c viet vao cong loi ra noi tiep. Tac ong nay
se ong mach vong va cho phep dong i qua. Chiet ap R2, c noi vi
bien tr, khi o se tien hanh ieu chnh cho dong ien i qua xap x 60mA
Nhc iem: de lam hong linh kien do dong ln.
Cach khac phuc: dung mach cach ly, bo ghep noi quang.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 18
D1
5.6V
Bo ghep noi quang
R4
2.2K
R1
220
Cong loi ra TTL
T1
Mach ien hnh tren
R3
+130V
R5
220

Mach ghep noi quang

b)VONG DONG IEN 20mA
Chuan vong dong ien ln hn a s dung dong ien vi cng o
20mA cho mc logic 1 va dong ien t 0 en 2mA cho mc logic 0 . Cac
may vi vong dong ien 60mA a cu, tren o s dung ma ien bao Baudot
5 bit, trong khi hau het cac may s dung vong 20mA eu s dung ma
ASCII.
D lieu vao
+5V
Loi ra 20 mA
R1
220
1 2
D1
1N4007
Bo ghep noi quang

Bo bien oi TTL sang tn hieu dong 20mA

hnh tren ch ra mot phng phap n gian cho phep s dung bo ghep noi
quang e ghep noi cong noi tiep cua may tnh vi mot vong dong ien
20mA. Nguyen tac hoat ong: khi d lieu vao la HIGH , th loi ra cua U1
chuyen sang mc LOW, do o cc am cua Diod se noi at. Tac ong nay
lam TST dan, va cho phep dong ien i qua mach. Diod D1 dung e ngan
nga hong hoc va nhng phien phc khac gay ra bi xung ien cam ng
khi phat sinh khi cac cuon day phong ien.

c)VONG DONG IEN 4 EN 20mA:
Trong ky thuat ieu khien cac qua trnh cong nghiep ngi ta thng
s dung he thong vong dong ien e truyen cac so lieu o lng. Hnh 4-9
ch ra mot he thong tieu bieu trong o 3 thiet b khac nhau thc hien trong
cung mot vong dong ien.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 19
Bo bien oi
ap ra dong
May ghi Analog May tnh so Bo ieu khien
Vong dong 4 - 20 mA

Vong dong ien 4 20mA dung trong ky thuat o lng

Tren cac bo ch th dong ien di dang so ang lu hanh tren th
trng, ta thay dai o khong phai la 0 20 mA ma la 4 20 mA. Cac bo
ch th nay s dung cho mot loai vong dong ie n khac, co pham vi cac gia
tr cho phep t 4 20mA. Muc ch cua viec s dung vong dong ien nay
la truyen cac gia tr nam trong mot vung, mo ta cac thong so ang c o.
Toan bo vung co o rong la 16 mA, nhng do vie c chon gia tr nho nhat la
4mA co the tang dong ien cc ai 20mA. Nguyen nhan cua s lech va
cung la u iem cua vong dong ien 4 en 20mA so vi cac vong dong
ien khac. Do mc logic 0 cua vong dong ien 20mA la 4mA nen de dang
phan biet gia tr zero va trang thai dong ien bang 0 ( LOW )

III. RS-232 va MAX 232:
1) at van e:
Ghep noi qua cong noi tiep RS-232 la mot trong nhng ky thuat
c s dung rong rai nhat e ghep noi cac thiet b ngoai vi vi may tnh.
Qua cong noi tiep co the ghep noi chuot, modem, may in, bo bien oi A/D,
cac thiet b o lng So lng va chung loai cac thiet b ngoai vi ghep
noi qua cong noi tiep ng hang au trong so cac kha nang ghep noi vi
may tnh. Cac cach ghep noi nay s dung phng phap truyen thong theo
kieu noi tiep, trong o moi thi iem ch co mot bit c gi i doc theo
mot ng dan. at iem nay khac vi phng pha p truyen thong theo
kieu song song, trong o nhieu bit c gi i ong thi. u iem chnh
cua kieu truyen noi tiep so vi cach truyen song song la mot ng dan
c s dung e truyen con mot ng dan khac dung e nhan.
Chuan RS-232 khi mi ch la chuan khong chnh thc ( defacto) a
c nhieu cong ty may tnh va thiet b o lng chap nhan. Sau ay, Hiep
hoi cac nha cong nghiep ien t ( EIA: The Electronic Industries
Association ), a xay dng thanh mot tieu chuan chnh thc, vao nam 1962.
ang tiec la tieu chuan nay ch cho phep s dung ng truyen ngan, vi
toc o bit thap, v du toc o truyen theo bit bang 19.600 bit/sec, vi khoang
cach cc ai bang 20m. Cac tieu chuan truyen thong noi tiep ra i sau,
nh RS-422, RS-449, RS-485, cho phep truyen tren ng cap rat dai, vi
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 20
toc o bit rat cao. Chang han RS-422 cho phep toc o truyen ln hn
10Mbps, con khoang cach tren 1000m, trong khi co the s dung cap hai si
xoan, cap ong truc hoac cap quang. Cac chuan mi cung co the c s
dung e xay dng cac mang may tnh.
2) Vai net ve nguon goc:
Sau mot thi gian lu hanh khong chnh thc, e nam 1962,
Hiep hoi cac nha Cong Nghiep ien T (EIA) a cho ban hanh chuan RS-
232 ap dung cho cong noi tiep. Cac ch RS c viet tat t Recommended
Standard ( Tieu chuan a gii thieu)
Co hai phien ban RS-232 c lu hanh trong thi gian tng oi
dai la RS-232B va RS-232C. Cho en nay RS-232B la phien ban cu con
RS-232C th ra i sau va hien van con ton tai. V chuan RS-232B a loi
thi t nhieu nam, nen trong cac tai lieu t e cap en. Tieu cuan ang
c ap dung hien nay la RS-232C, goi ngan gon la RS-232. cac nc
Tay Au, chuan ghep noi RS-232 con goi la chuan V.24.
EIA a cong bo tieu chuan RS-232C vi no lc nham tao ra kha
nang e ghep noi cac thiet b do nhieu nha san xuat lam ra ma khong oi
hoi co tieu chuan at biet cho tng trng hp.
Y tng e xay dng tieu chuan RS-232 la phai s dung cung loai
au noi day, v du au noi 25 chan hoac 9 chan, c noi theo cung mot
cach va phai s dung cung mc ien ap khi bieu dien cac so nh phan 1 va
0 tng ng. Vi y tng nay, neu nh moi ngi ieu tham gia vao tieu
chuan theo cung mot cach th co the noi cac thiet b vi cong RS-232 cua
cac hang khac nhau, cac mau ma khac nhau ma khong can co them ieu
kien nao. Cac modem, cac modem, cac may in va nhieu thiet b khac co
the c au noi vao giao dien RS-232. Ngay nay, hau het cac may tnh
eu trang b mot hoac hai cong noi tiep RS-232, va tat ca eu co kha nang
s dung RS-232, t nhat la nh mot kha nang tuy chon t nha san xuat may
tnh hoac t pha ngi s dung may tnh.
Viec thiet ke cong RS-232 cung tng oi de dang, ac biet neu nh
chon che o hoat ong la khong ong bo toc o truyen d lieu thap,
chang han nh trong khoang 110 en 1200 baud.
Cac mach ien tch hp ca bo phat va bo nhan RS-232C a c cac
nha san xuat khac nhau thiet ke va che tao, v du Motorola, National
Semiconductors. Cac chip bo/ bo em RS-232 tiep nhan vi mc ien ap
TTL loi vao va bien oi chung thanh cac mc danh rieng cho RS-232 e
truyen. Cac bo nhan RS-232 lam viec theo cach ngc lai: tiep nhan tn
hieu loi vao theo chuan RS-232 va bien oi cac tn hieu sang cac mc TTL
tng ng. Cac bo phan nay eu nam tren ban mach chnh hoac tren card
vao/ra, ngha la pha sau cua cong RS-232.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 21
3) Truyen d lieu noi tiep:
Co 2 loai nh dang truyen d lieu noi tiep la: nh dang ong bo va
nh dang khong ong bo.
a) nh dang ong bo:
Trong thu phat ong bo, tat ca cac thiet b s dung chung nguon
xung clock cua mot thiet b hoac mot nguon ben ngoai.


Clock
0 0 1
Data
0
Bit 0 Bit 7
1 0
(41H)
0 1


Phat ong bo MSB
Moi bit phat c xac nh bang canh len hoac canh xuong cua xung
clock. Ben nhan s dung xung clock ay e xax nh khi nao th bit c
oc vao.
Thu phat ong bo ch ap dung cho khoang cach ngan, chieu dai
cable toi a la 50m hoac t hn. Vi khoang cach ln, viec thu phat ong
bo t c dung v can truyen xung clock, ma ieu nay yeu cau mot day
phu ( extra line ), chnh v the de nhieu.
b) nh dang bat ong bo:
Trong thu phat bat ong bo ( asynchronous ) ket noi khong can day
clock. Moi byte c phat gom bit Start e ong bo clock, va co mot hoac
nhieu hn mot bit Stop e bao ket thuc viec phat mot t ( word )
Port RS-232 ( cong COM ) tren PC s dung nh dang khong ong
bo e thong tin vi modems va cac thiet b khac.
Thu phat ong bo co the s dung cho nhieu loai nh dang, pho bien
nhat la 8-N-1 ( 8 bit data, khong Parity, 1 bit Stop ). Moi byte data gom 1
bit Start ( bit 0, LSB ) va 1 bit Stop

Data
Start
0 Bit
Stop
0 0 1 0
Bit 7
Bit 1 1 0
Bit 0
(41H)


Thu phat bat ong bo LSB




uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 22
4) Cac at trng ien:
Cac ien ap ng truyen:
Tieu chuan RS-232 au tien ra i a mang ve loi thi cua cac
chuan TTL. Ly do la chuan RS-232 van s dung cac mc ien ap tng
thch TTL e mo ta cac mc logic 0 va 1, giong nh trng hp cong may
in ( cong song song ). Ngoai mc ien ap, tieu chuan cung co nh cac gia
tr tr khang tai c au vao bus cua bo nhan va cac tr khang cua bo
phat/bo em ( drivers).
Mc ien ap cua hai tieu chuan RS-232 cai tien ( RS-232B va RS-
232C ) c mieu ta tren hnh 3-1. trong phien ban cu hn, RS-232B, mc
logic 1 la mot ien ap bat ky, trong pham vi t 5 en 25V, trong khi
logic 0 la bat c mc ien ap nao nam trong khoang +5V en +25V. Cac
mc ien ap trong khoang t 3V en +3V la trang thai chuyen tiep, trong
khi cac pham vi t 63V en 65V khong c xac nh va se dan en ket
qua khong the d tnh trc neu nh c s dung; tnh trang nay a xuat
hien trong cac he thong c thiet ke s sai.
+25
+12
+5
+3
Khong xac nh
ien ap(V) 0
RS-232B
RS-232C
Logic 0
-25
-12
-5
-3
Khong xac nh
ien ap(V) 0
RS-232B
RS-232C
Logic 1
Ca c m c ie n a p chua n cu a RS-232

Cac ien cua tieu chuan RS-232 quy nh cu the ien ap cc tieu va ca ai
cua cac mc logic 0 va 1. Mc ien ap bang 0V bo nhan, c hieu nh
ng truyen b t hay b chap mach.
Trong chuan RS-232C, e co c toc o truyen d lieu nhanh hn,
ngi ta s dung khoang chenh lech hep hn gia mc logic 0 va 1. Cac
gii han tren oi vi mc logic 0 va logic 1 la 612V, ch khong dung gii
han 625V nh trong chuan RS-232B. Neu khong co cac xung xuat hien tren
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 23
ng dan th mc ien ap tng ng vi mc HIGH, tc la 12V. Hnh
3-2 ch ra mot v du ve mc ien ap va dang cua tn hieu c truyen.

Bi t Start
1 1 1 1 0 0 0 0
Bi t Stop
LOW
HIGH
+12V
-12V
T = 1/f
Baud
0,52ms
D0 D1 D2 D3 D4 D5 D6 D7
Ca c m c ie n a p va do ng d lie u v i to c o 19.200 baud

Ngoai viec thu hep gii han ien ap, chuan RS-232C ma ngay nay
ang ap dung a co nh tai trong pham vi t 3.000 en 7.000O, va tr
khang ra cua bo em thap hn trc o. ong thi, bo em can phai duy tr
mot toc o tang ien ap ( slew rate ) bang 30V trong mot s ( 30V/s ). Cac
vi mach Motorola loai MC1488 va MC1489 a hoan toan thoa man cac
thong so ky thuat nay.
Cac yeu cau ve mat ien trong chuan RS-232 nh sau:
1. Mc logic 1(mc dau) nam trong khoang: -3V en 12V;
mc logic 0(mc trong ) nam trong khoang: +3V en +12V.
2. Tr khang tai ve pha bo nhan cua tai phai ln hn 3.000 O
nhng phai nho hn 7.000O
3. Toc o truyen nhan d lieu cc ai la 100kbit/sec
4. Cac loi vao cua bo nhan phai co dien dung nho hn 2.500
pF
5. o dai cua cap noi gia may tnh va thiet b ghep noi qua
cong noi tiep khong the vt qua 15m neu khong s dung
modem
6. Cac gia tr toc o truyen d lieu chuan la 50,75, 110, 150,
300, 600, 1.200, 2.400, 4.800, 9.600, 19.200, 28.800, ,
56.600 baund.
Hnh 3-2 mo ta cac mc ien ap va o rong xung khi truyen mot ky t
vi toc o bang 19.200



uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 24
5) Khuong mau khung truyen:
Hnh sau ay th du ve mot ky t c truyen theo frame gom :
1 bit bat au, 8 bit d lieu, 1 bit chan le, va 1 bit ket thuc.
RS-232 s dung cach truyen thong tin theo kieu khong ong bo,
khuon mau d lieu vi cac bit bat au va dng, nh ch ra tren hnh 3-4. Ta
co the thay ro la tai mot thi iem ch co mot k t c truyen i va co
thi gian phan cach gia chung. Khoang thi gian tr hoan nay thc chat la
khoang thi gian hoat ong khong hieu qua va c at mc logic cao ( -
12V ) nh ch ra tren hnh 3-4. Bo truyen gi mot bit start e thong bao cho
bo nhan biet mot k t se c gi en trong lan gi bit tiep theo. Bit bat
au nay luon mc 0. Tiep theo 5, 6 hoac 7 bit d lieu c gi di dang
k t ma ASCII 7 bit, tiep theo la mot bit chan le va cuoi cung la 1, 1.5, 2
bit stop. Hnh 3-5 ch ra mot khuon dang khung truyen mot k t A va s
dung tnh chan le la le. Khoang thi gian phan cach cua mot bit n quy
nh toc o truyen . Ca bo em truyen va nhan can phai c at cung
khoang thi gian bit do hay noi cach khac la bo truyen va nhan phai co
cung toc o baund. Viec thiet lap ong bo ch mang tnh tng oi e bo
truyen va nhan co toc o xap x nhau, ly do la tn hieu mang d lieu ch
xuat hien trong thi gian tng oi ngan.
V du tren hnh 3-5 mo ta gian o mc logic the hien mot khung
truyen d lieu noi tiep RS-232 s dung: 1 bit start, 7 bit data, 1 bit parity, 2
bit stop. ay la mot oan cua thong bao gi tren luong d lieu sau ay:
Bit au tien gi

111110100010110000011111111111111000001111111100011001111011001
11111111111

khuon mau cua xau d lieu gi c ch ra di ay:
-12V
+12V
1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
Bit chan le (tuy chon)
Bit ket thuc
Trang thai anh dau
Bit thap
trc
Bit cao
sau
8 bit d lieu
11001001B
Bit bat au (mc 0)
Trang thai anh dau (mc 1)
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 25

{idle: khoang trong } 11111 { bit bat au } 0 {A} 1000001 { bit parity } 0 {
cac bit stop } 11 { bit bat au } 0 {p} 0000111 { bit parity } 1 { cac bit stop
} 11 {idle} 11111111 { bit bat au } 0 {p} 0000111 { bit parity } 1 { cac
bit stop } 11 {idle} 11 { bit bat au } 0 {L} 0011001 { bit parity } 1 { cac
bit stop } 11
Nh vay thong iep a gi la AppL

BIT CHAN LE:
Thc chat qua trnh kiem tra loi khi truyen d lieu la bo sung them d
lieu vao dong d lieu c truyen e tm ra hoac sa cha loi trong qua trnh
truyen. Chuan RS-232 s dung mot ky thuat n gian goi la chan le e co
kha nang phat hien loi.
Mot bit chan le se c bo sung vao d lieu c truyen e cho thay
so cac so 1 ( cac bit co gia tr bang 1 ) c gi trong mot khung truyen la
chan hay le. ay la mot phng phap n gian e ma hoa loi va ch can en
mot cong XOR e tao ra bit chan le. Bit chan le bo sung vao d lieu c
truyen bang cach chen no vao mot v tr chnh xac cua bit trong thanh ghi
dch sau khi a em xem co bao nhieu so 1 a c gi.
Mot bit chan n gian ch co the tm ra mot so le cac loi, chang han 1,
3, 5, Neu nh co mot so chan cac bit loi th bit chan le se trung vi bit
khong mac loi va khong phat hien ra loi. Ky thuat ma hoa loi theo cach nay
thng khong c s dung trong trng hp mot vai bit mac loi.
6) Cac au noi
Theo chuan RS-232-C, au noi phan cng xac nh vi 25 chan, goi la
chan cam D-Shell hay DB-25. Nhng khong phai tat ca cong noi tiep eu s
dung au noi DB-25. Mot so may tnh nh PCjr dung chan cam BERG 16
chan, may PC AT th s dung chan cam D-Shell 9 chan.
7) Mo ta chan
au noi
Chc nang Ten Hng
DB-25 DB-9 BERG
1 B2 at GND
2 3 A4 Truyen d lieu TXD Xuat
3 2 A8 Nhan d lieu RXD Nhap
4 7 A3 Yeu cau gi RTS Xuat
1 13
14 25
1 5
6 9
A1 A8
B1 B8
DB-25 DB-9 16-pin BERG
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 26
5 8 A7 Xoa viec gi CTS Nhap
6 6 A6 D lieu san sang DSR Nhap
7 5 B1 Noi at vo may GND
8 1 A5 Do song mang DCD
20 4 A2 Terminal san sang DTR Xuat
22 9 Bo ch th vong RI Nhap

8) MAX232 va ho IC dung bien oi TTLRS-232-C
Ho IC t MAX220-MAX249 c san xuat cho truyen thong EIA/TIA-232E
va V.28/V.24, cu the la cho nhng ng dung ma khong co san ien ap 12V.
Ho IC nay ac biet thch hp cho nhng he thong dung pin co cong suat thap,
do chung co che o ha nguon lam giam cong suat tieu tan xuong di 5W.
MAX225, MAX233, MAX235, MAX245-MAX247 khong can cac linh kien
phu ben ngoai, c dung cho nhng ni tiet kiem khong gian.
Cac ac iem chnh :
- Nguon cung cap +5V (MAX231/MAX239 dung nguon +5V va +12V).
- Ha nguon cong suat thap nhng van co the nhan (MAX223/MAX242).
- Ho tr chuan EIA/TIA-232E va V.28
- Nhieu bo nhan va phat.
- Phat hien t mach ng truyen (MAX243).
a) Cau tao chan
b) Mo ta chc nang chan
Ta thay rang MAX232 can co 4 tu ngoai (mac vao gia C1+ va
C1-, C2+ va C2-, V+ va nguon dng, V- va at e bien oi ien ap t 0V
en 5V thanh -12V en +12V phu hp cho truyen thong theo chuan RS-
232. Ngoai ra co 4 bo khuech ai ao nham chuyen t mc TTL ra chuan
RS-232 va ngc lai.
c) S o khoi va mach tieu bieu
S o sau ay cho thay cac khoi ben trong MAX232 va cac linh
kien mac ben ngoai theo dang chuan :
MAX232
13
8
11
10
1
3
4
5
2
6
12
9
14
7
16
15
R1IN
R2IN
T1IN
T2IN
C1+
C1-
C2+
C2-
V+
V-
R1OUT
R2OUT
T1OUT
T2OUT
VCC
GND
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 27













+5V
+5V
+5V
+5V
400K
400K
5K
5K
+ 10uF
+ 10uF
+
10uF
+
10uF
T1
T2
R1
R2
GND
15
R2IN
R1IN
T1OUT
T2OUT
T1IN
T2IN
R1OUT
R2OUT
C1+
C1-
C2+
C2-
VCC
V+
V-
16
1
3
4
5
2
6
TTL/CMOS
INPUT
TTL/CMOS
OUTPUT
11
10
12
9
14
13
7
8
RS-232
INPUT
RS-232
OUTPUT
BIE N O I IE N A P
-12V e n +12V
RS-232
OUTPUT
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 28











1) VI IEU KHIEN AT89C51:
Do ho MCS-51
TM
a tr thanh chuan cong nghiep nen co rat nhieu
hang san xuat ra no, ien hnh la ATMEL Corporation. Hang nay a ket
hp rat nhieu tnh nang da tren nen tang ky thuat cua mnh e tao ra cac
vi ieu khien tng thch vi MCS-51
TM
nhng manh me hn.
AT89C52 la mot vi ieu khien 8 bit do ATMEL san xuat, che tao
theo cong nghe CMOS, co chat lng cao, cong suat thap vi 8 KB Flash
(flash programmable and erasable read only memory). Thiet b nay c
che tao bang cach s dung ky thuat bo nh khong boc hi mat o cao cua
ATMEL va tng thch vi chuan cong nghiep MCS-51
TM
ve tap lenh va
cac chan ra. Flash on-chip cho phep bo nh lap trnh c lap trnh trong he
thong bi mot lap trnh vien bnh thng. Bang cach noi 1 CPU 8 bit vi
mot Flash tren mot chip n, AT89C51 la mot vi ieu khien manh (co cong
suat ln), cung cap mot s linh ong cao va giai phap ve gia ca oi vi
nhieu ng dung vi ieu khien.
Cac ac iem chu yeu cua AT89C51 :
- Tng thch hoan toan vi ho MCS-51
TM
cua Intel.
- Bo nh chng trnh 8K Byte thuoc loai Flash Memory.
- o ben : 1000 lan ghi/xoa.
- Tan so hoat ong : 0 Hz en 24 MHz.
- 3 che o khoa bo nh.
- 256 x 8-Bit RAM noi.
- 32 ng I/O lap trnh c (4 port).
- 3 timer/counter 16-bit.
- 8 nguon ngat.
- Che o ha nguon va che o li tieu ton cong suat thap.



uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 29
1.1. Cau tao chan
Tuy theo kha nang (ve kinh te, ky thuat, ) ma cac nha san xuat cac
san pham ng dung co the chon mot trong 3 kieu chan do ATMEL a ra.

1.2. S o khoi
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 30

1.3. Mo ta chc nang cua cac chan
Vcc : ap nguon.
GND : at.
Port 0 : la mot port I/O 8-bit hai chieu, cc mang h. Khi xuat ra, moi
chan port co the lai 8 au vao TTL. Neu ghi cac mc 1 ra cac chan port
th cac chan nay co the dung nh cac au vao tr khang cao.
Port 0 cung co the c cau hnh thanh mot bus multiplex gia a ch
thap va d lieu khi truy cap chng trnh hay d lieu t ben ngoai. Trong
che o nay, port 0 co ien tr pullup noi.
Port 0 cung nhan cac byte ma chng trnh khi lap trnh Flash va xuat
ra ma chng trnh khi kiem tra, khi o can co ien tr pullup ben ngoai.
Port 1 : la mot port I/O 8-bit hai chieu co pullup noi. au ra port 1 co
the lai 4 au vao TTL. Khi viet cac mc 1 ra cac chan port th chung
c keo len do co ien tr noi va co the dung lam au vao. Khi vai tro
la cong nhap, nhng chan cua port 1 b keo xuong thap se o dong v co
noi tr keo len.
Hn na, P1.0 va P1.1 co the c dung nh la au vao bo em
timer/counter 2 ben ngoai (P1.0/T2) va xung kch (P1.1/T2EX).
Port 1 cung nhan nhng byte a ch thap trong khi lap trnh Flash va
trong khi kiem tra Flash .
Port 2 : la mot port I/O 8-bit hai chieu co pullup noi. au ra port 2 co
the lai 4 au vao TTL. Khi viet cac mc 1 ra cac chan port th chung
c keo len do co ien tr noi va co the dung lam au vao. Khi vai tro
la cong nhap, nhng chan cua port 2 b keo xuong thap se o dong v co
noi tr keo len.
Port 2 phat byte a ch cao trong khi nhan lenh t bo nh chng trnh
ngoai va trong luc truy xuat en bo nh d lieu ngoai ma co s dung a
ch 16 bit (MOVX A, @DPTR). Trong ng dung nay no dung ien tr noi
keo len manh khi xuat 1. Khi truy xuat bo nh d lieu ngoai dung a ch
8 bit, port 2 se phat noi dung cua thanh ghi P2
Port 2 cung nhan byte a ch cao trong luc lap trnh Flash va trong luc
kiem tra Flash.
Port 3 : la mot port I/O 8-bit hai chieu co pullup noi. au ra port 3 co
the lai 4 au vao TTL. Khi viet cac mc 1 ra cac chan port th chung
c keo len do co ien tr noi va co the dung lam au vao. Khi vai tro
la cong nhap, nhng chan cua port 3 b keo xuong thap se o dong v co
noi tr keo len.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 31
Port 3 cung co nhng chc nang cua ho MSC-51 c liet ke bang sau:
BIT
TEN A CH BIT CHC NANG THAY THE
P3.0
RXD B0H Nhan d lieu cho port noi tiep
P3.1
TXD B1H Truyen d lieu cho port noi tiep
P3.2
INT0 B2H Ngat ngoai 0
P3.3
INT1 B3H Ngat ngoai 1
P3.4
T0 B4H Ngo vao t ben ngoai cho timer/counter 0
P3.5
T1 B5H Ngo vao t ben ngoai cho timer/counter 1
P3.6
WR B6H Xung ghi bo nh d lieu ngoai
P3.7
RD B7H Xung oc bo nh d lieu ngoai
Port 3 cung nhan vai tn hieu ieu khien trong luc lap trnh Flash va trong
luc kiem tra Flash.
RST : la ngo vao Reset. Khi ngo nay c a len cao (trong t nhat hai
chu k may), cac thanh ghi ben trong AT89C51 c tai nhng gia tr
thch hp e khi ong he thong.
ALE/PROG (Address Latch Enable) : ALE la xung xuat cho phep chot
byte a ch thap khi truy cap bo nh ngoai. Chan nay con la ngo vao cua
xung lap trnh (PROG) khi lap trnh Flash.
Trong hoat ong bnh thng, ALE c phat xung vi tan so 1/6 tan so
dao ong on-chip va co the c dung nh xung thi gian chuan ben
ngoai. Tuy nhien, can chu y la mot xung ALE se b mat khi truy cap bo
nh ngoai.
Co the huy bo chc nang cua ALE bang cach set bit 0 cua thanh ghi v
tr 8EH. Mot khi bit nay c set, ALE ch tch cc khi co lenh MOVX
hoac MOVC. Neu khong co cac lenh nay th ALE mc cao. Viec set bit
0 cua thanh ghi v tr 8EH khong lam anh hng en vi ieu khien khi
truy cap bo nh ngoai.
PSEN (Program Store Enable) : PSEN la xung strobe bao hieu viec oc
bo nh chng trnh ngoai, PSEN tch cc hai lan (mc thap) moi chu k
may, ngoai tr hai xung PSEN b mat khi truy xuat d lieu ngoai. Khi thi
hanh chng trnh trong RAM noi, PSEN se mc thu ong (mc cao).
EA/V
PP
(External Access) : EA la ngo vao e cho phep truy xuat bo nh
chng trnh t ben ngoai khi c noi vi GND. Khi EA c treo len
nguon V
CC
, chng trnh se c thc thi trong ROM noi. Chan nay cung
nhan ien ap 12v (V
PP
) trong khi lap trnh Flash.
XTAL1 : au vao cua bo khuech ai dao ong ao va cung la au vao
en mach tao xung clock noi.
XTAL2 : au ra cua bo khuech ai dao ong ao.


uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 32
2) GII THIEU VE SERIAL PORT CUA AT89C51:
2.1. GII THIEU:
AT8951 co mot port noi tiep trong chip co the hoat ong nhieu
che o tren mot dai tan so rong. Chc nang chu yeu cua port noi tiep la
thc hien chuyen oi song song sang noi tiep oi vi d lieu xuat, va
chuyen oi noi tiep sang song song vi d lieu nhap. Truy xuat phan cng
en port noi tiep qua cac chan TXD (P3.1) va RXD (P3.0).
Port noi tiep cho hoat ong song cong (full duplex: thu va phat
ong thi), va em luc thu (receiver buffering), cho phep mot ky t se c
thu va c gi trong khi ky t th hai c nhan. Neu CPU oc ky t th
nhat trc khi ky t th hai c thu c thu ay u th d lieu se khong
b mat.
Hai thanh ghi chc nang ac biet cho phep phan mem truy xuat
en port noi tiep la: SBUF va SCON. Bo em port noi tiep (SBUF) a
ch 99H that s la hai bo em. Viet vao SBUF e nap d lieu se phat, va
oc SBUF e truy xuat d lieu thu c. ay la hai thanh ghi rieng biet:
thanh ghi ch ghi e phat va thanh ghi ch oc e thu.
Thanh ghi ieu khien port noi tiep (SCON) a ch 98H la thanh
ghi co a ch bit cha cac bit trang thai va cac bit ieu khien. Cac bit ieu
khien at che o hoat ong cho port noi tiep, va cac bit trang thai bao ket
thuc viec phat hoac thu ky t. Cac bit trang thai co the c kiem tra bang
phan mem hoac co the c lap trnh e tao ngat.
Tan so lam viec cua port noi tiep, con goi la toc o baud co the co
nh (lay t bo dao ong tren chip) hoac thay oi. Neu s dung toc o baud
thay oi, Timer 1 se cung cap xung nhp toc o baud va phai c lap trnh.

S o khoi port noi tiep.

CLK SBUF Q
(ch ghi)

TXD
(P3.1)

Thanh ghi dch


D
CLK
Xung nhp
toc o baud
(phat)
Xung nhp
toc o baud
(thu)
RXD
(P3.0)

SBUF
(ch oc)

Bus noi 8051
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 33
2.2. THANH GHI IEU KHIEN (SCON) VA CAC CHE O HOAT ONG:
Che o hoat ong cua port noi tiep c at bang cach ghi vao
thanh ghi che o port noi tiep (SCON) a ch 98H.

Bit Ky
hieu
a ch Mo ta
SCON.7 SM0 9FH Bit 0 cua che o port noi tiep.
SCON.6 SM1 9EH Bit 1 cua che o port noi tiep.
SCON.5 SM2 9DH Bit 2 cua che o port noi tiep. Cho phep
truyen thong a x ly trong cac che o 2 va
3; RI se khong b tac ong neu bit th 9 thu
c la 0.
SCON.4 REN 9CH Cho phep thu, phai c at len 1 e thu
(nhan) cac ky t.
SCON.3 TB8 9BH Bit th 9 c phat trong cac che o 2 va 3;
c at va xoa bang phan mem.
SCON.2 RB8 9AH Bit th 9 thu c.
SCON.1 TI 99H C ngat phat. at len 1 khi ket thuc phat ky
t; c xoa bang phan mem.
SCON.0 RI 98H C ngat thu. at len 1 khi ket thuc thu ky t;
c xoa bang phan mem.
Bang tom tat thanh ghi SCON.
Port noi tiep co 4 che o hoat ong, trong o ba che o cho phep
truyen thong bat ong bo, vi moi ky t c thu hoac phat eu bat au
bang mot bit Start va ket thuc bang 1 bit Stop. che o th t, port noi tiep
hoat ong nh mot thanh ghi dich n gian.
SM0 SM1 Che o Mo ta Toc o baud
0 0 0 Thanh ghi dch Co nh (F
OSC
/12).
0 1 1 UART 8 bit Thay oi (at bang Timer).
1 0 2 UART 9 bit Co nh (F
OSC
chia cho 32 hoac
64).
1 1 3 UART 9 bit Thay oi (at bang Timer).
Bang cac che o cua Port noi tiep.

a) Thanh ghi dch 8 bit (che o 0):
D lieu noi tiep vao va ra qua RXD, con TXD xuat xung nhp dch. 8
bit c phat hoac thu vi bit au tien la LSB. Toc o baud co nh 1/12
tan so dao ong tren chip.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 34

Clock Thanh ghi

D lieu dch

TXD (P3.1)

RXD (P3.0)
8951
Them 8 ngo ra
12
Xung nhp toc
o baud
Dao ong tren
chip
Che o 0
32
Xung nhp toc
o baud
Toc o tran
Timer 1
Che o 1
16
SMOD = 0
SMOD = 1

Mot ng dung cua che o thanh ghi dch la m rong kha nang xuat
cua 8951. IC thanh ghi dch noi tiep ra song song co the c noi vao cac
ng TXD va RXD cua 8951 e cung cap them 8 ng ra. Co the noi
xau chuoi them cac thanh ghi dch e m rong them.

b) UART 8 bit vi toc o baud thay oi c (che o 1):
che o 1, port noi tiep cua 8951 lam viec nh mot UART 8
bit (8-bit Universal Asynchronous Receiver/Transmitter) vi toc o baud thay
oi c (bang toc o bao tran cua Timer 1).
Viec thu/phat tien hanh vi 10 bit, gom 1 bit Start (luon la 0), 8 bit d
lieu (LSB au tien) va 1 bit Stop (luon la 1).
Viec thu d lieu c khi ong bang mot chuyen trang thai t 1
xuong 0 tren RXD. Bo em 16 tc thi c xoa e ong bo so em vi
luong bit en. Luong bit en c lay mau gia 16 lan em. Gia s phat hien
c bit Start hp le, bit Start c bo qua va 8 bit d lieu c a vao
thanh ghi dch cong noi tiep theo xung nhp. Khi a co c tat ca 8 bit, ieu
sau ay xay ra:
- Bit th 9 (bit Stop) c chot vao RB8 trong SCON.
- SBUF c nap vi 8 bit d lieu.
- C ngat bo thu (RI) c at len 1 (c RI a xoa ve 0 trc khi ky t
c thu ve.)
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 35
64
Xung nhp toc
o baud
Dao ong tren
chip
Che o 2
32
SMOD = 0
SMOD = 1
32
Xung nhp toc
o baud
Toc o tran
Timer 1
Che o 3.
16
SMOD = 0
SMOD = 1

c) UART 9 bit vi toc o baud co nh (che o 2):
che o 2, port noi tiep cua 8951 lam viec nh mot UART 9 bit co
toc o baud co nh (bang 1/32 hoac 1/64 toc o dao ong tren chip). 11 bit
se c phat hoac thu gom: 1 bit Start, 8 bit d lieu, bit d lieu th 9 co the
lap trnh c va 1 bit Stop. Khi phat, bit th 9 la bit TB8 trong SCON (co
the la bit parity). Khi thu, bit th 9 thu c se trong RB8.
d) UART 9 bit vi toc o baud thay oi c (che o 3) :
Che o nay giong nh che o 2, ngoai tr toc o baud co the lap
trnh c theo toc o tran cua Timer.

Noi them ve SMOD:
Toc o baud b anh hng bi mot bit trong thanh ghi ieu khien
nguon cung cap (PCON, hay 87H). Bit 7 cua PCON la bit SMOD. at bit
SMOD len 1 lam gap oi toc o baud trong cac che o 1, 2 va 3.
V PCON khong c nh a ch bit nen e at bit SMOD len 1 co
the thc hien gian tiep qua mot thanh ghi nh a ch bit.

1
toc o baud

bit
Start

bit
Stop
D0 D1 D2 D3 D4 D5 D6 D7
TXD
TI (SCON.1)
Ngat phat, chuan
b cho d lieu)
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 36
Chang han:
MOV A, 87H ; Lay gia tr hien thi cua PCON
SETB ACC.7 ; at bit 7 (SMOD) len 1
MOV 87H, A ; Ghi gia tr ngc ve PCON.

S dung Timer 1 lam xung nhp toc o baud:
Cach thong dung e tao toc o baud la khi ong Timer 1 che o 8
bit t ong nap lai (che o 2) va at gia tr nap lai vao TH1 e toc o tran
ung vi toc o baud. Cung co the at c cac toc o baud thap bang
cach s dung Timer che o 1, tuy nhien cac thanh ghi TH1 va TL1 phai
c khi ong lai sau moi lan tran (Viec nay c thc hien trong chng
trnh phuc vu ngat). Mot chon la khac la cap xung nhp cho Timer 1 t
ngoai qua T1 (P3.5).
Cong thc tong quat e xac nh toc o baud trong cac che o 1 va 3
(SMOD = 0):
Toc o baud = Toc o tran cua Timer 1 32
V du, muon lam viec vi toc o baud la 1200 baud, th toc o tran cua
Timer 1 phai la:
1200 32 = 38.4 KHz.
Neu dung thach anh 12 MHz, Timer 1 c cap xung nhp 1 MHz
hay 1000 KHz. V toc o tran cua Timer 1 la 38.4 KHz va Timer 1 c
cap xung nhp 1000 KHz nen can tran sau 1000 38.4 = 26.04 xung nhp
(lam tron la 26). Timer em len va tran xay ra khi co s thay oi t FFH
xuong 00H so em nen gia tr can nap vao TH1 la 26 (vi che o 8 bit
t ong nap lai).
baud_const = 256 - (crystal / (12 * 32 * baud))
Do lam tron nen co sai so nho trong toc o baud. Tong quat th
cho phep dung sai 5% trong truyen thong bat ong bo (Start/Stop). Co the
co c toc o baud chnh xac neu dung thach anh 11.059 MHz.
Bang tom tat mot so chuan toc o baud thong dung.

Toc o
Baud (bps)
Tan so
MHZ
SMOD
(PCON.7
)
Gia tr nap
vao TH1
Toc o
Baud thc
(bps)
Sai so
(%)
1200 12 0 -26 (E6H) 1202 0.16
2400 12 0 -13(F3H) 2404 0.16
4800 12 0 -7(F9H) 4464 7
9600 12 0 -3(FDH) 10417 8.51
1200 12 1 -52(CCH) 1202 0.16
2400 12 1 -26(E6H) 2404 0.16
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 37
4800 12 1 -13(F3H) 4808 0.16
9600 12 1 -7(F9H) 8929 7
19200 12 1 -3(FDH) 20833 8.5
1200 11.059 0 -24(E8H) 1200 0
2400 11.059 0 -12(F4H) 2400 0
4800 11.059 0 -6(FAH) 4800 0
9600 11.059 0 -3(FDH) 9600 0
1200 11.059 1 -48(D0H) 1200 0
2400 11.059 1 -24(E8H) 2400 0
4800 11.059 1 -12(F4H) 4800 0
9600 11.059 1 -6(FAH) 9600 0
19200 11.059 1 -3(FDH) 19200 0
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 38
3) Cac thanh ghi chc nang (SFR-
Special Funtion Reisters)
AT89C52 co 26 thanh ghi chc nang c
thiet ke nh la mot thanh phan cua RAM
on-chip. Do o moi thanh ghi co mot a
ch cua no, nam trong vung t 80H en FFH. Tuy nhien, vung nay cung la vung bo nh
nen viec truy cap cac thanh ghi nay thong qua cac lenh dung nh v trc tiep khac vi
viec truy cap vung nh dung nh v gian tiep.
Bang v tr cac thanh ghi chc nang :
Chan Chc nang thay the
P1.0 T2 (au vao em cho Timer/Counter 2)
P1.1 T2EX (xung kch capture/reload cho
Timer/Counter 2 va ieu khien trc
tiep.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 39
Chu y la khong phai tat ca cac a ch eu co cac thanh ghi, nhng a ch khong
co thanh ghi nay co the khong co tren chip. oc nhng a ch nay se co nhng gia
tr ngau nhien va ghi nhng gia tri nay co nhng tac ong khong xac nh trc.
Phan mem cua ngi dung khong nen ghi nhng gia tr 1 en cac v tr nay, bi
v chung co the c dung trong tng lai. Trong trng hp o, gia tr cua cac bit
luon la 0.
Cac thanh ghi ngat tap cac bit rieng le cho phep ngat cha trong thanh ghi IE. Thiet
lap hai mc u tien cho 6 nguon ngat bang cach set cac bit thanh ghi IP.
4)Bo nh d lieu
AT89C52 co 256 byte bo nh RAM on-chip. Trong o, 128 byte tren co cung a
ch vi vung thanh ghi chc nang nhng co cau tao vat ly rieng biet.
Khi mot lenh truy cap mot v tr noi co a ch tren 7FH, che o a ch no s
dung se bao cho CPU biet vung a ch nao no can truy cap : RAM hay SFR. Cac
lenh dung a ch trc tiep se truy cap vung SFR. V du nh lenh sau ay se truy cap
SFR a ch 0A0H (port 2)
MOV 0A0H,#data
Lenh dung a ch gian tiep se truy cap 128
byte tren cua RAM. V du nh cung truy cap a
ch 0A0H nhng gian tiep thong qua R0.
MOV R0,#0A0H
MOV @R0,#data
Chu y rang cac tac vu cua stack von a s
dung a ch gian tiep nen vung 128 byte tren
cua RAM rat tien dung e lam vung stack.
5) ac tnh bo dao ong
XTAL1 la au vao va au ra tng ng cua
bo khuech ai ao c dung lam bo dao ong
noi on-chip. Co the dung thach anh hay bo cong
hng ceramic eu c.
e lai vi ieu khien t nguon xung clock
ben ngoai, XTAL2 phai c e trong trong khi
XTAL1 noi en nguon lai. Khong co yeu cau g
ve duty cycle nhng phai chu y en thi gian toi a va toi thieu cua mc ien ap cao
cung nh mc ien ap thap.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 40
6) Che o li
Trong che o li, CPU ri vao trang thai ngu trong khi tat ca thiet b ngoai vi
van con tch cc. Che o nay c tao ra bang phan mem. Noi dung cua RAM on-
chip va gia tr cua cac SFR van c gi nguyen. Ket thuc che o li bang cach
kch hoat mot ngat hoac reset phan cng.
Chu rang khi ket thuc che o li bang cach reset phan cng th thong thng
vi ieu khien se goi lai chng trnh ma no va thoat, cho en hai chu ky may trc
khi thuat toan reset chiem quyen ieu khien. Phan cng cam truy cap RAM noi trong
trng hp nay nhng khong cam truy cap en cac chan port, do o co the xay ra
nhng trng hp khong mong muon. e loai bo trng hp nay, lenh ngay sau lenh
goi che o li khong nen la lenh ghi port hay ghi bo nh ngoai.
7) Che o ha nguon
Trong che o ha nguon, bo dao ong ngng, va lenh goi ha nguon la lenh cuoi
cung c thc thi. RAM on-chip va SFR duy tr gia tr cua no cho en khi ket thuc
che o ha nguon.
Ket thuc che o ha nguon ch bang mot cach duy nhat : reset phan cng. Reset
se tao lai gia tr cho SFR nhng khong thay oi noi dung cua RAM on-chip. Khong
nen reset trc khi Vcc phuc hoi mc ien ap thong thng cua no va phai gi u lau
e bo dao ong phuc hoi va on nh.
8) Trang thai cua mot so chan trong che o li va che o ha nguon











uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 41












I. S LC VE CAC PHNG PHAP BIEN OI AD
Tn hieu trong the gii thc thng dang tng t (analog), nen mach ieu khien thu
thap d lieu t oi tng ieu khien ve (thong qua cac cam bien) cung dang tng
t. Trong khi o, bo ieu khien ngay nay thng la cac P, C x ly d lieu dang so
(digital). V vay, can phai chuyen oi tn hieu dang tng t thanh tn hieu dang so
thong qua bo bien oi AD.
Co nhieu phng phap bien oi AD khac nhau, ay ch gii thieu mot so phng
phap ien hnh.
1. Bien oi AD dung bo bien oi DA
Trong phng phap nay, bo bien oi DA c dung nh mot thanh phan trong mach.
Khoang thi gian bien oi c chia bi nguon xung clock ben ngoai. n v ieu
+
-
v
A
au vao analog

n v ieu
khien
1

0


Thanh
ghi

Bo bien
oi DA
.

.

.

v
AX
Ket qua digital

So sanh

OPAMP

EOC
(ket thuc chuyen oi)

Start

Clock

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 42
khien la mot mach logic cho phep ap ng vi tn hieu Start e bat au bien oi. Khi
o, OPAMP so sanh hai tn hieu vao angalog e tao ra tn hieu digital bien oi trang
thai cua n v ieu khien phu thuoc vao tn hieu analog nao co gia tr ln hn. Bo
bien oi hoat ong theo cac bc :
- Tn hieu Start e bat au bien oi.
- C moi xung clock, n v ieu khien sa oi so nh phan au ra va a vao lu
tr trong thanh ghi.
- So nh phan trong thanh ghi c chuyen oi thanh ap analog v
AX
qua bo bien
oi DA.
- OPAMP so sanh v
AX
vi ap au vao v
A
. Neu v
AX
< v
A
th au ra mc cao, con
ngc lai, neu v
AX
vt qua v
A
mot lng v
T
(ap ngng) th au ra mc thap
va ket thuc qua trnh bien oi. thi iem nay, v
AX
a xap x bang v
A
va so nh
phan cha trong thanh ghi chnh la gia tr digital xap x cua v
A
(theo mot o
phan giai va chnh xac nhat nh cua tng he thong).
- n v ieu khien kch hoat tn hieu EOC, bao rang a ket thuc qua trnh bien
oi.
Da theo phng phap nay, co nhieu bo bien oi nh sau :
a) Bo bien oi AD theo ham doc
ay la bo bien oi n gian nhat theo mo hnh bo bien oi tong quat tren. No dung
mot counter lam thanh ghi va c moi xung clock th gia tang gia tr nh phan cho en
khi v
AX
> v
A
. Bo bien oi nay c goi la bien oi theo ham doc v dang song v
AX
co
dang cua ham doc, hay noi ung hn la dang bac thang. oi khi no con c goi la bo
bien oi AD loai counter.
+
-
v
A
au vao analog



Counter

Bo bien
oi DA
.

.

.

v
AX
Ket qua digital

So sanh

OPAMP

EOC

S
t
a
r
t

Clock

Reset

Clock

v
AX
Start
v
A
EOC

t
C
Khi chuyen
oi hoan
tat, counter
ngng em
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 43
Hnh tren cho thay s o mach cua bo bien oi AD theo ham doc, bao gom mot
counter, mot bo bien oi DA, mot OPAMP so sanh, va mot cong AND cho ieu khien .
au ra cua OPAMP c dung nh tn hieu tch cc mc thap cua tn hieu EOC. Gia
s v
A
dng, qua trnh bien oi xay ra theo cac bc :
- Xung Start c a vao e reset counter ve 0. Mc cao cua xung Start cung
ngan khong cho xung clock en counter.
- au vao cua bo bien oi DA eu la cac bit 0 nen ap ra v
AX
= 0v.
- Khi v
A
> v
AX
th au ra cua OPAMP (EOC) mc cao.
- Khi Start xuong mc thap, cong AND c kch hoat va xung clock c a
vao counter.
- Counter em theo xung clock va v vay au ra cua bo bien oi DA, v
AX
, gia
tang mot nac trong mot xung clock
- Qua trnh em cua counter c tiep tuc cho en khi v
AX
bang hoac vt qua v
A

mot lng v
T
(khoang t 10 en 100v). Khi o, EOC xuong thap va ngan
khong cho xung clock en counter. T o ket thuc qua trnh bien oi.
- Counter van gi gia tr va bien oi xong cho en khi co mot xung Start cho qua
trnh bien oi mi.
T o ta thay rang bo bien oi loai nay co toc o rat cham (o phan giai cang cao th
cang cham) va co thi gian bien oi phu thuoc vao o ln cua ien ap can bien oi.
b) Bo bien oi AD xap x lien tiep
ay la bo bien c dung rong rai nhat trong cac bo bien oi AD. No co cau tao phc
tap hn bo bien oi AD theo ham doc nhng toc o bien oi nhanh hn rat nhieu. Hn
na, thi gian bien oi la mot so co nh khong phu thuoc gia tr ien ap au vao.
S o mach va giai thuat nh sau :
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 44
S o mach tng t nh bo bien oi AD theo ham doc nhng khong dung counter
cung cap gia tr cho bo bien oi DA ma dung mot thanh ghi. n v ieu khien sa oi
tng bit cua thanh ghi nay cho en khi co gia tr analog xap x ap vao theo mot o
phan giai cho trc.
2. Bo bien oi Flash AD
Bo bien oi loai nay co toc o
nhanh nhat va cung can nhieu linh
kien cau thanh nhat.
Co the lam mot phep so sanh: flash
AD 6-bit can 63 OPAMP, 8-bit can
255 OPAMP, va 10-bit can 1023
OPAMP. V le o ma bo bien oi
AD loai nay b gii han bi so bit,
thng la 2 en 8-bit.
V du mot flash AD 3-bit :
Mach tren co o phan giai la 1V,
cau chia ien ap thiet lap nen cac
ien ap so sanh (7 mc tng ng
1V, 2V, ) vi ien ap can bien
oi. au ra cua cac OPAMP c
+
-
v
A
au vao analog

n v ieu
khien
Thanh ghi
MSB LSB

Bo bien oi DA
. . .

v
AX
So sanh

OPAMP

EOC

Clock

. . .

Start

START
Xoa tat ca cac bit
Bat au MSB
Set bit = 1
V
AX
> V
A
? Clear bit = 0
Xong het bit ?
Qua trnh bien oi ket
thuc va gia tr bien oi
nam trong thanh ghi
END
ung

Sai

en bit
thap ke
Sai

ung

+10V
1K
1K
1K
1K
1K
3K
1K
1K
+
-
+
-
+
-
+
-
+
-
+
-
+
-
5V
6V
4V
3V
2V
1V
7V
C1
C2
C3
C4
C5
C6
C7
I7
I6
I5
I4
I3
I2
I1
Priority
encoder
MSB
C
B
A
Ap analog au vao
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 45
noi en mot priority encoder va au ra cua no chnh la gia tr digital xap x cua ien ap
au vao.
Cac bo bien oi co nhieu bit hn de dang suy ra theo mach tren.
3. Bo bien oi AD theo ham doc dang len xuong (tracking ADC)
Bo bien oi loai nay c cai tien t bo bien oi AD theo ham doc. Ta thay rang toc
o cua bo bien oi AD theo ham doc kha cham bi v counter c reset ve 0 moi khi
bat au qua trnh bien oi. Gia tr V
AX
la 0 luc bat au va tang dan cho en khi vt
qua V
A
. Ro rang la thi gian nay la hoan toan lang ph bi v ien ap analog thay oi
mot cach lien tuc, gia tr sau nam trong lan can gia tr trc.
Bo bien oi AD theo ham doc dang len xuong dung mot counter em len/xuong thay
cho counter ch em len bo bien oi AD theo ham doc va khong reset ve 0 khi bat
au. Thay v vay, no gi nguyen gia tr cua lan bien oi trc va tang giam tuy thuoc
vao gia tr ien ap mi so vi gia tr ien ap cu.
4. Bo bien oi AD dung chuyen oi ap sang tan so
Bo bien oi loai nay n gian hn bo bien oi AD dung bien oi DA. Thay v vay no
dung mot bo dao ong tuyen tnh c ieu khien bi ien ap e tao ra tan so tng
ng vi ap vao. Tan so nay c dan en mot counter em trong mot thi khoang co
nh va khi ket thuc khoang thi gian co nh nay, gia tr em ty le vi ien ap vao.
Phng phap nay n gian nhng kho at c o chnh xac cao bi v kho co the thiet
ke bo bien oi ap sang tan so co o chnh xac hn 0,1%.
Mot trong nhng ng dung chnh cua loai nay la dung trong moi trng cong nghiep co
nhieu cao. ien ap c chuyen t transducer ve may tnh ieu khien thng rat nho,
neu truyen trc tiep ve th se b nhieu tac ong ang ke va gia tr thu c hau nh
khong con ung na. Do o, ngi ta dung bo bien oi ap sang tan so ngay tai
transducer va truyen cac xung ve cho may tnh ieu khien em nen t b anh hng bi
nhieu.
5. Bo bien oi AD theo tch phan hai o doc
Bo bien oi loai nay la mot trong nhng bo co thi gian bien oi cham nhat (thng la
t 10 en 100ms) nhng co li iem la gia ca tng oi re khong dung cac thanh phan
chnh xac nh bo bien oi AD hoac bo bien oi ap sang tan so.
Nguyen tac chnh la da vao qua trnh nap va xa tuyen tnh cua tu vi dong hang. au
tien, tu c nap trong mot khoang thi gian xac nh t dong hang rut ra t ien ap
vao v
A
. V vay, cuoi thi iem nap, tu se co mot ien ap ty le vi ien ap vao. Cung
vao luc nay, tu c xa tuyen tnh vi mot dong hang rut ra t ien ap tham chieu
chnh xac v
ref
. Khi ien ap tren tu giam ve 0 th qua trnh xa ket thuc. Trong suot
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 46
khoang thi gian xa nay, mot tan so tham chieu c dan en mot counter va bat au
em. Do khoang thi gian xa ty le vi ien ap tren tu luc trc khi xa nen cuoi thi
iem xa, counter se cha mot gia tr ty le vi ien ap tren tu trc khi xa, tc la ty le
vi ien ap vao v
A
.
Ngoai gia thanh re th bo bien oi loai nay con co u iem chong nhieu va s troi
nhiet. Tuy nhien thi gian bien oi cham nen t dung trong cac ng dung thu thap d
lieu oi hoi thi gian ap ng nhanh. Nhng oi vi cac qua trnh bien oi cham (co
quan tnh ln) nh lo nhiet th rat ang e xem xet en.

II. ADC ICL7109:
1. Gii thieu:
- ICL 7107 la chip chuyen oi A/D 3
1
/
2
digit, hay 12 bit, 40 chan.
- Khac vi nhng chip chuyen oi A/D khac, ICL 7107 ngoai chc nang
chuyen oi A/D no con dung e lai LCD, va data ngo ra di dang ma 7 oan ch
khong phai ma BCD nh nhng chip chuyen oi khac.
S o chan:


2. ac tnh:
- Nguon cung cap: -9V +15V.
- V+ GND: 6V
- V- GND: -9V
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 47
- Hoat ong trong dai nhiet o: 0
o
C 70
o
C
- Tieu thu nang lng thap: thng nho hn 10mW
- t b anh hng cua nhieu: 15V
P-P

- t b troi: 1V/
o
C
- Ngo vao ap toan tam ( Full Scale ) 200mV, 2V tuy theo thay oi gia tr
ien tr, phan nay se noi trong phan thiet ke
Bang thong so chi tiet cua ICL 7107:










uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 48



3. Chc nang chan:







- Chan 1: ngo vao +5V
- Chan 28: ngo ra ma 7 oan hang n v
- Chan 914, 25: ngo ra ma 7 oan hang chuc
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 49
- Chan1518, 2224: ngo ra ma 7 oan hang tram
- Chan 19: ngo ra ma 7 oan hang nghn
- Chan 20: ngo cc tnh, tch cc mc cao. Khi mc cao th ngo vao co
mc ien ap am.
- Chan 21: GND
- Chan 26 : -5V
- Chan 27, 28 , 29: tao mach tch phan cho chip
- Chan 30, 31: Ngo vao Analog
- Chan 32: Common chan chung cua ngo vao Analog
- Chan 33, 34: C
REF-
va C
REF +
: cc am va dng cua tu tham chieu
- Chan 35, 36: REF LO va REF HI : mc ien ap tham chieu
- Chan 37 ( Test ): khi khong dung e lai LCD th chan Test e trong
- Chan 38, 39, 40: tao dao ong
4. Qua trnh bien oi A/D:
Qua trnh bien oi A/D cua ICL 7107 chia lam 3 pha:




Auto-Zero Phase: co 3 s kien xay ra trong pha Auto-Zero.
- Th nhat: ngo vao IN HI va IN LOW khong ket noi vi cac chan
ben ngoai, ma ket noi ben trong vi chan COMMON.
- Th hai: tu tham chieu C
REF
( chan 33, 34 ) c nap en ien ap
tham chieu
- Th ba: Vong hoi tiep c noi vong qua he thong e nap cho tu
Auto-Zero, C
AZ
nham bu vao ien ap b lech trong bo khuyech ai em, bo
tch phan, bo so sanh.
o chnh xac cua pha Auto-Zero phu thuoc vao nhieu cua he
thong. Trong cac trng hp th o lech ap ngo vao luon nho hn 10V
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 50

Pha Signal Integrate: Trong pha nay th vong hoi tiep Auto-Zero h, ket noi
ben gia chan IN LO, IN HI va chan COMMON khong con na, chung ket noi vi
chan ben ngoai. Khi nay bo bien oi tch phan se lay ien ap vi sai gia chan IN LO
va IN HI trong khoang thi gian nhat nh. ien ap vi sai nay phai nam trong tam ien
ap cua ngo vao va cc tnh.
Pha De-Integrate: pha nay ngo vao IN LO ngat vi tn hieu ben ngoai va
ket noi ben trong vi chan COMMON. Ngo vao IN HI ket noi vi tu tham chieu e
nap ien ap tham chieu cho no. Mach se ket noi chan IN HI chnh xac vi cc cua tu
tham chieu e am bao rang ngo ra cua bo tch phan tr ve 0. Thi gian yeu cau e
ngo ra tr ve 0 t le vi tn hieu ngo vao, cu the la 1000*V
IN
/V
REF

5. Chon gia tr cho cac linh kien:
- Tan so dao ong:
f
OSC
= 0.45/RC
- Tan so xung clock:
f
CLOCK
= f
OSC
/4
- ien tr tch phan:
INT
R =
INT
INFS
I
V

V
INFS
:

ien ap ngo vao(FullSale), thng bang 200mV hoac 2V
I
INT
: Dong ngo vao, I
INT
=4A
Khi ngo vao toan tam ( FullScale ) la 2V chon R2 = 470K, tng t R2 =
47K ng vi 2mV.
- Tu tch phan:
INT
C =
INT
INT INT
V
I t ) )( (

t
INT
= 1000*( 4/f
OSC
)
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 51
V
INT
=
INT
INT INT
C
I t ) )( (

V
INT
MaxSwing: (V
-
+ 0.5) < V
INT
< (V
+
- 0.5V), thng th V
INT
= 2V
ng vi cong thc tren th chon gia tr C
INT
= 0.22F va 0.1F
- Tu Auto-Zero (C
AZ
):
C
AZ
= 0.47F khi V
INFS
= 200mV
C
AZ
= 0.047F khi V
INFS
= 2V
- Tu tham chieu:
Chon 0.1F la tot nhat vi moi ng dung.
6. Gii thieu phan Digital cua ICL7107:
Dong lai LED 7 oan co the tang t 2mA 8mA. Tan so dao ong c chia cho
4 trc khi kch cho bo em.









uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 52

7. Mot vai cach chon gia tr va ng dung cua ICL7107




Hnh tren dung cho trng hp ngo vao 200mV ( FS - FullScale ), thi
gian chuyen oi 3lan/giay.

Vi cach mac nh tren ta ch s dung nguon n +5V, ngo vao Analog
200mV ( FS )
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 53

Khi ngo vao Analog la 2V ( FS ), cac gia tr, cach mac mach nh tren
s dung rat phu hp.


Hnh tren dung lay tn hieu ngo ra cua LoadCell, nguon cung cap 5V

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 54


Vi cach thiet ke mach nh hnh tren thng dung lay tn hieu ngo ra
cua cam bien ap suat, lu lng.





Khi ngo ra cua cac sensor hoac cac thiet b o lng co tn hieu ngo ra
la tn hieu xoay chieu, th ta cung khong can bo bien oi AC/DC phc tap,
mach hnh tren giup ta chuyen oi de dang va a vao ADC ICL7107.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 55
8. Gii thieu mot so chip chuyen oi A/D
8.1. ADC 0809:
Hien nay, tren th trng co rat nhieu loai IC chuyen dung cho bo bien oi
ADC.
Di ay la loai IC rat hu dung va c s dung nhieu trong thc te.
3.1 Bo bien oi ADC 0809
ay la loai bi mach ADC che tao da tren ky thuat ADC xap x lien tiep.
S o chan:

U1
ADC0809
26
27
28
1
2
3
4
5
12
16
10
9
7
17
14
15
8
18
19
20
21
25
24
23
6
22
IN0
IN1
IN2
IN3
IN4
IN5
IN6
IN7
REF+
REF-
CLK
OE
EOC
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
START
ALE


ac iem cau tao:
Thang ien tr 256 R vi ngo chuyen mach analog.
Thanh ghi xap x lien tiep.
Bo multiplexing.
Bo chot a ch ngo vao.
Bo giai ma.
Bo em ngo ra.
Tat ca nhng vi mach tren c tch tren mot chip CMOS n khoi va
khong oi hoi cac linh kien phu khac mac them ben ngoai.
Tai moi thi iem ch co the mau 1 trong 8 kenh analog vao qua mach
phan kenh 3 sang 8.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 56
S o khoi:


ac iem ky thuat cua ADC 0809:

ADC0809 co toc o bien oi nhanh, sai so lng hoa thap va cong tieu tan
thap.
Nguon cung cap 5v DC, ien ap chuan 5v DC.
Thi gian chuyen oi la 100s.
Co 8 kenh analog ngo vao.
ien ap ngo vao t 0 en 5V.
Tan so xung CLOCK t 10 1280KHz.

Address
Latch
enable

-
Tri-state
output
Latch
buffer
8

d
i
g
i
t
a
l

o
u
t
p
u
t

-
-
-
-
-
-
-
-
Address
Latch
And
decoder
-
-
-
3

b
i
t

A
d
d
r
e
s
s

Control
a timing


- -
SAR
Switches
tree
256 Register
Ladder

- -
-
8 chanel
multiplexing
analog
switch
-
-
-
-
-
-
-
-
8

a
n
a
l
o
g

i
n
p
u
t


-
Vcc
GROUND
-
REF+

REF-
START CLOCK
EOC
8 BIT AD
-
OE
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 57
Nguyen tac hoat ong :

Tai mot thi iem, 1 trong 8 ngo vao analog c chuyen oi. Viec chon
ngo vao c xac nh bi 3 ng a ch A, B, C thong qua bo phan kenh 3 sang 8.
Qua trnh chuyen oi c bat au khi 3 ng a ch c chon va khi xung
START va xung ALE bat len mot. Khi o, ALE chot a ch kenh c chon va se
a tn hieu vao bo so sanh, xung START bat au thc hien viec chuyen oi, EOC
mc 0, bus d lieu trang tong tr cao.
Sau khoang thi gian 100s, qua trnh chuyen oi ket thuc, tn hieu analog
c chuyen thanh 8 bit d lieu so ngo ra. Luc nay xung EOC bat len 1 va d lieu
c a vao vung em. e a d lieu t vung em len bus, phai at xung OE len
1.
Nh bo em 3 trang thai nen de dang ket noi vi data bus cua CPU.

Gian o thi gian:




CLOCK
START
ALE
AD
ANALOG
INPUT
OE
EOC
DATA

Tri - state
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 58


Cac so lieu ky thuat:

o phan giai : K = 5/256 = 0.196V
Day ong ien tr vao :
Trong ieu kien :
Vcc = Vref(+) = 5V
Vref(-) = GND
CLK = 640 KHz
th tong tr vao t 1 2.5 KO.
Mc logic cua tn hieu ra :Trong ieu kien 4.75V s Vcc s 5.5V th mc
ien ap logic 1 la V > Vcc 0.4 va mc ien ap logic 0 la V s0.45v
Toc o chuyen oi : 100s
Cong suat tieu tan : 15 mW.

8.2. ADC ICL7109:
ICL7109CPL la bo bien oi AD 12-bit dang n phien, bien oi theo phng
phap tch phan hai o doc, cong vi cac bit ch cc tnh, bit bao qua thang o co the
giao tiep vi P, C theo hai cach :
- Ghep trc tiep vao bus : thong qua chan chon chip, hai chan cho phep xuat
byte cao, byte thap.
- Ghep theo chuan cong nghiep UART : c ng dung trong truyen nhan d
lieu t xa, ngo ra c bien oi va a en mot UART trong che o bat tay,
trao oi d lieu noi tiep.
ICL7109CPL co o chnh xac cao, o troi nhiet nho hn 1V/
0
C. c ng
dung trong nhieu trong nhng he thong thu thap d lieu do gia thanh thap, cong suat
tieu tan va dong phan cc nho. Cac ac iem chu yeu nh sau :
- Pha zero-integrator giup khoi phuc qua tai nhanh.
- Loai bo vong tre va nhieu.
- Cai tien kha nang lai bus.
- Ngo ra 3 trang thai.
- UART che o bat tay e giao tiep noi tiep.
- Co san nguon tham chieu chuan.
- 30 lan bien oi trong 1 giay.
- Khoi n, cong nghe CMOS co cong suat thap
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 59
Cau tao chan:
Mo ta chc nang cua cac chan:
GND : at.
STATUS : ngo ra. Khi mc cao, bo bien oi ang trong pha integrate hoac pha
de-integrate cho en khi d lieu c chot. Khi mc thap, bo bien oi ang pha
auto-zero hoac de-integrate sau khi d lieu c chot.
POL : bit ch cc tnh (polarity), neu mc cao, ch ra rang tn hieu vao la ap
dng.
OR : bit ch qua thang (over-range), neu mc cao, ch ra rang ngo vao a v t
qua gii han cho phep.
B1B12 : ngo ra ba trang thai, la cac bit d lieu tng ng.
TEST : ngo vao, khi TEST = 1 th ADC hoat ong bnh thng, TEST = 0 th tat ca
bit d lieu ra eu mc cao, con khi khong ket noi th cac chot ngo ra bo em
c cho phep. Trong hoat ong bnh thng : noi TEST len +5v.
LBEN : che o trc tiep (MODE = 0 va CE/LOAD = 0) th LBEN la ngo vao, khi
mc tch cc se cho phep xuat byte thap; che o bat tay (MODE = 1) th LBEN
la ngo ra, co chc nang la c byte thap.
HBEN : che o trc tiep (MODE = 0 va CE/LOAD = 0) th HBEN la ngo vao,
khi mc tch cc se cho phep xuat byte cao; che o bat tay (MODE = 1) th
HBEN la ngo ra, co chc nang la c byte cao.
CE/LOAD : che o trc tiep, la ngo vao, khi tch cc se cho phep xuat ra 12 bit
d lieu B1B12, POL, OR neu LBEN, HBEN tch cc. che o bat tay, la ngo ra
strobe.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 60
MODE : ngo vao, khi mc thap : ADC hoat ong che o trc tiep, con khi
mc cao : ADC hoat ong che o bat tay.
OSC IN : ngo vao cua bo dao ong.
OSC OUT : ngo ra cua bo dao ong.
OSC SEL : ngo vao, dung e chon bo dao ong. ICL 7109 co mot bo dao ong vi
3 ngo, no co the hoat ong vi bo dao ong RC hay dao ong thach anh, cung co
the hoat ong vi nguon xung clock ben ngoai.
Neu chan OSC SEL e h (co pullup keo len) hay noi vi mc cao th xung clock
se lay t bo dao ong RC ben ngoai. Khi o, xung clock se cung pha, cung tan so
vi tn hieu tren chan BUF OSC OUT va tan so xung clock tnh theo cong thc :
RC
f
45 . 0
=
ien tr nen chon la 100K, tu chon sao cho khoang thi gian cua 2048 chu ky xung
clock gan vi mot boi so tch phan cua 50Hz e loai tr nhieu 50Hz, nhng khong
nen nho hn 50pF.
Neu chan OSC SEL c keo xuong mc thap th xung clock lay t dao ong thach
anh ben ngoai co tan so t 1MHz en 5MHz. Tan so xung clock ben trong khi o
se bang tan so cua tn hieu tren chan BUF OSC OUT chia cho 58.
BUF OSC OUT : ngo ra cua bo dao ong c em, tien dung lam nguon xung
clock cho cac IC khac.
RUN/HOLD : sau khi pha autozero hoan tat trong khoan thi gian nho nhat, can co
mot xung len cao t nhat 200ns tac ong vao chan RUN/HOLD e bat au mot qua
trnh bien oi. Tuy nhien can chu y rang neu co bat ky xung nao xuat hien trong
qua trnh bien oi hay trong vong 2048 chu ky xung clock sau khi chan STATUS
xuong thap se b bo qua. Neu ICL 7109 ang vao thi iem ket thuc pha
autozero, mot qua trnh bien oi se c bat au va chan STATUS se len cao trong
vong 7 chu ky xung clock sau khi RUN/HOLD len cao.
Them vao o, e bat au va ket thuc mot qua trnh bien oi, chan nay cung co the
c s dung e cc tieu thi gian bien oi. Bi v mot qua trnh bien oi bnh
thng se ton mat 8192 chu ky xung clock, trong o rieng pha de-integrate a lay
mat 4096 chu ky xung clock va oc lap vi ien ap vao. Nhng neu sau khi
STATUS xuong thap, RUN/HOLD xuong thap theo th ICL 7109 se nhay tc thi
en pha autozero hn la phai mat toan bo 4096 chu ky xung clock cho pha de-
integrate.
SEND : ngo vao, bao hieu rang thiet b ben ngoai a chap nhan d lieu khi ADC
hoat ong che o bat tay. Noi len +5v neu khong s dung.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 61
V- : nguon am cho ICL 7109, thng noi en -5v.
REF OUT : ngo ra ien ap tham chieu, thng nho hn V+ la 2,8v.
BUF : ngo ra bo khuech ai em.
AZ : c noi en tu C
AZ
.
INT : c noi en tu C
INT
.
COMMON : chan chung cua tn hieu tng t.
IN LO : cc am cua ien ap vao vi sai.
IN HI : cc dng cua ien ap vao vi sai.
REF IN+ : ngo vao dng cua ien ap tham chieu.
REF CAP+ : cc dng cua tu tham chieu.
REF CAP- : cc am cua tu tham chieu.
REF IN- : ngo vao am cua ien ap tham chieu.
V+ : Vcc (5v).

9. Nhan Xet:
ICL 7107 la chip chuyen oi A/D 12 bit toc o cham ( 3 lan/giay ), lai LCD.
Khi ta dung chuyen oi A/D toc o cham th dung ICL 7107 rat kinh te, gia
thanh cua ICL 7107 rat thap, t anh hng cua nhieu.
Co the ap dung ICL 7107 trong cac trng hp sau: theo doi nhiet o cac bon
xang dau; o man, l, chua, nhiet o trong cac ho nuoi tom















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 62










I. S lc ve logic m
1. Qua trnh phat trien cua logic m
Logic m c cong bo lan au tien tai My vao nam 1965. Cha e cua no la
Lotfi Zadeh, giao s ve ly thuyet he thong tai trng ai hoc Berkeley, bang
California. Ke t o, logic m a co nhieu phat trien qua cac chang ng sau : phat
minh My, ap dung Chau Au va a vao cac san pham thng mai Nhat.
a) ng dung cong nghiep au tien Chau Au
ng dung au tien cua logic m vao cong nghiep c thc hien Chau Au,
khoang sau nam 1970. Tai trng Queen Mary Luan on Anh, Ebrahim
Mamdani dung logic m e ieu khien mot may hi nc ma trc ay ong ay
khong the ieu khien c bang cac ky thuat co ien. Va tai c, Hans
Zimmermann dung logic m cho cac he ra quyet nh. Lien tiep sau o, logic m
c ap dung vao cac lnh vc khac nh ieu khien lo xi mang, nhng van khong
c chap nhan rong rai trong cong nghiep. Co mot so t ng dung dung no nhng
dau i cum t logic m ma thay bang cac t ng nh logic a gia tr hay logic lien
tuc.
Ke t nam 1980, logic m at c nhieu thanh cong trong cac ng dung ra
quyet nh va phan tch d lieu Chau Au. Nhieu ky thuat logic m cao cap c
nghien cu va phat trien trong lnh vc nay.
b) Nhat Ban vn len dan au
Cam hng t nhng ng dung cua Chau Au, cac cong ty cua Nhat bat au
dung logic m vao ky thuat ieu khien t nam 1980. Nhng do cac phan cng chuan
tnh toan theo giai thuat logic m rat kem nen hau het cac ng dung eu dung cac
phan cng chuyen ve logic m. Mot trong nhng ng dung dung logic m au tien tai
ay la nha may x ly nc cua Fuji Electric vao nam 1983, he thong xe ien ngam
cua Hitachi vao nam 1987.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 63
Nhng thanh cong au tien a tao ra nhieu quan tam Nhat. Co nhieu ly do
e giai thch tai sao logic m c a chuong. Th nhat, cac ky s Nhat thng bat
au t nhng giai phap n gian, sau o mi i sau vao van e. Phu hp vi viec
logic m cho phep tao nhanh cac ban mau roi tien en viec toi u. Th hai, cac he
dung logic m n gian va de hieu. S thong minh cua he khong nam trong cac he
phng trnh vi phan hay ma nguon. Cung nh viec cac ky s Nhat thng lam viec
theo to, oi hoi phai co mot giai phap e moi ngi trong to eu hieu c hanh vi
cua he thong, cung chia se y tng e tao ra he. Logic m cung cap cho ho mot
phng tien rat minh bach e thiet ke he thong. Va cung do nen van hoa, ngi Nhat
khong quan tam en logic Boolean hay logic m; cung nh trong tieng Nhat , t m
khong mang ngha tieu cc.
Do o, logic m c dung nhieu trong cac ng dung thuoc lnh vc ieu
khien thong minh hay x ly d lieu. May quay phim va may chup hnh dung logic m
e cha ng s chuyen mon cua ngi nghe s nhiep anh. Misubishi thong bao ve
chiec xe au tien tren the gii dung logic m trong ieu khien, cung nh nhieu hang
che tao xe khac cua Nhat dung logic m trong mot so thanh phan. Trong lnh vc t
ong hoa, Omron Corp. co khoang 350 bang phat minh ve logic m. Ngoai ra, logic
m cung c dung e toi u nhieu qua trnh hoa hoc va sinh hoc.
c) Chau Au uoi theo Nhat
Nam nam troi qua, cac to hp Chau Au nhan ra rang mnh a mat mot ky
thuat chu chot vao tay ngi Nhat va t o ho a no lc hn trong viec dung logic
m vao cac ng dung cua mnh. en nay, co khoang 200 san pham ban tren th
trng va vo so ng dung trong ieu khien qua trnh t ong hoa dung logic m.
T nhng thanh cong at c, logic m a tr thanh mot ky thuat thiet ke chuan
va c chap nhan rong rai trong cong ong.
d) Logic m My
Trong nhng nam gan ay, logic m thu c nhieu quan tam My, nhat la
trong nhng cong ty canh tranh vi Chau Au va Chau A. Tuy nhien co nhieu tranh
cai ve kha nang chien thang cua My trong lnh vc nay bi nhieu ly do. Th nhat,
nhng ng dung c thc hien tai Nhat la nhng san pham ma cac nha san xuat cua
My khong canh tranh vi Nhat. C ban la khong co mot nha san xuat ien t giai tr
nao cua My co mat tren th trng the gii; viec dung logic m trong camcorder,
camera, hifi ch la nham tang them kha nang canh tranh gia cac cong ty Nhat ma
thoi. Chau Au, cac ng dung logic m chu yeu tap trung vao t ong hoa cong
nghiep do gia lao ong cao. Trong cac lnh vc khac, nh la nganh che tao oto, My
phai oi mat vi cac oi thu en t Chau Au va Nhat. Va cac nha san xuat My trong
lnh vc nay buoc phai dung ky thuat thiet ke logic m.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 64
ieu nay tao ra nhieu phan khuc th trng cho My, nh la dung logic m
trong cac he ra quyet nh, bo nh, bo ieu khien a cng, cung nh cac giai thuat
nen dung cho am thanh va hnh anh. Va cac ng dung trong truyen thong nh loai bo
tieng on, tm ng trong mang, hay nhan dang tieng noi cung thu c nhieu ket
qua t logic m.
2) C s toan hoc cua logic m
Logic m va xac xuat thong ke eu no ve s khong chan chan. Tuy nhien moi
lnh vc nh ngha mot khai niem khac nhau ve oi tng.
a) S khong chac chan theo thong ke : lien quan en s xuat hien cua mot s
kien chac chan. Xet phat bieu sau :
Xac suat trung ch la 0,8
Ban than cua s kien nay (trung ch) a c nh ngha ro rang. S khong
chac chan ay la co trung ch hay khong, va c nh lng bi mc o xac suat
(trong trng hp nay la 0,8). Loai phat bieu nay co the c x ly va ket hp vi
cac phat bieu khac bang phng phap thong ke, nh la xac suat co ieu kien chang
han.
b) S khong chac chan trong ng ngha : lien quan en ngon ng cua con
ngi, tc la lien quan en s khong chnh xac trong cac t ng ma con ngi dung
e c lng van e va rut ra ket luan. V du nh cac t mo ta nhiet o nh : nong,
lanh, hay am khong co mot gia tr chnh xac e gan cho cac t nay bao nhieu
o la lanh : 2C hay -2C ? va cac khai niem nay cung khac nhau oi vi nhng
ngi khac nhau : ngi nay lanh nhng ngi khac th khong.
Mac du cac khai niem khong c nh ngha chnh xac nhng con ngi van
co the s dung chung cho cac c lng va quyet nh phc tap. Bang s tru tng
va oc suy ngh, con ngi co the giai quyet cau noi mang ng canh phc tap ma rat
kho co the mo hnh bi toan hoc chnh xac. Xet phat bieu :
Co the chung ta se thanh cong trong nam hoc nay
Mi nhn qua th phat bieu nay rat giong phat bieu tren. Tuy nhien, co mot so
khac biet quan trong. Th nhat, ban than s kien khong c nh ngha ro rang. oi
vi mot so sinh vien th nam hoc thanh cong la khong phai hoc lai mon nao. oi vi
mot so sinh vien khac th nam hoc thanh cong la so iem bnh quan nam nay tang
hn nam trc. Nhng ngay ca trong trng hp nay cung khong co mot ngng qui
nh s thanh cong (tang hn bao nhieu iem ?).
Mot khac biet na la xac xuat : trong khi phat bieu tren mo ta xac suat theo
toan hoc th phat bieu nay khong co mot gia tr nh lng ve xac suat.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 65
c) Mo hnh s khong chac chan theo ng vng :
Nh a noi tren, mac du dung nhng phat bieu khong mang tnh nh lng
nhng con ngi van co the thanh cong trong cac c lng phc tap. Trong nhieu
trng hp, con ngi dung s khong chac chan nay e tang them o linh hoat. Nh
trong hau het xa hoi, he thong luat phap bao gom mot so luat, moi luat mo ta mot
tnh huong. V du mot luat qui nh toi trom xe phai b tu 2 nam, mot luat khac lai
giam nhe trach nhiem. Va trong mot phien toa, chanh an phai quyet nh so ngay
phat tu cua ten trom da tren mc o ru trong ngi, trc ay co tien an hay tien
s khong, t o ket hp lai a ra mot quyet nh cong bang.
3) Logic m la logic cua con ngi
Trong thc te, ta khong nh ngha mot luat cho mot trng hp ma nh ngha
mot so luat cho cac trng hp nhat nh. Khi o nhng luat nay la nhng iem ri
rac cua mot tap cac trng hp lien tuc va con ngi xap x chung. Gap mot tnh
huong cu the, con ngi se ket hp nhng luat mo ta cac tnh huong tng t. S xap
x nay da tren s linh hoat cua cac t ng cau tao nen luat, cung nh s tru tng
va s suy ngh da tren s linh hoat trong logic cua con ngi.
e thc thi logic cua con ngi trong ky thuat can phai co mot mo hnh toan
hoc cua no. T o logic m ra i nh mot mo hnh toan hoc cho phep mo ta cac qua
trnh quyet nh va c lng cua con ngi theo dang giai thuat. D nhien cung co
gii han, o la logic m khong the bat chc tr tng tng va kha nang sang tao
cua con ngi. Tuy nhien, logic m cho phep ta rut ra ket luan khi gap nhng tnh
huong khong co mo ta trong luat nhng co s tng ng. V vay, neu ta mo ta
nhng mong muon cua mnh oi vi he thong trong nhng trng hp cu the vao luat
th logic m se tao ra giai phap da tren tat ca nhng mong muon o .
4) So sanh logic m vi ly thuyet xac suat thong ke
Khong the lam phep so sanh gia hai lnh vc nay bi v s khong chac chan
theo thong ke va s khong chac chan theo ng vng co ban chat khac nhau. Moi lnh
vc co mot oi tng phuc vu cua rieng no, c con ngi tao ra nham phuc vu cho
muc ch cua con ngi.
II. Cac khai niem dung trong logic m
1) Tap hp m va o phu thuoc
Neu nh con ngi khong co mot gia tr ngng xac nh cho lanh hay
nong th lam sao co the c lng no ?
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 66
Thc ra th ngi ta se lam mot phep so sanh gia gia tr nhiet o hien tai vi
hai gia tr nhiet o c cho la rat nong va rat lanh. T ket qua so sanh o, con
ngi c lng c mc o cua nong hay lanh.
Lam sao mo hnh hoa ieu nay theo toan hoc ?
Da tren ly thuyet tap hp, au tien ta mo ta mot tap cac nhiet o c cho la
rat nong, sau o nh ngha mot ham phu thuoc cho phep ta xac nh mot nhiet o
nao o co thuoc tap hp nay hay khong. Khac vi toan hoc co ien ni ma ham
phu thuoc ch xac nh duy nhat mot phan t co thuoc hay khong, ham phu thuoc
trong logic m cho phep xac nh mot phan t phu thuoc tap hp nhieu hay t, tc la
bien gii gia rat nong va rat lanh khong phai la mot ng phan biet ro rang
ma la mot vung cac gia tr lien tuc. Trong hnh tren, mc o xam cho phep ta thay
c vung bien gii nay va cung cho thay o phu thuoc cua mot gia tr nhiet o nao
o.
o phu thuoc cua mot phan t trong tap hp m co gia tr trong khoang [0,1].
Theo hnh tren, neu nh ta cho rang 0C la rat lanh va 100C la rat nong th o
phu thuoc cua gia tr nhiet o so vi tap rat nong la :
(0C) = 0,00 (15C) = 0,15 (37C) = 0,37
(60C) = 0,60 (72C) = 0,72 (87C) = 0,87
(100C) = 1,00
2) Ham phu thuoc
Mc o cua mot gia tr vat ly thoa man mot khai niem ngon ng c goi la
o phu thuoc. oi vi bien lien tuc, mc o nay c bieu dien bi mot ham goi la
ham phu thuoc. Ham nay anh xa tap cac gia tr vat ly thanh tap cac gia tr phu thuoc
oi vi cac gia tr ngon ng. Bien vat ly c goi la bien nen va tap cac gia tr vat ly
c goi la tap nen. Thong thng ngi ta ve nhieu ham phu thuoc tren cung mot
bieu o da tren tap nen a qui nh.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 67
V du ham phu thuoc cho cac nhiet o noi tren :
Tap hp m la s tong quat hoa cua tap hp co ien, trong o = 0 va = 1
cua ham phu thuoc co ien ch la mot trng hp ac biet cua ham phu thuoc trong
tap hp m. Viec dung cac tap hp m c nh ngha bi cac ham phu thuoc trong
bieu thc logic c goi la logic m. V du nh bieu thc nhiet o rat nong oi vi
gia tr 85C se cho ket qua la true vi mc o phu thuoc bang 0,85.
3) Bien ngon ng
La phan chu ao trong cac he thong dung logic m. ay, cac thanh phan
ngon ng mo ta cung mot ng canh c ket hp lai. V du nh trong trng hp mo
ta nhiet o noi tren, khong ch co rat nong ma con hi nong, trung bnh, hi
lanh va rat lanh eu mo ta nhiet o. Chung c goi la cac tap ngon ng, mang
mot khoang gia tr nao o cua bien ngon ng va c ve tren cung mot o th :
4) Luat m
Cac luat trong he logic m mo ta tri thc cua he. Chung dung cac bien ngon
ng nh la t vung e mo ta cac tang ieu khien trong he. Viec giai thch cac luat
m cung la viec trnh bay cach tnh cac khai niem ngon ng.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 68
III. Tnh toan m
Baogom ba bc chnh nh sau :
1) M hoa
M hoa co ngha la dung nhng ham phu thuoc cua cac bien ngon ng e tnh
mc o phu thuoc cho tng tap m oi vi mot gia tr cu the cua au vao.
V du nhiet o hien tai o c la 80C th ket qua cua phep m hoa la :
Rat lanh co o phu thuoc bang 0,00.
Hi lanh co o phu thuoc bang 0,00.
Trung bnh co o phu thuoc bang 0,00.
Hi nong co o phu thuoc bang 0,20.
Rat nong co o phu thuoc bang 0,80.
Ve mat ngon ng, nhiet o la 80C c xem nh la hau nh rat nong, ch mot
t hi nong.
M hoa la bc au tien trong qua trnh tnh toan cua he m. Ket qua cua no
c dung lam au vao e tnh cac luat m.
2) Tnh luat m
Hau het cac he thong hoat ong da tren nen tang logic m eu dung luat e
bieu dien moi quan he gia cac bien ngon ng va e rut ra hanh ong tng ng oi
vi au vao. Mot luat bao gom hai phan : phan ieu kien (phan If) va phan ket luan
(phan Then). Phan ieu kien co the gom nhieu ieu kien, ket hp vi nhau bang cac
lien t nh And, Or.
Cho rang chung ta dung quat may e ieu hoa nhiet o. Quat nay co 5 nut
bam anh so t 1 en 5 tng ng toc o quat tang dan. The th ta co nhng luat :
If nhiet o = rat lanh Then nut bam = 1
If nhiet o = hi lanh Then nut bam = 2
If nhiet o = trung bnh Then nut bam = 3
If nhiet o = hi nong Then nut bam = 4
If nhiet o = rat nong Then nut bam = 5
Phan If trong v du nay ch co mot ieu kien, bay gi gia s nh ta o c s
thay oi nhiet o va chia lam ba tap m nh : ang giam, khong thay oi, ang tang
th co the co cac luat nh :
If nhiet o = rat lanh And thay oi = ang giam Then nut bam = 1
If nhiet o = rat lanh And thay oi = khong thay oi Then nut bam = 1
If nhiet o = rat lanh And thay oi = ang tang Then nut bam = 2
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 69
If nhiet o = hi lanh And thay oi = ang giam Then nut bam = 1
If nhiet o = hi lanh And thay oi = khong thay oi Then nut bam = 2

3) Suy luan m
Viec tnh toan cac luat m c goi la suy luan m, bao gom hai bc chnh.
a) Tnh tng luat : xet rieng re tng luat m, da tren o phu thuoc cua cac tap
m au vao va lien t ket hp chung e tao ra o phu thuoc chung cho cac au vao,
va cung la ket qua cua rieng luat o.
Xet luat sau :
If nhiet o = rat lanh And thay oi = ang giam Then nut bam = 1
Cho rang rat lanh co o phu thuoc la 0,6 va ang giam co o phu thuoc la 0,4.
Lien t ang s dung la AND va dung phep lay min cho no th o phu thuoc chung
cua au vao cho luat nay la min(0,6;0,4) = 0,4. Vay tap m ra nut bam co o phu
thuoc la 0,4.
Thong thng ngi ta tnh AND bang phep lay min va OR bang phep lay
max, ieu nay nham lam gian n cac phep tnh trong cac ng dung ieu khien nho.
Tong quat hoa th ta co cac toan t sau ay e bieu dien moi quan he gia cac ieu
kien trong phan IF :
Min Max : 1 , 0 ), ( max ) ( min ) 1 (
.. 1 .. 1
= + =
= =

i
n i
i
n i

Min Avg : 1 , 0 , ) ( min ) 1 (
1
.. 1
= |
.
|

\
|
+ =

=
=


n
i
i
i
n i
n

Gamma : ( ) 1 . 0 , 1 1
1
1
1
=
|
|
.
|

\
|

|
|
.
|

\
|
=
[ [
=

=


n
i
i
n
i
i

Tuy theo gia tr cua hay ma ta co cac trng hp ac biet sau :
Min-Max, = 0 : MIN lay nho nhat (minimum), tng ng vi AND,
Min-Max, = 1 : MAX lay ln nhat (maximum), tng ng vi OR.
Min-Avg, = 1 : AVG lay trung bnh (average).
Gamma, = 0 : PROD lay tch (product).
b) Tong hp luat da tren ket qua cua tng luat a tnh tren, ngi ta tong hp
chung lai e co ket qua cuoi cung cua cac tap m au ra. Phng phap thng dung
trong bc nay la Max-Min hay Max-Prod.
V du co hai luat a tnh ket qua :
If nhiet o = rat lanh And thay oi = ang giam Then nut bam = 1
If nhiet o = rat lanh And thay oi = khong thay oi Then nut bam = 1
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 70
Luat th nhat cho ket qua co o phu thuoc bang 0,4 va luat th hai cho ket
qua co o phu thuoc bang 0,6. S dung phng phap Max-Min (hay Max-Prod), ta co
o phu thuoc cho tap m 1 cua nut bam la max(0,4;0,6) = 0,6.
Mot khi a tnh xong cac luat, ngi ta tien hanh giai m e tao ra ket qua
phu hp vi the gii thc.
4) Giai m
Ket qua c tao thanh sau khi tnh toan cac luat van con dang m va thiet
b chap hanh cua bo ieu khien th lai khong hieu nhng gia tr nh the.
Do o, ngi ta can chuyen oi nhng gia tr m o thanh gia tr ro cho thiet
b chap hanh.
Co nhieu phng phap c dung trong bc nay :
Nguyen ly cc ai : hay con goi la phng
phap o cao, ch dung cho loai tap m ra co
nh nhon, c bieu dien qua bieu thc

(z*) > (z), z e Z

Trong trng hp co nhieu nh nhon
hay gia tr cc ai khong phai la mot iem duy nhat th ngi ta s dung :
Trung bnh cac cc ai (MoM):

2
2 1
*
z z
z
+
=
Cc ai au tien (LoM):
z* = z1
Cc ai cuoi cung (RoM):
z* = z2

Phng phap trong tam (CoG Center of
Gravity hay CoA Center of Area) :
thng dung trong cac ng dung, c
bieu dien qua bieu thc

}
}
=
dz z
zdz z
z
) (
). (
*


Phng phap trung bnh theo trong so (CoM
Center of Maximum) : la mot bien dang
cua phng phap trong tam khi thay dau tch
phan bang dau sigma, c dung nham n
gian hoa s tnh toan, phu hp vi cac ieu

z z*

z z*

z z1 z2 z z2 z1

z
z1 z2 z3
2
3
1
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 71
khien nho.
Cac tap m ra co dang singleton :

=
) (
). (
*
z
z z
z



Cac tap m ra khong co dang nh, nhng oi
xng :

=
) (
). (
*
z
z z
z




Phng phap trong tam dien tch ln nhat : tnh theo phng phap trong tam nhng
ap dung trong trng hp co t nhat vung tren tap nen ra, tnh tren vung co dien tch
ln nhat.
Co rat nhieu phng phap giai m (hien con ang tiep tuc nghien cu), tuy
nhien trong thc te thng ch dung phng phap trong tam, trung bnh theo trong so
hay trung bnh cac cc ai. Phng phap trong tam hay phng phap trung bnh theo
trong so cho ket qua mang tnh chat thoa hiep cac tap m ra, thng dung trong cac
ng dung ieu khien. Trong khi phng phap trung bnh cac cc ai cho ket qua
mang tnh dung hoa cac tap m ra, thng dung trong cac ng dung nhan dang va
phan loai.



















z
z1 z2
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 72













I. S lc ve cac dung cu o nhiet o:
ieu au tien trong ieu khien nhiet o la chung ta phai co c mot thiet b
(cam bien) cho phep o c nhiet o hien ta i. Co rat nhieu loai khac nhau, phan
trnh bay ay se e cap mot so loai, ac biet chu trong en Thermocouple.
1) Buoi ban au cua thiet b o nhiet o:
Galileo c cho la ngi au tien phat minh ra thiet b o nhiet o , vao khoang
nam 1592. Ong ta lam th nghiem nh sau : tren mot bon h cha ay con, ong cho
treo mot ong thuy tinh dai co co hep, au tren cua no co bau hnh cau cha ay
khong kh. Khi gia tang nhiet, khong kh trong ba u n ra va soi sung suc trong con.
Con khi lanh th khong kh co lai va con dang len trong long ong thuy tinh. Do o, s
thay oi cua nhiet trong bau co the biet c bang cach quan sat v tr cua con trong
long ong thuy tinh. Tuy nhien, ngi ta ch biet s thay oi cua nhiet o ch khong
biet no la bao nhieu v cha co mot tam o cho nhiet o.
au nhng nam 1700, Gabriel Fahrenheit, nha che tao thiet b o ngi Ha Lan,
a tao ra mot thiet b o chnh xac va cho phep lap lai nhieu lan. au di cua thiet
b c gan la 0 o, anh dau v tr nhiet cua nc a tron vi muoi (hay ammonium
chloride) v ay la nhiet o thap nhat thi o. au tren cua thiet b c gan la 96
o, anh dau nhiet o cua mau ngi. Tai sao la 96 o ma khong phai la 100 o?.
Cau tra li la bi v ngi ta chia ty le theo 12 phan nh cac ty le khac thi o.
Khoang nam 1742, Anders Celsius e xuat y kien lay iem tan cua nc a gan
0 o va iem soi cua nc gan 100 o, chia lam 100 phan.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 73
au nhng nam 1800, William Thomson (Lord Kelvin) phat trien mot tam o
pho quat da tren he so gian n cua kh ly tng. Kelvin thiet lap khai niem ve o 0
tuyet oi va tam o nay c chon la tieu chuan cho o nhiet hien ai.
Sau ay la phng trnh chuyen oi cua 4 loai tam o :
C = 5/9(F 32) F = 9/5C + 32
K = C + 273,15 R = F + 459,67
Tam o Rankine (R) n gian la tng ng cua Fahrenheit theo tam Kelvin,
at ten theo W. J. M Rankine (ngi tien phong trong lnh vc nhiet ong).
2) Cac loai cam bien hien tai
Tuy theo lnh vc o va ieu kien thc te ma co the chon mot trong bon loai
cam bien : thermocouple, RTD, thermistor, va IC ban dan. Moi loai co u iem va
khuyet iem rieng cua no.
a) Thermocouple
u iem:
- La thanh phan tch cc, t cung cap cong suat.
- n gian.
- Re tien.
- Tam thay oi rong.
- Tam o nhiet rong.
Khuyet iem:
- Phi tuyen.
- ien ap cung cap thap.
- oi hoi ien ap tham chieu.
- Kem on nh nhat.
- Kem nhay nhat.
b) RTD (resistance temperature detector)
u iem:
- On nh nhat.
- Chnh xac nhat.
- Tuyen tnh hn thermocouple.
Khuyet iem:
- Mac tien.
- Can phai cung cap nguon dong.
- Lng thay oi AR nho.
- ien tr tuyet oi thap.
- T gia tang nhiet.
c) Thermistor
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 74
u iem:
- Ngo ra co gia tr ln.
- Nhanh.
- o hai day.
Khuyet iem:
- Phi tuyen.
- Gii han tam o nhiet.
- De v.
- Can phai cung cap nguon dong.
- T gia tang nhiet.
d) IC cam bien
u iem
- Tuyen tnh nhat.
- Ngo ra co gia tr cao nhat.
- Re tien.
Khuyet iem
- Nhiet o o di 200C.
- Can cung cap nguon cho cam bien.
II. Thermocouple
1)Hieu ng Seebeck:
Nam 1821, Thomas Seebeck a kham pha ra rang neu noi hai day kim loai
khac nhau hai au va gia nhiet mot au noi th se co dong ien chay trong mach
o.
Neu mach b h mot au th th hieu ien the mach h (hieu ien the
Seebeck) la mot ham cua nhiet o moi noi va thanh phan cau thanh nen hai kim
loai.
Khi nhiet o thay oi mot lng nho th hieu ien the Seebeck cung thay oi
tuyen tnh theo :
Kim loai B
Kim loai A Kim loai A
Kim loai B
Kim loai A
e
AB
+

-
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 75
Ae
AB
= oAT vi o la he so Seebeck

2) Cach o hieu ien the
Khong the o trc tiep hieu ien the Seebeck bi v khi noi volt ke
vi thermocouple th vo tnh chung ta lai tao them mot mach mi.
V du nh ta noi thermocouple loai T (ong-constantan).
Khi o , ta co mach tng ng nh sau :








Cai ma chung ta muon o la hieu ien the v
1
nhng khi noi volt ke vao
thermocouple th chung ta lai tao ra hai moi noi kim loai na : J
2
va J
3
. Do J
3
la moi
noi cua ong vi ong nen khong phat sinh ra hieu ien the, con J
2
la moi noi gia
ong vi constantan nen tao ra hieu ien the v
2
. V vay ket qua o c la hieu cua
v
1
va v
2
. ieu nay noi len rang chung ta khong the biet nhiet o tai J
1
neu chung ta
khong biet nhiet o tai J
2
, tc la e biet c nhiet o tai au o th chung ta cung
can phai biet nhiet o moi trng na.



Constantan
Cu
v
1
+

- Cu
J
3
J
1
J
2
Cu
-
-
+

+

v
3
v
2
Constantan
Cu
v
1
+

- Cu
J
1
J
2
-
+
v
2
Constantan
Cu
v
1
+

-
Cu
Cu
+

-
v

Volt ke

J
3
J
1
J
2
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 76
Mot trong nhng cach e xac nh nhiet o tai J
2
la ta tao ra mot moi noi vat ly
roi nhung no vao nc a, tc la ep nhiet o cua no ve 0C va thiet lap tai J
2
nh la
mot moi noi tham chieu.





Luc nay ca hai moi noi tai volt ke eu la ong ong nen khong xuat hien hieu
ien the Seebeck. So oc v tren volt ke la hieu cua v
1
va v
2
:
v = (v
1
v
2
) ~ o (t
J1
t
J2
)
neu ta dung ky hieu T
J1
e ch nhiet o theo o Celsius th :
T
J1
(C) + 273,15 = t
J1

do o v tr thanh :
v = v
1
v
2
= o [(T
J1
+ 273,15) (T
J2
+ 273,15)]
= o (T
J1
T
J2
) = o (T
J1
0)
v = oT
J1
Bang cach them hieu ien the cua moi noi tai 0C, gia tr hieu ien the oc
c luc nay la so vi moc 0C.
Phng phap nay rat chnh xac nen iem 0C c xem nh iem tham chieu
chuan trong rat nhieu bang tra gia tr ien ap ra cua thermocouple.
J
1
Constantan
Cu
v
1
+

-
J
1
T

J
2
T = 0C

+

-
v

Constantan
Cu
v
1
+

-
Cu
Cu
+

-
v

Volt ke

Cu
J
2
+

-
v
2
+

-
v
2
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 77
V du xet tren la mot trng hp ac biet, khi ma mot day kim loai cua
thermocouple trung vi kim loai lam nen volt ke (ong). Nhng neu ta dung loai
thermocouple khac khong co ong (nh loai J : sat constantan) th sao? n gian la
chung ta them mot day kim loai bang sat na th khi o ca hai au volt ke eu la
ong sat nen hieu ien the sinh ra triet tieu lan nhau.

Neu hai au noi cua volt ke khong cung nhiet o th hai hieu ien the sinh ra
khong triet tieu lan nhau, va do o xuat hien sai lech. Trong cac phep o lng can
chnh xac, ngi ta gan chung tren mot khoi ang nhiet. Khoi nay cach ien nhng
dan nhiet rat tot nen xem nh J
3
va J
4
co cung nhiet o (bang bao nhieu th khong
quan trong bi v hai hieu ien the sinh ra luon oi nhau nen luon triet tieu nhau
khong phu thuoc gia tr cua nhiet o).
3) Bu nhiet cua moi trng
Nh tren a phan tch, khi dung thermocouple th gia tr hieu ien the thu
c b anh hng bi hai loai nhiet o : nhiet o can o va nhiet o tham chieu.
Cach gan 0C cho nhiet o tham chieu thng ch lam trong th nghiem e rut ra cac
gia tr cua thermocouple va a vao bang tra. Thc te s dung th nhiet o tham
chieu thng la nhiet o cua moi trng tai ni mach hoat ong nen khong the biet
nhiet o nay la bao nhieu va do o van e bu tr nhiet o c at ra e sao cho ta
thu c hieu ien the ch phu thuoc vao nhiet o can o ma thoi.
Bu tr nhiet o khong co ngha la ta c lng trc nhiet o moi trng
roi khi oc gia tr hieu ien the th tr i gia tr ma ta a c lng. Cach lam nay
hoan toan khong thu c ket qua g bi hai ly do :
- Nhiet o moi trng khong phai la ai lng co nh ma thay oi theo thi
gian theo mot qui luat khong biet trc.
- Nhiet o moi trng tai nhng ni khac nhau co gia tr khac nhau.
J
1
Constantan
Fe
v
1
+

-
Cu
Cu
+

-
v

Volt ke

Fe
J
2
+

-
v
2
J
3
J
4
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 78
Bu nhiet moi trng la mot van e thc te va phai xet en mot cach
nghiem tuc. Co nhieu cach khac nhau, ve phan cng lan phan mem, nhng nhn
chung eu phai co mot thanh phan cho phep xac nh nhiet o moi trng roi t o
tao ra mot gia tr e bu lai gia tr tao ra bi thermocouple.
III) Cac loai thermocouple
Ve nguyen tac th ngi ta hoan toan co the tao ra mot thermocouple cho gia
tr ra bat ky bi v co rat nhieu to hp cua hai trong so cac kim loai va hp kim hien
co.
Tuy nhien e co mot thermocouple dung c cho o lng th ngi ta phai
xet en cac van e nh : o tuyen tnh, tam o, o nhay, va do o ch co mot so
loai dung trong thc te nh sau :
Loai J : ket hp gia sat vi constantan, trong o sat la cc dng va constantan la
cc am. He so Seebeck la 51V/C 20C.
Loai T : ket hp gia ong vi constantan, trong o ong la cc dng va
constantan la cc am. He so Seebeck la 40V/C 20C.
Loai K : ket hp gia chromel vi alumel, trong o chromel la cc dng va
alumel la cc am. He so Seebeck la 40V/C 20C.
Loai E : ket hp gia chromel vi constantan, trong o chromel la cc dng va
constantan la cc am. He so Seebeck la 62V/C 20C.
Loai S, R, B : dung hp kim gia platinum va rhodium, co 3 loai : S) cc dng
dung day 90% platinum va 10% rhodium, cc am la day thuan platinum. R) cc
dng dung day 87% platinum va 13% rhodium, cc am dung day thuan platinum.
B) cc dng dung day 70% platinum va 30% rhodium, cc am dung day 94%
platinum va 6% rhodium. He so Seebeck la 7V/C 20C.
IV) Mot so nhiet o chuan
Sau khi a thiet ke mach xong th ngi ta can mot so nhiet o chuan dung
cho can chnh. Bang sau ay a ra mot so loai nhiet o chuan :










uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 79













1) OP07
ac iem : Kieu chan :
- Offset thap : 10V.
- o troi offset thap : 0,2V/C.
- o on nh oi vi thi gian cao : 0,2V/thang.
- t b anh hng bi nhieu : 0,35V
p-p
.
- Tam ien ap cung cap rong : 3V 18V.
- Common Mode Input cao : 14V.
- Khong can linh kien rap them ben ngoai.
OP07 la mot IC OPAMP co o chnh xac cao, vi
offset thap (tieu chuan la 10V, max la 25V). o
troi offset khoang 0,2V/C va dong phan cc au
vao thap (0,7nA), cong them vi tr khang au
vao cao va o li vong h ln nen IC nay rat thch
hp vi cac ng dung o lng oi hoi chnh xac.
2) MOC3020
ac iem : Kieu chan :
- ien ap lai au ra len en 400V.
- Nguon kch la diode hong ngoai Gallium
Arsenide va nguon nhan e lai triac la cap
silicon quang (ong m hai chieu).
- Cach ly cao : 7500V nh.
- au ra c thiet ke e lai ien ap 220V.
- Dung vo PDIP 6 chan.
MOC3020 la OPTO TRIAC thng dung e kch nguon cong suat va cach ly mach cong suat
vi mach ieu khien.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 80
3) RAM 6264
RAM 8KB, tien dung cho lu tr trong cac mach ieu
khien. S o chan (PDIP 28 chan).







4) Chot 74573
74573 la IC chot 8-bit, dung trong ket noi vi x ly vi ngoai
vi hay trong phan vung a ch trong cac vi x ly hay vi ieu
khien dung che o a ch kieu multiplex (a ch va d lieu
ra chung ngo nhng khac thi iem) nh ho MCS-51
TM
. Thiet
ke tren kieu chan PDIP 20 chan.
5) BTA16


BTA16 la triac co dong nh mc 16A. Thiet ke tren vo TO-220.

. 6) 74LS245:
ay la IC co chc nang em 2 chieu , rat linh hoat trong viec giao tiep
nhap xuat (tuy thuoc vao chan DIR), v vay thng dung e ket noi vi may tnh hoac
MCU.
Trong mach nay 74LS245 lam nhiem vu nhap d lieu t ICL7107







Bang chan tr:

ieu
khien G
D
IR
H
ng truyen
0 A
U1
74LS245
2
3
4
5
6
7
8
9
19
1
18
17
16
15
14
13
12
11
A1
A2
A3
A4
A5
A6
A7
A8
G
DIR
B1
B2
B3
B4
B5
B6
B7
B8
GND
14
VCC
28
D7
19
D6
18
D5
17
D4
16
D3
15
D2
13
D1
12
D0
11
WE
27
OE
22
CS2
26
CS1
20
A12
2
A11
23
A10
21
A9
24
A8
25
A7
3
A6
4
A5
5
A4
6
A3
7
A2
8
A1
9
A0
10
NC
1
GND
10
VCC
20
Q8
12
Q7
13
Q6
14
Q5
15
Q4
16
Q3
17
Q2
18
Q1
19
OC
1
C
11
D8
9
D7
8
D6
7
D5
6
D4
5
D3
4
D2
3
D1
2
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 81
0 B

0
1 B
A

1
X High
-Z

7) PPI 8255:
PPI 8255 la IC giao tiep song song lap trnh c . ay la vi mach rat thong
dung thng co trong cac may tnh PC/AT va cac thiet b trao oi thong tin khac.














Cac ngo vao t D0-D7 la data bus dung e giao tiep vi vi x ly hoac
data bus cua may tnh. Co 3 ngo ra la Port A (PA0-PA7), Port B (PB0-PB7) va Port C
(PC-PC7).
- Port A : thanh ghi em so lieu (8 bit ) vao hoac ra tuy theo chng trnh khi
phat (se c noi cu the hn phan sau).
- Port B : thanh ghi em so lieu (8 bit ) vao hoac ra tuy theo chng trnh khi
phat.
- Port C : co the c s dung nh la mot cong 8 bit hoac hai cong 4 bit (moi
cong la 4 bit cao hoac 4 bit thap ).
U7
8255
34
33
32
31
30
29
28
27
5
36
9
8
35
6
4
3
2
1
40
39
38
37
18
19
20
21
22
23
24
25
14
15
16
17
13
12
11
10
D0
D1
D2
D3
D4
D5
D6
D7
RD
WR
A0
A1
RESET
CS
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PC0
PC1
PC2
PC3
PC4
PC5
PC6
PC7
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 82
Phng thc hoat ong cua cac port A, port B, port C (tc la che o hoat ong
cua PPI 8255 ) c at bang gia tr cua thanh ghi t ieu khien cua PPI 8255 .




Nh vay e at che o ieu khien cho PPI 8255 th ta ch can nap gia tr cua t
ieu khien vao a ch cua thanh ghi ieu khien .Tuy theo che o s dung ghi bi t
ieu khien , ca C co the c dung:
-Trao oi so lieu vao hoac ra (mode 0)
-ieu khien hoac oi thoai vi thiet b ngoai hoac vi x ly khi port A va port B
mode 0 bang cach xac lap va xoa tng bit port C
-ieu khien hoac oi thoai vi thiet b ngoai hoac vi x ly khi port A va port B
mode 1 hoac 2. cac mode 1 va 2 nay, oc cac bit port C ta biet c
trang thai cua cac port A va B .
Cac mode s dung cua PPI 8255 :
mode 0 :Che o nay con goi la che o vao ra c s v :
-Cac port A, B va C c s dung oc lap vi nhau.
-Cac port A, B va C co the hoat ong che o vao hoac ra tuy thuoc vao gia
tr cua t ieu khien
-So lieu ra c chot
-So lieu vao khong c chot.
mode 1: mode nay cac port c chia lam 2 nhom:
-nhom A gom port A e trao oi so lieu va na byte cao cua port C (PC
7
-PC
4
)
dung e oi thoai vi vi x ly va thiet b ngoai.
-nhom B gom port B e trao oi so lieu va na byte thap port C (PC
0
-PC
3
) e
oi thoai vi vi x ly va thiet b ngoai.
mode 2:Che o nay dung cho port A vi kha nang vao ra thuan nghch 2 chieu
va cac bit PC
3
, PC
4
-PC
7
dung lam cac tn hieu oi thoai .









uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 83







































uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 84





1. Cau truc tong quat
CPU CPU CPU
BUS
RS-232 RS-485


a) KIT IEU KHIEN NHIET O:
Board mach ieu khien c thiet ke nham muc ch ieu khien mot lo nng dan
dung co cong suat di 3000W, chia ra cac khoi nh sau :
- Khoi x ly trung tam : dung vi ieu khien AT89C51.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 85
- Khoi giai ma a ch : chia vung bo nh d lieu ngoai (64KB) thanh 8 vung 8KB
dung 74LS138.
- Khoi bo nh : RAM 8KB dung UM6264B.
- Khoi hien th : 4 LED 7 oan cho phep hien th trang thai cua he thong cho
ngi dung
- Khoi cam bien va gia cong : dung cam bien nhiet o la thermocouple loai K ,
mach gia cong gom co mach khuech ai, mach bu nhiet o moi trng, va mach
chnh 0V khi nhiet o la 0
0
C.
- Khoi bien oi AD : dung ICL7107CPL co kha nang bien oi 12 bit, cung cap
4096 mc cho nhiet o ln nhat khoang 409,6C (0,1C/LSB).
- Khoi ban phm : 16 phm thiet ke kieu ma tran 4x4 tien dung e nhap cac thong
so ieu khien, chc nang cua tng phm cu the c qui nh bi phan mem
ieu khien .
- Khoi cong suat : co kha nang ieu khien oi tng dung ien ap 220V, 16A
(ay la gia tr ln nhat) dung BTA16-600B.
- Khoi giao tiep vi may tnh : dung MAX232, giao tiep theo kieu 3 day, khong
dung che o bat tay ma dung ngat.
- Khoi nguon : nguon chnh cung cap ien ap 5V cho toan mach va nguon
backup nuoi RAM khi mat ien nham muc ch bao toan d lieu.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 86
CPU
Kho i ca m bie n
va gia co ng
Kho i ba n phm Nguo n Backup
RAM 8K
Kho i bie n o i
AD
Hie n th tra ng
tha i
Ma ch co ng sua t
S O KHO I KIT IE U KHIE N NHIE T O


b) KIT QUAN LY NHAN VIEN:
CPU Kho i ba n phm
Nguo n Backup
RAM 8K
Hie n th
S O KHO I KIT QUA N LY NHA N VIE N


uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 87
c) KIT QUANG BAO:

CPU
Nguo n Backup
RAM 8K
Hie n th
S O KHO I KIT QUANG BA O

2. Khoi x ly trung tam
Do 3 kit thiet ke ac 3 v tr khac nhau, nen khong the dung chung khoi x ly
trung tam, moi kit co mot khoi x ly, co chc nang khac nhau. e minh hoa ch mo
ta chung, chc nang cua moi khoi nh the nao c trnh bay trong phan mem
ong vai tro bo ieu khien trung tam, chu trach nhiem ve tat ca cac hoat ong
cua mach. Board mach cung cap mot cong cu e co the ieu khien theo bat c
phng phap nao, mien la co giai thuat va viet chng trnh nap cho AT89C52.

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 88
(2)RD
A14
JP3
Port 1
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
A5
AD3
R1
100
AD5
AD4
AD3
+5V(2)
SW1
RESET
+5V(2)
AD0
U1
AT89C52
9
18
19
29
30
31
1
2
3
4
5
6
7
8
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
39
38
37
36
35
34
33
32
RST
XTAL2
XTAL1
PSEN
ALE/PROG
EA/VPP
P1.0/T2
P1.1/T2-EX
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INTO
P3.3/INT1
P3.4/TO
P3.5/T1
P3.6/WR
P3.7/RD
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
A11
A6
+C3
10uF
A12
A8
A9
TXD
J17
NP3.2
1
2
3
4
R3
4.7k
AD2
X1
11.059MHz
AD1
A15
A0
A3
A2
Data Bus
AD6
AD2
AD0
AD1
+5V(2)
RXD
AD6
C1 30p
AD7
A10
SW2
1 2
A1
A13
(2)/WR
Address Bus
C2 30p
AD4
A7
A4
R2
8.2K
AD5
AD7
U2
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8

ng trung tam la vi ieu khien AT89C51. S d dung AT89C51 ma khong
dung cac IC khac trong ho MCS-51
TM
la v IC nay co 2 timer 16-bit, phu hp cho
hoat ong ieu khien nh : mot timer cung cap xung e tao baudrate cho truyen
thong noi tiep RS-232, mot timer em thi gian thc, mot timer tao cac khoang thi
gian tre cho lap trnh.
- Chan EA c noi en mot switch va ien tr 4.7KO cho phep tuy chon noi len
+5V hay noi xuong GND, ieu nay tng ng vi viec AT89C52 se thc thi
chng trnh ben trong bo nh noi hay chng trnh ben ngoai RAM.
- Bo dao ong gom thach anh X1 va 2 tu C1, C2 c noi en chan XTAL1 va
XTAL2. Xung clock cho cac hoat ong ben trong cua AT89C51 se co tan so
bang tan so cua thach anh chia cho 12. Thong thng, ngi ta hay dung thach
anh 12MHz e tan so xung clock la 1MHz, tng ng vi mot chu ky may ton
1s nen rat de tao mot timer thi gian thc chnh xac. Tuy nhien trong mach lai
dung thach anh 11,059MHz la e tao baudrate chnh xac. Hoat ong tao
baudrate co the giai thch nh sau : oi vi ho MCS-51
TM
, ngi ta phai dung
mot timer (thng la timer1) va toc o tran cua no se tao ra baudrate. Khi o, ta
co cong thc:
BAUDRATE = TOC O TRAN TIMER1 12
V du, gia s ta muon co toc o 1200 baud th tnh nh sau :
1200 = toc o tran timer1 12
toc o tran timer1 = 1200x32 = 38,4KHz
Neu thach anh co tan so 12MHz th timer1 c clock vi tan so 1MHz hay
1000KHz. e co toc o tran la 38,4KHz th timer1 phai tran sau moi 1000
38,4 = 26,04 xung clock (lam tron la 26). Do timer em len va se tran khi
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 89
chuyen t FFH sang 00H, can phai nap so -26 vao timer va the la baudrate c
tao ra.
Nh ta a thay, trong phep tnh tren co lam tron, ieu nay dan en sai so trong
baudrate tao ra. T o ta can phai tm thach anh co tan so sau cho baudrate tao
ra khong co sai so e viec truyen thong am bao chnh xac. Qua cac phep tnh
th thach anh 11,059MHz cho baudrate rat chnh xac. Bang sau se cho thay s so
sanh sai so khi dung thach anh 12MHz va thach anh 11,059MHz trong mot so
baudrate thong dung :

BAUDRATE
TAN SO
THACH ANH
SMOD GIA TR NAP
BAUDRATE
THC S
SAI SO
9600
2400
1200
19200
9600
2400
1200
12,000MHz
12,000MHz
12,000MHz
11,059MHz
11,059MHz
11,059MHz
11,059MHz
1
0
0
1
0
0
0
-7(F9H)
-13(F3H)
-26(E6H)
-3(FDH)
-3(FDH)
-12(F4H)
-24(E8H)
8923
2404
1202
19200
9600
2400
1200
7%
0,16%
0,16%
0
0
0
0
(Neu SMOD = 1 th baudrate = toc o tran timer1 16)

- Mach reset gom C3, R2 cho tac vu auto-reset (reset khi mi cap nguon). Ngoai
ra con co R1 va SW1 cho tac vu manual-reset (reset bang tay khi an phm SW1
bat c khi nao).
- Chan P3.2, P3.3, P3.3 la ngo ra cua Port3 cung ong thi la ngo vao cua ngat
ngoai. Trong thiet ke khong dung en nen bo trong.
- Chan P3.5 dung e ieu khien mach cong suat (PWR), khi chan nay mc 1 th
lo nung c cap ien.
- Port1 danh rieng cho 16 phm trong khoi ban phm.
Do dung cac thiet b ngoai vi nen Port0 va Port2 dung trong che o a ch va d lieu :
Port0 va la byte thap cua a ch, va la byte d lieu (AD0AD7). Port2 la byte cao
cua a ch (A8A15). Ta xem gian o xung :
Nh vay, khi truy xuat d lieu ben ngoai th au tien tren Port0 se la byte thap cua a ch,
ALE se tac ong canh xuong khi cac gia tr a on nh luc nay can mot IC e chot cac gia
tr nay lai thong qua tac ong cua ALE dung IC 74HCT573, ALE noi en chan C. Sau o,
A CH D LIE U
A8-A15
AD0-AD7
ALE
A CH
CHU KY NH
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 90
gia tr tren Port0 se la d lieu (nhap hay xuat tuy theo read hay write thong qua tac ong cua
chan RD hay WR, chan PSEN thay the vai tro cua chan RD khi oc chng trnh ngoai). Gia
tr tren Port2 luon la byte cao cua a ch. Sau khi qua IC 74HCT573 la ta a co 8-bit d lieu
va 16-bit a ch.
3. Phan vung a ch
Tuyen a ch 16-bit co the ma hoa en 64KB. Tuy nhien, ngoai tr RAM can
mot lng vung nh ln (8KB) th cac
ngoai vi con lai ch can mot hay hai
ng a ch. Nham de dang cho viec
thiet ke, ta phan lam 8 vung (moi vung
8KB) thong qua IC 74138 noi vi 3 bit
cao cua tuyen a ch :
Bang phan vung a ch cua kit
ieu khien nhiet o:
Hien tai co 3 loai thiet b ngoai vi : RAM, ADC, va LED. Trong o RAM can
mot tn hieu chon, ADC can 1 tn hieu chon oc d lieu thong qua 8255 , LED can 2
tn hieu chon chon led (do dung phng phap quet) va xuat d lieu. Tong cong la 4
tn hieu chon nen ta bo 4 tn hieu con lai.
Bang phan vung a ch :
Vung a ch
Tn hieu
chon
Thiet b ngoai vi
0000H1FFFH CS0 RAM 8KB (IC HM6264).
2000H3FFFH CS1 8255
4000H5FFFH CS2 Chot d lieu ra led.
6000H7FFFH CS3 Chon led (1 trong 4 led).
8000H9FFFH CS4 Khong dung.
A000HBFFFH CS5 Khong dung.
C000HDFFFH CS6 Khong dung.
E000HFFFFH CS7 Khong dung.

Bang phan vung a ch cua kit oc ma vach:
Hien tai co 2 loai thiet b ngoai vi : RAM va LED. Trong o RAM can mot tn
hieu chon, LED can 2 tn hieu chon chon led (do dung phng phap quet) va xuat d
lieu. Tong cong la 3 tn hieu chon nen ta bo 5 tn hieu con lai.
Bang phan vung a ch :
Vung a ch
Tn hieu
chon
Thiet b ngoai vi
0000H1FFFH CS0 RAM 8KB (IC HM6264).
+5V
/CS5
/CS3
/CS0 A13
/CS6
/CS2 A15
/CS1
/CS7
/CS4
A14
U3
74LS138
1
2
3
6
4
5
15
14
13
12
11
10
9
7
A
B
C
G1
G2A
G2B
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
ADDRESS BUS [A0..A15]
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 91
2000H3FFFH CS1 Chot d lieu ra led.
4000H5FFFH CS2 Chon led (1 trong 8 led).
6000H7FFFH CS3 Khong dung.
8000H9FFFH CS4 Khong dung.
A000HBFFFH CS5 Khong dung.
C000HDFFFH CS6 Khong dung.
E000HFFFFH CS7 Khong dung.



Bang phan vung a ch cua kit quang bao:
Hien tai co 2 loai thiet b ngoai vi : RAM va LED. Trong o RAM can mot tn
hieu chon, LED can 6 tn hieu chon chon led (do dung phng phap quet) va xuat d
lieu. Tong cong la 7 tn hieu chon nen ta bo 1 tn hieu con lai.
Bang phan vung a ch :
Vung a ch
Tn hieu
chon
Thiet b ngoai vi
0000H1FFFH CS0 RAM 8KB (IC HM6264).
2000H3FFFH CS1 Chot d lieu ra led 1.
4000H5FFFH CS2 Chot d lieu ra led 2
6000H7FFFH CS3 Chot d lieu ra led 3
8000H9FFFH CS4 Chot d lieu ra led 4
A000HBFFFH CS5 Chot d lieu ra led 5
C000HDFFFH CS6 Quet cot
E000HFFFFH CS7 Khong dung.

Tuy nhien, viec truy xuat thiet b ngoai vi (oc hay ghi) oi hoi phai ket hp 2
tn hieu : tn hieu phan vung a ch va tn hieu RD hay WR (tuy theo oc hay ghi)
qua to hp cong logic thch hp. T o mi tao ra tn hieu ket noi vao thiet b ngoai
vi e truy xuat.
V vay, tuy theo thiet b ngoai vi ma se co mot cong logic phu hp i kem.
4. Khoi bo nh va nguon backup
Bo nh dung RAM 8KB (UM6264B) c thiet ke vi hai chc nang : trong qua
trnh viet va chay th chng trnh, cho phep tai chng trnh t may tnh vao RAM
va sau o cho vi ieu khien thc thi chng trnh tren tren RAM (chng trnh ngoai
EA = 0). Cach nay rat thuan tien bi v trong qua trnh phat trien mot phan mem,
khong bao gi ngi ta co the viet ung ngay t lan viet chng trnh au tien, ma la
mot qua trnh viet - kiem tra - sa sai va co the lap lai rat nhieu lan. Neu nh ta nap
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 92
chng trnh trc tiep cho vi ieu khien th phai nap nhieu lan ton tien va anh
hng en tuoi tho cua vi ieu khien. Chc nang th hai la mot khi ieu khien th ta
phai x ly d lieu, va do o can phai co ni lu tr d lieu. Nh vay RAM va la bo
nh chng trnh ngoai, va la bo nh d lieu ngoai nen tn hieu oc RAM la s ket
hp (mot trong hai : tai moi thi iem ch co mot tn hieu tch cc) cua 2 tn hieu : tn
hieu oc chng trnh ngoai (PSEN), va tn hieu oc d lieu ngoai (RD) cho thao tac
oc thong qua cong AND c tao bi hai diode D2, D3 va ien tr R10o a vao
chan OE cua RAM. Chan ra WR cua AT89C52 c noi thang vao chan WE cua
RAM.
Data Bus
A10
AD3
A5
A7
A8
A11
A1
AD5
A9
/WR
A4
+5V
R4
330
A6
AD0
AD1
+C8
10uF
A3
/CS0
AD4
U5
HM6264A
10
9
8
7
6
5
4
3
25
24
21
23
2
20
26
22
27
11
12
13
15
16
17
18
19
2
8
1
4
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
CS1
CS2
OE
WE
D0
D1
D2
D3
D4
D5
D6
D7
V
C
C
G
N
D
A2 AD2
D1
1
2
BT1
3.6V
A12
A0
/RD
+5V
Address Bus
AD6
AD7

e am bao khong mat d lieu ngay ca khi mat ien th RAM c thiet ke vi
2 nguon cung cap : nguon chnh cung cap cho toan mach va nguon backup thong qua
pin 3,6V.
Tn hieu chon vung CS0 la tn hieu chon RAM nen c noi en chan CS1 cua
RAM, chan CS2 cua RAM cho noi len mc tch cc +5V. Diode D1 va ien tr R4
hnh thanh nen mach sac cho pin BT1 (pin sac 3.6V) : khi co ien cung cap cho mach
th D1 dan cung cap ien cho RAM, ong thi sac ien cho pin. Khi khong co ien
nguon th D1 ngat, RAM c cap ien t pin. Tu C8 dung e chong xung nhieu xuat
hien khi xay ra chuyen nguon cung cap.
Truy xuat d lieu trong RAM thong qua a ch cha trong DPTR va lenh
MOVX. V du oc o nh 1234H va xuat ra o nh 1555H :

MOV DPTR,#1234H ;Byte at 1234H
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 93
MOVX A,@DPTR ;Read byte
MOV DPTR,#1555H ;Byte at 1555H
MOVX @DPTR,A ;Write byte

5. Khoi hien th
Do thiet ke 3 kit lam 3 chc nang khac nhau ( at tai 3 v tr khac nhau ), nen
khoi hien th moi kit khac nhau: kit ieu khien lo nhiet va kit theo doi gi lam viec cua
nhan vien do hien th bang led 7 oan nen mo ta chung, con kit quang bao do dung led
ma tran nen trnh bay rieng.
LED(2)2
R67
10k
/CS13
LED(2)3
AD0
D
C
(
2
)
/CS12
R62
1k
AD1
D
F
(
2
)
D
C
(
2
)
Q9
3
2
1
.
L7
Led 7-Seg
7642191
0
5
3
8
ABCDEFG
Dp
A1
A2
AD7
/CS12
U32B
74LS02
5
6
4
DC(2)
Q10
3
2
1
AD7
D
E
(
2
)
D
A
(
2
)
D
F
(
2
)
D
A
(
2
)
D
E
(
2
)
330
AD4
DA(2)
Q8
A1015
3
2
1
U13
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
LED(2)2
/CS3
D
G
(
2
)
R64
1k
Q11
3
2
1
DG(2)
D
C
(
2
)
DF(2)
/WR
LED(2)0 LED(2)1
DE(2)
D
C
(
2
)
AD2
D
D
(
2
)
R61
10k
AD2
U19
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
DB(2)
R60
1k
AD3
LED(2)3
R63 10k
AD4
AD6
WR
.
L6
Led 7-Seg
7642191
0
5
3
8
ABCDEFG
Dp
A1
A2
/CS13
.
L5
Led 7-Seg
7642191
0
5
3
8
ABCDEFG
Dp
A1
A2
D
G
(
2
)
D
G
(
2
)
AD0
D
A
(
2
)
D
F
(
2
)
AD5
D
D
(
2
)
DD(2)
AD5
D
G
(
2
)
D
B
(
2
)
D
B
(
2
)
D
E
(
2
)
+5V(2)
R66
1k
U32A
74LS02
2
3
1
D
D
(
2
)
LED(2)1
LED(2)0
R52
D
D
(
2
)
D
A
(
2
)
D
B
(
2
)
AD6
D
E
(
2
)
AD1
D
B
(
2
)
/CS2
.
L8
Led 7-Seg
7642191
0
5
3
8
ABCDEFG
Dp
A1
A2
AD3
D
F
(
2
)
R65
10k


Khoi hien th cua kit ieu khien lo nhiet
Hien th LED co the s dung mot trong hai phng phap : quet hoac la chot.
ay chon phng phap quet, bi v dung phng phap chot trong trng hp nay
khong kinh te lam ( v moi led can 8 ien tr 330O va 1 IC chot hay giai ma BCD).
D nhien, khi ta c mat nay th phai chu mat kia, o la ve mat lap trnh gap
nhieu kho khan hn : can am bao ung mot khoang thi gian co nh (c 3ms) th
phai quet led.
Viec truy xuat mot led thong qua 2 bc : chon led can xuat va sau o xuat d
lieu ra. V vay trong thiet ke dung 2 IC chot : mot cho chon led (U13) va mot cho d
lieu (U14). Tn hieu truy xuat la s ket hp cua WR va tn hieu chon vung a ch
qua cong NOR dan en chan chot C
Chng trnh sau ay minh hoa viec xuat ra led. Sau o dung mot chng trnh
tao thi gian tre ( ngat timer0) goi chng trnh nay.
COLLED EQU 6000H
DATALED EQU 4000H
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 94
LEDT0 EQU 40H
LEDT1 EQU 41H
LEDT2 EQU 42H
LEDT3 EQU 43H

; CHUONG TRINH NGAT QUET PHIM
ISRT0:
; Khoi tao lai Timer
CLR TR0
MOV TH0, #HIGH (-3000)
MOV TL0, #LOW (-3000)
SETB TR0

; Xac dinh vi tri led de xuat
MOV A, POSLED
;Quet Led 0
CJNE A, #0, SCANL1

CALL DISL0
JMP QSCAN
;Quet Led1
SCANL1:
CJNE A, #1, SCANL2

CALL DISL1
JMP QSCAN
;Quet Led2
SCANL2:
CJNE A, #2, SCANL3

CALL DISL2
JMP QSCAN
;Quet Led3
SCANL3:
CJNE A, #3, QSCAN

CALL DISL3

QSCAN:
INC POSLED
MOV A, POSLED
CJNE A, #4, QISCAN
MOV POSLED, #0

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 95
QISCAN:
RETI

DISL0:
MOV A, LEDT0
MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV DPTR, #DATALED
MOVX @DPTR, A
MOV DPTR, #COLLED
MOV A, #01H
MOVX @DPTR, A
RET

DISL1:
MOV A, LEDT1
MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV DPTR, #DATALED
MOVX @DPTR, A
MOV DPTR, #COLLED
MOV A, #02H
MOVX @DPTR, A
RET

DISL2:
MOV A, LEDT2
MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV DPTR, #DATALED
MOVX @DPTR, A
MOV DPTR, #COLLED
MOV A, #04H
MOVX @DPTR, A
RET

DISL3:
MOV A, LEDT3
MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV DPTR, #DATALED
MOVX @DPTR, A
MOV DPTR, #COLLED
MOV A, #08H
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 96
MOVX @DPTR, A
RET
KHOI HIEN TH CUA KIT QUANG BAO
Do kit quang bao can hien th nhieu ch cai khac nhau, do o khong the dung
led 7 oan hien th ma phai dung led ma tran, th trng co nhieu loai led ma tran:
5x7, 6x8,
Khoi hien th nay toi dung 5 led ma tran 5x7, do tnh chat minh hoa toi ch trnh
bay 2 led
Do led ma tran c tao thanh t nhng node rieng biet, do o e the hien c
nhng k t co y ngh th phai ket hp nhng node o lai vi nhau. V tnh phc tap
cua viec the hien k t, nen ta khong dung phng phap chot trong thiet ke, do rat ton
IC, khong kinh te.
Toi thiet ke dung phng phap quet. Dung 5 IC chot e xuat data, con 1 con IC
chot khac dung quet cot chung
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 97
LD7
LD0
LH2
HEADER 7(L2)
1
2
3
4
5
6
7
L/WR
L
C
3
L
C
0
U1492713498D
74LS02
11
12
13
L
C
4
LCS3
JP49(L1)
LH1
1
2
3
4
5
6
7
8
LD4
U1492713499A
74LS02
2
3
1
U 573LH2
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
U 573LH1
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
LD4
LD6
LD3
ooooo
ooooo
ooooo
o
o
o
o
o
o
o
o
ooo
ooo
ooo
ooo
LED1
Led Matri x 1
12
11
2
9
4
5
6
131
0
78
R0
R1
R2
R3
R4
R5
R6
C
0
C
1
C
2
C
3
C
4
LD1
LD5
LD0
L
C
0
L/CS4
LD2
U 573LC
74HCT573
2
3
4
5
6
7
8
9
11
1
19
18
17
16
15
14
13
12
D1
D2
D3
D4
D5
D6
D7
D8
C
OC
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
LCS6
L/CS5
L/WR
LCS1
LCS1
JP50(L2)
LH2
1
2
3
4
5
6
7
8
LD5
U1492713498C
74LS02
8
9
10
LD5
L/WR
LD2
LD4
LD3
L
C
3
L/CS1
L/WR
L/CS6
LD6
LCS2
L
C
2
L/WR
ooooo
ooooo
ooooo
o
o
o
o
o
o
o
o
ooo
ooo
ooo
ooo
LED2
Led Matri x 2
12
11
2
9
4
5
6
131
0
78
R0
R1
R2
R3
R4
R5
R6
C
0
C
1
C
2
C
3
C
4
U1492713498A
74LS02
2
3
1
L/CS2
LH1
HEADER 7(L1)
1
2
3
4
5
6
7
L/WR
LCS6
LD2
LD7
L
C
1
LC1
HEADER 5(L1)
1
2
3
4
5
LD1
LD1
L
C
1
LCS2
JP54(CL)
CL
1
2
3
4
5
6
7
8
U1492713498B
74LS02
5
6
4
U1492713499B
74LS02
5
6
4
LD7
L/CS3
L
C
4
LD6
LD3
L
C
2
LD0
LCS4
LCS5




uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 98


Viec dung IC xuat data cho tng con led va quet chung cot se thuan tien hn
rat nhieu trong viec viet chng trnh hien th led v khi o ta ch viec xuat data ra,
sau o quet cot
Do kit nay ch co nhiem vu quang bao, nen trong chng trnh quet khong dung
ngat timer ma quet chng trnh chnh
Chng trnh minh hoa quet led:

DISLED:
MOV R0, #0 ; v tr tro data cua led1
MOV 3AH, #5 ; v tr tro data cua led2
MOV 3BH, #0AH ; v tr tro data cua led3
MOV 3CH, #0FH ; v tr tro data cua led4
MOV 3DH, #14H ; v tr tro data cua led5
LOOP1:
; Xuat led

MOV DPTR, #0800H ; a ch lay data
MOV 3EH, R0
CALL INCDPTR
MOV DPTR, #0A000H ; tro led
MOVX @DPTR, A

MOV R7, 3AH
MOV 3EH, R7
MOV DPTR, #0800H
CALL INCDPTR
MOV DPTR, #8000H
MOVX @DPTR, A
INC R7
MOV 3AH, R7

MOV R7, 3BH
MOV 3EH, R7
MOV DPTR, #0800H
CALL INCDPTR

MOV DPTR, #6000H
MOVX @DPTR, A
INC R7
MOV 3BH, R7
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 99

MOV R7, 3CH
MOV 3EH, R7
MOV DPTR, #0800H
CALL INCDPTR

MOV DPTR, #4000H
MOVX @DPTR, A
INC R7
MOV 3CH, R7

MOV R7, 3DH
MOV 3EH, R7
MOV DPTR, #0800H
CALL INCDPTR

MOV DPTR, #2000H
MOVX @DPTR, A
INC R7
MOV 3DH, R7
; COT
MOV A, R0
MOV DPTR, #COT
MOVC A, @A+DPTR
MOV DPTR, #0C000H
MOVX @DPTR, A
;CALL DELAY
;DELAY:
MOV R1, #17
NHAN:
MOV R7, #250
DJNZ R7, $
DJNZ R1, NHAN

;RET ; Xong ScanCot
INC R0
CJNE R0, #5, LOOP1
RET
Vi thiet ke nh vay, se co bang ma rieng ( trnh bay ben di )
Bang ma hien th thng dung:

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 100

Kyt Ma nh phan Hex Ky t Ma nh phan Hex Ky t Ma nh phan Hex
0 11000000B C0H H. 00001001B 09H i. 01001111B 4FH
1 11111001B F9H I. j. 01110001B 71H
2 10100100B A4H J. 01100001B 61H k.
3 10110000B B0H K. l.
4 10011001B 99H L. 01000111B 47H m.
5 10010010B 92H M. n. 01001000B 48H
6 10000010B 82H N. o. 00100011B 23H
7 11111000B F8H O. 01000000B 40H p.
8 10000000B 80H P. 00001100B 0CH q. 00011000B 18H
9 10010000B 90H Q. r. 01001100B 4CH
0. 01000000B 40H R. s.
1. 01111001B 79H S. 0010010B 12H t. 00000111B 07H
2. 00100100B 24H T. 01001110B 4EH u. 01100011B 63H
3. 00110000B 30H U. 01000001B 41H v. 01100011B 63H
4. 00011001B 19H V. 01000001B 41H w.
5. 00010010B 12H W. x.
6. 00000010B 02H X. y. 00010001B 11H
7. 01111000B 78H Y. 00011001B 19H z.
8. 00000000B 00H Z. 00100100B 24H ! 01111001B 79H
9. 00010000B 10H a 10100000B A0H 11011101B DDH
A 10001000B 88H b 10000011B 83H #
B c 10100111B A7H $
C 11000110B C6H d 10100001B A1H %
D e 10000100B 84H &
E 10000110B 86H f 11111101B FDH
F 10001110B 8EH g 10010000B 90H (
G 11000010B C2H h 10001011B 8BH )
H 10001001B 89H i 11001111B CFH *
I j 11110001B F1H +
J 11100001B E1H k ` 11011111B DFH
K l - 10111111B BFH
L 11000111B C7H m . 01111111B 7FH
M n 11001000B C8H /
N o 10100011B A3H :
O 11000000B C0H p ;
P 10001100B 8CH q 10011000B 98H <
Q r 11001100B CCH >
R s = 10110111B B7H
S 10010010B 92H t 10000111B 87H ? 00101100B 2CH
T 11001110B CEH u 11100011B E3H [ 11000110B C6H
U 11000001B C1H v 11100011B E3H \
c
D7 D6 D5 D4 D3 D2 D1 D0
h a b c d e f
h
g
g
f
e
d
b
a
sa ng : bit Di = 0
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 101
V 11000001B C1H w ] 11110000B F0H
W x ^
X y 10010001B 91H _ 11110111B F7H
Y 10011001B 99H z {
Z 10100100B A4H a. 00100000B 20H ~
A. 00001000B 01H b. 00000011B 03H }
B. c. 00100111B A7H @
C. 01000110B 46H d. 00100001B 21H

10110110B B6H
D. e. 00000100B 04H
0
10011100B 9CH
E. 00000110B 06H f.
F. 00001110B 0EH g. 00010000B 10H
G. 01000010B 42H h. 00001011B 0BH


Bang ma led thiet ke trong chng trnh:
Do led ma tran moi k t c tao thanh t nhng node rieng biet nen ma cua chung
ng vi moi ch cung khac nhau tuy theo cach quy c cua tng ngi, va tuy theo
cach thiet ke ma xuat data cho led sang la mc 0 hay mc 1, xuat tn hieu quet cot
led la 0 hay 1. Trong chng trnh thiet ke chon: tn hieu quet cot cho led la mc 0
va tn hieu xuat data chon node sang la mc 1.

COT: DB 0FEH, 0FDH, 0FBH, 0F7H, 0EFH

K_TRANG: DB 00H, 00H, 00H, 00H, 00H

SO_0: DB 3EH, 41H, 41H, 41H, 3EH

SO_1: DB 44H, 42H, 7FH, 40H, 40H

SO_2: DB 32H, 49H, 49H, 49H, 46H

SO_3: DB 22H, 41H, 49H, 49H, 36H

SO_4: DB 0FH, 08H, 08H, 08H, 7FH

SO_5: DB 4FH, 49H, 49H, 49H, 79H

SO_6: DB 3FH, 49H, 49H, 49H, 32H
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 102

SO_7: DB 00H, 01H, 01H, 01H, 7FH

SO_8: DB 36H, 49H, 49H, 49H, 36H

SO_9: DB 26H, 49H, 49H, 49H, 3EH

CHU_A: DB 7EH, 09H, 09H, 09H, 7EH

CHU_B: DB 7EH, 49H, 49H, 49H, 36H

CHU_C: DB 3EH, 41H, 41H, 41H, 22H

CHU_D: DB 7FH, 41H, 41H, 41H, 3EH

CHU_E: DB 7FH, 49H,49H, 49H, 00H

CHU_F: DB 7FH, 09H, 09H, 09H, 00H

CHU_G: DB 3EH, 41H, 49H, 49H, 3AH

CHU_H: DB 7FH, 08H, 08H, 08H, 7FH

CHU_I: DB 00H, 41H, 7FH, 41H, 00H

CHU_J: DB 20H, 41H, 3FH, 41H, 20H

CHU_K: DB 7FH, 08H, 14H, 22H, 41H

CHU_L: DB 7FH, 40H, 40H, 40H, 40H

CHU_M: DB 7FH, 02H, 04H, 02H, 7FH
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 103

CHU_N: DB 7FH, 02H, 04H, 08H, 7FH

CHU_O: DB 3EH, 41H, 41H, 41H, 3EH

CHU_P: DB 7FH, 09H, 09H, 09H, 06H

CHU_Q: DB 3EH, 41H, 51H, 61H, 7EH

CHU_R: DB 7FH, 09H, 19H, 29H, 46H

CHU_S: DB 26H, 49H, 49H, 49H, 36H

CHU_T: DB 01H, 01H, 7FH, 01H, 01H

CHU_U: DB 3FH, 40H, 40H, 40H, 3FH

CHU_V: DB 1FH, 20H, 40H, 20H, 1FH

CHU_W: DB 1FH, 20H, 78H, 20H, 1FH

CHU_X: DB 22H, 14H, 18H, 14H, 22H

CHU_Y: DB 27H, 48H, 48H, 48H, 3FH

CHU_Z: DB 22H, 32H, 2AH, 26H, 22H

HAI_CHAM: DB 00H, 00H, 36H, 00H, 00H

CHAM_PHAY: DB 00H, 00H, 56H, 30H, 00H

NHO_HON: DB 00H, 08H, 14H, 22H, 00H
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 104

BANG: DB 00H, 14H, 14H, 14H, 00H

LON_HON: DB 00H, 22H, 14H, 08H, 00H

DAU_HOI: DB 06H, 01H, 39H, 09H, 06H

NHAY_KEP: DB 00H, 04H, 02H, 04H, 02H

PHAY: DB 00H, 50H, 30H, 00H, 00H

CHAM: DB 60H, 60H, 60H, 00H, 00H

MO_NGOAC: DB 3EH, 4EH, 00H, 00H, 00H

DONG_NGOAC: DB 00H, 00H, 00H, 4EH, 3EH

SAO: DB 2AH, 14H, 3EH, 14H, 2AH

TIM: DB 0CH, 12H, 24H, 12H, 0CH ; Shift {, 7B

RO: DB 08H, 24H, 22H, 24H, 08H ; Shift | , 7C

RO_CONG: DB 08H, 2CH, 3EH, 2CH, 08H; Shift } , 7D


uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 105
6. Khoi ban phm

0 1 2 3
4 5 6 7
8 9 < >
Del
KHOI BAN PHM CUA KIT
NHAN VIEN

Ban phm dung chung cho 2 kit: kit ieu khien nhiet o va kit nhan vien.
Gom 16 phm thiet ke theo kieu ma tran 4x4 gan vao Port1 :
SW5 SW3 SW2
SW6
SW10 SW12
SW7
SW4
SW14
SW13
SW8
SW15 SW17 SW16
SW9
SW11
U1
AT89C52
9
18
19
29
30
31
1
2
3
4
5
6
7
8
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
39
38
37
36
35
34
33
32
RST
XTAL2
XTAL1
PSEN
ALE/PROG
EA/VPP
P1.0/T2
P1.1/T2-EX
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INTO
P3.3/INT1
P3.4/TO
P3.5/T1
P3.6/WR
P3.7/RD
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
0 1 2
4 5 6 7
8 9 A B
C D E F
3
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 106
Chng trnh con quet phm (co chong rung) se tra ve ma hex cua phm nh ghi
tren s o. Gom hai phan long vao nhau : GET_KEY xac nh co phm nao b nhan
hay khong, tra ve ma hex cua phm b nhan (neu co), long ben ngoai no la chng
trnh IN_HEX thc hien chong rung (luc nhan cung nh luc nha bang cach lap
khoang 50 lan cho moi trang thai nhan hay nha).
a) Chng trnh con GET_KEY
Thc hien viec quet hang va cot e tm xem co phm nao b nhan hay khong.
Ket qua tra ve thong qua c carry : C = 1 neu co phm b nhan va ma hex nam trong
nibble thap cua thanh ghi tch luy, C = 0 neu khong co phm nao b nhan.
Giai thuat :
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 107
GET_KEY
Ma quet = 11111110B
(quet cot 0)
Co bit hang = 0 ?
Giam So em
So em = 0 ?
Sai
ung
Sai
ung
So em = 4
Xuat ma quet ra port1
Nhap port1 vao ACC
Xoa cac bit cot (4 bit thap)
Gi cac bit hang (4 bit cao)
1
Dch trai ma quet
(quet cot ke)
2
Xoa c C = 0
Chuyen ma hang ve 4 bit thap
So th t cot = 4 - So em
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 108

Chng trnh :
;*********************************************************************************************
; GET_KEY : chng trnh oc trang thai phm, tra ve :
; C = 0 neu khong co phm an.
; C = 1, ma phm trong nibble thap cua ACC neu co phm an.
;************************************************************************************************
GETKEY: MOV A,#0FEH ;bat au cot 0
MOV R6,#4 ;R6 : bo em
TEST: MOV P1,A ;kch hoat cot
MOV R7,A ;lu ACC
Ma phm = so th t cot
So em = 4
Dch MSB cua ACC vao c C
1
C = 0 ?
Ma phm = so th t cot + 4
Giam So em
So em = 0 ?
C = 1
Cat ma phm vao ACC
RET
2
Sai
ung
Sai
ung
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 109
MOV A,P1 ;nhan trang thai phm
ANL A,#0F0H
CJNE A,#0F0H,KEYHIT ;co phm an xac nh phm
MOV A,R7 ;khong co phm an, qua cot ke
RL A
DJNZ R6,TEST
CLR C ;khong co mot phm nao an
JMP EXIT ;thoat vi C = 0
KEYHIT:MOV R7,A
MOV A,#4 ;tnh trong so cot
CLR C
SUBB A,R6 ;4 - R6 = trong so
MOV R6,A
MOV A,R7
SWAP A
MOV R5,#4
AGAIN: RRC A ;tnh ma phm
JNC DONE
INC R6
INC R6
INC R6
INC R6
DJNZ R5,AGAIN
DONE: SETB C ;C = 1 va ACC cha ma phm
MOV A,R6
EXIT: RET
b) Chng trnh con IN_HEX
Chng trnh con co nhiem vu chong rung phm, bang cach lap lai GET_KEY khoang
50 lan. Neu nh 50 lan eu tra ve C = 1 th tc la co mot phm c an, con neu co
mot lan C = 0 th o la rung ong va bo em c reset. Sau khi a phat hien co phm
an, IN_HEX se ch mot khoang thi gian tng ng 50 lan goi GET_KEY e am bao
rang khong con rung cho lan goi GET_KEY ke tiep.
Giai thuat :










uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 110

IN_HEX
Lap = 50
GET_KEY
C = 1
Giam lap
Lap = 0
No
Y
e
s
No
Y
e
s
Lap = 50
GET_KEY
C = 1
Giam lap
Lap = 0
No
Y
e
s
No
Y
e
s
Cat ma phm
Phuc hoi ma phm
RET

Chng trnh :
;******************************************************
; N_IFX : DD . Di. c DcD roD rD D cD D *
; Dc o D cD D Dc o DD.
*
;******************************************************
NIFX: \OV F,=cD ;:c D
FACK: CALL CFTKFY ;c Di. D .
.NC NIFX ;DcD, i
L.N7 F,FACK ;c, cD D
JL:I ACC
FACK2: \OV F,=cD
FACK: CALL CFTKFY ;Di. DD .
.C FACK2 ;DcD, i
L.N7 F,FACK ;c, cD D
JOJ ACC ;. Di. trcD ACC
FFT



uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 111

7)Lu o giai thuat:
a) KIT IEU KHIEN NHIET O:
GIAO DIE N CHUNG GI A PC & KIT IE U KHIE N NHIE T O
CPU
Ngat Port noi tiep
LED
Ngat
Timer

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 112
LU O GIA I THUA T NGA T TIMER
Ngat Timer 0
Khi Tao Timer MOV
TH0, #HIGH(-2501)
TH0, #LOW(-2501)
Quet Led
So led a quet
(Bien Posled)
Posled = n
Quet Led n
Tang Posled
n=8
Yes
n=0
No
Reti
oc Nhiet o
oi ma 7 oan sang
so thap phan
Lu vao R2:R3
Reti












uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 113



b) KIT QUANG BAO:
Bat au
LU O GIAI THUAT CUA KIT QUANG BAO
CPU
Ngat Port Noi Tiep
va Xuat Led
Khi tao gia tr cho port noi tiep
hoat ong
Cho phep ngat port
Tang con tro
Kien tra k t ket thuc
Tra bang
Xuat Led
Dch
Y
e
s
No



uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 114

c) KIT QUAN LY NHAN VIEN:
GIAO DIE N CHUNG GI A PC & KIT NHA N VIE N
CPU
Ngat Port noi tiep
LED
Ngat
Timer







uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 115
LU O GIA I THUA T NGA T PORT NO I TIE P
Ngat Port Noi Tiep
Message nhan ID
a Ch Kit
No
Y
e
s
Chnh ong Ho
No
Y
e
s
Nhan xong ID
No
Message Bao
ung hay Sai ID
Message Chnh TG
Y
e
s
Lu gi, phut vao cac o
nh 0103H, 01 04H,
0105H,0106H
N
o
RETI
Gi ID ve PC
Bao ung ID
Yes

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 116
LU O GIA I THUA T NGA T TIMER
Ngat Timer 0
Khi Tao Timer MOV
TH0, #HIGH(-2501)
TH0, #LOW(-2501)
ong Ho
So led a quet
(Bien Posled)
Posled = n
Quet Led n
Tang Posled
n=8
Yes
n=0
No
Reti
Khi tao bien em(Chng trnh
chnh)
MOV LTIME4, #0
MOV LTIME5, #0
MOV LTIME6, #0
MOV LTIME7, #0
MOV LTIMEC, #201
MOV R4, #101
Y
e
s
LTIME7 = LTIME7 +1
LTIME7 = 10
No
Y
e
s
LTIME7 = 0
LTIME6 = LTIME6 +1
LTIME6 = 6
LTIME6 = 0
LTIME5 = LTIME5 +1
LTIME5 = 4
LTIME5 = 0
LTIME4 = LTIME4 +1
LTIME4 = 2
Y
e
s
Y
e
s
Y
e
s
Y
e
s
No
Y
e
s
LTIME4 = 2
LTIME5 = 10
No
N
o
Y
e
s
LTIMEC = 0
R4 = 0
Yes
No
No
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 117
LU O GIAI THUAT X LY PHM CUA KIT NHAN VIEN
Khi Tao so lan phm c an
MOV KEYNUM, #0
IN_HEX
Tang KEYNUM
KEYNUM = 0 Lan th 1 an phm
No
Y
e
s
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
N
o
Lu vao o nh
LEDT0
1
K
0 1 2 3
4 5 6 7
8 9 < >
Del
KHOI BAN PHM CUA KIT
NHAN VIEN





uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 118
KEYNUM = 2 Lan th 3 an phm
No
Y
e
s
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
Lu vao o nh
LEDT0
3
2
K K
KEYNUM = 1 Lan th 2 an phm
No
Y
e
s
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
Lu vao o nh
LEDT0
2
1
K K
Dch o nh
No
Dch o nh
No

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 119
No
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
5
4
K K
No
Y
e
s
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
4
3
K K
KEYNUM = 3
KEYNUM = 4
Lu vao o nh
LED0
Lu vao o nh
LEDT0
Lan th 3 an phm
Lan th 4 an phm
Dch o mh
No
Dch o nh
No

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 120
Phm <
N
o
Yes
Phm >
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
N
o
7
6
K
K
No
Y
e
s
Phm <
N
o
Yes
Phm >
N
o
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
N
o
6
5 K K
KEYNUM = 5 Lan th 5 an phm
Lu vao o nh
LEDT5
Dch o nh
KEYNUM = 6 Lan th 6 an phm
N
o
No
Lu vao o nh
LEDT0
Dch o nh
Khi tao gia tr
au
Xoa o nh
LEDT0, dch
Dch phai o nh
Dch trai o nh

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 121
Phm <
N
o
Yes
Phm >
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
N
o
8
7
K K
KEYNUM = 7 Lan th 7 an phm
N
o
No
Lu vao o nh
LEDT0
Dch o nh
Khi tao gia tr
au
Xoa o nh
LEDT0, dch
Dch phai o nh
Dch trai o nh
Phm <
N
o
Yes
Phm >
Yes
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
Yes
N
o
9
8
K K
KEYNUM = 8 Lan th 8 an phm
N
o
No
Lu vao o nh
LEDT0
Dch o nh
Khi tao gia tr
au
Xoa o nh
LEDT0, dch
Dch phai o nh
Dch trai o nh

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 122
Phm <
N
o
Yes
Phm >
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
9
K
KEYNUM = 9 Lan th 9 an phm
N
o
No
Gi 8 so a an
en PC
Khi tao gia tr
au
Xoa o nh
LEDT0, dch
Dch phai o nh
Dch trai o nh
Y
e
s
No
Yes
Phm <
N
o
Yes
Phm >
Phm Del
Phm Enter
Phm
N
o
N
o
Yes
Yes
N
o
Khi tao gia tr
au
Khong tac ong
Khong tac ong
Khong tac ong
Yes
N
o
Lap Lai
Gi 8 so a an
en PC
Y
e
s
Lap Lai

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 123

8)Truyen thong noi tiep

Khoi nay am nhan vai tro truyen thong gia board ieu khien vi may vi tnh qua
cong noi tiep (theo chuan RS-232), qua mach chuyen oi RS-232 sang RS-485, dung
cho viec truyen thong tin i xa ma khong b nhieu. Nh vay ma board ieu khien co
the hoat ong theo mot trong hai che o :
- Hoat ong di s ieu khien cua may vi tnh : dung trong giai oan thiet ke he
thong, mang tnh th nghiem la chnh. Cac phng phap ieu khien lan lt
c neu ra, thong qua mot phan mem tnh toan va x ly d lieu roi ieu khien
board e kiem nghiem.
- Hoat ong oc lap : mot khi giai oan thiet ke a xong, em ra san xuat ai tra
th khong co ly do g ma lai kem may vi tnh theo, t ban than board phai ieu
khien oi tng cua mnh, khi o chng trnh c nap vao vi ieu khien roi
cho he thong hoat ong. D nhien la luc nay van co the xay ra truyen thong,
nhng ch la hanh ong quan sat qua trnh ieu khien cua board thong qua ma y
vi tnh ma thoi.
MACH CHUYEN OI RS-232 SANG RS-485:
JP1
HEADER 3
1
2
3
U2
75176
1
2 7
6
3
4
R
RE B
A
DE
D
VCC
C9
.01x3
S3
SWITCH
A
R4 560
SW1
1
2
VCC
D2
1N914
C1
0.1
D4
C8
R5
100
VCC
C5
0.01
S2
SWITCH
VCC
U1
MAX232
13
8
11
10
1
3
4
5
2
6
12
9
14
7
1
6
1
5
R1IN
R2IN
T1IN
T2IN
C+
C1-
C2+
C2-
V+
V-
R1OUT
R2OUT
T1OUT
T2OUT
V
C
C
G
N
D
U3
ICM7555
2
5
6 4
3
7
8
1
TRIG
CONTV
THOLD RESET
OUT
DISCH
V
C
C
G
N
D
C6
0.01
VB1
SUB-D 9
5
9
4
8
3
7
2
6
1
S4
SWITCH
S1 C4
0.1
R2 560
C2
0.1
C3
0.1
VCC
R6
VCC
R7
2x4.7K
RS232-485 Converter for PC
B
C7
R3 120
VCC
VCC
R1 3.9K
D3


GIAI THCH S O THIET KE:
T cong Com cua PC ta dung chan 2, 3 ket noi vi chan 7, 8 cua Max 232 e
xuat nhap data, ong thi chuyen oi sang mc TTL phu hp vi hoat ong cua kit
VXL.
Ngo ra cua Max 232
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 124
Chan 9( xuat data) noi en chan 4(nhan data) cua 75176 ( tng ng Max
485)
Chan 10 (nhan data) noi en chan 1(xuat data) cua 75176
Hai led D3, D4 e hien th khi nao data xuat, nhap.
Hai cong tac S1, S2 dung che o mach ch xuat hoac ch nhap ( S1 ong,
S2 h), hoac mach luon nhan neu chan DE khong tch cc ( S1 h, S2 ong)
trang thai mach khong xuat nhap data ( chon S1 h, S2 ong), chan 2 cua
IC nh thi 555 tch cc mc cao, ngo ra 555 mc thap, chan DE khong tch
cc mc cao, khong truyen data. Khi ta truyen data th chan 9 cua Max 232
chuyen mc cao sang thap, kch chan 2 cua 555, IC nh thi 555 hoat ong, ngo
ra chan 3 tch cc mc cao, DE tch cc mach phat data
Khi ta can truyen data i xa ong S3 & S4, R2, R4 co chc nang chong h
mach au cuoi gia 2 node truyen, R2 chong ngan mach va tao ap gia hai chan
vi sai 6,7 cua 75176 khoang 200 300 mV, e mach co the hoat ong c.
MACH CHUYEN OI RS-485 KIT AT89C51
R86
100
C10
104
R84
330
JP23
NODNHIET
1 2
3 4
5 6
+5V(2)
+5V(2)
RXD
TXD
+5V(2)
UN555
LM555
3
4
8
5
2
6
7
OUT
RST
VCC
CV
TRG
THR
DSCHG
D18
1N914
1
2
R77
3.9k
D26
LEDG
R69
120
+5V(2)
C47
103
+5V(2)
C46
103
D25
LEDR
N Ctrl
R85
330
U17
75176BP(2)
1
2
3
4
5
6
7
8
RO
RE
DE
DI
G
N
D
A
B
+VCC

Mach chuyen oi RS-485 kit AT89C51
T s o mach tren, ta thay rang viec truyen thong dien ra thong qua 3 day :
TXD, RXD, va GND, tc la khong dung che o bat tay bang phan cng (cap
DSR/DTR hay CTS/RTS). Hnh thc nay dien ra kha pho bien bi v toc o may vi
tnh hien nay rat cao, bat ky luc nao cung co the x ly c. Khong phai nh luc
trc : co luc may vi tnh ang lam viec g o th phai kiem tra xem may vi tnh lam
xong cha, neu xong roi th thc hien viec truyen thong. oi vi board ieu khien
tuy toc o cham (c vai MHz), nhng do c thiet ke chuyen dung (ch lam mot
cong viec g o) nen d nhien la ap ng de dang. Do o, ta bo i hai trong bon
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 125
ng truyen cua MAX232 (bo R2 va T2). Neu v ly do g o ma can phai bat tay th
ta co the dung che o bat tay bang phan mem thong qua cap Xon/Xoff.
Chon cong noi tiep cua vi ieu khien mode 1 (SM0 = 0, SM1 = 1) e truyen 8
bit d lieu , co baudrate thay oi c.

;**************************
; INITIALIZE SERIAL PORT *
;**************************
MOV SCON,#01010000B ;UART 8-BIT, ENABLE REN
MOV TMOD,#21H ;TIMER1 8-BIT AUTORELOAD, TIMER0 16-BIT
MOV TH1,#0FDH ;9600 BAUD
MOV TL1,TH1
SETB TR1
...
;***************
; IN CHARACTER *
;***************
JNB RI,$
CLR RI
MOV A,SBUF
...
;****************
; OUT CHARACTER *
;****************
JNB TI,$
CLR TI
MOV SBUF,A
...
G goi khi thiet ke mach chuyen oi RS-232 sang RS-485:
Khi thiet ke mach chuyen oi RS-232 sang RS-485 mot so loi thng xay ra,
sau ay la mot vai trng hp toi a gap:
Chu y cc cua diod, mac phai ung cc. Cc anode cua diod noi vi chan
6,7 cua IC 555, Cathode noi vi chan 2 cua IC 555
trang thai mach khong chuyen oi, chan 2 cua IC 555 phai tch cc
mc cao, ien ap t 3V en 5,5V. Khi o ma ap di mc o th kha nang hoat ong
khong cao.
Ap chan so 5 cua IC 555, trong khoang 3,2V en 3,5. Ap at gia chan
2 va chan 6,7 khoang 2V en 2,3V.
Chan 4 cua 75176 noi vi chan 2 cua IC 555, khi ta phat data th co s
chuyen mc t cao xuong thap, kch IC 555 hoat ong ngo ra 555 len mc cao, chan
DE, RE mc cao data c phat. Chu y khi ban kiem tra thay chan 2 cua 555 khong
mc cao th khong han la 555 b h. Luc nay ban nen kie m tra lai vi x ly, thay vi
x ly khac.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 126
ien ap gia 2 chan 6,7 cua 75176 nho nhat la 200mV, neu nho hn
mach se khong hoat ong.

12. Khoi cam bien va gia cong
Cam bien nhiet dung thermocouple loai K co o nhay la 40V/
0
C, rat tuyen
tnh.
Mach gia cong can thc hien 3 chc nang sau : bu nhiet cho au t do, khuech ai, va
tao ien ap ra la 0V khi o 0
0
C. Xet mach tren :
- U7, U8, U9 (dung OP07 cho offset thap) ong vai tro mot bo em ien ap ly tng : co
tr khang vao rat ln va tr khang ra rat nho, khong e cac au vao anh hng lan
nhau.
- ien ap ra tren thermocouple :

V3 = S(T
d
T
a
) = S.T
d
S.T
a
Vi : T
d
la nhiet o can o.
T
a
la nhiet o moi trng.
S la o nhay cua thermocouple (40V/C).
+5V
-5V
-5V
-5V
+5V
+5V
+5V
-5V
+5V
+5V
+
-
U7
OP07 3
2
6
71
48
+
-
U9
OP07 3
2
6
71
48
+
-
U10
OP07
3
2
6
71
48
R12
VR10K
1
3
2
+C14
10u
R13
2.2K
U12
LM335
3
1
2
R14
VR10K
1
3
2 +C15
10u
+C16
10u
R15 100
R16 100
R17 27K
R22
27K
R23
VR10K
R24 VR10K
J2
ANALOG OUT
1
2
+
-
U8
OP07 3
2
6
71
48
R11
3M
V1
V2
V3 +
-
Thermocouple
Vout
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 127
Nh vay la gia tr ien ap ra tren cap nhiet ien ngoai nhiem vu mang thong tin cua
nhiet o can o con b anh hng bi nhiet o moi trng.
e loai tr anh hng tren, ta can phai co mot khoi tao ra ien ap theo nhiet o moi
trng nhng co dau ngc lai dung IC cam bien LM335A.
- IC LM335A la loai cam bien nhiet o ban dan, co o nhay la 10mV/K. Ap tao ra do
LM335A cam bien c la :

V2 = K.T
a
[K] = K(273 + T
a
) [C]
= K.273 + K.T
a
= C + KT
a
(C = K.273)
vi K = 10mV/K; C = 2,73V

co the triet tieu anh hng cua Ta, nhng lai tao ra mot mc ien ap la
2,73V 0C nen can phai co mot khoi e tr 2,73V nham tao ien ap au ra la 0V
0C.
- Bien tr R12 chnh la thanh phan bu tr ien ap 2,73V nh a noi tren.
- U10 (dung OP07) ong vai tro bo cong co khuech ai, ien ap ra cuoi cung la :

( ) | | 1
15
23 22
16
3
24 17
2
16 // 24 17
15
23 22
1 V
R
R R
R
V
R R
V
R R R
R
R R
V
out
+
|
.
|

\
|
+
+
+ |
.
|

\
| +
+ =


( ) | | |
.
|

\
|
+
+
+
+
+
|
.
|

\
| +
+ =
16
.
16
.
24 17
.
24 17
16 // 24 17
15
23 22
1
R
T S
R
T S
R R
T K
R R
C
R R R
R
R R
V
a d a
out

1
15
23 22
V
R
R R +


Khong b anh hng cua nhiet o moi trng :
250
40
10
16
24 17
0
16
.
24 17
.
= = =
+
=
+ V
mV
S
K
R
R R
R
T S
R R
T K
a a

KO
chon R16 = 100O R17 + R24 = 25KO chon R17 = 22KO va R24 la bien tr
10KO. Khi o can ieu chnh R24 e triet tieu T
a
.
Triet tieu ien ap tnh (2,73V) :

( ) | | 0 1
15
23 22
24 17
16 // 24 17
15
23 22
1 =
+
|
.
|

\
|
+
+ |
.
|

\
| +
+ V
R
R R
R R
C
R R R
R
R R


vi (R17 + R24)//R16 = (25KO)//(100O) = 99,6O





uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 128


) 1 (
285 , 321
73 , 2
285 , 321
73 , 2
1
15
23 22
:
1
15
23 22
32000
73 , 2
6 , 99
15
23 22
1
= |
.
|

\
|

+
+
=
|
.
|

\
| +
+
V
R
R R
hay
xV
R
R R
x x
R
R R

khi o, ien ap ra la :

( ) | |
16
.
16 // 24 17
15
23 22
1
R
T S
R R R
R
R R
V
d
out
+ |
.
|

\
| +
+ =


ien ap nay c a trc tiep vao ADC 12-bit (ICL7107) nen can phai co mot
s tng thch ve o phan giai :
ADC 12-bit co 4096 mc.
ien ap vao toi a = 4,096V
1LSB = 4,048V/4096 = 1mV
ieu khien en 409,6C :
1LSB = 409,6/4096 = 0,1C
tc moi khi tang 0,1C th ien ap ra tang 1mV :
( ) | |
250
15
23 22
251
15
23 22
1
100
688 , 99
16
16 // ) 24 17 (
:
1
16
. 1 , 0
16 // 24 17
15
23 22
1
=
+
=
+
+
=
+
= +
|
.
|

\
| +
+
R
R R
R
R R
R
R R R
do
mV
R
S
R R R
R
R R


chon R15 = 100O chon R22 = 22KO; R23 la bien tr 10KO.
Chnh R23 cho o phan giai.
Thay vao (1) :
mV V V x 5 , 8 1
285 , 321
73 , 2
285 , 321
73 , 2
1 250 = = |
.
|

\
|

V1 c tao ra t cau chia ien ap R11 = 3MO va R12 la bien tr 10KO.
can chnh R12 e V1 at 8,5mV
- Cac tu C14, C15, C16 chon gia tr 10F e chong nhieu.
Lu y :
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 129
1. Cac bien tr nen dung loai bien tr tinh chnh (hay bien tr o lng) co cau tao
gom nhieu vong day ien tr xoan ben trong (chnh nhieu vong mi het gia tr), tranh
dung bien tr thong thng rat kho chnh va khong on nh (khi va cham nhe b thay
oi gia tr).
2. Cac OPAMP dung loai OP07 hoac tng ng, co mc offset thap e phu hp vi
cac ai lng o co gia tr nho, cac chan 1 va 8 dung e chnh offset khong dung trong
thiet ke nay.


10. KHOI CHUYEN OI AD:
2V
C4
0.1uF
AD4
NPA3
1V
R8
20k NPA6
NPA2
NPB4
A1
NPC1
+5V(2)
Data bus
(2)/RD
AD7
R9 470k
(2)/WR
NPB1
NPC7
NPC4
NPB5
+5V(2)
U26
ICL7107CPL
31
30
32
37
20
19
5
4
3
2
8
6
7
12
11
10
9
14
13
25
23
16
24
15
18
17
22
36
35
28
27
40
39
38
29
34
33
1
26
IN HI
IN LO
COM
TEST
POL
AB4
A1
B1
C1
D1
E1
F1
G1
A2
B2
C2
D2
E2
F2
G2
A3
B3
C3
D3
E3
F3
G3
REF HI
REF LO
BUFF
INT
OSC1
OSC2
OSC3
A/Z
CREF+
CREF-
V+
V-
NPC6
C9 100p
+5V(2)
NPB7
NPA7
R7
1M
NPC3
C6 473
NPA4
NPB2
NPA0
(2)CS1
A IN
AD6
JP33
Anal og IN
1 2
3 4
A0
NPB6
AD2
NPC0
AD3
NPA1
-5V(2)
C7
224
U23
8255
34
33
32
31
30
29
28
27
4
3
2
1
40
39
38
37
18
19
20
21
22
23
24
25
14
15
16
17
13
12
11
10
5
36
9
8
35
6
D0
D1
D2
D3
D4
D5
D6
D7
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PC0
PC1
PC2
PC3
PC4
PC5
PC6
PC7
RD
WR
A0
A1
RESET
CS
R6 100k
NPA5
AD0
C5
203
R43
RV
NPB0
NPB3
NPC2
AD1
NPC5
AD5
R5
5.6k


Khoi chuyen oi AD dung ICL 7107
Chon gia tr cho cac linh kien:
- Tan so dao ong:
f
OSC
= 0.45/RC
- Tan so xung clock:
f
CLOCK
= f
OSC
/4
- ien tr tch phan:
INT
R =
INT
INFS
I
V

V
INFS
:

ien ap ngo vao(FullSale), thng bang 200mV hoac 2V
I
INT
: Dong ngo vao, I
INT
=4A
Khi ngo vao toan tam ( FullScale ) la 2V chon R2 = 470K, tng t R2 =
47K ng vi 2mV.
- Tu tch phan:
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 130
INT
C =
INT
INT INT
V
I t ) )( (

t
INT
= 1000*( 4/f
OSC
)
V
INT
=
INT
INT INT
C
I t ) )( (

V
INT
MaxSwing: (V
-
+ 0.5) < V
INT
< (V
+
- 0.5V), thng th V
INT
= 2V
ng vi cong thc tren th chon gia tr C
INT
= 0.22F va 0.1F
- Tu Auto-Zero (C
AZ
):
C
AZ
= 0.47F khi V
INFS
= 200mV
C
AZ
= 0.047F khi V
INFS
= 2V
- Tu tham chieu:
Chon 0.1F la tot nhat vi moi ng dung.
Ngo ra cua ICL 7107 la ma 7 oan. Gom 3 port cho 3 so hang n v,
hang chuc, hang tram moi port gom 7 bit, va 1 chan cho so hang nghn va 1 chan cc
tnh. Do 8255 co 3 port, e oc data ve 89C51 ket hp chan hang nghn vi port n
v a vao port A cua 8255. Ket hp chan cc tnh vi port hang chuc a vao port B
cua 8255. Port hang tram a vao port C cua 8255.
Do ICL 7107 ch chuyen oi mc ap toi a la 2V. Ma khi thiet ke cho chuyen
oi 12 bit th can ien ap 0 4V. Do vay ngo vao cua ICL 7107 a vao ien ap 2V.
That vay, khi ien ap vao la 0V th ICL7107 hieu la 2V, khi ap vao la 4V th
ICL7107 hieu la 2V.
Chng trnh chuyen oi ngo ra ICL7107 phu hp vi mc ap ngo vao e
hien th len Led
;**************************************************************
; OUTVAL_7107: *
; Doan chuong trinh nay xac dinh: Don Vi, Chuc, Tram, Nghin, PoL . Luu vao
; (34H)R3:R2 *
;**************************************************************
;~~~~~~
; Gia tri tam
;~~~~~~~~~~~
TEMP_UNIT EQU 30H
TEMP_TEN EQU 31H
TEMP_HUNDR EQU 32H
TEMP_THOU EQU 33H
TEMP_POL EQU 34H
;~~~~~~~~~~~~~~
; Kiem tra viec nhap data tu A/D 7107
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 131
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

OUTVAL_7107: ; XAC DINH GIA TRI RA CUA 7107
CHECK_EMPTY:
MOV DPTR, #2000H
MOVX A, DPTR
CJNE A, #11H, SAVEDATA

MOV DPTR, #2001
MOVX A, DPTR
CJNE A, #11H, SAVEDATA

MOV DPTR, #2002
MOVX A, DPTR
CJNE A, #11H, SAVEDATA
JMP CHECK_EMPTY

SAVEDATA:
MOV DPTR, #2000H
MOVX A, DPTR ; Tro Port A
MOV TEMP_UNIT, A

MOV DPTR, #2001
MOVX A, DPTR ; Tro Port B
MOV TEMP_TEN, A

MOV DPTR, #2002
MOVX A, DPTR ; ; Tro Port C
MOV TEMP_HUNDR, A

;~~~~~~~~~
; Xu ly hang don vi
;~~~~~~~~~~~~~~~~

MOV B,TEMP_UNIT ; Mov hang don vi vao B
ANL B, #7FH ; Che bit AB(Hang nghin)
MOV R0, #0 ; Bat dau kiem tra hang don vi la so may
LOOP_UNIT:
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 132
MOV A, R0
MOV DPTR, #TAB_7SEG
MOVC A, A + @DPTR
CJNE A, B, CHECK_UNIT ; So sanh voi so trong bang, neu bang,
gia tri do
;MOV UNIT, R0 ; chinh la gia tri R0
MOV R2, R0 ; Mov donvi vao R2
JMP SETTLE_TEN
CHECK_UNIT:
INC R0
JMP LOOP_UNIT

;~~~~~~~~~
; Xu ly hang chuc
;~~~~~~~~~~~~~~~~

SETTLE_TEN:
MOV B,TEMP_TEN ; Mov hang chuc vao B
ANL B, #7FH ; Che bit POL(Cuc Tinh)
MOV R0, #0 ; Bat dau kiem tra hang chuc la so may
LOOP_TEN:
MOV A, R0
MOV DPTR, #TAB_7SEG
MOVC A, A + @DPTR
CJNE A, B, CHECK_TEN ; So sanh voi so trong bang, neu bang, gia tri
do
;MOV UNIT, R0 ; chinh la gia tri R0
MOV A, R0
;ANL A, #0FH
SWAP A ; A chua hang chuc, nam o byte cao
CLR C ; Cac so tu 0 - 9
ADD A, R2 ; R2 chua hang don vi, nam o byte thap
;**************************************
MOV R2, A ; R2 chua hang chuc va hang don vi
;**************************************
JMP SETTLE_HUNDR
CHECK_TEN:
INC R0
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 133
JMP LOOP_TEN

;~~~~~~~~~
; Xu ly hang tram
;~~~~~~~~~~~~~~~~

SETTLE_HUNDR:
MOV B,TEMP_HUNDR ; Mov hang tram vao B
ANL B, #7FH ;
MOV R0, #0 ; Bat dau kiem tra hang tram la so may
LOOP_HUNDR:
MOV A, R0
MOV DPTR, #TAB_7SEG
MOVC A, A + @DPTR
CJNE A, B, CHECK_HUNDR ; So sanh voi so trong bang, neu bang, gia tri
do
;MOV UNIT, R0 ; chinh la gia tri R0
MOV R3, R0 ; R3 chua hang tram, nam chi o byte thap(do 0-
9)
JMP SETTLE_THOU
CHECK_HUNDR:
INC R0
JMP LOOP_HUNDR

;~~~~~~~~
; Xu ly hang ngan
;~~~~~~~~~~~~~~

;Lay data tu o nho tam don vi (TEMP_UNIT)
SETTLE_THOU:
MOV A, TEMP_UNIT
ANL A, #80H
JNZ THOU ; do ngo ra cua 7107 tich cuc thap
MOV TEMP_THOU, #1 ;Neu A =0 thi co hang nghin(save
vao THOU =1)
MOV A, #00010000B
ADD A, R3
;*******************************************
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 134
MOV R3, A
;*******************************************
JMP SETTLE_POL
THOU:
MOV TEMP_THOU, #0 ;Neu A = 1 thi khong co hang nghin

;~~~~~~~
; Kiem tra cuc tinh
;~~~~~~~~~~~~~

;Lay data tu o nho tam hang chuc
SETTLE_POL:
MOV A, TEMP_TEN
ANL A, #80H
JNZ POL ; do ngo ra cua 7107 tich cuc thap
MOV TEMP_POL, #1 ; A= 0 co cuc tinh ( o nho tam POL =1 )
RET
POL:
MOV TEMP_POL, #0
RET
11. Khoi mach cong suat

Dung OPTO TRIAC (MOC3020) e am bao hai yeu cau : cach ly ve ien va ang tin
cay trong ong ngat. Tuy nhien, do dong do opto triac rat nho, khong u lai lo nng
nen phai kch mot triac khac (BTA16).
+5V
PWR
LO NUONG
BTA16
R20
470
Q2
2SC828
R18
330
1
MOC3020
1
2
6
4
R19
2.2K
1
220VAC
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 135
Opto triac c lai qua transistor 2SC828 gan vao chan P3.5 cua AT89C51 nen e bat
hay tat lo nng, ch can set hay clear bit tng ng :
PWR EQU 0B5H ;P3.5
...
SETB PWR ;TURN ON THE OVEN
...
CLR PWR ;TURN OFF THE OVEN
...
12. NGUON CUNG CAP
Cac khoi trong mach can nguon 5V nen can thiet ke nguon cung cap hai mc ien ap
nay. Trong thiet ke nay dung IC on ap LM7805 va LM7905 :
+5V(N)
-5V(N)
D13
LED
C13
1uF
GND(N)
D14
LED
JP19
-5V
1
2
3
4
5
6
7
8
R34
330
JP17
+5V
1
2
3
4
5
6
7
8
U22
LM7905CT/TO220
2 3
1
IN OUT
G
N
D
GND(N)
D7
6V
D8 D6
C11
1uF
6V
U24
LM7805C/TO220
1 3
2
IN OUT
G
N
D
D5
JP18
Dat
1
2
3
4
5
6
7
8
Nguon
Bien Ap
R33
330
+5V(N)
C36
220uF
C35
220uF
C37
1uF
C33
2200uF
-5V(N)
C12
1uF
C34
2200uF


13. Cach can chnh mach
Bc 1 : Sau khi a rap mach xong, cha voi noi Vout cua mach gia cong vao Vin cua
ICL7107, nap cho AT89C51 chng trnh sau ay e hien th ra so thap phan cua gia tr ien
ap o c :
------------------------------------------------------
TAFLF: LF 4DI, 'I, 24I,DI ;D, , 2,
LF 'I, 2I, D2I, I ;4, c, t,
LF DDI, DI, DI, DI ;, ', A, F
LF 4tI, 2I, DtI, DFI ;C, L, F, F

FNL
Bc 2 : cho chay mach (cap nguon cho mach), noi V2 vao Vin cua ICL7107, e
LM355 tiep xuc vi nc a ang tan (0C) chnh bien tr R14 sao cho gia tr hien th
la 2730 (tng ng 2,73V).
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 136
Bc 3 : noi V1 va Vin cua ICL7107, chnh bien tr R12 sao cho gia tr hien th la
008.5(tng ng 8,5mV).
Bc 4 : cho V2 = 0V, V3 = 0V, khi o ien ap ra la :
Vout = -
R22+R23
R15
V1 =
- 338,893 x 8,5mV = 2,88V

nen khi noi Vout vao Vin cua ICL7109, ta chnh bien tr R23 sao cho gia tr hien th la 2880
(tng ng 2,88V).
Bc 5 : tra lai trang thai bnh thng (V1 mang ien ap t bien tr R11, V2 mang
ien ap t LM335, V3 mang ien ap t thermocouple), cho thermocouple tiep xuc vi
nc a ang tan, chnh R24 sao cho gia tr hien th la 0000 (tng ng 0V).
14. X ly 16-bit tren vi ieu khien 8- bit
Mac du la vi ieu khien 8-bit, nhng do o lng 12-bit nen ta phai m rong
mot so phep toan gia lap 16-bit e co the x ly nhng ai lng nay nham muc ch
ieu khien.
a) Chng trnh con cong 16-bit
;**********************************************************;
ADD_16: ADD TWO NUMBER 16-BIT R1:R0 = R1:R0 + R3:R2 *
;**********************************************************
ADD_16: PUSH ACC
MOV A,R0
ADD A,R2
MOV R0,A
MOV A,R1
ADDC A,R3
MOV R1,A
POP ACC
RET
b) Chng trnh con oi dau mot so
Thay v thc hien phep tr, ta cho cong vi so bu hai cua no nen can phai co
chng trnh oi ra so bu hai :
;**********************************************************;
CHANGE_SIGN: CHANGE SIGN OF NUMBER R1:R0 = -(R1:R0) *
;**********************************************************
CHANGE_SIGN: PUSH ACC
MOV A,R0
CPL A
ADD A,#1
MOV R0,A
MOV A,R1
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 137
CPL A
ADDC A,#0
MOV R1,A
POP ACC
RET
c) Chng trnh con nhan so 16-bit cho so 8-bit
;**********************************************************
; MUL_16_8: MULTIPLY NUMBER R1:R0 = R1:R0 x B *
;**********************************************************
MUL_16_8: PUSH 04H
PUSH 03H
PUSH 02H
PUSH ACC
MOV R2,#0
MOV R3,#0
MOV R4,#8
MULT: MOV A,R2
ADD A,R2
MOV R2,A
MOV A,R3
ADDC A,R3
MOV R3,A
MOV A,B
RLC A
MOV B,A
JNC MULT_LOOP
MOV A,R2
ADD A,R0
MOV R2,A
MOV A,R3
ADDC A,R1
MOV R3,A
MULT_LOOP:DJNZ R4,MULT
MOV R1,03H
MOV R0,02H
POP ACC
POP 02H
POP 03H
POP 04H
RET
d) Chng trnh con chia so 16-bit cho so 8-bit
;**********************************************************
; DIV_16_8: DIVIDER (R1:R0) = (R1:R0) DIV B *
; B = (R1:R0) MOD B *
;**********************************************************
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 138
DIV_16_8: PUSH 02H
PUSH ACC
MOV R2,#16
CLR A
DIV_16_8_1: XCH A,R0
CLR C
RLC A
XCH A,R0
XCH A,R1
RLC A
XCH A,R1
RLC A
CJNE A,B,DIV_16_8_2
SJMP DIV_16_8_3
DIV_16_8_2: JC DIV_16_8_4
DIV_16_8_3: SUBB A,B
XCH A,R0
ORL A,#1
XCH A,R0
DIV_16_8_4: DJNZ R2,DIV_16_8_1
XCH A,B
POP ACC
POP 02H
RET



















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 139

Chng II: Chng Trnh Tren May Tnh
A. nh Dang va Ngan Loi
I. NH DANG D LIEU ( Format Data):
1) D lieu dang nh phan:
Vi loai d lieu kieu nh phan, cu phap trong Visual Basic:
Bit 0 = BitValue * ( 2^0 )
Bit 1 = BitValue * ( 2^1 )
Bit 7 = BitValue * ( 2^7 )
2) D lieu dang Text:
Khi can gi mot thong bao hoac mot file text.
Gi text, chng trnh s dung ma, ma no an nh mot gia tr cho moi k t
text. Co nhieu loai ma, ma thong dung nhat la ma ASCII ( American Standard Code
for Information Exchange ), bao gom 128 ma ng vi 7 bit data. Bit th 8 neu co s
dung la bit 0 hoac bit parity. Ma ANSI ( American National Standards Institute ) s
dung 256 ma. Mot loai nh dang khac la s dung 16 bit, cho phep 65.536 k t khac
nhau
Trong chng trng nay toi nh dang ASCII text, s dung ieu khien
MSComm
3) ASCII Hex:
Kieu text th chon chuoi hoac byte cha chuoi e phat. Nhng ta cung co
the s dung text e phat d lieu nh phan, bang cach an nh d lieu di dang
ASCII Hex. Moi byte la mot cap ASCII code ma no ai dien 2 k t Hex cua byte.
Khi may tnh nhan th no x ly theo nh dang kieu nh phan.
V du: khi ta phat k t A th may tnh se phat 41H ASCII hoac 0100
0001B.
Trong Visual Basic: A3H c viet la &HA3.Ma ASCII cua A va 3 la
41H, 33H.

II. NGAN LOI TRONG THU PHAT DATA:
Trong thu phat noi tiep hay song song, ta khong chan chan c rang data
truyen en may nhan luon luon ung. Loi se xuat hien trong khi truyen, loi nay
xuat hien chu yeu do nhieu. e am bao rang thong tin truye n i luon ung, co
nhieu cach x ly: bat tay, bo em, hoi vong va ngat, s phan hoi ( bao cho biet a
nhan c ACK ), kiem tra loi.


uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 140
1) Dung tn hieu bat tay:
Vi tn hieu bat tay, bo phat co the c ch nh khi nao th phat data, va bo
nhan co the ch nh khi nao th nhan data.
Tn hieu bat tay thng dung cho phan cng, khi ngo vao bo nhan mc cao
th no san sang nhan data, va bo phat ch tn hieu nay e phat data. Ngo vao bo
nhan co the xuong mc thap bat ky luc nao, bo phat phai biet ieu nay va ngng
phat, ch cho en khi no len mc cao va phat tiep data con lai.
Khi bat tay bang phan mem, khi bo nhan can nhan data th no gi en bo
phat mot ma ma c ch nh trc. Khi ngng nhan th no cung gi mot ma e
dng.
2) Bo em:
nh ngha: Bo em la mot n v cua bo nh c giao nhiem vu tam thi
lu gi cac thong tin, ac biet la trong trng hp phai i cho cac bo phan co toc
o cham uoi theo kp
Bo em la mot cach e bo nhan chac chan rang chung khong e mat data
khi gi en chung. Va chung cung rat co t cho bo phat, khi data can gi th no em
ra bo em va x ly cac chng trnh khac ben trong bo phat.
Bo em co trong phan cng hoac phan mem hoac ca hai. Trong PC bo em
co ca trong phan cng lan phan mem. Khi bo em phan cng khong u, PC s dung
bo em mem, bo em mem tuy thuoc vao dung lng bo nh cua PC.

3) Hoi vong va ngat:
Nhng s kien xay ra tai port noi tiep bao gom viec nhan va phat data,
chuyen oi tn hieu bat tay, gi va nhan thong bao loi. Co 2 cach e phat hien
nhng s kien nay
Ngat :Chng trnh t ong nhay en mot thu tuc khi phat hien c s
kien xay ra. Loai chng trnh nh the goi la chng trnh ieu khien theo s kien
Trong Visual Basic, s kien MSComms On Comm thc hien chc na ng nay.
Hoi vong: thu/phat data tai thi iem nh san, loai nay khong dung ngat
phan cng. Tan so hoi vong tuy thuoc vao kch thc bo em va toc o phat data.
V du khi kch thc bo em nhan la 16 byte thi gian hoi vong la 16byte/giay. No
cung co the nhan hn 16byte/giay nhng luc o bo em hoac b tran hoac b mat
data
Hoi vong thng ap dung khi lng d lieu t, va no cung khong yeu cau ngat
phan cng. Thong thng ta dung ngat timer cua he thong truy cap port.
4) ACK ( Acknowledgments )
Trong mang ket noi nhieu thiet b vi nhau s dung chung mot ng truyen
th s dung tn hieu ACK rat co t. ACK thng nh ngha di dang byte. e
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 141
truyen thong tin cho mot node nao o th trc tien Master gi ACK en node can
truyen, khi node nhan c ACK (cua no) th no bao cho master biet rang master
co the gi thong tin en cho no. Tng t khi node muon gi thong tin en master.
5)Kiem tra loi:
Bo nhan co the s dung viec kiem tra loi e am bao rang data gi ti luon
ung. Cach e kiem tra loi la gi byte data tha ( redundant data) va kiem tra byte
loi ( hay byte tha o )
Cach n gian kiem tra loi la dung byte tha, hoac gi 2 lan byte o. Bo phat
gi moi thong tin 2 lan, bo nhan phai nhan thong tin giong nhau th thong tin truyen
i mi am bao ung. ng nhien truyen theo cach nay th mat 2 lan thi gian
truyen mot byte. Tuy nhien no rat co t trong viec truyen thong tin khi co s co ac
biet. Phng phap nay thng ng dung trong ieu khien bang tia hong ngoai.
Mot cach khac e kiem tra loi la gi 1 byte kiem tra loi theo byte data, goi
kiem tra Checksum. Checksum la mot phep toan c thc hien tren bieu thc toan
hoc va logic cua mot byte. Kiem tra checksum ch thc hien tren mot byte, khi
truyen lng thong tin ln khong the dung checksum e kiem tra
Mot loai kiem tra loi khac la CRC ( cyclic redundacy code ma d tuan
hoan). Cach kiem tra nay thng dung cho truyen lng thong tin ln. Thng dung
trong Kermit, Xmodem, Ymodem va Zmodem.
B. TIEN CH:
I. CACH XAC NH HE QUY TAC M TREN MATLAB
Khi ong Matlab, anh vao trang man hnh chnh ch Fuzzy
Hien len ca so FIS Editor. e them so ngo vao/ ra chon Edit, Add
input/Add output
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 142

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 143
Chon ham lien thuoc, dang tap m, dai hoat ong: nhap up vao input
1

chon Add MFs






uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 144

Click OK, muon thay oi ten ham lien thuoc click vao ng mf1, mf2, mf3





Chon luat, ong cac ca so lai, click o gia input va output
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 145

Ket thuc save lai, c dang file .fis. khi chay chng trnh Visual Basic hoac
Delphi, goi file nay ra e x ly.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 146


















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 147
II.CACH XAC NH HE QUY TAC TREN FUZZYTECH
Khi ong FuzzyTech chon New

Click OK


Click in1, in2, out
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 148

Cuoi cung nhap up vao khung Min-Max c bang luat
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 149




III. Phng phap tao ieu khien cua rieng ban(.OCX)
Phan nay gii thieu cach tao tap tin .OCX, chng trnh viet trong Visual Basic.
Khi co tap tin nay nay co the s dung chung trong cac chng trnh khac nhau, v du
nh: Visual Basic , Delphi, hay trong Visual C
++
,
Do e tai lien quan en quan ly nhan vien, v vay tao OCX lien quan en ieu
khen rang buoc d lieu . Trong phan nay xay dng 2 ieu khien khach hang:
- ieu khien ADONavBar cung cap cac nut First, Previous, Next, Last e di
chuyen t au en cuoi dataset.
- ieu khien ADOActionBar cung cap cac hanh ong sa oi record ien hnh
nh Update, Delete, Add, Save e hieu chnh cac record trong mot recordset.
IEU KHIEN THANH IEU HNG KHACH HANG (ADONavBar):
Bo sung mot e an mi trong moi trng phat trien tch hp cua Visual Basic.
Chon File/Add Project t menu chnh va chon ActiveX Control t oi thoai Add
Project.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 150
Sau khi bo sung mot e an ActiveX Control, thiet lap ten cua no la
ADOButtons, ten nay chnh la ten cua OCX sau nay ban s dung. at ten cho
UserControl la ADONavBar
+ Cac ieu khien cho ADONavBar:


















+ Ma hoa thanh ieu khien hng:
Bo sung tham chieu en th vien Microsoft ActiveX Data Objects 2.0 COM vao
e an. Chon Project/ References t menu chnh, tm va chon ADO Library.
ieu khien nay co mot thuoc tnh chung(ADORecordset) va mot s kien chung
( Error ). e ho tr cho no, bo sung oan ma lenh sau vao phan khai bao tong quat
cua User Control.
Option Explicit

Enum rsMove
mvFirst = 0
mvPrevious = 1
mvNext = 2
mvLast = 3
End Enum

Public Event Error(Number, Description, Source)
ieu Khien Thuoc Tnh Thiet Lap

UserControl Name ADONavBar
CommandButton Name cmdNavigate
Caption First
Index 0
CommandButton Name cmdNavigate
Caption Previous
Index 1
CommandButton Name cmdNavigate
Caption Next
Index 2
CommandButton Name cmdNavigate
Caption Last
Index 3


uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 151
Public Event MoveCompleted(Message As rsMove)
Public Event WillMove(Message As rsMove)

Private mADORecordset As ADODB.Recordset

Tiep theo bo sung ma lenh sau vao, viec nay tao ra thuoc tnh chung e
chuyen vao mot ADO recordset.

Public Property Get ADORecordset() As Recordset
Set ADORecordset = mADORecordset
End Property

Public Property Let ADORecordset(ByVal vNewValue As Recordset)
Set mADORecordset = vNewValue
End Property
Ma lenh e ieu hng recordset c ket noi vao recordset

Private Sub cmdNavigate_Click(Index As Integer)
'
'
On Error GoTo LocalErr
'
With mADORecordset
Select Case Index
Case 0
RaiseEvent WillMove(mvFirst)
.MoveFirst
RaiseEvent MoveCompleted(mvFirst)
Case 1
RaiseEvent WillMove(mvPrevious)
.MovePrevious
If .BOF Then
.MoveFirst
End If
RaiseEvent MoveCompleted(mvPrevious)
Case 2
RaiseEvent WillMove(mvNext)
.MoveNext
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 152
If .EOF Then
.MoveLast
End If
RaiseEvent MoveCompleted(mvNext)
Case 3
RaiseEvent WillMove(mvLast)
.MoveLast
RaiseEvent MoveCompleted(mvLast)
End Select
End With
'
Exit Sub
'
LocalErr:
RaiseEvent Error(Err.Number, Err.Description, Err.Source)
'
End Sub
Bay gi ban save lai va ong tat ca cac ca so bien soan ma lenh va cac form
cua User Control. Tren thanh cong cu se xuat hien mot bieu tng, ay chnh la ieu
khien OCX ban mi tao ra. Chung c dung nh cac bieu tng khac yten thanh
cong cu, tc la nhap up vao hoac kch vao no roi keo chuot tren form.

IEU KHIEN THANH HOAT ONG KHACH HANG:
Thanh hoat ong cha tat ca cac nut can thiet e ieu khien viec sa, xoa va
them record vao mot dataset. Cung nh ieu khien ADONavBar va ADOActionBar
yeu cau ban ket noi mot recordset vao ieu khien va cho phep ngi dung nhan nut
tren thanh ieu khien e hoan thanh cac nhiem vu yeu cau.
Bo sung mot User Control vao e an ADOButtons
+ Cac ieu khien cho ieu khien khach hang ADOActionBar:

ieu Khien Thuoc Tnh Thiet Lap


UserControl Name ADONavBar
CommandButton Name cmdAction
Caption &Save
Index 0
CommandButton Name cmdAction
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 153
Caption &Cancel
Index 1
CommandButton Name cmdAction
Caption &New
Index 2
CommandButton Name cmdAction
Caption &Udate
Index 3
CommandButton Name cmdAction
Caption &Delete
Index 3
+ Ma hoa thanh hoat ong:
Bo sung ma lenh sau vao phan khai bao chung cua User Control. No khai
bao mot phng phap Error chung, mot kieu kiet ke rieng va hai bien rieng phu hp
cac thuoc tnh chung cua cac ieu khien nay.
Option Explicit

Public Event Error(Number, Description, Source)

'
Enum ADOFormMode
Add = 0
Edit = 1
End Enum
'
Private mADORecordset As ADODB.Recordset
Private mFormMode As ADOFormMode

Bo sung ma lenh e bieu th thuoc tnh chung, ADORecordset va FormMode.
Public Property Get ADORecordset() As Recordset
Set ADORecordset = mADORecordset
End Property

Public Property Let ADORecordset(ByVal vNewValue As Recordset)
Set mADORecordset = vNewValue
End Property

Public Property Get FormMode() As ADOFormMode
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 154
FormMode = mFormMode
End Property

Public Property Let FormMode(ByVal vNewValue As ADOFormMode)
mFormMode = vNewValue
Call SetFormMode(mFormMode)
End Property
Phng phap Let FormMode cha ma lenh e goi phng phap rieng goi la
setFormMode. Phng phap nay c s dung e cho phep va khong cho phep cac
ieu khien tren thanh cha cac nut khi can. Thanh nay co hai che o: Add va Edit.
Khi ieu khien che o Add, ch co cac nut Save va Cancel c s dung. Khi ieu
khien che o Edit ch co nut New, Update va Delete c s dung

+ Ma hoa phng phap SetFromMode vao ieu khien
Private Sub SetFormMode(Mode As ADOFormMode)
'
Dim blnFlag As Boolean
'
If Mode = Add Then
blnFlag = False
Else
blnFlag = True
End If
'
cmdAction(0).Enabled = Not blnFlag
cmdAction(1).Enabled = Not blnFlag
cmdAction(2).Enabled = blnFlag
cmdAction(3).Enabled = blnFlag
cmdAction(4).Enabled = blnFlag
'
End Sub







uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 155
+ Ma hoa s kien cmdAction_click:
Private Sub cmdAction_Click(Index As Integer)
'
'
On Error GoTo LocalErr
'
Dim intAnswer As Integer
'
With mADORecordset
Select Case Index
Case 0 ' Save
.Update
SetFormMode Edit
Case 1 'Cancel
.CancelUpdate
.MoveFirst
SetFormMode Edit
Case 2 ' New
.AddNew
SetFormMode Add
Case 3 ' Update
.Update
Case 4 ' Delete
intAnswer = MsgBox("Delete Current Record?", _
vbYesNo + vbQuestion, "Delete")
If intAnswer = vbYes Then
.Delete
.MovePrevious
End If
End Select
End With
'
Exit Sub
'
LocalErr:
RaiseEvent Error(Err.Number, Err.Description, Err.Source)
'
End Sub
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 156
Lu ieu khien ADOActionBar va ong tat ca cac ca so from va ma lenh cua
User Control. Khi nay tren thanh cong cu se xuat hien bieu tng cho phep ban s
dung e them, xoa .. ten khach hang nao ma ban muon.


IV. GIAO DIEN:
Chng nay trnh bay giao dien giao tiep gia PC va cac kit AT89C51, cung nh
hng dan s dung. Con phan source chng trnh th trong a CD.










uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 157


















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 158


















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 159









uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 160






















uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 161








Ket qua thu thap d lieu rat tot
Ket qua truyen nhan cac toc o baud :
1200bps, 2400bps, 9600bps: khong sai so
19.200bps: truyen t PC xuong kit AT89C51 sai so 40%, PC en PC khong sai
so
56Kbps: PC den Kit sai so 90%, PC en PC sai so 0%.
Qua trnh quan ly gi ra vao cua nhan vien trong cong ty rat thuan tien.
Thong bao thay oi de dang t trung tam ieu khien
Ket qua mo phong qua trnh thay oi nhiet o rat tot
Sau khi a thiet ke va toi u, ta cho ieu khien theo ham nac cac nhiet o khac nhau
Ket qua at c kha tot khi ieu khien theo ham nac. Do ch dung hai tap m nen ket
qua cho thay s phu thuoc kha ro vao gia tr nhiet o at. Tuy nhien, a so eu vot lo
nho 10% hoac khong vot lo, sai so xac lap nho hn 1C.
V cha th ieu khien theo ham doc nen khong biet ket qua nh the nao.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 162
1. ieu khien 100C
at gia tr nhiet o at la 100C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 70x3 = 210 giay = 3,5 phut (vi nhiet o ban au la 28C).
- o vot lo :
% 2 , 8 % 100 .
0 , 100
0 , 100 2 , 108
=

= POT
- Thi gian xac lap (theo chuan 5%) la 145x3 = 435 giay = 7 phut 15 giay.
- Thi gian xac lap (theo chuan 2%) la 220x3 = 660 giay = 11 phut.
- Sai so xac lap la 0,4C = 0,4%.
ng ben di la duty cycle tng ng.
8,2C 0,4C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 163
2. ieu khien 125C
at gia tr nhiet o at la 125C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 70x3 = 210 giay = 3,5 phut (vi nhiet o ban au la 37C).
- o vot lo :
% 16 , 6 % 100 .
0 , 125
0 , 125 7 , 132
=

= POT
- Thi gian xac lap (theo chuan 5%) la 125x3 = 375 giay = 6 phut 15 giay.
- Thi gian xac lap (theo chuan 2%) la 203x3 = 609 giay = 10 phut 9 giay.
- Sai so xac lap la 0,6C = 0,48%.
ng ben di la duty cycle tng ng.
7,7C
0,6C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 164
3. ieu khien 150C
at gia tr nhiet o at la 150C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 90x3 = 270 giay = 4,5 phut (vi nhiet o ban au la 38C).
- o vot lo :
% 4 , 3 % 100 .
0 , 150
0 , 150 1 , 105
=

= POT
- Thi gian xac lap (theo chuan 5%) la 96x3 = 288 giay = 4 phut 48 giay.
- Thi gian xac lap (theo chuan 2%) la 145x3 = 435 giay = 7 phut 15 giay.
- Sai so xac lap la 0,4C = 0,267%.
ng ben di la duty cycle tng ng.

5,1C 0,4C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 165
4. ieu khien 175C
at gia tr nhiet o at la 175C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 99x3 = 297 giay = 6 phut 57 giay (vi nhiet o ban au la 42C).
- o vot lo :
% 23 , 2 % 100 .
0 , 175
0 , 175 9 , 178
=

= POT
- Thi gian xac lap (theo chuan 5%) la 106x3 = 318 giay = 5 phut 18 giay.
- Thi gian xac lap (theo chuan 2%) la 144x3 = 432 giay = 7 phut 12 giay.
- Sai so xac lap la 0,3C = 0,17%.
ng ben di la duty cycle tng ng.

3,9C 0,3C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 166
5. ieu khien 200C
at gia tr nhiet o at la 200C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 130x3 = 390 giay = 6,5 phut (vi nhiet o ban au la 39C).
- o vot lo :
% 0 , 1 % 100 .
0 , 200
0 , 200 0 , 202
=

= POT
- Thi gian xac lap (theo chuan 5%) la 142x3 = 426 giay = 7 phut 6 giay.
- Thi gian xac lap (theo chuan 2%) la 152x3 = 456 giay = 7 phut 36 giay.
- Sai so xac lap la 0,1C = 0,05%.
ng ben di la duty cycle tng ng.

2,0C 0,1C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 167
6. ieu khien 225C
at gia tr nhiet o at la 225C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 167x3 = 501 giay = 8 phut 21 giay (vi nhiet o ban au la
37C).
- o vot lo :
% 4 , 0 % 100 .
0 , 225
0 , 225 9 , 225
=

= POT
- Thi gian xac lap (theo chuan 5%) la 181x3 = 543 giay = 9 phut 3 giay.
- Thi gian xac lap (theo chuan 2%) la 194x3 = 582 giay = 9 phut 42 giay.
Sai so xac lap la 0,3C = 0,13%.
ng ben di la duty cycle tng ng.

0,9C
0,3C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 168
7. ieu khien 250C
at gia tr nhiet o at la 250C. Ket qua thu c nh sau :
Vi chu ky lay mau va ieu khien la 3s.
Cac thong so thu c :
- Thi gian len : 192x3 = 576 giay = 9 phut 36 giay (vi nhiet o ban au la
30C).
- o vot lo : khong co vot lo
- Thi gian xac lap (theo chuan 5%) la 216x3 = 648 giay = 10 phut 48 giay.
- Thi gian xac lap (theo chuan 2%) la 234x3 = 702 giay = 11 phut 42 giay.
- Sai so xac lap la 0,6C = 0,24%.
ng ben di la duty cycle tng ng.

0,6C
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 169











Tai Lieu Tham Khao
1. ieu khien t ong (quyen 1,2) Nguyen Th Phng Ha Nha xuat ban khoa hoc
va ky thuat 1996.
2. Giao trnh cam bien Phan Quoc Pho, Hoang nh Chien Nha xuat ban khoa hoc
va ky thuat 2000.
3. Ly thuyet ieu khien m Phan Xuan Minh, Nguyen Doan Phc Nha xuat ban
khoa hoc va ky thuat 1999.
4. Hng dan th nghiem vi x ly Bo mon ky thuat ien t 1999.
5. Hng dan th nghiem ieu khien t ong 1, 2 Bo mon ieu khien t ong.
6. The 8051 Microcontroller I. Schott MacKenzie Prentice Hall 1995.
7. Fuzzy logic with engineer application Timothy J. Ross McGraw Hill 1997.
8. The temperature handbook Copyright by Omega Engineering Inc., 1995.
9. Fuzzy Logic Robert Fuller.
10. Ky thuat ghep noi may tnh Ngo Dien Tap1
11. Ghep noi may tnh trong Windows Ngo Dien Tap
12. So tay cho ngi lap trnh PC Julio Sanchez, Maria P. Canton Nha xuat ban
thong ke 1997.
13. Serial Port Complete Jan Axelson
14. Programmers Guide to Serial Communications By Richard Grier
15. Digital System : Principles and Applications Ronald J. Tocci Prentice Hall
1991.
16. LS Data sheet Motorola.
uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 170
17. T hoc lap trnh c s d lieu vi Visual Basic Nguyen nh Te
18. Ky thuat lap trnh Visual Basic Nathan Gurewich
Va mot so sach khac cung nh tai lieu download tren internet qua mot so website nh :
http://www.atmel.com
http://www.maxim-ic.com
http://www.rs-485.com
http://www.harris.com
http://www.blackbox.com
http://www.blueearthresearch.com
http://www.cimetrics.com
http://www.micromint.com
http://www.sealevel.com
http://www.circuitcellar.com
http://www.robustdc.com
http://www.top219.org

uploaded by http://scribd.com/pvdai
Mang Thu Thap D Lieu Va Quang Bao GVHD : Nguyen Ngoc Khai
SVTH : Nhan Minh Tien Trang 171















uploaded by http://scribd.com/pvdai