You are on page 1of 10

VnCourier Chng I Cc b vi iu khin 8051 1.1 cc b vi iu khin v cc b x l nhng.

Trong mc ny chng ta bn v nhu cu i vi cc b vi iu khin (VK) v so snh chng vi cc b vi x l cng dng chung nh Pentium v cc b vi x l 86 khc. Chng ta cng xem xt vai tr ca cc b vi iu khin trong th trng cc sn phm nhng. Ngoi ra, chng ta cung cp mt s tiu chun v cch la chn mt b vi iu khin nh th no. 1.1.1 B vi iu khin so vi b vi x l cng dng chung S khc nhau gia mt b vi iu khin v mt b vi x l l g? B vi x l y l cc b vi x l cng dung chung nh h Intell 86 (8086, 80286, 80386, 80486 v Pentium) hoc h Motorola 680 0(68000, 68010, 68020, 68030, 68040 v.v...). Nhng b VXL ny khng c RAM, ROM v khng c cc cng vo ra trn chp. Vi l do m chng c gi chung l cc b vi x l cng dng chung.
Data bus CPU Genera lPurpos e Microprocess or RA M RO M I/O Port Tim er Seri al COM Port RA M RO M Seri al COM Port

CPU

I/O

Tim er

Address bus (a) General-Purpose Microcessor System

(b) Microcontroller

Hnh 1.1: H thng vi x l c so snh vi h thng vi iu khin. a) H thng vi x l cng dng chung b) H thng vi iu khin Mt0 nh thit k h thng s dng mt b vi x l cng dng chung chng hn nh Pentium hay 68040 phi b xung thm RAM , ROM, cc cng vo ra v cc b nh thi ngoi lm cho chng hot ng c. Mc d vic b xung RAM, ROM v cc cng vo ra bn ngoi lm cho h thng cng cnh v t hn, nhng chng c u im l linh hot chng hn nh ngi thit k c th quyt nh v s lng RAM, ROM v cc cng vo ra cn thit ph hp vi bi ton trong tm tay ca mnh. iu ny khng th c c i vi cc b vi iu khin. Mt b vi iu khin c mt CPU (mt b vi x l) cng vi mt lng c nh RAM, ROM, cc cng vo ra v mt b nh thi tt c trn cng mt chp.

Hay ni cch khc l b x l, RAM, ROM cc cng vo ra v b nh thi u c nhng vi nhau trn mt chp; do vy ngi thit k khng th b xung thm b nh ngoi, cng vo ra hoc b nh thi cho n. S lng c nh ca RAM, ROM trn chp v s cc cng vo - ra trong cc b vi iu khin lm cho chng tr nn l tng i vi nhiu ng dng m trong gi thnh v khng gian li hn ch. Trong nhiu ng dng, v d mt iu khin TV t xa th khng cn cng sut tnh ton ca b vi s l 486 hoc thm ch nh 8086. Trong rt nhiu ng dng th khng gian n chim, cng sut n tiu tn v gi thnh trn mt n v l nhng cn nhc nghim ngt hn nhiu so vi cng sut tnh ton. Nhng ng dng thng yu cu mt s thao tc vo - ra c cc tn hiu v tt - m nhng bit nht nh. V l do ny m mt s ngi gi cc b x l ny l IBP (Itty-Bitty-Processor), (tham kho cun Good things in small packages are Generating Big product opportunities do Rick Grehan vit trn tp BYTE thng 9.1994; WWW. Byte. Com bit v nhng trao i tuyt vi v cc b vi iu khin). iu th v l mt s nh sn xut cc b vi iu khin i xa hn l tch hp c mt b chuyn i ADC v cc ngoi vi khc vo trong b vi iu khin. Bng 1.1: Mt s sn phm c nhng s dng cc b vi iu khin Thit b ni tht gia nh in trong nh My m thoi My in thoi Cc h thng an ton Cc b m ca ga-ra xe My tr li My Fax My tnh gia nh Tivi Truyn hnh cp VCR My quy camera iu khin t xa Tr chi in t in thoi t ong Cc nhc c in t My khu iu khin nh sng My nhn tin My chi Football chi Cc dng c tp th hnh Vn phng in thoi My tnh Cc h thng ton My Fax L vi sng My sao chp My in lazer My in mu My nhn tin t My tnh hnh trnh iu khin ng c an Ti m kh Thit b ABS o lng H thng bo mt u khin truyn tin Gii tr iu ho nhit in thoi t ong M ca khng cn cha kho

