You are on page 1of 49

DO AN : HE THONG CO DIEN TU GVHD: PGS.

TS TRAN XUN TUY



SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 1

MJC LJC
Loi noi du....................................................................................................................... 2
Chuong 1 GIOI THIEU VA PHN TICH PHUONG AN THIET KE ............................. 3
1.1. Thit k robot phn loai san phm theo mau sc. .................................................... 3
1.2. Phn tich lua chon phuong an thit k .................................................................... 4
Chuong 2 THIET KE NGUYN LY VA KET CAU MAY ............................................. 7
2.1. Nguyn ly hoat dng cua h thng: ........................................................................ 7
2.2. Nguyn ly hoat dng so b cua chuong trinh diu khin tu may tinh : ................... 8
2.3. Thit k kt cu may: .......................................................................................... 10
Chuong 3 GIOI THIEU THIET BI DIEU KHIEN SU DUNG ....................................... 13
Vi diu khin P89V51RD2:.................................................................................. 13
3.2. Dng co din 1 chiu : (DC) ................................................................................ 15
3.3. Encoder ................................................................................................................ 16
3.4. Ro le va FET: ....................................................................................................... 18
3.5. Valve solenoid 52 va xylanh 5x10 ........................................................................ 19
3.6. Ngun cung cp: .................................................................................................. 20
Chuong 4 TINH TOAN THIET KE ............................................................................... 21
4.1. So d mach diu khin : ....................................................................................... 21
4.2. Giai thut cua chuong trinh trn vi diu khin : .................................................... 24
4.3. Giai thut nhn dang hinh anh : ............................................................................ 25
4.4. Gioi thiu v xu ly anh -ung dung xu ly anh phn bit mau sc san phm: ........... 26
Chuong 5 CHUONG TRINH VA SOFTWARE DIEU KHIEN ................................. 27
5.1. Chuong trinh asm:................................................................................................ 27
5.2. Chuong trinh visual basic ..................................................................................... 37



DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 2

Li ni du

gay nay khoa hoc ki thut phat trin manh m va dat duoc nhiu thanh tuu to
lon trong nhiu linh vuc, dc bit la trong linh vuc tu dng hoa san xut. Vic
ung dung tin hoc va diu khin vao trong cac loai may ct kim loai khin cho chung co
d tin cy voi tc d xu li nhanh hon va gia thanh ha hon. Trong dy chuyn san xut
linh hoat thi may moc diu khin du su dung h thng co din tu va diu khin giam sat
ht thng qua may tinh. H thng co din tu ( HTCDT ) lun duoc ch tao va hoat dng
dng b ln nhau nhm tng cng sut, hiu qua kinh t dng thoi rut ngn duoc qua
trinh san xut.
Voi nhung nhung uu dim vuot bt do, thi h thng co din tu ( HTCDT ) ngay
cang duoc su dung rng ri trong nhiu linh vuc , nht la trong cng nghip,trong cac nha
may xi nghip. Do vy vic nm bt thit k cac HTCDT la mt vic v cung quan trong
di voi cac sinh vin nganh co din tu .Vic thit k nhu la mt uu tin hang du ma cac
k su cn phai nm bt va diu khin. Voi yu cu thuc t do thi d an mn hoc H
Thng Co Din Tu danh cho sinh vin la rt cn thit.
Muc tiu chu yu cua d an mn hoc nay giup sinh vin nm bt duoc cac phuong
phap phn tich d lp mt quy trinh san xut ,diu khin thit bi mt cach tu dng,phn
tich la lp trinh h thng hoat dng mt cach logic, dn lam quen voi cac thit bi ,cac linh
kin thuc. Do thoi gian hoan thanh d an khng nhiu va qua trinh gia cng ch tao d an
con rt nhiu han ch nn chc chn d an con co nhiu thiu sot mong cac thy gop y d
dn hoan thin hon. Cui cung em xin chn thanh cam on thy giao PGS.TS Trn Xun
Tuy d huong dn, giup d chung em rt nhiu trong tin trinh hoan thanh d an nay.
Sinh vin thuc hin:
Vn Huu An
Nguyn Trung Kin


N
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 3

ranh truot san pham
san pham do
san pham xanh
webcam quan sat
robot
may tinh
Chuong 1 GII THIJU V PHAN TICH PHUONG N THIET KE
1.1.Thit k robot phn loi san phm theo mu sc.
Yu cu:
- San phm co hinh dang nhu sau :





Hinh 1.1 san phm cn phn loai.
La san phm mu co dang hinh tru.
Co 4 loai san phm nhu hinh 1.1 nhung ung voi mi san phm thi co 1
mau ring bit.
-H thng hoat dng hoan toan tu dng.
-Phai duoc diu khin va giam sat qua may tinh.
-Su dung canh tay may d phn loai san phm.
-H thng nhu sau :









Hinh 1.2 So d tng quan.

DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 4

J1
J2
1.2.Phn tch la chn phuong n thit k
Tu yu cu dt ra ta lua chon cac co cu cn thit,d xy dung nn h thng co
din tu :
Lua chon co cu:
-Co cu d phn loai san phm co rt nhiu loai nhu la : h thng bng tai co su
dung cn gat,h thng bng tai dung pittong d dy san phm,su dung canh tay robot d
phn loai san phm.
-Yu cu h thng khng don gian ma cng khng qua phuc tap,nn lua chon co
cu nhu sau:
- Dung canh tay robot 2 hoc 3 bc tu do d gp san phm.
- Su dung h thng ranh truot d dua san phm bt ky dn vi tri cn gp.
- Dung dng co lad d lam co cu quay.
- D giam gia thanh san phm,su dung it co cu ma canh tay robot vn hoat
dng ti uu nn ta lua chon co cu chi co 2 dng co d lam 2 bc tu do R-R :













Hinh 1.3 Kt cu robot.

DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 5

Uu dim cua robot
- Khu thu 3 cua canh tay lun o vi tri song song voi mt phng chua chi tit.Do
do,canh tay rt d diu khin,va hoat dng chinh xac.
- -Tuy co cu co phn phuc tap nhung diu khin h thng lai don gian hon.
- Co cu kep cua robot duoc thit k bng pittong khi nen ,nn gioi han duoc luc
kep cht chi tit.
Nhuoc dim :Robot loai nay kho ch tao,doi hoi cac chi tit phai co d chinh xac cao.
Co cu ranh truot d san phm di qua :











Hinh 1.4 Ranh truot.
- Kt cu ranh truot phai phu hop d tung san phm 1 chay qua.
- Ung voi san phm do ta s xu ly hinh anh thu duoc tu webcam d nhn bit co
san phm hay khng,ri tu do phn tich tip d bit duoc san phm do thuc
loai nao ri dua ra chuong trinh diu khin phu hop.
Lua chon cam bin :
-Trn thi truong co rt nhiu loai cam bin duoc dung d phn bit mau sc cua
san phm.Mt trong s do la cam bin mau trong cng nghip,loai cam bin nay rt nhiu
tin nn khng phu hop voi tai chinh cua sinh vin.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 6

-Loai cam bin thu 2 do la su dung bin tro ,va dua vao su thay di din ap trn
bin tro khi co anh sang chiu nguoc tro lai tu san phm thi nguoi ta phn bit mau
sc,loai cam bin nay thuong duoc dung trong cac cuc thi robocon,dung d phn bit
vach mau.






Hinh 1.5 Cam bin duoc su dung trong h thng.
-Loai cam bin thu 3 duoc ch tao dua trn cng ngh xu ly anh,thuong duoc ch
tao thanh mt modun ring le.Do chinh la cng ngh xu ly anh, d phu hop voi tai chinh
cua sinh vin,va diu khin duoc linh hoat,chon loai cam bin la webcam d phn bit .
- Su dung webcam d lam cam bin phn bit mau sc cua san phm.
Su dung encoder 100xung/ vong d do s vong quay cua truc dng co.
- Su dung cng tc hanh trinh d xac dinh cac dim du va cui.








DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 7

