Está en la página 1de 20

Trng i hc Bch Khoa H Ni Khoa in t - vin thng

Bo co bi tp ln

K thut vi x l ti : My bn hng t ng

Gio vin hng dn: TH.S Hn Huy Dng Nhm sinh vin thc hin: 1.L Vn Nguyn - T2-K48 2.Trn L Vinh - T3-K48

H Ni thng 5 nm 2006

LI GII THIU
S ra i ca cc my rt tin t ng,cc bng qung co s dng quang bo,h thng hn gi tt m trong cc h thng giao thng gn y ti Vit Nam cng khng inh s ng dng mnh m ca k thut vi x l.N thc s i vo i sng v phc v nhu cu ca chng ta. Ban u bn em c tng s thit k ng h in t v chng em m phng thnh cng bng Proteus lp m phng trn Panel mch chy tt.Cng lm cng thy s th v thc s ca n,chng em li c tng m rng sn phm ca mnh .Kt hp n vi LCD,vit phn lp trnh trn READ51 sau cho chy trn phn mm m phng v thnh cng.Tip tuc m rng chng em ngh ra s thit k phn hin th ca my bn hng t ng. Hin nay c rt nhiu b vi iu khin nh PIC,PSOC, nhng do y l ln u tin bn em tip xc vi vi iu khin cho nn bn em la chn vi iu khin 8051 l h vi iu khin c nhiu ti liu nghin cu nht (theo chng em).

QUI TRNH THC HIN Phn I :Khi qut chung v cch thc hin
1.Tho lun a ra tng cui cng 2.Hi bit cch s dng tho cc phn mm nh Read51,proteus.y l 2 phn mm rt hay dng lp trnh v m phng cho mch.Phn mm thit k mch in nh Ocad 9.2,su tm cc phn mm phc v cho vic np mch. 3.M phng mch trn Proteus, vit phn lp trnh trn Read51 tnh ton mua linh kin 4.Cc linh kin s dng v c im: a)AT89S52 -L sn phm ca hng Atmel c 256 bytes Ram,8 Kbyte Rom ,32 chn vo ra ,3 b nh thi,8 ngun ngt,1 cng ni tip -Kiu b nh NV-RAM l kiu b nh m c kh nng np chng trnh vo ROM trn chip trong khi n vn trong h thng m khng phi ly ra,ngoi ra kiu b nh ny cn c u vit cho php thay i ni dung Rom theo tng byte trong khi b nh kiu Flash v EPROM phi c xa ht trc khi lp trnh li. -cc chn ca AT89S52 c miu t nh hnh bn cnh -Mt s iu quan trng i vi AT89S52: + to c thi gian tr th AT89S52 phi c ni vi thch anh c tn s t 10 n 12 MHZ . trnh sai s cho bit th chng ta thng chn tn s thch anh l 11.0592 MHZ. +Mt chu k my bng 12 chu k dao ng ca thch anh . + Do AT89S52 c ROM trn chip nn chn 31 ca n c ni vi ngun VCC

S ni cc chn cn thit ca AT89S52

+Cng P0 phi c ni vi cc in tr ko thit lp n lm cng vo,do cng P0 c thit k khng c in tr ko khng ging nh cng P1,P2,P3 (cu to ca cng P0 c dng cc mng)

a) LCD 16X2 -Cc chn ca LCD 16x2 c biu din nh hnh v.

-Cc chn ca LCD c ni vi vi iu khin nh hnh sau:

b) IC 74LS47 -Trn hnh v cc chn 7,1,2,6 tng ng vi A,B,C,D l cc chn vo. Cc chn 13,12,11,10,9,15,14 tng ng vi QA,QB,QC,QD,QE,QF,QG l cc cng c ni vi cc chn ca LED 7 thanh. -S ni 74LS47 vi AT89S52 nh sau.

c) LED 7 Thanh ( Anode chung )

Tm li ,s nguyn l ca mch:

Phn II : Phn lp trnh : Ta c s thut ton

BEGIN

HIN TH CH CHY

KHNG

B TIN? (BM NT) C HIN TH MENU

KHNG CHN (SAU 10S)