1.1.2 Cc b VK cho cc h thng nhng. Trong ti liu v cc b vi x l ta thng thy khi nim h thng nhng (Embeded system). Cc b vi x l v cc b vi iu khin c s dng rng ri trong cc sn phm h thng nhng. Mt sn phm nhng s dng mt b vi x l (hoc mt b vi iu khin thc hin mt nhim v v ch mt m thi. Mt my in l mt v d v mt vic nhng v b x l bn trong n ch lm mt vic l nhn d liu v in n ra. iu ny khc vi mt my tnh PC da trn b x l Pentium (hoc mt PC tng thch vi IBM 86 bt k). Mt PC c th c s dng cho mt s bt k cc trm dch v in, b u cui kim k nh bng, my chi tr chi in t, trm dch v mng hoc trm u cui mng Internet. Phn mm cho cc ng dng khc nhau c th c np v chy. Tt nhin l l do hin nhin mt PC thc hin hng lot cc cng vic l n c b nh RAM v mt h iu hnh np phn mm ng dng thng c t vo trong ROM. Mt my tnh PC 86 cha hoc c ni ti cc sn phm nhng khc nhau chng hn nh bn phm, myin, Modem, b iu khin a, Card m thanh, b iu khin CD = ROM. Chut v.v... Mt ni ngoi vi ny c mt b vi iu khin bn trong n thc hin ch mt cng vic, v d bn trong mi con chut c mt b vi iu khin thc thi cng vic tm v tr chut v gi n n PC Bng 1.1 lit k mt s sn phm nhng. 4.1.3 Cc ng dng nhng ca PC 86. Mc d cc b vi iu khin l s la chn a chung i vi nhiu h thng nhng nhng c nhiu khi mt b vi iu khin khng cho cng vic. V l do m nhng nm gn y nhu nh sn xut cc b vi s l cng dng chung chng hn nh Intel, Motorla, AMD (Advanced Micro Devices, Inc...). V Cyric (m by gi l mt b phn ca National Senicon ductir, Inc) hng ti b vi x l cho hiu sut cao ca th trng nhng. Trong khi Intel, AMD v Cyrix y cc b x l 86 ca h vo cho c th trng nhng v th trng my tnh PC bn th Motorola vn kin nh gi h vi x l 68000 li ch yu hng n cho cc h thng nhng hiu sut cao v by gi Apple khng cn dng 680 trong cc my tnh Macintosh na. Trong nhng nm u thp k 90 ca th k 20 my tnh Apple bt u s dng cc b vi x l Power PC (nh 603, 604, 620 v.v...) thay cho 680 0 i vi Macintosh. Bvi x l Power PC l kt qu lin doanh u t ca IBM v Motorola v n c hng cho th trng nhng hiu sut cao cng nh cho c th trng my tnh PC. Cn phi lu rng khi mt cng ty hng mt b vi x l cng dng chung cho th trng nhng n ti u ho b x l c s dng cho cc h thng nhng. V l do m cc b vi x l ny thng c gi l cc b x l nhng hiu sut cao. Do vy cc khi nim cc b vi iu khin v b x l nhng thng c s dng thay i nhau. Mt trong nhng nhu cu kht khe nht ca h thng nhng l gim cng sut tiu th v khng gian. iu ny c th t c bng cch tch hp nhiu chc nng vo trong chp CPU. Tt c mi b x l nhng da trn 86 v 680 0 u

c cng sut tiu thu thp ngoi ra c b xung mt s dng cng vo ra, cng COM v b nh ROM trn mt chp. Trong cc b x l nhng hiu sut cao c xu hng tch hp nhiu v nhiu chc nng hn na trn chp CPU v cho php ngi thit k quyt nh nhng c tnh no h mun s dng. Xu hng ny cng ang chim lnh thit k h thng PC. Bnh thng khi thit k bo mch ch ca PC (Motherboard) ta cn mt CPU cng mt chp - set c cha cc cng vo - ra, mt b iu khin cache, mt b nh Flash ROM c cha BIOS v cui cng l b nh cache th cp. Nhng thit k mi ang khn trng i vo cng nghip sn xut hng lot. V d Cyrix tuyn b rng h ang lm vic trn mt chp c cha ton b mt my tnh PC ngoi tr DRAM. Hay ni cch khc l chng ta sp nhn thy mt my tnh PC trn mt chp. Hin nay do chun ho MS - DOS v Windows nn cc h thng nhng ang s dng cc my tnh PC 86 . Trong nhiu trng hp vic s dng cc my tnh PC 86 cho cc ng dng nhng hiu sut cao l khng tit kim tin bc, nhng n lm rt ngn thi gian pht trin v c mt th vin phn mm bao la c vit cho nn DOS v Windows. Thc t l Windows l mt nn c s dng rng ri v d hiu c ngha l vic pht trin mt sn phm nhng da trn Windows lm gim gi thnh v rt ngn thi gian pht trin ng k. 1.1.4 La chn mt b vi iu khin. C 4 b vi iu khin 8 bit chnh. l 6811 ca Motorola, 8051 ca Intel z8 ca Xilog v Pic 16 ca Microchip Technology. Mi mt kiu loi trn y u c mt tp lnh v thanh ghi ring duy nht, nu chng u khng tng thch ln nhau. Cng c nhng b vi iu khin 16 bit v 32 bit c sn xut bi cc hng sn xut chp khc nhau. Vi tt c nhng b vi iu khin khc nhau nh th ny th ly g lm tiu chun la chn m cc nh thit k phi cn nhc? C ba tiu chun la chn cc b vi iu khin l: 1) p ng nhu cu tnh ton ca bi ton mt cch hiu qu v mt gi thnh v y chc nng c th nhn thy c (kh d). 2) C sn cc cng c pht trin phn mm chng hn nh cc trnh bin dch, trnh hp ng v g ri. 3) Ngun cc b vi iu khin c sn nhiu v tin cy. 1.1.5 Cc tu chun la chn mt b vi iu khin. 1. Tiu chun u tinv trc ht trongla chn mt b vi iu khin l n phi p ng nhu cu bi ton v mt mt cng sut tnh ton v gi thnh hiu qu. Trong khi phn tch cc nhu cu ca mt d n da trn b vi iu khin chng ta trc ht phi bit l b vi iu khin no 8 bit, 16 bit hay 32 bit c th p ng tt nht nhu cu tnh ton ca bi ton m tcch hiu qu nht? Nhng tiu chun c a ra cn nhc l: a) Tc : Tc ln nht m b vi iu khin h tr l bao nhiu. b) Kiu ng v: l ku 40 chn DIP hay QFP hay l kiu ng v khc (DIP -ng v theo 2 hng chn. QFP l ng v vung dt)? y l iu quan trng i vi yu cu v khng gian, kiu lp rp v to mu th cho sn phm cui cng.