Chuong 2 THIET KE NGUYN L V KET CU MY
2.1.Nguyn l hot dng cua h thng:
-San phm thuc duoc thay th bng chi tit hinh tru,duoc trang tri bng mau sc
bn ngoai,va duoc dn qua h thng ranh truot.
San phm truot xung ranh truot ln luot tung cai mt,ri bi chn boi 1 cn
chn.Tai cn chn co b tri 1 camera d quan sat duoc diu khin bng may tinh.Camera
nay duoc dung d nhn bit loai san phm,hoc nhn bit co san phm hoc khng co san
phm.
Nu san phm tai ranh truot co mau do,xanh hoc mau khac thi camera s nhn
ra,ung voi tung mau s truyn xung robot d diu khin chay chuong trinh thich hop.
-Di voi san phm do : robot s gp san phm do d dua sang ranh truot 1
d dua san phm dn vi tri khac.
-Di voi san phm xanh: lam tuong tu voi san phm do ,nhung dua sang
ranh truot 2
Nu tai ranh truot khng co san phm, thi may tinh khng truyn lnh
diu khin xung robot.
Khi robot nhn lnh,thi robot s hoat dng,va truoc khi robot hoat dng
thi s thng bao ln may tinh la robot dang lam vic va khng nhn thm lnh nao
tu may tinh truyn xung.Khi nao robot thuc hin xong 1 lnh nao do thi robot s
thng bao voi may tinh la robot d thuc hin lnh do xong va sn sang d nhn
lnh moi.
Aguyn l cnh tay robot:
Chi voi 2 bc tu do ma vn co th vn dung ti da uu dim thi kt cu cua robot
phai co net dc trung ring bit so voi cac loai robot thuong thy.Do do sau qua trinh
phn tich,tim hiu ta xac dinh duoc so d nguyn ly hoat dng cua robot nhu sau :
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 8

DC1
DC2
J2
J1






Hinh 2.1 Nguyn ly robot.
2.2.Nguyn l hot dng so b cua chuong trnh diu khin t my tnh :
Chuong trinh diu khin trn may tinh duoc thit k va lp trinh trn phn mm
Visual studio .NET
Co giao din thn thin va d su dung:









Hinh 2.2 Chuong trinh diu khin.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 9

Nhim vu cua chuong trinh la nhn hinh anh tu webcam , xu ly hinh anh , ri sau
do truyn tin hiu diu khin xung robot khi robot khng xu ly.
Truoc khi su dung h thng ta phai thit lp chuong trinh truoc. Nghia la phai
thit lp vung xu ly hinh anh cua webcam,thit lp cac thng s cua san phm trn cac
kho chua hang.






Hinh 2.3 Thit lp vung xu ly.
Sau khi thit lp vung xu ly hinh anh,thi ta thit lp s luong gioi han cac san
phm trong kho chua hang, khi d o ch d mc dinh thi s luong cac san phm trong
kho chua hang la khng gioi han.








Hinh 2.4 Phn thit lp cac thng s trong kho chua hang.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 10

2.3.Thit k kt cu my:
Kt cu phn d :






















Hinh 2.5 kt cu phn d.
Do su dung bi do chn gn lin truc d co sn nn kt cu chua th thit k gon
nhe duoc.D tao tinh di xung ,phn d duoc thit k theo mt khi hinh vung.

DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 11


Kt cu khop quay thu 2:















Hinh 2.6 kt cu khop quay 2.
Khop 2 quay voi vn tc vua phai,nhung cn momen lon nn su dung b truyn
banh rng co ti s truyn phu hop d tng momen quay cho dng co.
Co cu kep chi tit:







Hinh 2.7 co cu kep
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 12

Co cu kep duoc su dung la co cu kep bng khi nen,rt thng dung va hiu qua,thuong
duoc su dung nhiu trong vic nghing cuu robot cng nghip.
Luc kep duoc tinh toan dua vao ap sut,va duong kinh cua piston su dung,nn ta co th
d dang tao ra luc kep phu hop ung voi tung chi tit ring bit.
Co cu toan b h thng.s























Hinh 2.8 co cu toan b robot.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 13

Chuong 3 GII THIJU THIET BJ DIEU KHIEN SU DJNG
Vi diu khin P89V51RD2:
Khai quat.
P89V51RD2 la vi diu khin 80C51 co 64kB Flash va 1024bytes1kB~ b nho du
liu RAM.
Tinh nng dc bit cua P89V61RD2 la o ch d hoat dng mode x2. Nguoi thit k
chon chay ung dung cua minh o ch d nay d nng di tc d khi hoat dng o cung
tn s dao dngmt chu ki may6 chu ki xung nhip~
B nho chuong trinh Flash cho phep lp trinh ISP hoc/va song song. Ch d lp trinh
song song duoc dua ra d thich ung voi tc d cao, giam thoi gian va gia thanh.
IAP/ISP.
So d khi cua MCU P89V51RD2:











Hinh 3.1 so d cu truc vi diu khin.
Khi moi cp din vao MCU, tt ca cac port du o trang thai bt ki nao do toi khi
oscillator bt du hoat dng va qua trinh reset keo tt ca cac pin ln muc cao. Qua trinh
bt ngun ma khng di di voi vic Reset MCU hop ly s dn toi tinh trang ta khng bit
MCU thuc thi lnh o vung nho nao! Diu do co th dn dn m lnh trong Ilash bi thay
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 14

di. Reset h thng trong khi chuong trinh dang hoat dng s khng co anh huong toi
RAM cua MCU, tuy nhin, ni dung cua vung nho RAM trn chip trong qua trinh bt
ngun la cac gia tri ngu nhin.
Khi bt du mo ngun, chn RST phai duoc giu o muc cao mt khoang thoi gian
du cho oscillator khoi dng thuong la vai mili giy di voi dao dng o tn s thp~,
thm nua, d qua trinh reset la hop l, cn giu muc cao it nht 2 chu ki may.





















Hinh 3.2 Mach MCU P89V51RD2 va mach ngun cung cp.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 15

A - +
Eu
1 2
+
+
Lkt
--
Uu
Ru
Rkt
--
Ukt
3.2.Dng co din 1 chiu : (DC)
Dng co din 1 chiu kich tu dc lp





Hinh 3.3 So d nguyn ly DC KTDL
l3 co di3 mt chiu kich t so3 so3



Hinh 3.4 So d nguyn ly DC KTSS
l3 co di3 mt chiu kich t 3i tip









+
Ru
Lkt
A
- +
Eu
1 2
Rkt
--
Ukt = Uu

Hinh 3.5 So d nguyn ly DC KTNT
Ud
A
- +
Eu
1 2
+
Rkt
_
Ru
Lkt
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 16

Trong d an nhom chon dng co din mt chiu kich tu dc lp vi :
- Lam vic tai nho
- Diu khin tc d d dang, chinh xac khi co phan hi tu encoder
cau to .
Cu tao dng co gm: vo, truc, bi, phn cam (stato), phn ung (roto), c gop va
chi din.Ngoai ra dng co con duoc gn lin voi b truyn truc vit banh vit nhm tranh
hin tuong truot boi luc doc truc.Ngun din mt chiu DC tac dng ln cun ung qua c
gop. Cuong d tu truong khng thay di. Tc d dng co chi co th diu khin thng qua
dong roto. Co th dao chiu chuyn dng bng cach dao chiu dong din qua roto.






Hinh 3.6 cu tao bn trong dng co.
3.3.ncoder
ii thiu v E3coder.
Encoder hay con goi la b m hoa quang k thut s la mt thit bi chuyn di
chuyn dng thanh mt chui cac xung k thut s. Bng cach dm mt cach don le hoc
bng cach giai m mt tp hop cac bit, xung co th duoc chuyn di d do luong vi tri
tuong di hay tuyt di. Encoders co cu hinh ca tuyn tinh va quay, nhung loai ph bin
nht la quay. Rotary encoders duoc san xut trong hai hinh thuc co ban: cac b m hoa
tuyt di noi mt tu k thut s duy nht tuong ung voi mi vi tri cua truc quay, va m
hoa cac gia tng, trong do san xut xung k thut s nhu cac truc quay, cho phep do vi tri
tuong di cua truc. Hu ht cac m hoa quay duoc bao gm mt dia thuy tinh hoc nhua
m voi mt m hinh xuyn tm photographically gui t chuc theo di. Theo duong xuyn
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 17

