trịnh phi hùng

  • Published on
    03-Jan-2016

  • View
    72

  • Download
    2

Embed Size (px)

Transcript

sinh vin: trnh phi hng v nguyn ng khoa

[sinh vin: trnh phi hng v nguyn ng khoa]April 25, 2013

Hc Vin Cng Ngh Bu Chnh Vin ThngC s ti thnh ph H Ch Minh

N MN HC

Mn Hc: Thit K H Thng Nhng & K Thut Ghp Ni V Thit B Ngoi Vi ti : o nhit v t gi ti nc cho vnGio vin hng dn: Ths. Tn Tht Bo tThs. Phm Th DuyH v tn sinh vin: 1. Trnh Phi Hng MSSV : 4091900092. Nguyn ng Khoa MSSV : 409190011

H ch minh nm 2013----------MC LCtrangLi ni u

I.M T L DO V MC TIU CNG VIC:- 5 -1.L do chn ti:- 5 -2.M t ti:- 5 -II.TM HIU CC LINH KIN THIT B TRONG TI :- 6 -1.MCU ATmega32:- 6 -a.c im:- 6 -b.Cc I/O:- 8 -c.Chc nng ADC:- 8 -d.Giao tip s dng I2C:- 10 -e.Giao tip USART:- 12 -2.IC thi gian thc DS1307:- 15 -a.Cu to ngoi v c im:- 15 -b.Cc thanh ghi ca IC:- 16 -c.Giao tip i2c vi AVR:- 17 -3.Cm bin nhit LM35:- 18 -a.c im k thut v cu to chn linh kin:- 18 -b.Nguyn l hot ng:- 19 -4.LCD 1602:- 19 -a.c im v cu to chn LCD 1602:- 19 -b.Cc hm iu khin LCD- 20 -5.Truyn nhn d liu qua cng ni tip- 20 -a.Cu trc cng ni tip:- 20 -b.Cng RS-232 trn PC- 22 -c.Truyn thng gia hai nt:- 22 -d.Lp trnh giao tip trn my bng C#- 23 -6.IC chuyn i tn hiu USART RS-232 MAX232:- 23 -a.c im v s chn IC MAX 232:- 23 -b.Nguyn l hot ng:- 23 -7.USB-COM vi PL 2303- 23 -a.c im v s chn IC:- 24 -b.Nguyn l hot ng:- 26 -8.Kt ni mng RS-485:- 29 --Khi nim a mng:- 29 --Chun RS-485:- 30 --Mt s vn lin quan n RS-485:- 30 --Cc kiu truyn nhn trong mng RS 485:- 34 -III.THIT K PHN CNG :- 36 -1.Khi x l v hin th:- 36 -2.Khi thi gian thc- 36 -3.Khi giao tip my tnh:- 36 -IV.THIT K PHN MM- 39 -1.Gii thut cho my tnh:- 39 -a.Gii thut cho my tnh:- 39 -b.Giao din giao tip:- 39 -2.Gii thut cho vi iu khin:- 40 -a.Lu chng trnh chnh:- 40 -b.Gii thut hin th thi gian v nhit :- 41 -c.Gii thut hin gi ti trong ngy:- 42 -d.Gii thut iu chnh thi gian thc t:- 43 -3.Kt qu thi cng:- 44 -a.Hnh nh:- 44 -Thi cng mch cng:- 44 -b.Hn ch:- 46 -c.Hng pht trin tip theo:- 46 -

Li ni uVi mt lng ln dn s trong nc l nng dn v nhng nm gn y cc m hnh nh VAC, VACR, trang tri, nh knh, c cc h dn quy hoch vi din tch c th ln n hng trm hecta, ngoi ra cc nhn lc lm trong ngnh nng nghip thng cao tui. Khi gnh nng cng vic t ra lm sao c mt m hnh ti cy, rau, vn m mt cch hon ton t ng hoc bn t ng l mc tiu cho chng em chn ti ny. Hi vng vi m hnh ti cy s gim c phn no cng vic cho cc h gia nh v nng cao nng sut cy trng, t c gi tr thng phm cao hn.Tuy nhin do hn ch ca ti ch dng li mc nghin cu n gin v tm hiu nn nhm em mong c s hng dn v gp thm chng em hoang thnh ti trong tng lai.Khng thy my lm nn . Em xin cm n tt c cc thy, c trong khoa in t 2 gip chng em trong thi gian hc tp ti trng v gp cho em nhng kin qu bu. c bit em xin cm n thy Phm Th Duy v thy Tn Tht Bo t l gio vin b mn v giao vin hng dn khuyn khch v gip chng em trong qu trnh thit k v thi cng ti.