c) Cng sut tiu th: iu ny c bit kht khe i vi nhng sn phm dng pin, c quy. d) Dung lng b nh RAM v ROM trn chp. e) S chn vo - ra v b nh thi trn chp f) Kh nng d dng nng cp cho hiu sut cao hoc gim cng sut tiu th. g) Gi thnh cho mt n v: iu ny quan trng quyt nh gi thnh cui cng ca sn phm m mt b vi iu khin c s dng. V d c cc b vi iu khin gi 50 cent trn n v khi c mua 100.000 b mt lc. 2) Tiu chun th hai trong la chn mt b vi iu khin l kh nng pht trin cc sn phm xung quanh n d dng nh th no? Cc cn nhc ch yu bao gm kh nng c sn trnh lng ng, g ri, trnh bin dch ngn ng C hiu qu v m ngun, trnh m phng h tr k thut v kh nng s dng trong nh v ngoi mi trng. Trong nhiu trng hp s h tr nh cung cp th ba (ngha l nh cung cp khc khng phi l hng sn xut chp) cho chp cng tt nh, nu khng c tt hn, s h tr t nh sn xut chp. 3) Tiu chun th ba trong la chn mt b vi iu khin l kh nng sn sng p ng v s lng trong hin ti v tng lai. i vi mt s nh thit k iu ny thm ch cn quan trong hn c hai tiu chun u tin. Hin nay, cc b vi iu khin 8 bit du u, h 8051 l c s lng ln nht cc nh cung cp a dng (nhiu ngun). Nh cung cp c ngha l nh sn xut bn cnh nh sng ch ca b vi iu khin. Trong trng hp 8051 th nh sng ch ca n l Intel, nhng hin nay c rt nhiu hng sn xut n (cng nh trc kia sn xut). Cc hng ny bao gm: Intel, Atmel, Philips/signe-tics, AMD, Siemens, Matra v Dallas, Semicndictior. Bng 1.2: a ch ca mt s hng sn xut cc thnh vin ca h 8051. Hng Intel Antel Plips/ Signetis Siemens Dallas Semiconductor a ch Website www.intel.com/design/mcs51 www.atmel.com www.semiconductors.philips.com www.sci.siemens.com www.dalsemi.com