tm trong mi ca khuc gian doan giua mt chum photoemitter-cp may do, xung k thut
s duoc san xut.
Phn loai : Co 2 loai Encoder nhung ta chi su dung loai : Incremental encoder
Nguyn ly hoat dng cua Incremental encoder

Hinh 3.6 Nguyn ly Incremental encoder
Gia su encoder co 3 xung la A,B,Z nhu hinh
Khi truc dng co quay nho 3 cp led thu va phat hng ngoai s di trang thai lin tuc.Do
2 xung A,B lch pha nhau 1 goc
0
90 va xung Z chi co 1 xung trn vong nn ta co gian d
xung nhu hinh trn
Ta dung b dm d dm xung nay tu do bit duoc vi tri dng co nhu th nao.Tuy vao
tung loai encoder ma ta co cac d phn giai khac nhau.Vd nhu encoder ghi
r / p
200 nghia
la khi dng co quay 1 vong ta do duoc 200 xung. Encoder trong d an cng la loai 200
xung/vong.Chi co 2 xung A va B khng co xung Z.


DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 18







Hinh 3.7 hinh anh bn ngoai encoder.
3.4.Ro le v FT:
Ro le trong mach duoc su dung la loai role 8 chn , 24 v








Hinh 3.8 hinh anh bn ngoai role 8.
Fet duoc su dung la Iet irI540N :








Hinh 3.9 FET IRF540N.
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 19

3.5.Valve solenoid 52 v xylanh 5x10











Hinh 3.10valve solenoid 52
Mt vai thng s cua valve :
Model 4V110-06
OriIice Size : 12 mm2
Pressure Range : 1.5 - 8.0 bar
Port Size : 1/8"







Hinh 3.11xylanh airtac 5x10
Mt vai thng s cua xylanh :
-Khng co tu tinh, co ren ngoai o du pit-tng
- Duong kinh trong xylanh: 10mm
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 20

-Chiu dai 1 hanh trinh: 50mm
-Luu cht: khi
- Ap sut hoat dng: 1~9.0 bar
- Nhit d cho phep: -5~70
0
C
- Tn s lam vic cua pit-tng: 30~500 mm/s
3.6.Ngun cung cp:
Ngun cung cp cho mach rt quan trong,d tranh duoc nhiu,sut ap,va cac diu kin
khach quan khac ta lua chon ngun cung cp cho h thng la ngun may tinh.











Hinh 3.12 Ngun may tinh.
Thng s cua ngun :
-Cng sut cung cp 420w
-24pin
- Tn s :50-60Hz
-Din ap 220 AC
-cung cp cac dy voi din ap : 0v,5v,12v,-12v,..


DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 21

Chuong 4 TINH TON THIET KE
4.1.So d mch diu khin :















Hinh 4.1 Mach chinh.










DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 22

%i3h toa3 mch diu khi3 d3 co.
Mach cach ly :
Chon ap roi trn opto 1,4V,ap trn led 2V,d led sang binh thuong ta chon dong qua led
va opto la 10mA
R(5v-2,4v)/10mA 260 ohm
Chon R 270
Opto dn bao hoa ~ Icsat 20mA,Vce sat 0,2V
Chon ap qua led 2v ~ tro dinh thin dong :
R( 12-2-0,2)/20 mA 500ohm
Chon R 576 ohm
Tinh toan tu va diod xa nng luong du trong cac cun dy:
D tinh din dung tu, ta dng nht hai cng thuc tinh nng
luong tich tru trong mach cng huong:
! C J
2
/ 2
! L I
2
/ 2
trong do:
! nng luong tich tru |Ws| hay |CV|
C din dung |F|
J din ap hai du tu
L d tu cam cua cun dy |H|
I dong din qua cun dy
Ta tinh kich thuoc nho nht cua tu din d tranh qua ap trn cng tc theo cng
thuc:
C ~ L I
2
/ (Jb Js)
2

trong do:
Jb din ap danh thung mach chuyn
Js din ap cung cp
Dng co tu tro bin thin co d tu cam thay di tuy thuc vao goc cua truc. Do
do, truong hop xu nht duoc dung d lua chon tu din. Hon nua, d tu cam
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 23

cua dng co thuong it duoc ghi r, nn chung ta phai lam vy.
Chon diod 4007 ~ chon tu su 104 d tng thoi gian xa nng luong.
Cac mach diu khin khac tinh toan tuong tu.







Hinh 4.3 mach diu khin role van

















Hinh 4.4 Mach diu khin dng co
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 24

start
nap cac gia
tri mac dinh
t lap ngat
ex1,nt
doi lenh tu
PC
Y
N
lenh reset
Y
call ct reset
N.
lenh xl
xanh
lenh xl do
N
Y
call ct xl
xanh
call ct xl do
Y
call ct xl
sp thua
N
4.2.Giai thut cua chuong trnh trn vi diu khin :



























Hinh 4.5 giai thut vi diu khin
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 25

thiet lap webcam
get driver
start
2s lay hinh anh
1 lan
lay lan luot cac
pixel trong anh
loai bo cac
pixel co R,G,B
50
loai cac pixel
, R - B , 20
trung binh cong
cac pixel con lai
sum.R ~ 200
sum.B 200
N
Y
N
sum.R 200
sum.B ~ 200
sp do
sp xanh
Y
khong
co sp
4.3.Giai thut nhn dng hnh anh :



























Hinh 4.6 giai thut nhn dang hinh anh
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 26

4.4.Gii thiu v xu l anh -ng dng xu l anh phn bit mu sc san
phm:
Xu ly anh la mt linh vuc mang tinh khoa hoc va cng ngh. No la mt nganh
khoa hoc moi me so voi nhiu nganh khoa hoc khac nhung tc d phat trin cua no rt
nhanh, kich thich cac trung tm nghin cuu, ung dung, dc bit la may tinh chuyn dung
ring cho no.
Co rt nhiu ung dung quan trong di voi xu ly anh trong cuc sng.Dung d xac
dinh duong bin,xac dinh tm vt th,nhn dang vn tay,nhn dang chu s,phn bit
mau....v.v..
Voi ni dung cua d an mn hoc ,em xin trinh bay mt phn nho v ung dung xu
ly anh d nhn dang san phm theo mau.
Hinh anh dua v PC tu webcam la anh mau,mi hinh anh duoc m ta boi rt
nhiu dim anh(goi la pixel) ma mt thuong thuong khng th nhn dang duoc duong
bin cua dim anh do ,va mi dim anh duoc dinh nghia bng 3 byte ung voi su pha trn
3 mau RED,GREEN,BLUE d tao nn mau dc trung cua mi dim anh do.
D dua hinh anh tu webcam v chuong trinh diu khin sa su dung cac ham co
trong thu vin avicap32.dll (LL (Dynamic Link Library))
Ham trong ' avicap.32 dung d chon driver cua webcam.














DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 27

Chuong 5 CHUONG TRINH V SOFTWAR DIEU KHIEN
5.1.Chuong trnh asm:

;KHI KHOI DONG CHO DONG CO 1 QUAY LECH 1 GOC 30 DEGREE SO VOI VITRI 1,
;ROI QUAY TRO VE LAI DE CO 1 NGAT NGOAI KHI CHAM CTHT
;CHUONG TRINH SE DOI CHO DEN KHI CO NGAT NGOAI 0 --~XONG KHOI DONG