I. M T L DO V MC TIU CNG VIC:1. L do chn ti: Nhm em chn ti m hnh ti cy t ng v cm bin nhit v m vi l do: Cng vic nh nng rt vt v v nhiu cng on Xu hng trng ra oan ton trn nhng cnh ng ln ang c trin khai v nhn rng khp cc tnh thnh i tng lm nng ch yu l ngi ln tui v vy mun gim gnh nng cng vic cho khi lm nng M hnh c th p dng cc cnh ng rau, cc vn cy n qu hoc cc vn cy cng nghip.2. M t ti: M hnh hot ng da trn ng h thi gian thc, chnh xc cao, t t gi ti v cc thng s khc (ln ti, thi lng ti) mt cch chnh xc. Hot ng hon ton t ng, ch cn t mt ln v hot ng cho cc ln k tip. Cc cm bin m v nhit gip thu thp thng tin vn cy c cc phng n ti ph hp. C giao tip my tnh c th cp nhp thng tin v vn cy, rau qua giao din my tnh. S khi:analogLM35I/O1/0LCD 1602

MCU(ATmega8 hoc 32)

ADCI2C1/0DS1307

analogp ng(vi ti)Cm bin m

I/O1/0

My tnh

Cc phm bmRS-232

USART

I/O1/0

Vcc,Vref,GND5V DCNgun

M t: MCU (atmega8 hoc atmega32): lm b x l trung tm cc tn hiu s, tng t hin th v thc thi chng trnh chnh v lm mt s giao tip vi IC khc hoc vi my tnh c nhn. IC DS1307: IC thi gian thc c giao tip vi MCU qua giao tip I2C. Cc sensor: dng lm chc nng o cc thng s mi trng ri gi cc tn hiu tng t ti b ADC ca MCU chuyn i v hin th n mc ch kim sot v iu khin. Cc phm bm: dng khi ta c thao tc iu khin v ci t cc thng s bng tay trn mch. Lcd 1602 : hin th cc thng s(thi gian, ci t ti, nhit ) khi thc hin t thng s bng tay. Vi ti: c dng ng m ci relay khi n thi gian ti nh sn. My tnh: giao tip vi cc mch bn ngoi v iu khin cc mch. N cn c dng qun l cc vn khc nhau. Ngun: (ngun cho mch): s dng in p DC5V cc IC, MCU, lcd hot ng.

II. TM HIU CC LINH KIN THIT B TRONG TI : ti c s dng mt s linh kin in t l cc IC v MCU cng mt s chun giao tip c bn nh USART, I2C, cm bin c s dng nh LM35, cm bin m, hin th bng LCD 1602L, giao tip my tnh c IC MAX232, IC chuyn i USB-COM hoc cable chuyn dng.1. MCU ATmega32:a. c im: y l dng vi iu khin ca hng Atmel c nhiu tnh nng ni tri Cu trc tp lnh thu gn RISC, n gin, d lp trnh Tit kim nng lng C 32 chn I/O, 4 port xut nhp d liu a chc nng 32 thanh ghi a dng B nh 32Kb b nh Flash lp trnh c, 1024Byte EEPROM Tc ti a ln ti 16MHz, c th s dng c dao ng ni chip v thch anh ngoi 2 b Timer/counter 8 bit, mt b so snh 1 b timer/counter 16 bit 4 knh PWM 8 knh ADC h tr phn gii 10 bit v 8 bit Cc giao tip h tr nh: I2C, SPI, USART in p hot ng 4,5-5 V S chn v ng gi: loi 40 chn PDIP v loi TQFP/MLF (linh kin dn)

Chn sTn chnChc nng

1-8PORT BPort xut nhp B, ngoi ra cn c chc nng l giao tip SPI

9RESETChn reset ca atmega 32, chn ny c kch khi c mt tch cc mc thp tc ng ln, khi atmega32 s hot ng li

10, 11NgunVCC, chn cp ngun dng VCC v GND

12, 13Chn gn dao ng ngoi

Hai chn gn thch anh dao ng ngoi ca chip khi s dng, mun s dng c dao ng ngoi ta cn fuse bt chip c set s dng thch anh

14-21PORT DPort truy xut I/O, ngoi ra cn c chc nng khc nh: Pd0-pd1: chn rxd v txd s dng giao tip USART Pd2-pd3: chn ngt ngoi Pd4-pd5: ng ra so snh

22-29Port CPort truy xut I/O, ngoi ra cn c chc nng khc nh: Pc0-pc1: chn giao tip i2c

30-31Chn ngunChn acvv v gnd

32VrefChn in p so snh (dng trong ch adc)

33-40Port APort truy xut I/O, ngoi ra cn c chc nng l 8 knh adc.

b. Cc I/O: Ng ra cc mng h.

ATmega32 c 4 PORT xut nhp d liu l: A, B,C,D C 3 thanh ghi chc nng lp trnh vo ra cho cc chn I/O l: DDR, PIN, PORT. Cu hnh I/O theo bng sau:DDxnPORTxnI/OPull-upChc nng

00InputkhngTrng thi Hi-z tr khng cao

01InputCNg vo c in tr ko ln

01InputKhngTrng thi Hi-z tr khng cao

10OutputKhngNg ra mc thp

11OutputKhngNg ra mc cao