Cng nn lu rng Motorola, Zilog v Mierochip Technology dnh mt lng ti nguyn ln m bo kh nng sn sng v mt thi gian v phm vi rng cho cc sn phm ca h t khi cc sn phm ca h i vo sn xut n nh, hon thin v tr thnh ngun chnh. Trong nhng nm gn y h cng bt u bn t bo th vin Asic ca b vi iu khin. 1.2 Tng quan v h 8051. Tr ong mc ny chng ta xem xt mt s thnh vin khc nhau ca h b vi iu khin 8051 v cc c im bn trong ca chng.

ng thi ta im qua mt s nh sn xut khc nhau v cc sn phm ca h c trn th trng. 1.2.1 Tm tt v lch s ca 8051. Vo nm 1981. Hng Intel gii thiu mt s b vi iu khin c gi l 8051. B vi iu khin ny c 128 byte RAM, 4K byte ROM trn chp, hai b nh thi, mt cng ni tip v 4 cng (u rng 8 bit) vo ra tt c c t trn mt chp. Lc y n c coi l mt h thng trn chp. 8051 l mt b x l 8 bit c ngha l CPU ch c th lm vic vi 8 bit d liu ti mt thi im. D liu ln hn 8 bit c chia ra thnh cc d liu 8 bit cho x l. 8051 c tt c 4 cng vo - ra I/O mi cng rng 8 bit (xem hnh 1.2). Mc d 8051 c th c mt ROM trn chp cc i l 64 K byte, nhng cc nh sn xut lc cho xut xng ch vi 4K byte ROM trn chp. iu ny s c bn chi tit hn sau ny. 8051 tr nn ph bin sau khi Intel cho php cc nh sn xut khc sn xut v bn bt k dng bin th no ca 8051 m h thch vi iu kin h phi m li tng thch vi 8051. iu ny dn n s ra i nhiu phin bn ca 8051 vi cc tc khc nhau v dung lng ROM trn chp khc nhau c bn bi hn na cc nh sn xut. iu ny quan trng l mc d c nhiu bin th khc nhau ca 8051 v tc v dung lng nh ROM trn chp, nhng tt c chng u tng thch vi 8051 ban u v cc lnh. iu ny c ngha l nu ta vit chng trnh ca mnh cho mt phin bn no th n cng s chy vi mi phin bn bt k khc m khng phn bit n t hng sn xut no. Bng 1.3: Cc c tnh ca 8051 u tin. c tnh ROM trn chp RAM B nh thi Cc chn vo - ra Cng ni tip Ngun ngt
EXTERNAL INTERRUPTS

S lng 4K byte 128 byte 2 32 1 6


ETC

1.2.2 B v iu khin 8051 TIMER B vi iu khin 8051 l thnh u tin ca h 8051. Hng INTERRUP ON vin 0 TIMER Intel k 3.1 trnh by cc c tnh ca T hiu n nh l MCS51. Bng CHIP 1 CONTROL RAM 8051.
COUNTER INPUTS

CPU

OS C

BUS CONTRO L

4 I/O PORTS

SERIAL PORT

ADDRESS/DA

P P P P 0 1 2 3

TXD RX D