DC1 EQU 0FDH ;DUA GIA TRI VAO DC,THI BAM XUNG TUONG UNG
DC2 EQU 0FEH ;MODUL CAPTURE HIGH (CHUA GTRI BAM XUNG)
CCAPM3 EQU 0DDH
CCAPM4 EQU 0DEH;MODE USE FOR PWM 8BIT....
CMOD EQU 0D9H ;CHE DO 1/2T,1/6T
CR BIT 0D8H.6
PWM1 EQU 25H
PWM2 EQU 26H
ROLE1 BIT P1.2
ROLEVAN BIT P1.5
ROLE2 BIT P1.0
START EQU 21H
DEME1 EQU 22H
DEME2 EQU 23H
DEMPHU1 EQU 28H
DEMPHU2 EQU 29H
GTE1 EQU 33H
GTE2 EQU 32H
DEMXONGE EQU 24H
BYTERECEIVE EQU 27H
DEMTIMER0A EQU 30H
DEMTIMER0B EQU 31H
ORG 00H
LJMP MAIN
ORG 0BH
LJMP INTTIMER0
ORG 13H
LJMP INTEX1
ORG 23H
LJMP INTSERIAL
ORG 30H
MAIN:
;THIET LAP CAC THONG SO BAN DAU VE 0
;THIET LAP DE BAM XUNG
MOV CMOD,#0 ; CHE DO DIEU XUNG 1/2T
SETB CR ;CHO PHEP PCA (CHO PHEP PROGRAM COUNTER ARRAY)
MOV CCAPM3,#01000010B
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 28

MOV CCAPM4,#01000010B
MOV PWM1,#30
MOV PWM2,#30
MOV P1,#0FFH ;TAT CAC ROLE
MOV P0,#0FFH ;xoa cac cong tac hanh trinh
MOV BYTERECEIVE,#0
MOV SCON,#50H ;THIET LAP SERIAL,MODE 1,BAUD THAY DOI , CHO PHEP
NHAN
MOV IE,#10010000B ;NGAT NT,(DUNG NGAT NGOAI 1 O DOAN LENH DUOI
,KHJ NAO CAN THI SET IE.2)
SETB PS ;UU TIEN NGAT NTIEP
SETB TCON.2 ;NGAT NGOAI 1 THEO SUOON
MOV TMOD,#20H ;TIMER0 -~ MODE 1; TIMER1 --~MODE2 (timer 2 dung cho toc
do baud)
MOV TH1,#0FDH ;TOC DO BAUD 9600
SETB TR1 ;CHO FEP XUNG DUNG TRONG GIAO TIEP NT
;GIAI THUAT NGAT NOI TIEP NHU SAU:
;TRUYEN DATA THI LAM CTRINH CON : A-~ SBUF,TRUYEN XONG TI 1,RI 0
---~ VAO CTRINH NGAT NTIEP
;CTRINH NGAT NTIEP CHI XET VOI RI ---~ THOAT NGAT NTIEP----~
;VE LAI CTRINH TRUYEN DATA --~XOA TI DE LAM TIEP
;DOI VOI NHAN DATA,KHJ SBUF NHAN XONG -~ RI 1 -~ CO NGAT NOITIEP -
~ XU LY NGAT NAY,XOA RI, RETI
MOV DEMTIMER0A,#200
MOV DEMTIMER0B,#10
;KIEM TRA BYTE NHAN NTN
;SAU KHI KT BYTERECEVE XONG,THUC HIEN LENH TUONG UNG -~ XOA
REVEIVE LAI
;VONG LOOP CUA CHUONG TRINH TAI DAY
;byte nhan ban dau 0
;mov bytereceive,#1 ; xoa doan nay di , xoa 1 lenh trong chuong trinh khoi dong nua(
khoi dong xong la xly do,chi di xuong 1 doan,dung dong co ~ xoa 1 lenh stop trong xly do nua
)
LCALL KHOIDONGCT
;BYTE NHAN 1 :KHOI DONG CT
;BYTE NHAN 2 :DO
;BYTE NHAN 3 :VANG
;BYTE NHAN 4 :XANH
;BYTE NHAN 5 :XANH BIEN
;BYTE NHAN 0 :KHONG LAM GI
CHUONGTRINH:
MOV A,BYTERECEIVE
CJNE A,#0,CHUONGTRINHDO
JMP CHUONGTRINH
CHUONGTRINHDO:
CJNE A,#2,CHUONGTRINHXANH
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 29

LCALL XULYDO
JMP CHUONGTRINH ;XULY XONG NHO XOA BYTERECEIVE,BAO
ROBOT BUSY -----------------------
CHUONGTRINHVANG:
CJNE A,#3,CHUONGTRINHXANH
LCALL XULYVANG
SJMP CHUONGTRINH
CHUONGTRINHXANH:
CJNE A,#4,CHUONGTRINHRESET
LCALL XULYXANH
SJMP CHUONGTRINH
CHUONGTRINHRESET:
CJNE A,#1,CHUONGTRINHXANHBIEN
LCALL KHOIDONGCT
SJMP CHUONGTRINH
CHUONGTRINHXANHBIEN:
CJNE A,#5,CHUONGTRINHPHU
LCALL XULYXANHBIEN
SJMP CHUONGTRINH
CHUONGTRINHPHU:
CJNE A,#6,CHUONGTRINH
LCALL XULYXANHBIEN
SJMP CHUONGTRINH
;--------------------------------
;CHUONG TRINH KHI MOI KHOI DONG
;----------------~CHU Y:3 CONG TAC HANH TRINH,CONG TAC NAO CHAM THI
PHAI CO DEN BAO LA DA CHAM
KHOIDONGCT:
LCALL ROBOTWORKING
MOV BYTERECEIVE,#0 ;XOA BYTE NHAN
MOV DEMXONGE,#0 ;KHI KHOI DONG DEN VITRI 400XUNG THI BIEN
NAY 1
LCALL ROLE1OFF
LCALL ROLEVANOFF
LCALL ROLE2OFF
SETB IE.2 ;CHO NGAT NGOAI 1,de co the dem xung encoder
;kiem tra xem, neu robot dang o vi tri 12,thi phai cho tro ve vi tri 1
LCALL VITRI1
HERE5: JB P0.1,VITRIBT
LCALL DELAY20MS ;TRANH NHIEU~ THOOI
;----~ CHU Y DIEM NAY KHJ CHAY CHUONG TRINH THAT
JB P0.1,VITRIBT
;DANG O VI TRI 12
;DK VE VI TRI 1
LCALL VITRI21
VITRIBT:
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 30

MOV DEME1,#5 ;dem XUNG
MOV DEME2,#2
MOV DEMPHU1,DEME1
MOV DEMPHU2,DEME2
LCALL PWMDC1 ; CHAY DONG CO 1
MOV A,DEMXONGE
CJNE A,#1,$ ;BIEN DEM XONGE 1 THI QUAY DONG CO TRO LAI VTRI1,
;NEU 0 THI DOI CHO DEN KHI QUAY DDEN VTRI 400 XUNG.
;CHUONG TRINH LOOP TAI DAY CHO DEN KHJ DU 400 XUNG
ENCODER
;QUAY NGUOC VE VITRI1
CLR IE.2 ;KO CHO NGAT1? CAN THIET KO?
LCALL DUNGPWMDC1

LCALL DELAY2S
LCALL DELAY2S ;1S
LCALL ROLEVANON ;kep
;LCALL ROLEVANOFF ;--------~ko can thjet
LCALL DELAY2S
;------~ CHU Y'
LCALL VITRI1 ;ROBOT QUAY VE VI TRI 1 ,SAU KHJ CHAM CONG TAC
HT MOI DEN LENH BEN DUOI
;---~ DEVELOPING: KHI QUAY VE VTRI1 THI PHAI KIEM TRA
XEM CTHT 2 CO DONG KO?
;NEU KO DONG THI CALL VITRI2
;XONG VITRI2 THI QUAY VE THUC HIEN TIEP
;VE VITRI 1.(DA CHINH ROLE1OFF)
;LCALL DUNGPWMDC1 DA CO LENH NAY
LCALL ROBOTFREE
RET
;--------------------------------------------------------
XULYPHU:
MOV GTE1,#5 ;2 200 DE DUOC 400 XUNG
MOV GTE2,#1
LCALL XULYSP
RET
;--------------------------------------------------------
XULYDO:
MOV GTE1,#5 ;3 200 DE DUOC 600 XUNG
MOV GTE2,#2
LCALL XULYSP
RET
;--------------------------------------------------------
XULYVANG:
MOV GTE1,#5
MOV GTE2,#3
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 31