CHN 1 HAY L 2 1 LY 1 ( N XANH SNG)

LY 2 ( N SNG)

I 10S

END

Phn code ny nh sau:


ORG 0000H ;Ni bt u

LJMP MAIN1 ;Nhy khi bng vector ngt ORG 0013H ;a ch ca ngt INT1 SETB P3.6 ;n sng bo hiu chon 2 ACALL LED1 RETI ORG 0030H ;bt u chng trnh chnh MAIN1: MOV A,#01H ;XOA MAN HINH HIEN THI ACALL COMMAND ;GUI LENH DEN LCD MOV A,#38H ;ma trn 2 dng 5x7 ACALL COMMAND ACALL DELAY CLR P3.6 CLR P3.7 MOV P0,#00H ;ban u Led 7 thanh hin th 00 MOV P1,#00H ; MAIN: MOV A,#0CH ;BAT HIEN THI , TAT CON TRO ACALL COMMAND ;GUI LENH DEN LCD MOV A,#01H ;XOA MAN HINH HIEN THI ACALL COMMAND ;GUI LENH DEN LCD ACALL DELAY STRING : DB ' WELCOME! WELCOME!' ;Hin th ch WELCOME chy MOV IE,#00H ;cm ngt MOV A,#38H ACALL COMMAND ACALL DELAY MOV A,#0CH ;BAT HIEN THI , TAT CON TRO ACALL COMMAND ;GUI LENH DEN LCD MOV A,#01H ;XOA MAN HINH HIEN THI ACALL COMMAND ;GUI LENH DEN LCD LCALL DELAY ;GOI TRE MOV A,#93H ;DUNG DE CHAY LCALL COMMAND ACALL DELAY MOV R0,#16 ;HIEN TOI DA 16 KI TU (LCD 16.2) MOV DPTR,#STRING CLR A MOVC A,@A+DPTR ACALL DATA_DISPLAY ;HIEN THI ACALL DELAY TAO_VA_DICH :MOV A,#18H ;dich toan bo hien thi sang trai ACALL COMMAND MOV A,#93H ACALL COMMAND ACALL DELAY INC DPTR CLR A MOVC A,@A+DPTR ACALL DATA_DISPLAY ACALL DELAY1 DJNZ R0,TAO_VA_DICH MOV R1,#19 DICH : MOV A,#18H ; dich toan bo hien thi sang trai ACALL COMMAND

ACALL DELAY DJNZ R1,DICH MOV A,#38H ACALL COMMAND ACALL DELAY MOV A,#0CH ;BAT HIEN THI , TAT CON TRO ACALL COMMAND ;GUI LENH DEN LCD ACALL DELAY MOV A,#01H ;XOA MAN HINH HIEN THI LCALL COMMAND ;GUI LENH DEN LCD ACALL DELAY LCALL COMMAND ACALL DELAY MOV A,#0EH ;bt hin th nhp nhy con tr LCALL COMMAND MOV A,#01H ;xa mn hnh hin th LCALL COMMAND MOV A,#06H ;dch con tr sang phi LCALL COMMAND MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ; ch hin th vo gia LCD ACALL COMMAND ACALL DELAY MOV A,#'M' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'Y' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'B' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'N' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'H' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A'

LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'N' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'G' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 SETB P1.7 JNB P1.7,LUACHON ; ;nhy dn LUACHON khi bam nut MOV A,#0C0H ;a con tr v u dng th 2 ACALL COMMAND ACALL DELAY1 MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY1 MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY1 MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY1 MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY1 MOV A,#'T' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'U' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' ACALL DATA_DISPLAY ACALL DELAY1 MOV A,#'D' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'O' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'N' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'G' LCALL DATA_DISPLAY ;HIEN THI JNB P1.7,LUACHON ;nhy dn LUACHON khi bam nut LCALL DATA_DISPLAY ;HIEN THI MOV A,#01H ;XOA MAN HINH HIEN THI ACALL COMMAND ;GUI LENH DEN LCD ACALL DELAY LJMP MAIN RET ;---------------------;DOAN THU 2 LUACHON: MOV A,#38H

ACALL COMMAND ACALL DELAY MOV A,#01H ;XOA MAN HINH HIEN THI LCALL COMMAND ;GUI LENH DEN LCD ACALL DELAY LCALL COMMAND ACALL DELAY MOV A,#0EH LCALL COMMAND MOV A,#01H LCALL COMMAND MOV A,#06H LCALL COMMAND ACALL DELAY1 MOV A,#'1' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'.' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'C' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'F' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'F' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'E' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'B' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'U' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'O' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'N' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'M' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'E' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1

MOV A,#0C0H ACALL COMMAND ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'2' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'.' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'C' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'O' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'C' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'C' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'O' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'L' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 HERE: MOV IE,#84H ;cho php ngt SETB p1.4 JNB p1.4,led ;nhy khi bm nt MOV A,#00H ;m thi gian i (10s) MOV R5,#10 MOV B,#00H LAP10:MOV IE,#84H SETB p1.4 JNB p1.4,led MOV A,#00H MOV P1,B SETB p1.4 ACALL DELAY2 MOV IE,#84H JNB p1.4,led INC B DJNZ R5,LAP10 JNB p1.4,led MOV P1,#00H SETB p1.4

MOV P0,#01H ACALL DELAY2 MOV IE,#84H JNB p1.4,led LJMP MAIN1 ;nu khng bm nt hoc ;ngt th quay li ban u SJMP HERE ;---------------------------------------------LED: SETB P3.7 ;n xanh sang bo hiu chn 1 led1: MOV IE,#0000H MOV A,#01H ;XOA MAN HINH HIEN THI LCALL COMMAND ;GUI LENH DEN LCD MOV A,#38H LCALL COMMAND MOV A,#0EH LCALL COMMAND MOV A,#01H LCALL COMMAND MOV A,#06H LCALL COMMAND MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY ACALL DELAY1 MOV A,#'P' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'L' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'E' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'S' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'E' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'W' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1

MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'I' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'T' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'!' LCALL DATA_DISPLAY ;HIEN THI MOV A,#00H ;m thi gian luc i ly hng MOV R6 ,#1 MAIN2: MOV P0,A ACALL DEMDONVI INC A DJNZ R6, MAIN2 MOV P1,#00H MOV P0,#01H ACALL DELAY2 ;DOAN KET THUC MOV A,#01H ;XOA MAN HINH HIEN THI LCALL COMMAND ;GUI LENH DEN LCD MOV A,#38H LCALL COMMAND MOV A,#0EH ;bt hin th nhp nhy con tr LCALL COMMAND MOV A,#01H LCALL COMMAND MOV A,#06H LCALL COMMAND MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACA LL DELAY MOV A,#14H ;DICH VI TRI CON TRO SANG PHAI ACALL COMMAND ACALL DELAY1 MOV A,#'T' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'H' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'A' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'N' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'K'

LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#' ' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'Y' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'O' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'U' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY1 MOV A,#'!' LCALL DATA_DISPLAY ;HIEN THI ACALL DELAY2 ACALL DELAY2 MOV A,#01H ;XOA MAN HINH HIEN THI ACALL COMMAND ;GUI LENH DEN LCD SETB IE.2 MOV IE,#84H LJMP MAIN1 RET ;------------------------------------------------------------------------;THIET KE BO DEM ;-------------------------------------------------------------------DEMDONVI: MOV R5,#10 MOV B,#00H LAP1: MOV P1,B ACALL DELAY2 INC B DJNZ R5,LAP1 RET COMMAND : MOV P2,A ;SAO A DEN CONG P2 ; 8chn ca P2 ni vi D0-D7 ca LCD CLR P3.0 ;P3.0=0->RS=0 GUI LENH DEN LCD ;P3.0 ni vi RS ca LCD CLR P3.1 ;P3.1=0->R/W=0 DE GHI DU LIEU ;P3.1 ni vi R/ ca LCD SETB P3.2 ;P3.2=1->E=1 XUNG CAO ;P3.2 ni vi chn E(cho php) CLR P3.2 ;E-0 XUNG THAP ;c xung cao xung thp th cht d liu(xung>450ns) RET DATA_DISPLAY : MOV P2,A ;SAO A DEN CONG P2 SETB P3.0 ;P3.0=1->RS=1 GUI DU LIEU DEN LCD CLR P3.1 ;P3.1=0->R/W=0 DE GHI DU LIEU SETB P3.2 ;P3.2=1->E=1 CHO XUNG CAO CLR P3.2 ;E=0 CHO XUNG THAP RET DELAY : ;tr dng cho dng ch chy MOV R7,#4 LAP: MOV TMOD,#01H MOV TL0,#0FFH MOV TH0,#8FH SETB TCON.4

AGAIN : JNB TF0,AGAIN CLR TR0 CLR TF0 DJNZ R7,LAP RET DELAY1: MOV R7,#10 LAP2: MOV TH0,#0F0H MOV TL0,#0FH SETB TR0 LAP3: JNB TF0,LAP3 CLR TF0 CLR TR0 DJNZ R7,LAP2 RET DELAY2: MOV R7,#15 LAP8: MOV TH0,#10H MOV TL0,#00H SETB TR0 LAP9: JNB TF0,LAP9 CLR TF0 CLR TR0 DJNZ R7,LAP8 RET ;----------------------------------END ;tr mi khi 1 ch c hin th Lcd

;tr 1s dng cho ng h

PHN III : QU TRNH CHY CA MCH


1.Khi bt ngun mn hnh s xut hin

2.Bn mun mua g,hy b tin vo ( y l bm cng tc chn loi hng)

My s i 10s nu bn khng chn g th n s t ng quay v thi im ban u. 3.Khi bn chn mt hng mnh mua v d nh caffe bun m bn bm cng tc la chn,cng tc ny c thit k sn,mn hnh hin th s c dng sau: Khi LCD hin th Please wait v ng h s bt u m n 10 giy bn s c hng cho mnh ng thi n xanh bt sng:

4.Sau khi bn c hng cho mnh my s hin th li cm n bn s dng

5.Nu bn khng thch caffe bun m bn c th la chn sn phm khc m my c ph hp vi s thch ca bn chng hn bn chn coca my s hin th tng t nh trn v lc ny n bt sng.

6.Sau khi bn chn c sn phm mnh thch my s t ng quay li trng thi ban u.

Mt khc mch c thit k cng tc RESET c tc dng quay li trng thi ban u . Do y l bi lm mu nn chng ti ch la chn 2 sn phm tng trng.Trong thc t chng ta c th cho nhiu loi hng ha khc cng vi gi c ca n khch hng a tin vo sau i khong 10 giy cho my x l bn s c

hng . ti trn y ch l lm chy th nn chng gi thit tin mua 2 sn phm vi gi nh nhau.

TNG KT
Chng em bit s dng cc phn mm trong vic thit k mch,kt hp l thuyt v thc hnh.Theo chng em y s l nhng iu ht sc quan trng cho cc nh k s, trnh khi ra thc t vp phi nhng li sai tt nht bn nn m phng mch trc khi lm. Ni ring v ti bn em thc hin :Ban u bn em ch c tng nh l dng vi x l thit k b m ,sau khi thc hin thnh cng bn em tip tc pht trin ti ca mnh ln thnh ti trn. y ch l mch hot ng theo mt tng cha th p dng vo thc t c mun p dng vo c thc t cn c b sung thm. Bn em s tip tc nghin cu cc h vi iu khin khc ngy cng nng cp sn phm ca mnh.Xu hng ca bn em sau ny s tip tc nghin cu PIC,PSOC, thy c nhng mt mnh v mt yu ca cc h vi iu khin nhm p dng chng cho nhng ng dng c ch. y l ln u tin nghin cu v vi x l nn cn rt nhiu mt hn ch v kin thc cng nh cch nhn nhn vn v mt thc t nn chng em mong nhn c s ph bnh cng nh gp ca cc thy sn phm ngy cng hon thin hn. Cui cng chng em xin chn thnh cm n thy HN HUY DNG nhit tnh gip chng em trong qu trnh thc hin.