Hnh 1.2: B tr bn trong ca s khi 8051. 1.2.3 cc thnh vin khc ca h 8051 C hai b vi iu khin thnh vin khc ca h 8051 l 8052 v 8031. a- B vi iu khin 8052: B vi iu khin 8052 l mt thnh vin khc ca h 8051, 8052 c tt c cc c tnh chun ca 8051 ngoi ra n c thm 128 byte RAM v mt b nh thi na. Hay ni cch khc l 8052 c 256 byte RAM v 3 b nh thi. N cng c 8K byte ROM. Trn chp thay v 4K byte nh 8051. Xem bng 1.4. Bng1.4: so snh cc c tnh ca cc thnh vin h 8051. c tnh ROM trn chp RAM B nh thi Chn vo - ra Cng ni tip Ngun ngt 8051 4K byte 128 byte 2 32 1 6 8052 8K byte 256 byte 3 32 1 8 8031 OK 128 byte 2 32 1 6

Nh nhn thy t bng 1.4 th 8051 l tp con ca 8052. Do vy tt c mi chng trnh vit cho 8051 u chy trn 8052 nhng iu ngc li l khng ng. b- B vi iu khin 8031: Mt thnh vin khc na ca 8051 l chp 8031. Chp ny thng c coi nh l 8051 khng c ROM trn chp v n c OK byte ROM trn chp. s dng chp ny ta phi b xung ROM ngoi cho n. ROM ngoi phi cha chng trnh m 8031 s np v thc hin. So vi 8051 m chng trnh c cha trong ROM trn chp b gii hn bi 4K byte, cn ROM ngoi cha chng trinh c gn vo 8031 th c th ln n 64K byte. Khi b xung cng, nh vy ch cn li 2 cng thao tc. gii quyt vn ny ta c th b xung cng vo - ra cho 8031. Phi php 8031 vi b nh v cng vo - ra chng hn vi chp 8255 c trnh by chng 14. Ngoi ra cn c cc phin bn khc nhau v tc ca 8031 t cc hng sn xut khc nhau.

1.2.4. Cc b vi iu khin 8051 t cc hng khc nhau. Mc d 8051 l thnh vin phi bin nht ca h 8051 nhng chng ta s thy n trong kho linh kin. l do 8051 c di nhiu dng kiu b nh khc nhau nh UV - PROM, Flash v NV - RAM m chng u c s ng k linh kin khc nhau. Vic bn lun v cc kiu dng b nh ROM khc nhau s c trnh by chng 14. Phin bn UV-PROM ca 8051 l 8751. Phin bn Flash ROM c bn bi nhiu hng khc nhau chng hn ca Atmel corp vi tn gi l AT89C51 cn phin bn NVRAM ca 8051 do Dalas Semi Conductor cung cp th c gi l DS5000. Ngoi ra cn c phin bn OTP (kh trnh mt ln) ca 8051 c sn xut bi rt nhiu hng. a- B vi iu khin 8751: Chp 8751 ch c 4K byte b nh UV-EPROM trn chp. s dng chp ny pht trin yu cu truy cp n mt b t PROM cng nh b xo UV- EPROM xo ni dung ca b nh UV-EPROM bn trong 8751 trc khi ta c th lp trnh li n. Do mt thc t l ROM trn chp i vi 8751 l UV-EPROM nn cn phi mt 20 pht xo 8751 trc khi n c th c lp trnh tr li. iu ny dn n nhiu nh sn xut gii thiu cc phin bn Flash Rom v UV-RAM ca 8051. Ngoi ra cn c nhiu phin bn vi cc tc khc nhau ca 8751 t nhiu hng khc nhau. b- B vi iu khin AT8951 t Atmel Corporation. Chp 8051 ph bin ny c ROM trn chp dng b nh Flash. iu ny l l tng i vi nhng pht trin nhanh v b nh Flash c th c xo trong vi giy trong tng quan so vi 20 pht hoc hn m 8751 yu cu. V l do ny m AT89C51 pht trin mt h thng da trn b vi iu khin yu cu mt b t ROM m c h tr b nh Flash. Tuy nhin li khng yu cu b xo ROM. Lu rng trong b nh Flash ta phi xo ton b ni dung ca ROM nhm lp trnh li cho n. Vic xo b nh Flash c thc hin bi chnh b t PROM v y chnh l l do ti sao li khng cn n b xo. loi tr nhu cu i vi mt b t PROM hng Atmel ang nghin cu mt phin bn ca AT 89C51 c th c lp trnh qua cng truyn thng COM ca my tnh IBM PC . Bng 1.5: Cc phin bn ca 8051 t Atmel (Flash ROM). S linh ROM kin AT89C51 AT89LV51 AT89C105 1 AT89C205 1 AT89C52 AT89LV52 4K 4K 1K 2K 8K 8K RAM 128 128 64 128 128 128 Chn I/ O 32 32 15 15 32 32 Time r 2 2 1 2 3 3 Ng Vcc t 6 6 3 6 8 8 5V 3V 3V 3V 5V 3V ng v 40 40 20 20 40 40

Ch C trong k hiu AT89C51 l CMOS. Cng c nhng phin bn ng v v tc khc nhau ca nhng sn phm trn y. Xem bng 1.6. V d rng ch C ng trc s 51 trong AT 89C51 -12PC l k hiu cho CMOS 12 k hiu cho 12 MHZ v P l kiu ng v DIP v ch C cui cng l k hiu cho thng mi (ngc vi ch M l qun s ). Thng thng AT89C51 - 12PC rt l tng cho cc d n ca hc sinh, sinh vin. Bng 1.6: Cc phin bn 8051 vi tc khc nhau ca Atmel. M linh kin AT89C5112PC Tc 42MHZ S chn 40 ng v DTP Mc ch Thng mi

c- B vi iu khin DS5000 t hng Dallas Semiconductor. Mt phin bn ph bin khc na ca 8051 l DS5000 ca hng Dallas Semiconductor. B nh ROM trn chp ca DS5000 di dng NVRAM. Kh nng c/ ghi ca n cho php chng trnh c np vo ROM trn chp trong khi n vn trong h thng (khng cn phi ly ra). iu ny cn c th c thc hin thng qua cng ni tip ca my tnh IBM PC. Vic np chng trnh trong h thng (in-system) ca DS5000 thng qua cng ni tip ca PC lm cho n tr thnh mt h thng pht trin ti ch l tng. Mt u vit ca NV-RAM l kh nng thay i ni dung ca ROM theo tng byte ti mt thi im. iu ny tng phn vi b nh Flash v EPROM m b nh ca chng phi c xo sch trc khi lp trnh li cho chng. Bng 1.7: Cc phin bn 8051 t hng Dallas Semiconductor. M linh kin DS5000-8 DS5000-32 DS5000T-8 DS5000T-8 ROM 8K 32K 8K 32K RAM 128 128 128 128 Chn I/O 32 32 32 32 Time r 2 2 2 2 Ng Vcc t 6 5V 6 5V 6 5V 6 5V ng v 40 40 40 40

Ch T ng sau 5000 l c ng h thi gian thc. Lu rng ng h thi gian thc RTC l khc vi b nh thi Timer. RTC to v gi thi gian l pht gi, ngy, thng - nm k c khi tt ngun. Cn c nhiu phin bn DS5000 vi nhng tc v kiu ng gi khc nhau.( Xem bng 1.8). V d DS5000-8-8 c 8K NV-RAM v tc 8MHZ. Thng thng DS5000-8-12 hoc DS5000T-8-12 l l tng i vi cc d n ca sinh vin. Bng 1.8:Cc phin bn ca DS5000 vi cc tc khc nhau M linh kin DS5000-8-8 NV- RAM 8K Tc 8MHz

DS5000-8-12 DS5000-32-8 DS5000T-32-12 DS5000-32-12 DS5000-8-12

8K 32K 32K 32K 8K

12MHz 8MHz 8MHz (with RTC) 12MHz 12MHz (with RTC)

d- Phin bn OTP ca 8051. Cc phin bn OTP ca 8051 l cc chp 8051 c th lp trnh c mt ln v c cung cp t nhiu hng sn xut khc nhau. Cc phin bn Flash v NV-RAM thng c dng pht trin sn phm mu. Khi mt sn pohm c thit k v c hon thin tuyt i th phin bn OTP ca 8051 c dng sn hng lot v n s hn rt nhiu theo gi thnh mt n v sn phm e- H 8051 t Hng Philips Mt nh sn xut chnh ca h 8051 khc na l Philips Corporation. Tht vy, hng ny c mt di la chn rng ln cho cc b vi iu khin h 8051. Nhiu sn phm ca hng c km theo cc c tnh nh cc b chuyn i ADC, DAC, cng I/0 m rng v c cc phin bn OTP v Flash.