LCALL XULYSP
RET
;--------------------------------------------------------
XULYXANH:
MOV GTE1,#5
MOV GTE2,#4
LCALL XULYSP
RET
;--------------------------------------------------------
XULYXANHBIEN:
MOV GTE1,#10
MOV GTE2,#5
LCALL XULYSP
RET
XULYSP:
LCALL ROBOTWORKING
LCALL ROLEVANOFF ;mo tay kep
MOV BYTERECEIVE,#0 ;XOA BYTE NHAN
MOV DEMXONGE,#0 ;KHI DEN VI TRI DO THI BIEN NAY 1
LCALL VITRI12
LCALL DELAY1S
LCALL DELAY1S
LCALL DELAY1S
LCALL ROLEVANON ;KEP CHI TIET
LCALL DELAY1S
LCALL DELAY1S
LCALL VITRI21
;CHUYEN DEN KHAY DO
SETB IE.2 ;CHO NGAT NGOAI 1

MOV DEME1,GTE1 ;1 200 DE DUOC 800 XUNG
MOV DEME2,GTE2

MOV DEMPHU1,DEME1
MOV DEMPHU2,DEME2

LCALL ROLE1OFF
LCALL PWMDC1 ;CHAY DONG CO 1
;BAT DAU NGAT NGOAI E1 KHI CO XUNG O ENCODER
MOV A,DEMXONGE
CJNE A,#1,$ ;NHAY TAI DAY CHO DEN KHI DEM XONG XUNG
CLR IE.2 ;
;DUNG XUNG DC1
LCALL DUNGPWMDC1
LCALL VITRI12
lcall delay1s
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 32

lcall delay1S
LCALL ROLEVANOFF ; NHA SAN PHAM
LCALL DELAY1S
LCALL DELAY1S ; DAY PHAI CO TRE
LCALL ROLEVANON
LCALL DELAY1S
LCALL DELAY1S
LCALL VITRI21
LCALL VITRI1
LCALL ROBOTFREE
RET
;--------------------------------------------------------

;--------------------------------------------------------
;--------------------------------------------------------
;--------------------------------------------------------
;--------------------------------------------------------
;NEU NHAN BYTE TU PC THI CO NGAT NT
;KHI ROBOT FREE ,PC MOI SEND LENH
;MAY TINH GUI XUONG 1BYTE LENH,BYTE
;1 : LENH RESET
;2 : LENH XU LY MAU DO
;3 : LENH XU LY MAU XANH

;------------------------------------------------------

;DOI VOI GIAO TIEP VS MAY TINH
;CHUONG TRINH DON GIAN:
;VDK GOI LEN PC 1 BYTE
;BYTE 1 ----~CANH TAY DANG BAN
;BYTE 2 ----~CANH TAY DANG RANH(BAO' CHO PC PHAT LOA NHAN LENH MOI)
;
;KHI PHAT HIEN SAN PHAM MAU GI THI
;DOI CANH TAY RANH ,ROI`
;GOI XUONG VDK 1 BYTE DKHIEN
;NEU BYTE 1 : MAU DO ----~ CHAY CHUONG TRINH DO
;NEU BYTE 2 : MAU XANH ---~ CHAY CT XANH
;NEU BYTE 3 : RESET HE THONG
;----------------------------------------------------------
;CHUONG TRINH BAO ROBOT BAN:
ROBOTWORKING:
MOV SBUF,#1
JNB TI,$
CLR TI
MOV SBUF,#1 ;1 CUNG DC
JNB TI,$
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 33

CLR TI
RET
;CHUONG TRINH BAO ROBOT RANH:
ROBOTFREE:
MOV SBUF,#2
JNB TI,$
CLR TI
MOV SBUF,#2
JNB TI,$
CLR TI
RET
;--------------------------
INTSERIAL: JB RI,NHAN
RETI
NHAN:

CLR RI
MOV A,SBUF
MOV BYTERECEIVE,A
;MOV P2,BYTERECEIVE ;DE KIEM TRA THOI
RETI
;-------------------------------------------
;CHUONG TRINH NGAT NGOAI 1DUNG DE DEM XUNG ENCODER
;DEM DUNG SO XUNG THI DUNG DK DONG CO

INTEX1:
LCALL DELAY20MS ;THAY 20MS 10 HAY 5 MS DE HOAT DONG
NHANH HON,NHUNG KO GIAM NHIEU BANG 20MS,TEST THUC TE MOI BIET
JNB P3.3,HAVEINT
RETI
HAVEINT:

;KO CAN DUNG DEN STATUS
DJNZ DEME1,THOATEX1
MOV DEME1,DEMPHU1
DJNZ DEME2,THOATEX1
MOV DEME2,DEMPHU2

MOV DEMXONGE,#1
THOATEX1:
MOV A,DEMXONGE
RETI
;---------------------------------------------------------
INTTIMER0: ;SUA CHUA BO DEM TIMER,KHI DEM 0.5S XONG THI CO NGAT
;KHI DO TA THAY DOI PWM DE GIAM TOC DO DONG CO
DJNZ DEMTIMER0A,THOATTIMER
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 34

DEC PWM2
MOV DC2,PWM2
MOV DEMTIMER0A,#200
MOV DEMTIMER0B,#10

THOATTIMER:
MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)

RETI
;---------------------------------------------------------
;CAC VI TRI


VITRI1:
;LCALL ROLEVANOFF
;LCALL ROLE2OFF
LCALL ROLE1ON
MOV PWM1,#30
LCALL PWMDC1 ;DONG CO DANG CHAY,VONG LAP DUNG LAI O CAU
LENH DUOI
HERE1: JB P0.2,HERE1
;LCALL DELAY20MS ;TRANH NHIEU~ THOOI
;----~ CHU Y DIEM NAY KHJ CHAY CHUONG TRINH THAT
;JB P0.2,HERE1 ;NHAY TAI DAY CHO DEN KHJ CHAM CTHT 1
LCALL DUNGPWMDC1
LCALL ROLE1OFF
RET
;---------------------------------------------------------
VITRI12:mov pwm2,#33
;THAY DOI PWM THEO TGIAN
;
MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
SETB TR0

LCALL ROLE2OFF ;OFF LA CHIEU XUONG
LCALL ROLE1OFF
LCALL PWMDC2 ;DONG CO DANG CHAY,VONG LAP DUNG LAI O CAU
LENH DUOI
HERE2: JB P0.1,HERE2
LCALL DELAY20MS ;TRANH NHIEU~ THOOI
;----~ CHU Y DIEM NAY KHJ CHAY CHUONG TRINH THAT
JB P0.1,HERE2 ;NHAY TAI DAY CHO DEN KHJ CHAM CTHT 1
LCALL DUNGPWMDC2
;LCALL ROLE2ON ;DAO CHIEU DONG CO ,KO CAN CAU LENH NAY
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 35

RET
;---------------------------------------------------------
VITRI21:mov pwm2,#43
LCALL ROLE2ON ;LA CHIEU LEN TREN
LCALL ROLE1OFF
LCALL PWMDC2 ;DONG CO DANG CHAY,VONG LAP DUNG LAI O CAU
LENH DUOI
HERE21: JB P0.0,HERE21
LCALL DELAY20MS ;TRANH NHIEU~ THOOI
;----~ CHU Y DIEM NAY KHJ CHAY CHUONG TRINH THAT
JB P0.0,HERE21 ;NHAY TAI DAY CHO DEN KHJ CHAM CTHT 1
LCALL DUNGPWMDC2
LCALL ROLE2OFF
RET
;---------------------------------------------------------

;---------------------------------------------------------

;---------------------------------------------------------
;NEU CAC SW NAO CO CHAM -~ CO NGAT NGOAI:
;CHUONGTRINH NGAT NGOAI.


;CAC CHUONG TRINH CON PHU KHAC:
ROLE1ON:
CLR P1.2
LCALL DELAY2S
RET
ROLE1OFF:
SETB P1.2
LCALL DELAY20MS
RET
ROLE2ON:
CLR P1.0
LCALL DELAY2S
RET
ROLE2OFF:SETB P1.0
LCALL DELAY20MS
RET
ROLEVANON:
CLR P1.5
LCALL DELAY2S
RET
ROLEVANOFF:
SETB P1.5
LCALL DELAY20MS
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 36

RET
;-------------------------------
;CHUONG TRINH BAM XUNG DONG CO
PWMDC1:
MOV DC1,PWM1
RET
DUNGPWMDC1:
MOV DC1,#0
RET
PWMDC2:
MOV DC2,PWM2
RET
DUNGPWMDC2:
MOV DC2,#0
RET

;------------------------------------------
;CHUONG TRINH DELAYS
DELAY50US: PUSH 6
MOV R6,#25
LOOP74: DEC R6
NOP
CJNE R6,#0,LOOP74
POP 6
RET
;----------------
DELAY20MS: PUSH 7
PUSH 6
MOV R6,#10
LOOP89: MOV R7,#250
LOOP77: DEC R7
NOP
CJNE R7,#0,LOOP77
DJNZ R6,LOOP89
POP 6
POP 7
RET
;----------------
DELAY2S:
PUSH 5

MOV R5,#100
LOOP111: CALL DELAY20MS
DJNZ R5,LOOP111
POP 5
RET
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 37

;--------------------------
DELAY1S:
PUSH 5

MOV R5,#100
LOOP1110: CALL DELAY20MS
DJNZ R5,LOOP1110
POP 5
RET
END
5.2.Chuong trnh visual basic
Chuong trinh chinh:
'ban dau robot khoi dong
'wc 1s take a photo 1 time
'process & detected -color
'if it have no color - no produce
'if it's red -- robot free. --y--send command red to U
'if it's blue -- robot free..--y--send command blue to u
'khi nao co tin hieu free goi len tu vdk thi capture
'bat form truoc,chinh cac thong so xong , timer 2 dang hoat dong(1tick = 1
anh de xu ly )
'sau do gan mach,cam nguon.mach doi lenh tu pc
'reset robot = may tinh

Imports System.Runtime.InteropServices
Imports System.IJ
Imports System.Drawing
Imports System.Windows
Imports System.Media
Public Class Form1

Public bytenhan(1) As Byte 'chuoi 2 byte , 1,1;2,2
Public bytegui(6) As Byte


Public start_nhan As Integer = 0
Public stop_nhan As Integer = 0

Public demsanphamxanh As Integer = 0
Public demsanphamdo As Integer = 0

Public nolimiteddo As Integer = 1 'ko gioi han sp
Public nolimitedxanh As Integer = 1
Public loa_cap As Integer = 1 ' cho phep loa_cap
Public loa_aud As Integer = 1 ' cho phep loa_aud

Public gioihando As Integer = 0 'sl sp do gioi han
Public gioihanxanh As Integer = 0

Public thongbaododay As Integer = 0
Public thongbaoxanhday As Integer = 0
Public catgiatrisosanh As Integer
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 38


Public chophep_dkrobot As Integer = 0

Public highx As Integer = 0
Public highy As Integer = 0
Public widthx As Integer = 0
Public widthy As Integer = 0

Public track1 As Integer = 20
Public track2 As Integer = 100
Public track3 As Integer = 20
Public track4 As Integer = 230

Public pixelcolor1 As Color
Public hinh1 As Bitmap
Public hinh2 As Bitmap
Public r, g, b As Long
Public sum1, sum2, sum3, d As Long
Dim a As Integer = 0
Dim n As Boolean
Public test As Integer = 0 ' bin ny dung d phn loai loai sp
Dim BitmapCaptureImageA As Image
Const WM_CAP_START = &H400S
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000

Const WM_CAP_DRIVER_CJNNECT = WM_CAP_START + 10
Const WM_CAP_DRIVER_DISCJNNECT = WM_CAP_START + 11
Const WM_CAP_EDIT_CJPY = WM_CAP_START + 30
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_GRAB_FRAME = WM_CAP_START + 60

Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50

Const SWP_NJMJVE = &H2S
Const SWP_NJSIZE = 1
Const SWP_NJZJRDER = &H4S
Const HWND_BJTTJM = 1
'--The capGetDriverDescription function retrieves the version description
of the capture driver--
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As
String, _
ByVal cbVer As Integer) As Boolean
'--The capCreateCaptureWindow function creates a capture window--
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWnd As Integer, _
ByVal nID As Integer) As Integer
'--This function sends the specified message to a window or windows--
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 39

(ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer,
_
<MarshalAs(UnmanagedType.AsAny) ByVal lParam As Jbject) As Integer
'--Sets the position of the window relative to the screen buffer--
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As
Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As
Integer
'--This function destroys the specified window--
Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As
Boolean
Dim hWnd As Integer
' I set the default video source to zero which is my only capture card
' Delete or change the lines below if you do not want a default source,
' or want a different default source number
Dim DefaultVideoSource As Integer = 0
Dim VideoSource As Integer = DefaultVideoSource
' the counters below are used as part of the filename when video or still
shots are saved
' It would be better to have the date as part of the filename
' otherwise, video and still shots with the same name will overwrite
previous files.
'---list all the various video sources---
Private Sub ListVideoSources()
Dim DriverName As String = Space(80)
Dim DriverVersion As String = Space(80)
For i As Integer = 0 To 9
If capGetDriverDescriptionA(i, DriverName, 80, DriverVersion, 80)
Then
listvideodriver.Items.Add(i & " - " & DriverName.Trim)
End If
Next
End Sub

Private Sub listvideodriver_SelectedIndexChanged(ByVal sender As Jbject,
ByVal e As System.EventArgs) Handles listvideodriver.SelectedIndexChanged
'---stop video in case it is on---
StopPreviewWindow()
'---check which video source is selected---
VideoSource = listvideodriver.SelectedIndex
'---preview the selected video source
PreviewVideo(PictureBox1)
End Sub
'---preview the selected video source---
Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
hWnd = capCreateCaptureWindowA(VideoSource, WS_VISIBLE Jr WS_CHILD,
0, 0, 0, _
0, pbCtrl.Handle.ToInt32, 0)
If SendMessage(hWnd, WM_CAP_DRIVER_CJNNECT, VideoSource, 0) Then
'---set the preview scale---
SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
'---set the preview rate (ms)---
SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
'---start previewing the image---
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 40

'---resize window to fit in PictureBox control---
SetWindowPos(hWnd, HWND_BJTTJM, 0, 0, _
pbCtrl.Width, pbCtrl.Height, _
SWP_NJMJVE Jr SWP_NJZJRDER)
textboxvideosource.Text = "VSource = " & VideoSource
Else
'--error connecting to video source---
MessageBox.Show(" camera chua san sang ")
DestroyWindow(hWnd)
End If
End Sub
'--disconnect from video source---
Private Sub StopPreviewWindow()
SendMessage(hWnd, WM_CAP_DRIVER_DISCJNNECT, VideoSource, 0)
DestroyWindow(hWnd)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Jbject, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SerialPort1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Jbject, ByVal e As
System.EventArgs) Handles Me.Load
If SerialPort1.IsJpen Then SerialPort1.Close()
SerialPort1.Jpen()
ListVideoSources()
PreviewVideo(PictureBox1)


Button7.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
Timer1.Enabled = False
Timer2.Enabled = False

Button1.Enabled = False

reset.Enabled = False
TextBox3.Enabled = False 'o so sanh
TextBox3.Enabled = False

End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Jbject, ByVal e As
System.IJ.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
SerialPort1.Read(bytenhan, 0, 2)
'kiemtra byte dau tien nhan duoc
If bytenhan(0) = 1 Then
statusrobot.Text = ("robot is busy now")
chophep_dkrobot = 0
ElseIf bytenhan(0) = 2 Then
statusrobot.Text = ("robot is free now")
chophep_dkrobot = 1
Loa()
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button6.Click
StopPreviewWindow()
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 41

Button7.Enabled = True
End Sub
Private Sub Button7_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button7.Click
PreviewVideo(PictureBox1)
End Sub
Private Sub Loa()
Dim play As New SoundPlayer
play = New SoundPlayer("c:\ht\king.wav")
If CheckBox4.Checked Then
play.Play()
End If
End Sub
Private Sub LoaCAP()
Dim play As New SoundPlayer
play = New SoundPlayer("c:\ht\cap.wav")
If CheckBox5.Checked Then
play.Play()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Timer1.Tick
SendMessage(hWnd, WM_CAP_GRAB_FRAME, 0, 0) 'Grab the frame
SendMessage(hWnd, WM_CAP_EDIT_CJPY, 0, 0) 'Copy it to the clip board
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0) 'Keep previewing in
live window
'Copy clipboard to a bitmap image (we will use there later to
manipulate image)
BitmapCaptureImageA =
CType(Clipboard.GetDataJbject().GetData(GetType(System.Drawing.Bitmap)),
Image)
hinh1 = BitmapCaptureImageA.GetThumbnailImage(300, 224, Nothing,
Nothing)
End Sub
Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Jbject,
ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
Timer1.Enabled = True
Timer2.Enabled = False
Form2.Show()

End Sub
Private Sub Button1_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button1.Click
start_nhan = 1 'ban dau = 0
stop_nhan = 0 'ban dau = 0
Form3.CheckBox3.Checked = False 'de lay cac thong so gioi han trong
check box

If Form3.CheckBox1.Checked = True Then
nolimiteddo = 1
Else
nolimiteddo = 0
gioihando = Form3.TextBox1.Text
End If
If Form3.CheckBox2.Checked = True Then
nolimitedxanh = 1
Else
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 42

nolimitedxanh = 0
gioihanxanh = Form3.TextBox2.Text
End If
End Sub
Private Sub reset_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles reset.Click
'goi xuong 1 byte ,cho robot khoi dong ,chuong trinh trong robot chay
trong 1 vong lap,doi lenh tu pc
bytegui(0) = 1
start_nhan = 0
stop_nhan = 0
demsanphamdo = 0
demsanphamxanh = 0
thongbaododay = 0
thongbaoxanhday = 0
chophep_dkrobot = 1
Label2.Text = " "
Label4.Text = " "

SerialPort1.Write(bytegui, 0, 1) 'gui byte = 1 xuong = robbot
reset

Button1.Enabled = True
TextBox5.Text = 0
TextBox4.Text = 0
End Sub
Private Sub xulyanh()
' Retrieve the image.
'hinh2 = Image.FromFile("c:\ht\trang.jpg")
'Dim hinh3 As Image
'hinh2 = hinh1
'------------- dem so diem anh co do chenh lech lon == phan tram
sum1 = 0
sum2 = 0
sum3 = 0
d = 0
' Loop through the images pixels to reset color.
For x = widthx To widthy
For y = highx To highy
Dim pixelColor As Color = hinh1.GetPixel(x, y)
r = pixelColor.R
g = pixelColor.G

b = pixelColor.B
If (((r < 50) And (b < 50) And (g < 50))) Jr ((Math.Abs(r -
b) < 20) And (Math.Abs(r - g) < 20) And (Math.Abs(g - b) < 20)) Then
d = d + 1
Else
sum1 += r
sum2 += g
sum3 += b
End If
Next
Next
If d (((widthy - widthx + 1) (highy - highx + 1)) 50) / 100
Then
sum1 = 0
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 43

sum2 = 0
sum3 = 0
Else
sum1 = sum1 / (((widthy - widthx + 1) (highy - highx + 1)) - d)
sum2 = sum2 / (((widthy - widthx + 1) (highy - highx + 1)) - d)
sum3 = sum3 / (((widthy - widthx + 1) (highy - highx + 1)) - d)
End If
Label8.Text = sum1
Label9.Text = sum2
Label10.Text = sum3
End Sub
Private Sub phanloai()
If sum1 TextBox3.Text And sum3 < TextBox3.Text And sum1 sum2 Then
test = 1 ' mu do
If sum2 TextBox3.Text And sum3 < TextBox3.Text And sum2 = sum1 And
sum1 sum3 Then test = 2 'mu vng
If sum2 TextBox3.Text And sum1 < TextBox3.Text And sum2 sum3 And
sum3 = sum1 Then test = 3 'mu xanh l cy
If sum3 TextBox3.Text And sum1 < TextBox3.Text And sum2 < sum3 Then
test = 4 'mu xanh bin
' xu l mi mu xong th tra lai gi tri test = 0 ban du
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Timer2.Tick
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0 Then
LoaCAP()
End If
xulyanh()
TextBox7.Text = d
bytegui(0) = 1 'reset
bytegui(1) = 2 'chay sf do
bytegui(2) = 3 'chay sf vang
bytegui(3) = 4 'chay sf xanh
bytegui(4) = 5 'chay sf xanh bien
bytegui(5) = 6 'chay sf phu
phanloai()
If CheckBox6.Checked Then
If test = 0 Then
PictureBox6.Image = Image.FromFile("c:\ht\none.jpg")
End If

If test = 1 Then
PictureBox6.Image = Image.FromFile("c:\ht\red.jpg")
xuly_sanpham()
test = 0
End If
If test = 2 Then
PictureBox6.Image = Image.FromFile("c:\ht\yellow.jpg")
xuly_sanpham()
test = 0
End If
If test = 3 Then
PictureBox6.Image = Image.FromFile("c:\ht\green.jpg")
xuly_sanpham()
test = 0
End If
If test = 4 Then
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 44

PictureBox6.Image = Image.FromFile("c:\ht\blue.jpg")
xuly_sanpham()
test = 0
End If
'-------------------------------------

Else
If ((sum1 < TextBox3.Text) And (sum3 < TextBox3.Text)) Jr ((sum1
TextBox3.Text) And (sum3 TextBox3.Text)) Then
PictureBox6.Image = Image.FromFile("c:\ht\none.jpg")
'ko lam ji ca-- ko can gui byte xuong
ElseIf sum1 TextBox3.Text Then
PictureBox6.Image = Image.FromFile("c:\ht\red.jpg")
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0
And thongbaododay = 0 Then
SerialPort1.Write(bytegui, 1, 1) ' goi ctrinh chay sp
do
demsanphamdo = demsanphamdo + 1
TextBox4.Text = demsanphamdo
'kim tra gii han san phm
If nolimiteddo = 0 Then
If demsanphamdo = gioihando Then
thongbaododay = 1
Label4.Text = "full"
chophep_dkrobot = 0
Else
TextBox4.Text = demsanphamdo
chophep_dkrobot = 0
End If
Else
TextBox4.Text = demsanphamdo
chophep_dkrobot = 0 'd bo robot dang bn
End If
ElseIf chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan =
0 And thongbaododay = 1 And thongbaoxanhday = 0 Then 'ANG CJ MU J (SF J
AY) M MU XANH CHUA AY = GAP SF J I QUA VI TRI PHU
SerialPort1.Write(bytegui, 5, 1) 'gui xuong byte ph ,d
robot chuyn qua vi tr ph ct san phm do thua di
chophep_dkrobot = 0 'd bo robot dang bn
End If
ElseIf sum3 TextBox3.Text Then
PictureBox6.Image = Image.FromFile("c:\ht\blue.jpg")
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0
And thongbaoxanhday = 0 Then
SerialPort1.Write(bytegui, 4, 1) 'goi chuong trinh sp
xanh o vdk
demsanphamxanh = demsanphamxanh + 1
TextBox5.Text = demsanphamxanh
'kim tra gii han sp xanh
If nolimitedxanh = 0 Then
If demsanphamxanh = gioihanxanh Then
thongbaoxanhday = 1
Label2.Text = "full"
chophep_dkrobot = 0
Else
TextBox5.Text = demsanphamxanh
chophep_dkrobot = 0
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 45

End If
Else
TextBox5.Text = demsanphamxanh
chophep_dkrobot = 0
End If
ElseIf chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan =
0 And thongbaoxanhday = 1 And thongbaododay = 0 Then 'chuyn sphan xanh du
sang vi tr ph
SerialPort1.Write(bytegui, 5, 1) 'gui xung byte ph
d robot chuyn qua vi tr ph
chophep_dkrobot = 0
End If
End If

End If
End Sub
Private Sub xuly_sanpham()
If test = 1 Then
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0 And
thongbaododay = 0 Then
SerialPort1.Write(bytegui, 1, 1) ' goi ctrinh chay sp do
demsanphamdo = demsanphamdo + 1
TextBox4.Text = demsanphamdo
'kim tra gii han san phm
If nolimiteddo = 0 Then
If demsanphamdo = gioihando Then
thongbaododay = 1
Label4.Text = "full"
chophep_dkrobot = 0
Else
TextBox4.Text = demsanphamdo
chophep_dkrobot = 0
End If
Else
TextBox4.Text = demsanphamdo
chophep_dkrobot = 0 'd bo robot dang bn
End If
ElseIf chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0
And thongbaododay = 1 And thongbaoxanhday = 0 Then 'ANG CJ MU J (SF J
AY) M MU XANH CHUA AY = GAP SF J I QUA VI TRI PHU
SerialPort1.Write(bytegui, 5, 1) 'gui xuong byte ph ,d
robot chuyn qua vi tr ph ct san phm do thua di
chophep_dkrobot = 0 'd bo robot dang bn
End If
ElseIf test = 2 Then
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0 Then
SerialPort1.Write(bytegui, 2, 1) 'goi chuong trinh sp vang
o vdk
chophep_dkrobot = 0
End If

ElseIf test = 3 Then
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0 Then
SerialPort1.Write(bytegui, 3, 1) 'goi chuong trinh sp xanh
o vdk
chophep_dkrobot = 0
End If
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 46

ElseIf test = 4 Then
If chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0 And
thongbaoxanhday = 0 Then
SerialPort1.Write(bytegui, 4, 1) 'goi chuong trinh sp xanh
bien o vdk
demsanphamxanh = demsanphamxanh + 1
TextBox5.Text = demsanphamxanh
'kim tra gii han sp xanh
If nolimitedxanh = 0 Then
If demsanphamxanh = gioihanxanh Then
thongbaoxanhday = 1
Label2.Text = "full"
chophep_dkrobot = 0
Else
TextBox5.Text = demsanphamxanh
chophep_dkrobot = 0
End If
Else
TextBox5.Text = demsanphamxanh
chophep_dkrobot = 0
End If
ElseIf chophep_dkrobot = 1 And start_nhan = 1 And stop_nhan = 0
And thongbaoxanhday = 1 And thongbaododay = 0 Then 'chuyn sphan xanh du sang
vi tr ph
SerialPort1.Write(bytegui, 5, 1) 'gui xung byte ph d
robot chuyn qua vi tr ph
chophep_dkrobot = 0
End If
End If
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As Jbject, ByVal e
As System.EventArgs) Handles RadioButton1.CheckedChanged
catgiatrisosanh = TextBox3.Text
TextBox3.Enabled = True
TextBox3.Enabled = True
Timer2.Enabled = False
End Sub
Private Sub Button8_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button8.Click
Timer2.Enabled = True
TextBox3.Enabled = False
TextBox3.Enabled = False
RadioButton1.Checked = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button3.Click
Timer2.Enabled = True
TextBox3.Enabled = False
TextBox3.Enabled = False
RadioButton1.Checked = False
TextBox3.Text = catgiatrisosanh
End Sub
Private Sub Button2_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button2.Click
stop_nhan = 1
End Sub
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 47

Private Sub SetupParameterToolStripMenuItem_Click(ByVal sender As
System.Jbject, ByVal e As System.EventArgs) Handles
SetupParameterToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub AboutUsToolStripMenuItem1_Click(ByVal sender As
System.Jbject, ByVal e As System.EventArgs) Handles
AboutUsToolStripMenuItem1.Click
Form4.Show()
End Sub
Private Sub AboutUsToolStripMenuItem_Click(ByVal sender As System.Jbject,
ByVal e As System.EventArgs) Handles AboutUsToolStripMenuItem.Click
help.Show()
End Sub
End Class
Chuong trinh phu 1:

'set form2 de lay thong so dua ve lai form 1
Imports System.Runtime.InteropServices
Imports System.IJ
Imports System.Drawing
Imports System.Windows
Imports System.Media
Public Class Form2
Private Sub Form2_Load(ByVal sender As Jbject, ByVal e As
System.EventArgs) Handles Me.Load
Timer1.Enabled = True
TrackBar1.Value = Form1.track1
TrackBar2.Value = Form1.track2
TrackBar3.Value = Form1.track3
TrackBar4.Value = Form1.track4
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Timer1.Tick
For i As Integer = TrackBar1.Value To TrackBar2.Value
For j As Integer = TrackBar3.Value To TrackBar4.Value
Dim pixelcolor As Color = Form1.hinh1.GetPixel(j, i)
Dim newcolor As Color = Color.FromArgb(0, pixelcolor.G,
pixelcolor.B)
Form1.hinh1.SetPixel(j, i, newcolor)
Next
Next
PictureBox1.Image = Form1.hinh1
End Sub

Private Sub Button1_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button1.Click
Form1.highx = TrackBar1.Value
Form1.highy = TrackBar2.Value
Form1.widthx = TrackBar3.Value
Form1.widthy = TrackBar4.Value
Form1.track1 = TrackBar1.Value
Form1.track2 = TrackBar2.Value
Form1.track3 = TrackBar3.Value
Form1.track4 = TrackBar4.Value
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 48

Form1.reset.Enabled = True
Form1.Timer2.Enabled = True
Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button2.Click

Close()
End Sub
End Class
+ Chuong trnh ph 2:
Public Class Form3
Private Sub Form3_Load(ByVal sender As Jbject, ByVal e As
System.EventArgs) Handles Me.Load
GroupBox3.Enabled = False 'group chon sluong
GroupBox4.Enabled = False
Button4.Enabled = False 'ok group
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Jbject, ByVal
e As System.EventArgs) Handles CheckBox3.CheckedChanged
GroupBox3.Enabled = True
GroupBox4.Enabled = True
Button4.Enabled = True
Form1.stop_nhan = 1 'ging nhu c nhn 1 ln stop
End Sub
Private Sub Button4_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button4.Click
CheckBox3.Checked = False
GroupBox3.Enabled = False
GroupBox4.Enabled = False
'lay cac gia tri khac ra
If CheckBox1.Checked = True Then
Form1.nolimiteddo = 1
Form1.thongbaododay = 0
Else
Form1.nolimiteddo = 0
Form1.gioihando = TextBox1.Text
If Form1.gioihando = Form1.TextBox4.Text Then
Form1.thongbaododay = 0
Else : Form1.thongbaododay = 1
End If
End If
If CheckBox2.Checked = True Then
Form1.nolimitedxanh = 1
Form1.thongbaoxanhday = 0
Else
Form1.nolimitedxanh = 0
Form1.gioihanxanh = TextBox2.Text
If Form1.gioihanxanh = Form1.TextBox5.Text Then
Form1.thongbaoxanhday = 0
Else : Form1.thongbaoxanhday = 1
End If
End If

Form1.stop_nhan = 0
Close()
End Sub
DO AN : HE THONG CO DIEN TU GVHD: PGS.TS TRAN XUN TUY

SVTH: VN HU AN NGUYN TRUNG KIN LOP 06CDT2 trang 49

Private Sub Button5_Click(ByVal sender As System.Jbject, ByVal e As
System.EventArgs) Handles Button5.Click
Close()
End Sub
End Class