Thanh ghi PINx nhn cc tn hiu vo.c. Chc nng ADC: PORT A ca ATmega32 c chc nng ADC kim cng vo ra sc im : phn gii 10 bit hoc 8 bit ty chc nng 8 knh ADC n Tc chuyn i 13s - 260s. 0 Vcc ADC di in p ng vo. Ngt ADC khi chuyn i xong

C 4 thanh ghi trong AVR dng chc nng ADC ADMUX: thanh ghi 8 bit dng chn in p tham chiu cho ADC, 1 trong 3 ngun in p tham chiu c th chn l : in p t chn VREF, in p tham chiu ni 2,56V hoc in p VCC theo bng sau:

ADCSRA (ADC Control and Status Register A): l thanh ghi iu khin hot ng v cha trng thi ca module ADC.

Bit 7 - ADEN(ADC Enable): vit gi tr 1 vo bit ny tc bn cho php module ADC c s dng. Tuy nhin khi ADEN=1 khng c ngha l ADC hot ng ngay, bn cn set mt bit khc ln 1 bt u qu trnh chuyn i, l bit ADSC. Bit 6 - ADSC(ADC Start Conversion): set bit ny ln 1 l bt u khi ng qu trnh chuyn i. Trong sut qu trnh chuyn i, bit ADSC s c gi nguyn gi tr 1, khi qu trnh chuyn i kt thc (t ng), bit ny s c tr v 0. V vy bn khng cn v cng khng nn vit gi tr 0 vo bit ny bt k tnh hung no. thc hin mt chuyn i, thng thng chng ta s set bit ADEN=1 trc v sau set ADSC=1. Bit 4 ADIF(ADC Interrupt Flag): c bo ngt. Khi mt chuyn i kt thc, bit ny t ng c set ln 1, v th ngi dng cn kim tra gi tr bit ny trc khi thc hin c gi tr chuyn i m bo qu trnh chuyn i thc s hon tt. Bit 3 ADIE(ADC Interrupt Enable): bit cho php ngt, nu bit ny c set bng 1 v bit cho php ngt ton cc (bit I trong thanh ghi trng thi ca chip) c set, mt ngt s xy ra khi mt qu trnh chuyn i ADC kt thc v cc gi tr chuyn i c cp nht (cc gi tr chuyn i cha trong 2 thanh ghi ADCL v ADCH). Bit 2:0 ADPS2:0(ADC Prescaler Select Bits): cc bit chn h s chia xung nhp cho ADC. ADC, cng nh tt c cc module khc trn AVR, cn c gi nhp bng mt ngun xung clock. Xung nhp ny c ly t ngun xung chnh ca chip thng qua mt h s chia. Cc bit ADPS cho php ngi dng chn h s chia t ngun clock chnh n ADC. Tham kho bng 4 bit cch chn h s chia. ADCL v ADCH (ADC Data Register): hai thanh ghi cha gi tr chuyn i. Do phn gii ca module ADC trn AVR l 10 bit nn cn hai thanh ghi cha gi tr chuyn i. Do tng hai thanh ghi l 16 bit nn bt ADLAR trong thanh ghi ADMUX quy nh cch ghi kt qu vo hai thanh ghi ny:ADLAR =0:

ADLAR =1:

d. Giao tip s dng I2C: Giao thc truyn thng n gin, ng bus ch cn hai dy scl v sda 7 bit a ch cho php ln ti 128 thit b slave. Tc truyn d liu ln ti 400kHz.

Giao tip I2C l mt ng dng h tr trong nhiu dng vi x l, n cho php thit k h thng kt ni ln n 128 thit b m ch cn hai dy bus, mt dy clock (scl) v mt dy data (sda).

Master: l chip khi ng qu trnh truyn nhn, pht i a ch ca thit b cn giao tip v to xung gi nhp trn ng SCL. Slave : l chip c a ch c nh, c gi bi master v phc v yu cu ca master. Cc thanh ghi s dng giao tip I2C trn AVR gm 5 thanh ghi gm c thanh ghi tc gi nhp TWBR, thanh ghi iu khin TWCR, thanh ghi trng thi TWSR, thanh ghi a ch TWAR, thanh ghi d liu TWDR. TWBR: quy nh tc pht xung gi nhp trn ng SCL ca chip master.

Tc xung gi nhp tnh theo cng thc:

TWBR : gi tr trong thanh ghi TWBRTWPS : gi tr hai bit TWPS1 v TWPS0 nm trong thanh thi trng thi TWSR TWCR: thanh ghi iu khin hot ng ca I2C:

Thanh ghi ny gm 8 bt iu khin cc hot ng ca I2C:

TWSR: thanh ghi trng thi 8 bit, trong c 5 bt cha code trng thi ca TWI v 3 bit la chn h s prescaler.

TWDR: thanh ghi d liu chnh ca TWI. Trong qu trnh nhn d liu c lu trong TWDR, trong qu trnh gi d liu s c ly v truyn trn ng SDA.

TWAR: