Codesign Methods and Tools Automatic Watering System Group 1: Busignani Fabio 197! Gianoglio E"anuele #$$$9$ %nno %ccade"ico #$1!&#$1' Vese1 root Actors Name Documentation Actor - User (ser is an adult person )ho uses the %uto"atic*+atering*,-ste". Actor - Technician Man Technician Man is a person )ho has technical s/ills 0or )hat concern the %uto"atic*+atering*,-ste". ,he&1e is able to repair the s-ste" substituting the sensors Actor - Soil ,oil is the terrain )here the %uto"atic*+atering*,-ste" "anages +atering Pu"p to dri2e the )atering pu"p. The s-ste" "easures the hu"idit- and decides i0 acti2ate the )atering or not. Actor - Air %ir is the en2iron"ent around the %uto"atic*+atering*,-ste". The s-ste" "easures the te"perature o0 the air in order to decide i0 acti2ate the )atering or not. Actor - Watering Pump Automatic Watering Project %uto"atic +atering Pro3ect consist in an %uto"atic*+atering*,-ste" that is con0igurable b- the (ser through an LC4 displaa-. The s-ste" dri2e the )atering pu"p through a rela- that is acti2e onl- )hen the (ser decide to start )atering or )hen the ti"e reach the hour set b- the (ser in the auto"atic "ode. The s-ste" start )atering a0ter ha2e 2eri0ied that the "oisture percentage in the soil is not too high. The s-ste" "oreo2er control the air te"perature and pro2ides all the data to the (ser through the LC4 displa-. (ser can interact )ith the s-ste" through a 5e-Pad )ith '6' /e- "atri6. Technician Man can act on the system to repair it and connect it. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 3 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 4 of 124 Vese1 root Use Case - Turn ON System (ser shi0t the s)itch in 78 position to turn on the %uto"atic*+atering*,-ste". Turn ON System The (ser acti2ate the s-ste" b- s)itching on the po)er suppl- s)itch. "ain9: initiali;es the peripherals and the LC4 sho)s the Principal Men<. The pro3ect is co"pletel- lin/ed through the 2arious "en< displa-ed b- the LC4. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 5 of 124 Vese1 root Use Case - Turn OFF System (ser shi0t s)itch in 7FF position to turn o00 the %uto"atic*+atering*,-ste". Turn OFF System (ser turn o00 the s-ste" b- s)itching o00 the po)er suppl-. Use Case - Configure System (ser= 0ollo)ing the instruction on LC4*'>#$ and through press9,+i: 0unction =)here ,+i is one o0 a"ong the 1? buttons o0 the 5e-Pad 90ro" $ to 9= 0ro" % to 4= @ and A:= is able to use and con0igure the %uto"atic*+atering*,-ste". It is possible to: B start )atering "anuall- B stop )atering "anuall- B enter in a "enu )here it is possible to: @ set ti"e @ turn on&o00 the auto"atic )atering @ set ti"e and duration o0 the )atering @ set hu"idit- and te"perature thresholds B read the current 2alues o0 soil hu"idit- and air te"perature
In all o0 the cases (ser can return to the pre2ious "enu b- pressing A. Use Case - Principal men The LC4*'>#$ sho)9string: the 0ollo)ing "enu on ' lines: ,tart +atering ,top +atering %uto". s-s. "en< 1u"&Te"p (ser press9,+i: ,+i on 5e-Pad to acti2ate the relati2e 0unctionalit-= in particular: ,+iC1$ 9%: calls use case ,tart )ateringD ,+iC11 9B: calls use case ,top )ateringD ,+iC1# 9C: calls use case %uto"atic s-ste" "enuD ,+iC1! 94: calls use case ,ho) hu"idit- and te"peratureD
(ser press9,+i: ,+i C 1E 9A: to return bac/ in the pre2ious "en<.
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 6 of 124 Vese1 root Principal enu This is the 0irst "enu that appears at the (ser on LC4 displa-. The (ser can decide ho) to na2igate it b- pressing one a"ong %=B=C or 4 on the /e-pad. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 7 of 124 Vese1 root Use Case - Stop !atering (ser orders the %uto"atic*+atering*,-ste" to turn o00 the +atering Pu"p )ithout an- 2eri0ication on the current 2alues o0 te"perature and hu"idit-. Stop !atering (ser has pressed button B 9/e-C11: in the Principal Men<= this "eans that the s-ste" is deacti2ated "anuall- and so the s) control i0 the rela- status is on and i0 this is the case= turn o00 it and stop to dri2e the )atering pu"p. %t the end o0 the operation the s-ste" returns in status $ 9principal "en< )aiting 0or a ne) press on /e-pad: Use Case - Start !atering (ser orders the %uto"atic*+atering*,-ste" to turn on the +atering Pu"p )ithout an- 2eri0ication on the current 2alues o0 te"perature and hu"idit-. Start !atering (ser has pressed button % 9/e-C1$: in the Principal Men<= this "eans that the s-ste" is acti2ated "anuall- and so the s) control i0 the rela- status is o00 and i0 this is the case= turn on it and dri2e the )atering pu"p. %t the end o0 the operation the s-ste" returns in status $ 9principal "en< )aiting 0or a ne) press on /e-pad: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 8 of 124 Vese1 root Use Case - S"o! "umi#ity an# temperature LC4*'>#$ sho)9string: to (ser t)o lines. In the 0irst line is sho)n the %ir te"perature "easured b- 9"odel ele"ent not 0ound: in the 0or"at F66 GCFD In the second line is sho)n the ,oil hu"idit- "easured b- Moisture,ensor in the 0or"at F66 HFD S"o! "umi#ity an# temperature (ser has pressed button 4 9/e-C1!: in the Principal Men<= this "eans that the s-ste" sho) on LC4 the current hu"idit- and te"perature. (ser can press A to return in the Principle "en< Vese1.docx - 2014-02-20 - 1:20 PM Pag. 9 of 124 Vese1 root Use Case - Automatic system menu LC4*'>#$ sho)9string: to (ser a ne) "en< )here it is possible to set the 0unctionalities o0 the auto"atic )atering li/e set ti"e= turn on and o00 the auto"atic )atering "ode= set ti"e and duration o0 the )atering and set hu"idit- thresholds abo2e that the s-ste" starts )atering b- acti2ating +atering Pu"p. Use Case - Settings men The LC4*'>#$ sho)9string: the 0ollo)ing "enu on ' lines: ,et ti"e %uto". s-s. 78&7FF +atering settings ,et 1u" thresh. (ser press9,+i: ,+i on 5e-Pad to acti2ate the relati2e 0unctionalit-= in particular: ,+iC1$ 9%: calls use case ,et ti"eD ,+iC11 9B: calls use case %uto"atic s-ste" 78&7FFD ,+iC1# 9C: calls use case +atering settingsD ,+iC1! 94: calls use case ,et hu"idit- thresholdsD
(ser press9,+i: ,+i C 1E 9A: to return bac/ in the pre2ious "en<.
Settings men (ser has pressed button C 9/e-C1#: in the Principal Men<= this "eans that the LC4 changes the displa-ed option and o00er a ne) list o0 possible action. (ser can na2igate it b- pressing %=B=C=4 or can return to the principle "en< b- pressing A Vese1.docx - 2014-02-20 - 1:20 PM Pag. 10 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 11 of 124 Vese1 root Use Case - Set time LC4*'>#$ sho)9string: the ti"e in 0or"at hh:"" (ser can set the current ti"e b- press9,+i: ,+i on 5e-Pad )ith ,+i 0ro" $ to 9 9nu"bers 0ro" $ to 9:. %t the 0irst press the user sets the "ost signi0icant digit o0 the hour= at the second press sets the last signi0icant digit o0 the hour. %t the third press the user sets the "ost signi0icant digit o0 the "inutes and at the 0ourth press sets the last signi0icant digit o0 the "inutes. Set time (ser has pressed %9/e-C1$: in the ,ettings "en<. (ser can set the ti"e b- pressing the digits on the /e-pad. ,+ trans0er the set ti"e to the ITCC that gi2e the ti"e re0erence to the s-ste". In an- "o"ent user can press A to return to the ,ettings "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 12 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 13 of 124 Vese1 root Use Case - Set "umi#ity t"res"ol#s LC4*'>#$ sho)9string: the hu"idit- in 0or"at 11 H (ser can set the )atering duration b- press9,+i: ,+i on 5e-Pad )ith ,+i 0ro" $ to 9 9nu"bers 0ro" $ to 9:. %t the 0irst press the user sets the "ost signi0icant digit o0 the hu"idit-= at the second press sets the last signi0icant digit o0 the hu"idit-. %0ter that 1u"idit-T1: unsigned char is set= LC4*'>#$ sho)9string: the 0ollo)ing string: F,etJ 11HF= in )hich 11 is substituted b- 1u"idit-T1: unsigned char current 2alue. Set "umi#ity t"res"ol#s (ser has pressed 4 9/e- C 1!: in the ,ettings "en<. (ser can set the hu"idit- threshold b- pressing the digits on the /e-pad. (ser can press A to return to the ,ettings "enu . Vese1.docx - 2014-02-20 - 1:20 PM Pag. 14 of 124 Vese1 root Use Case - Automatic system ON$OFF (ser can decide i0 the %uto"atic*+atering*,-ste" is able to turn on auto"aticall- the +atering Pu"p at the preBset hour b- chec/ing the te"perature and the hu"idit- or i0 the auto"atic s-ste" is turned 7FF. Use Case - Automatic system ON$OFF men The LC4*'>#$ sho)9string: the 0ollo)ing "enu on ' lines: %uto". s-s. 78 %uto". s-s. 7FF %ctual ,tatus (ser press9,+i: ,+i on 5e-Pad to acti2ate the relati2e 0unctionalit-= in particular: ,+iC1$ 9%: calls use case %uto"atic s-ste" 78D ,+iC11 9B: calls use case %uto"atic s-ste" 7FFD
(ser press9,+i: ,+i C 1E 9A: to return bac/ in the pre2ious "en<.
Automatic System ON$OFF men (ser has pressed B 9/e- C 11: in the ,ettings "en<. LC4 sho)s a ne) "en< )ere user can decide i0 press % or B to set the auto"atic s-ste" on or o00. (ser can press A to return to the ,ettings "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 15 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 16 of 124 Vese1 root Use Case - Automatic system OFF The %uto"atic*+atering*,-ste" is 7FF and isnKt able to control auto"aticall- +atering Pu"p. The )atering can be started onl- "anuall- )ith ,tart )atering. The LC4*'>#$ sho)9string: the 0ollo)ing string: F,tatus 7FFF Automatic system OFF (ser has pressed B 9/e- C 11: in the %uto"atic ,-ste" 78&7FF "en<. In this )a- the auto"atic s-ste" is acti2ated b- put %uto,tatusC$. This is a global 2ariable that is used b- the interrupt subroutine that control the auto"atic )atering. %t the end o0 the operation the s-ste" return in the pre2ious "en<. Use Case - Automatic system ON The %uto"atic*+atering*,-ste" is 78 and is able to control +atering Pu"p. The LC4*'>#$ sho)9string: the 0ollo)ing string: F,tatus 78F Automatic system ON (ser has pressed % 9/e- C 1$: in the %uto"atic ,-ste" 78&7FF "en<. In this )a- the auto"atic s-ste" is acti2ated b- put %uto,tatusC1. This is a global 2ariable that is used b- the interrupt subroutine that control the auto"atic )atering. %t the end o0 the operation the s-ste" return in the pre2ious "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 17 of 124 Vese1 root Use Case - Watering settings (ser can decide the hour at )hich the auto"atic s-ste" start )atering during the da- 9i0 there are properl- hu"idit- and te"perature conditions:= and the duration o0 the )atering. Use Case - Automatic system settings men The LC4*'>#$ sho)9string: the 0ollo)ing "enu on ' lines: +atering ti"e +atering duration (ser press9,+i: ,+i on 5e-Pad to acti2ate the relati2e 0unctionalit-= in particular: ,+iC1$ 9%: calls use case ,et )atering ti"eD ,+iC11 9B: calls use case ,et )atering durationD
(ser press9,+i: ,+i C 1E 9A: to return bac/ in the pre2ious "en<.
Automatic system settings men (ser has pressed C 9/e- C 1#: in the ,ettings "en<. LC4 sho)s a ne) "en< )ere user can decide i0 press % or B to set the )atering start ti"e and stop ti"e. (ser can press A to return to the ,ettings "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 18 of 124 Vese1 root Use Case - Set watering duration LC4*'>#$ sho)9string: the s)itchBo00 ti"e in 0or"at hh:"". (ser can set the )atering duration b- press9,+i: ,+i on 5e-Pad )ith ,+i 0ro" $ to 9 9nu"bers 0ro" $ to 9:. %t the 0irst press the user sets the "ost signi0icant digit o0 the hour= at the second press sets the last signi0icant digit o0 the hour. %t the third press the user sets the "ost signi0icant digit o0 the "inutes and at the 0ourth press sets the last signi0icant digit o0 the "inutes. Set !atering #uration (ser has pressed B9/e- C 11: in the %uto"atic s-ste" settings "en<. (ser can set the stop )atering ti"e b- pressing the digits on the /e-pad. This hour is sent to the ITCC that create an interrupt )hen that hour is reached. (ser can press A to return to the %uto"atic s-ste" settings "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 19 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 20 of 124 Vese1 root Use Case - Set !atering time LC4*'>#$ sho)9string: the ti"e in 0or"at hh:"" (ser can set the )atering ti"e b- press9,+i: ,+i on 5e-Pad )ith ,+i 0ro" $ to 9 9nu"bers 0ro" $ to 9:. %t the 0irst press the user sets the "ost signi0icant digit o0 the hour= at the second press sets the last signi0icant digit o0 the hour. %t the third press the user sets the "ost signi0icant digit o0 the "inutes and at the 0ourth press sets the last signi0icant digit o0 the "inutes. Set !atering time (ser has pressed % 9/e- C 1$: in the %uto"atic s-ste" settings "en<. (ser can set the start )atering ti"e b- pressing the digits on the /e-pad. This hour is sent to the ITCC that create an interrupt )hen that hour is reached. (ser can press A to return to the %uto"atic s-ste" settings "en<. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 21 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 22 of 124 Vese1 root Use Case - Sensor su%stitution Technician Man substitutes the bro/en sensor. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 23 of 124 Vese1 root Automatic Watering Project Class - oistureSensor&Ca%le It is a shielded cable co"posed b- ! )ires. 'eferences Type (alue URL http://vegetronix.com/Products/VG-WRE-SH3/ Tagge# (alues manufactorer Value Vegetronix Name Value VG-WRE-SH3 Cost Value 1.99 $/m Num%er of con#uctors Value 3 S"iel#e# Value Yes Vese1.docx - 2014-02-20 - 1:20 PM Pag. 24 of 124 Vese1 root a) Operating *oltage Value 300V Operations Signature: connect() This operation is e6ecuted b- Technician Man to connect ! pins )ith others three pins. Class - Po!er&Supply Po)er*,uppl- pro2ides the po)er that our s-ste"s needs. %t this class t)o attribute are associated: G84 LCC Attri%utes Signature Documentation -GND It is the electrical re0erence to $L. -VCC It is the electrical 2alue o0 2oltage suppl- and itKs eMual to EL. Class - Po!erOnCircuit Po)er7nCircuit is the part o0 circuit )hich interrupts the current co"ing 0ro" Po)er*,uppl-. +hen (ser )ants to turn on the s-ste"s uses the ,)itch= to shortCircuit9:. 7r= )hen (ser )ants to turn o00 the s-ste"s uses the ,)itch= to openCircuit9:.
The sche"atic 2ie) o0 this Po)er7nCircuit is the 0ollo)ing: Attri%utes Signature Documentation -SW2 : Switch Class - DS+,-./ It is a digital sensor )ith co""unicates )ith "icrocontroller= or an a general CP(= using 1+ire protocol.
The I&7 digital port o0 this co"ponent 94$9:: "ust to be connected )ith a pullup resistor= as sho)n in 0igure: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 25 of 124 Vese1 root 'eferences Type (alue URL http://www.newark.com/maxim-integrated-products/ds18b20/thermometer-prog- 12bit-3to92/dp/96K8885?ost=ds18b20&rpsku=DS18B20 URL http://www.farnell.com/datasheets/46379.pdf Tagge# (alues anufactorer Value MAXM NTEGRATED PRODUCTS Ne!ar0 Part No1 Value 96K8885 anufacturer Part No Value DS18B20+ 2C Output Type Value Digital No1 of Pins Value 3 Pac0aging Value TO - 92 'esolution 3-its4 Value 12 bit Sensing Accuracy 'ange Value 0.5C Sensing Temperature a) Value 125C Vese1.docx - 2014-02-20 - 1:20 PM Pag. 26 of 124 Vese1 root Sensing Temperature in Value -55C Supply Current Value 1mA Supply (oltage a) Value 5.5V Supply (oltage in Value 3V Cost Value 6.46$ Operations Signature: VDD() It is an electrical pin that has to be connected to L44 Signature: GND() It is an electrical pin that has to be connected )ith G84 Signature: D0() It is the digital pin that reali;e the I&7 serial port o0 4,1B#$. Signature: ShowTemperature_DS18B20() This operation allo)s the (ser to see the current 2alue o0 te"perature in the LC4*'>#$#. The algorith" that i"ple"ents this 0unction is sho)n belo): Vese1.docx - 2014-02-20 - 1:20 PM Pag. 27 of 124 Vese1 root Vese1.docx - 2014-02-20 - 1:20 PM Pag. 28 of 124 Vese1 root Code Body: if(!ResetPulse_OW()) //controlla la presenza del sensore, eseguendo anche un reset sulla linea { /***************************** Accesso al DS18B20 ******************************/ OW_write_byte(SKP_ROM_DS18B20); //salta la ricezione del ROM CODE, in quanto presente un solo sensore sul bus OW_write_byte(CONVERT_T_DS18B20); //invia la richiesta di conversione, il cui risultato posto in memoria del sensore delay_ms(750); //attesa conversione OW_reset_pulse(); //controllo presenza + reset sulla linea OW_write_byte(SKP_ROM_DS18B20); //salta ricezione ROM CODE OW_write_byte(READ_COMMAND_DS18B20); //invio richiesta di lettura, il sensore trasmette tutto il contenuto della sua memoria a partire da banco 0 fino a banco 9 /***************************** Acquisizione temperatura ******************************/ LSB=OW_read_byte(); //byte meno significativo temperatura (banco 0) MSB=OW_read_byte(); //byte pi significativo temperatura (banco 1)
if(MSB & 0x08) //controllo il bit di segno (1=temp negativa) { LSB = ~LSB; //complemento a 1 LSB MSB = ~MSB; //complemento a 1 MSB if(LSB == 0xFF) //verifico quando necessario sommare 1 all'MSB { //altrimenti sommo 1 aolo al byte meno significativo MSB = MSB +1; LSB = ~LSB; }else{ LSB = LSB +1; } WriteStringLCD("Temp. -"); }else{ WriteStringLCD("Temp. +"); } NTbin=(LSB>>4)|(MSB<<4)&0X3f; //contiene la sola parte intera senza segno 0 0 2^(5) 2^(4) 2^(3) 2^(2) 2^(1) 2^(0) DECbin=LSB<<4; //contiene la sola parte decimale 2^(-1) 2^(-2) 2^(-3) 2^(-4) 0 0 0 0 if(NTbin>100) //nel nostro caso con un and a 0x3f non si verifica tale condizione { //in quanto al max si pu arrivare a un numero intero = 63 NTbin/100; } /************************** Temperatura parte intera ***************************/ unita=NTbin%10; // esempio con 32C restituisce Vese1.docx - 2014-02-20 - 1:20 PM Pag. 29 of 124 Vese1 root 2 decine=NTbin/10; // 32/10 = 3 /***************************** Teperatura parte decimale *****************************/ dec=0; if (DECbin & 0x80) //si preleva da DECbin il solo valore 2^(-1), il quale se vale 1 si incrementa { //la variabile dec di 0.5 gradi dec=dec+5000; } if (DECbin & 0x40) //si preleva da DECbin il solo valore 2^(-2), il quale se vale 1 si incrementa { //la variabile dec di 0.25 gradi dec=dec+2500; } if (DECbin & 0x20) //si preleva da DECbin il solo valore 2^(-3), il quale se vale 1 si incrementa { //la variabile dec di 0.125 gradi dec=dec+1250; } if (DECbin & 0x10) //si preleva da DECbin il solo valore 2^(-4), il quale se vale 1 si incrementa { //la variabile dec di 0.0625 gradi dec=dec+625; } decimi=dec/1000; //esempio con dec = 4375 restituisce 4 centesimi=(dec%1000)/100; //4375 % 1000 = 375; 375/100 = 3 millesimi=(dec%100)/10; //4375 % 100 = 75; 75/10 = 7 decimill=dec%10; //4375 % 10 = 5 /******************************* Scrittura su display LCD ********************************/ WriteCharLCD(decine+0x30); //si somma 0x30 = 48 perch i caratteri WriteCharLCD(unita+0x30); //numerici iniziano da tale posizione (vedi Tabella Ascii) WriteStringLCD("."); WriteCharLCD(decimi+0x30); WriteCharLCD(centesimi+0x30); WriteCharLCD(millesimi+0x30); WriteCharLCD(decimill+0x30); }else{ WriteStringLCD ("18B20 assente "); GotoLineLCD(1); } GotoLineLCD(1); Signature: fixing() The 4,1B#$ is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo): Vese1.docx - 2014-02-20 - 1:20 PM Pag. 30 of 124 Vese1 root Signature: connection() Class - 'TCC This co"ponent reali;es a Ieal Ti"e Cloc/ Calendar. ,o= using the I#C protocol to co""unicate )ith it= a "icrocontroller can /no)s e2er- in0or"ation about the cloc/ and the calendar. Microcontroller can also set this attribute and the alar".
'eferences Type (alue URL http://it.farnell.com/nxp/pcf8563t-f4-112/ic-rtc-calendario-smd-8563- soic8/dp/8906130 URL http://www.farnell.com/datasheets/1696817.pdf Tagge# (alues anufactorer Value NXP Cost Value 1.36C Farnell Co#e Value 8906130 anufactorer Co#e Value PCF8563T/F4,112 Supply (oltage in Vese1.docx - 2014-02-20 - 1:20 PM Pag. 31 of 124 Vese1 root Value 1V Supply (oltage a) Value 5.5V Digital 2C Case Style Value SOC N1 of Pins Value 8 2C 2nterface Type Value 2C Operating Temperature in Value -40C Operating Temperature a) Value 85C Attri%utes Signature Documentation -BypassCapacitor_RTCC : SMD_Capacitor_0402 Operations Signature: OSC() It is an electrical pin associated )ith oscillator input. Signature: OSCO() It is an electrical pin associated )ith oscillator output. Signature: NT() It is a digital output )hich is nor"all- set at 2alue 1. +hen an alar" is generated inside the ITCC= this output port changes its 2alue. Signature: VSS() This electrical pin "ust to be connected )ith the ground re0erence o0 the circuit. Signature: VDD() This electrical pin has to be connected to L44 o0 the circuit. Signature: CLKOUT() This is an electrical output pin= in )hich cloc/ output is a2ailable. Signature: SCL() This is a digital pin )hich represents the serial cloc/ input o0 I#C co""unication. Signature: SDA() This is a digital pin )hich represents the serial data input and output o0 I#C co""unication. Signature: setMinutes_RTCC(minutes : unsigned char) : void This 0unction allo)s to set "inutes o0 the ITCC. "inutes ha2e to be e6pressed as t)o digits BC4 0or"at. Code Body: EEByteWrite (0xA2,0x03,minutes); Signature: setHours_RTCC(hours : unsigned char) : void This 0unction allo)s to set hours o0 the ITCC. hours ha2e to be e6pressed as t)o digits BC4 0or"at. Code Body: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 32 of 124 Vese1 root EEByteWrite (0xA2,0x04,hours); Signature: setDays_RTCC(days : unsigned char) : void This 0unction allo)s to set the da-s in ITCC. The da-s that has to be )ritten is e6press as t)o digits B4C 0or"at. Code Body: EEByteWrite (0xA2,0x05,days); Signature: setMonths_RTCC(months : unsigned char) : void This 0unction allo)s to )rite the "onths in the ITCC. The "onths is co"posed b- t)o digits BC4 0or"at. Code Body: EEByteWrite (0xA2,0x07,months); Signature: setYears_RTCC(years : unsigned char) : void This 0unction allo)s to set the -ears in ITCC. The -ears that has to be )ritten is e6press as t)o digits B4C 0or"at. For e6a"ple= #$1' is onl- $61'. Code Body: EEByteWrite (0xA2,0x08,years); Signature: setMinutes_Alarm_RTCC(minutes : unsigned char) : void This 0unction allo)s to )rite the "inutes 0or the alar" interrupt in the ITCC. The "inutes that has to be )ritten is e6pressed in t)o digit BC4 0or"at. Code Body: EEByteWrite (0xA2,0x09,minutes); Signature: setHours_Alarm_RTCC(hours : unsigned char) : void This 0unction allo)s to )rite the hours 0or the alar" interrupt in the ITCC. The hours that has to be )ritten is e6pressed in t)o digit BC4 0or"at. Code Body: EEByteWrite (0xA2,0x0A,hours); Signature: enableAlarm_RTCC() : void This 0unction enables the interrupt generated b- ITCC. Code Body: EEByteWrite (0xA2,0x01,0x02); Signature: disableAlarm_RTCC() : void This 0unction disables the interrupt generated b- ITCC. Code Body: EEByteWrite (0xA2,0x01,0x00); Signature: getMinutes_RTCC() : unsigned char This 0unction returns the 2ale o0 current "inutes in ITCC. Minutes are e6presses )ith t)o digits BC4 0or"at. Code Body: //initialize a temp variable for minutes unsigned char TempMinutes; TempMinutes = EERandomRead (0xA2,0x03); // because of the max value for the minutes is 59 = 0b01011001, //the MSB is a not significant bit. n order to be sure that its value //isn't read we use a mask return (TempMinutes && 0b01111111); Signature: getHour_RTCC() : unsigned char This 0unction returns the 2ale o0 current hours in ITCC. 1ours are e6presses )ith t)o digits BC4 0or"at. Code Body: //initialize a temp variable for hours unsigned char TempHours; TempHours = EERandomRead (0xA2,0x04); // because of the max value for the minutes is 24 = 0b00100100, //the first two bit are not significant bits. n order to be sure that its value //isn't read we use a mask return (TempHours && 0b00111111); Signature: getTime_RTCC() : unsigned char This 0unction returns the ti"e 0ro" the ITCC. The 0or"at is 11:MM. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 33 of 124 Vese1 root Code Body: /* we need two chars for hours (HH), * a char for ':'; * others two chars for minutes (MM) * and finally a char for termination '\0' * So, we need 6 chars: */ static unsigned char time[6]; unsigned char a; a = getHours_RTCC(); // with +48 convert the number in ASC number //first char is the units of minutes time[1] = (a & 0b00001111)+48; //the second char is the tens of minutes time[0] = (a >> 4)+48; //the third char is ':' time[2] = ':'; a = get_minutes_RTCC(); //the forth char is the units of hours time[4] = (a & 0b00001111)+48; //the fiveth char is the tens of hours time[3] = (a >> 4)+48; //the sixth and last char is the termination one time[5] = '\0'; return (time); Signature: getDays_RTCC() : unsigned char This 0unction returns the 2ale o0 current da-s in ITCC. 4a-s are e6presses )ith t)o digits BC4 0or"at. Code Body: //initialize a temp variable for days unsigned char TempDays; TempDays = EERandomRead (0xA2,0x05); // because of the max value for the minutes is 31 = 0b00110001, //the first two bit are not significant bits. n order to be sure that its value //isn't read we use a mask return (TempDays && 0b00111111); Signature: getMonths_RTCC() : unsigned char This 0unction returns the 2ale o0 current "onths in ITCC. Months are e6presses )ith t)o digits BC4 0or"at. Code Body: //initialize a temp variable for month unsigned char TempMonth; TempMonth = EERandomRead (0xA2,0x07); // because of the max value for the minutes is 12 = 0b00010010, //the first three bit are not significant bits. n order to be sure that its value //isn't read we use a mask return (TempMonth && 0b00011111); Signature: getYears_RTCC() : unsigned char This 0unction returns the 2ale o0 current -ears in ITCC. Nears are e6presses )ith t)o digits BC4 0or"at. Code Body: //initialize a temp variable for month unsigned char TempYears; TempYears = EERandomRead (0xA2,0x08); Vese1.docx - 2014-02-20 - 1:20 PM Pag. 34 of 124 Vese1 root return (TempYears); Signature: fixing() This co"ponent has to be soldered in sur0ace o0 PCB. The di"ensions o0 it are sho)n belo):
Class - +N5//5 It is a standard diode. In 0irst appro6i"ation 18'$$' is used as unidirectional conducti2e path. I0 the 2oltage applied to pin %9: is bigger than 2oltage applied to pin 59:= and their di00erence is also higher than 18'$$' threshold 2oltage= due to depleted region= so a current can 0lo) 0ro" %9: to 59:. 7ther)ise= the beha2ior o0 this co"ponent is eMual to an open circuit. 'eferences Type (alue URL http://http://it.farnell.com/multicomp/1n4004/diodo-standard-1a-400v-do- 41/dp/9565027 URL http://www.farnell.com/datasheets/574765.pdf Tagge# (alues anufactorer Value MULTCOMP Farnell Co#e Value 9565027 anufactre# Co#e Value 1N4004 Dio#e 6in# Value Standard Recovery 'epetiti*e 'e*erse (oltage (rrm a) Value 400V Vese1.docx - 2014-02-20 - 1:20 PM Pag. 35 of 124 Vese1 root For!ar# Current 2f Value 1A For!ar# (oltage (F a) Value 1V For!ar# Surge Current 2fsm a) Value 30A Pac0age Value DO-41 Operating Temperature min1 Value -65 Operating Temperature ma)1 Value 150 Operations Signature: A() It is the anode pin o0 18'$$'. Signature: K() It is the cathode pin o0 18'$$'. Signature: fixing() The i"age belo) sho)s ho) 18'$$' can be 0i6ed and its di"ension. The 0i6ing is through round hole. Class - Pus"%utton Pushbutton is a "echanical button that can be 0i6ing9: through hole. (ser can press9: it on the top side.
It has 0our electric contact C19:= C#9: = C!9: and C'9: in order to i"ple"ent open 9)hen released: and short 9)hen pressed: circuit bet)een the".
%s can be see b- the picture= the pair o0 contact C19:BC#9: and C!9: BC'9: are shortBcircuited bet)een the". ,o= 0ro" the logical point o0 2ie)= it has onl- t)o ter"inal. Comments Documentation C! is nor"all- closed and opens upon press9: Date Time nov 7, 2013 7:19:52 AM 'eferences Type (alue URL http://http://it.farnell.com/omron-electronic-components/b3f1105/interruttore-piatto- 6x6x4-3-260gf/dp/1960951 URL http://www.farnell.com/datasheets/611570.pdf Tagge# (alues anufacturer Value OMRON ELECTRONC COMPONENTS Farnell Co#e Value 1960951 anufacturer Part Num%er Value B3F1105 Cost Value C 0,198 a) *oltage Value 24V a) current Value 50ma Vese1.docx - 2014-02-20 - 1:20 PM Pag. 37 of 124 Vese1 root Sol#ering Value THT a) Operating temperatures37C4 Value 70C in Operating temperature37C4 Value -25C Operating Force Value 2.55N Contact resistance Value 100Mohm Operations Signature: press() (ser through press9: operation is able to press and release Pushbutton. +hen pressed the pair C19:BC#9: are short circuited to the pair C!9:BC'9:. +hen released this contact is open. Signature: C1() Electric ter"inal= scre) t-peD nor"all- at C!9:D shorts to C#9: )hen press9:D open other)ise. Signature: C2() Electric ter"inal= scre) t-peD nor"all- openD shorts to C19: )hen press9:D open other)ise. Signature: C3() Electric ter"inal= scre) t-peD nor"all- at C19: Dopen other)ise. Signature: C4() Electric ter"inal= scre) t-peD nor"all- at C19: Dopen other)ise. Signature: fixing() The i"age belo) sho)s ho) Pushbutton can be 0i6ed and its di"ension. The 0i6ing is through round hole. Class - 'esetCircuit IesetCircuit is the circuit sho)n belo).
This circuit i0 connected to "aster clear reset o0 MicroPIC*1F'E#$ allo)s the (ser to reset the s-ste" b- operation press9: o0 Pushbutton. Attri%utes Signature -PullUpResistor_RST : SMD_Resistor_1206 -SeriesResistor_RST : SMD_Resistor_0805 -BypassCapacitor_RST : SMD_Capacitor_0402 -SW1 : Pushbutton Operations Signature: VDD() L449: pin is an electrical pin that has to be connected to the L44 pin o0 the po)er suppl- connector Signature: GND() G849: pin is an electrical pin that has to be connected to the G84 pin o0 the po)er suppl- connector Signature: MCRST() MCI,T9: pin is an electrical pin that has to be connected to the "aster clear reset pin o0 MicroPIC*1F'E#$. Class - 8.09:&Oscillator !#/1;*7scillator is a co"ponents that uses the "echanical resonance o0 a Muart; to create an electrical signal )ith a 0reMuenc- eMual to !#.7? 51;. 'eferences Type (alue URL http://it.farnell.com/abracon/abs06-32-768khz-1-t/cristallo-32-768khz-12-5pf- smd/dp/2101344 URL http://www.abracon.com/Resonators/ABS06.pdf Tagge# (alues anufactorer Value ABRACON Vese1.docx - 2014-02-20 - 1:20 PM Pag. 39 of 124 Vese1 root Farnell Co#e Value 2101344 anufactorer Co#e Value ABS06-32.768KHZ-1-T Fre;uency Value 32.768kHz Fre;uency Tolerance< Value 10ppm =oa# Capacitance Value 12.5pF Operating Temperature in Value -40C Operating Temperature a) Value 85C Crystal ounting Type Value SMD Num%er of Pins Value 2 Attri%utes Signature Documentation -N it is the input pin o0 !#/1;*7scillator -OUT it is the output pin o0 !#/1;*7scillator Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture:
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 40 of 124 Vese1 root Class - Connector&+). For rela-It is a connector )hich has in a ro) t)o positions.
'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=1792766 URL http://www.farnell.com/datasheets/528137.pdf Tagge# (alues anufactorer Value PHOENX CONTACT Farnell Co#e Value 1792766 anufactorer Co#e Value MKDSN2,5/2-5.08 Vese1.docx - 2014-02-20 - 1:20 PM Pag. 41 of 124 Vese1 root Series Value MKDSN N1 of Contacts Value 2 Wire Si:e AW> in Value 24AWG Wire Si:e AW> a) Value 14AWG a) Operating Current Value 16A a) Operating (oltage Value 250Vac Operations Signature: connect() (sing a scre)dri2er Technician Man can connect an e6ternal )ire to PCB s-ste". Signature: pin1() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin2() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: fixing() The Connector*16# is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo):
Class - 6eyPa#Con#itioning 5e-PadConditioning is a circuit that allo) to read the button pressed on 5e-Pad through the adc: %4C. It is co"posed b- I1$: ,M4*Iesistor*$$E= I11: ,M4*Iesistor*$$E= I1#: ,M4*Iesistor*$$E= I1!: ,M4*Iesistor*$$E= I7: ,M4*Iesistor*$$E= I: ,M4*Iesistor*$$E= I9: ,M4*Iesistor*$$E that gi2e a di00erent analogue 2alue on pin 7(T9: in order to discri"inate the pressed button. The connection are sho)n in the 0igure abo2e. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 42 of 124 Vese1 root Attri%utes Signature -R7 : SMD_Resistor_0805 -R8 : SMD_Resistor_0805 -R9 : SMD_Resistor_0805 -R10 : SMD_Resistor_0805 -R11 : SMD_Resistor_0805 -R12 : SMD_Resistor_0805 -R13 : SMD_Resistor_0805 -connector : Connector_1x8 Operations Signature: readPressedButton() : unsigned char This 0unction returns )hat button is pressed 0ollo)ing this codi0ication: return $ i0 user pressed ,+1'D return 1 i0 user pressed ,+1D return # i0 user pressed ,+#D return ! i0 user pressed ,+!D return ' i0 user pressed ,+ED return E i0 user pressed ,+?D return ? i0 user pressed ,+7D return 7 i0 user pressed ,+9D return i0 user pressed ,+1$D return 9 i0 user pressed ,+11D return 1$ i0 user pressed ,+'D return 11 i0 user pressed ,+D return 1# i0 user pressed ,+1#D return 1! i0 user pressed ,+1?D return 1' i0 user pressed ,+1!D return 1E i0 user pressed ,+1ED Code Body: //Set AN0 as channel wich will be tied to ADC input SelectChannel_ADC(1); Vese1.docx - 2014-02-20 - 1:20 PM Pag. 43 of 124 Vese1 root //Start the convertion Convert_ADC(); //Wait until the convertion is done while(Busy_ADC()); //Read result of convertion unsigned int result; result = Read_ADC(); if (result<15) { return 1; } else if (esult<79) { return 4; } else if (result<145) { return 7; } else if (result<198) { return 14; } else if (result<257) { return 2; } else if (result<294) { return 5; } else if (result<334) { return 8; } else if (result<367) { return 0; } else if (result<420) { return 3; } else if (result<443) { return 6; } else if (result<469) { return 9; } else if (result<491) { return 15; } else if (result<524) { return 10; } else if (result<535) Vese1.docx - 2014-02-20 - 1:20 PM Pag. 44 of 124 Vese1 root { return 11; } else if (result<550) { return 12; } else if (result<575) { return 13; } else { return 20; } Signature: VDD() L449: pin is an electrical pin connected to the L44 pin o0 the po)er suppl- connector Signature: GND() G849: pin is an electrical pin connected to the G84 pin o0 the po)er suppl- connector Signature: OUT() 7(T9: pin is an electrical pin connected to %819: pin o0 the adc: %4C. Signature: C0() C$9: pin is an electrical pin connected toIo)19: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C1() C19: pin is an electrical pin connected toIo)#9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C2() C#9: pin is an electrical pin connected toIo)!9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C3() C!9: pin is an electrical pin connected toIo)'9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C4() C'9: pin is an electrical pin connected toCol19: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C5() CE9: pin is an electrical pin connected toCol#9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C6() C?9: pin is an electrical pin connected toCol!9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Signature: C7() C79: pin is an electrical pin connected toCol'9: pin o0 5e-Pad through the Connector*16 "ounted on PCB. Class - Connector&+), It is a connector header 0or PCB )hich has in a ro) eight connections. 'eferences Type (alue URL http://www.globalconnectortechnology.com/pcb-board-to-board/pdf/BG030.pdf URL http://it.farnell.com/global-connector-technology/bg030-08-a-0650-0300-n- g/board-board-connector-header-a/dp/1798955 Vese1.docx - 2014-02-20 - 1:20 PM Pag. 45 of 124 Vese1 root Tagge# (alues anufactorer Value GLOBAL CONNECTOR TECHNOLOGY Farnell co#e Value 1798955 anufactorer co#e Value BG030-08-A-0650-0300-N-G Cost Value 0.27C Pitc" Spacing Value 2.54mm N1 of 'o!s Value 1 N1 of Conctacts Value 8 Contact Termination Value Through Hole Vertical Contact Plating Value gold Contact aterial Value copper Operating Temperature a) Value 125 Operating Temperature in Value -55 Class - oistureSensor Moisture,ensor is a soil "oisture sensor na"ed L1'$$. It as be planted in the soil in order to "easure the soil hu"idit-. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 46 of 124 Vese1 root
ItKs an analog sensor )hich has three pins= that co""unicate )ith the s-ste" through a Moisture,ensor*Cable connected to the PCB e6ploiting a Connector*16!. These three pins are: Lcc9:= the 2oltage suppl- that it needsD G849:= the ground re0erenceD L79:= analog output pinD 'eferences Type (alue URL http://www.vegetronix.com/Products/Soil-Moisture-Sensor-Probes.phtml/ Tagge# (alues anufactorer Value Vegetronix Value VH400 Cost Value 37.95$ Operating *oltage min Value 3.3Vdc Operating *oltage ma) Value 20Vdc Po!er on to Output sta%le Vese1.docx - 2014-02-20 - 1:20 PM Pag. 47 of 124 Vese1 root Value 400 ms in1 operation temperature Value -40C a)1 operation temperature Value 85C Output (oltage min Value 0V Output (oltage ma) Value 3V a) current Value 7mA Attri%utes Signature Documentation -cable : MoistureSensor_Cable This is a Moisture,ensor*Cable that has one side soldered )ith Moisture,ensor. Operations Signature: readMoisture() : float This 0unction returns the 2alue o0 soil hu"idit- Code Body: //Set AN0 as channel wich will be tied to ADC input SelectChannel_ADC(0); //Start the convertion Convert_ADC(); //Wait until the convertion is done while(Busy_ADC()); //Read result of convertion unsigned int result; result = Read_ADC(); float humidity; humidity = (result*5)/1023; if(humidity<1.1) humidity= (humidity* 10) - 1; else if(humidity<1.3) humidity= (humidity*25) - 17.5; else if(humidity<1.82) humidity= (humidity*48.08) - 47.5; else humidity= (humidity*26.32) - 7.89; return humidity; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 48 of 124 Vese1 root Signature: Vcc() It is the input pin in )hich 2oltage suppl- has to be pro2ided. Its range 2alue is O!.! B #$P Ldc Signature: GND() It is an electrical pin in )hich ground re0erence is connected. Signature: VO() It is an analog output pin= its 2alue gi2e us an in0or"ation about soil "oisture. L79: 0ollo)s this 0igure in 0unction o0 "oisture:
This characteristic can be e6presses b- the 0ollo)ing eMuation: "oisture C 1$@L79:B1 i0 L79: is in the range O$ B 1.1PLD "oisture C #E@L79:B17.E i0 L79: is in the range O1.1 B 1.!PLD "oisture C '.$@L79:B'7.E i0 L79: is in the range O1.! B 1.#PLD "oisture C #?.!#@L79:B7.9 i0 L79: is in the range O1.# B !PLD Signature: fixing() Moisture,ensor is si"pl- planted in the soil. Its di"ension are sho)n in the 0ollo)ing 0igure:
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 49 of 124 Vese1 root Class - S!itc" It is an electrical co"ponent able to interrupt a current 0lo).
%s can be see in the 0ollo)ing 0igure= the ,)itch connects ter"inal c9: )ith or a9: or b9:= in 0unction o0 )here the (ser has i"posed. 'eferences Type (alue URL http://it.farnell.com/eao/09-03290-01/interruttore-spdt-co-0-5a-12v-pcb/dp/674345 URL http://www.farnell.com/datasheets/1683364.pdf Tagge# (alues anufactorer Value EAO Farnell Co#e Value 674345 anufactorer co#e Value 09-03290.01 Contact Configuration Value SPDT-CO Contact (oltage DC a) Value 12V Contact Current a) Value 500mA S!itc" ounting Vese1.docx - 2014-02-20 - 1:20 PM Pag. 50 of 124 Vese1 root Value THT Contact 'esistance Value 22Mohm Operating Temperature a) Value 85C Operating Temperature in Value -40C Series Value 1K2 S!itc"ing Po!er a) Value 6W Operations Signature: shortCircuit() Through this operation= ,)itch creates a conducti2e path bet)een c9: and b9:= )hile a9: is 0loating. Signature: openCircuit() Through this operation= ,)itch creates a conducti2e path bet)een c9: and a9:= )hile b9: is 0loating. Signature: a() Electrical pin o0 ,)itch. Signature: b() Electrical pin o0 ,)itch. Signature: c() Electrical pin o0 ,)itch. Signature: fixing() The ,)itch is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo): Class - Connector&+)8 It is a connector )hich has in a ro) three connections.
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 51 of 124 Vese1 root 'eferences Type (alue URL http://it.farnell.com/phoenix-contact/1714984/morsettiera-pcb-9-5mm-3- vie/dp/3704713 URL http://www.farnell.com/datasheets/100944.pdf Tagge# (alues anufactorer Value PHOENX CONTACT Farnell Co#e Value 3704713 anufactorer Co#e Value 1714984 Series Value MKDS Num%er of Contacts Value 3 Wire Si:e AW> in Value 24AWG Wire Si:e AW> a) Value 10AWG a) Operating Current Value 32A a) Operating (oltage Value 500Vac Vese1.docx - 2014-02-20 - 1:20 PM Pag. 52 of 124 Vese1 root ounting Type Value THT Connector Type Value Screw Operations Signature: connect() (sing a scre)dri2er Technician Man can connect an e6ternal )ire to PCB s-ste". Signature: fixing() The Connector*16! is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo):
Signature: pin1() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin2() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin3() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Class - =CD&5?./. It is an alphanu"eric LC4 displa-= in )hich seMuences o0 chars can be 2ie)ed.
'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2063162/ URL http://http://www.farnell.com/datasheets/1485434.pdf Tagge# (alues Name Value MC42004A6W-BNMLW Vese1.docx - 2014-02-20 - 1:20 PM Pag. 53 of 124 Vese1 root anufacturer Value MDAS Cost Value 15.56 C Num%er of Digitis $ Alp"a Value 80 C"aracter Count ) =ine Value 20x4 -ac0lig"ting Colour Value White C"aracter Si:e Value 2.30 x 4.03 mm (oltage Supply Value 5 V Display o#e Value Transmissive Display Area Value 22x60 mm Operating Temperature in Value -20 C Operating Temperature a) Value 70 C @)ternal (olume Value 47x77x14.5 mm 2llumination Colour Value Blue Vese1.docx - 2014-02-20 - 1:20 PM Pag. 54 of 124 Vese1 root 2nterface Value Parallel Operations Signature: Vss() It is an electrical pin that has to be connected to G84. Signature: Vcc() It is an electrical pin that has to be connected to Lcc. Signature: VO() It is an analog input pin )hich allo)s to dri2e the contrast o0 chars )ritten in LC4*'>#$#. Signature: RS() It is a digital input pin )hich reali;es the 0unction o0 register selection. I0 its 2alue is: $= Instruction register 90or )rite: Bus- 0lag :address counter 90or read:D 1= 4ata register 90or )rite and read:. Signature: RW() It is a digital input pin )hich reali;es the 0unction o0 read or )rite selection. I0 it is: $= )e reali;e a read operationD 1= )e reali;e a )rite operation.
Signature: E() It is the enable digital input pin: i0 it is asserted= LC4*'>#$# stars the read or )rite operation. Signature: D0() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. It is donKt used i0 'Bbit "ode is enabled. Signature: D1() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. It is donKt used i0 'Bbit "ode is enabled. Signature: D2() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. It is donKt used i0 'Bbit "ode is enabled. Signature: D3() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. It is donKt used i0 'Bbit "ode is enabled. Signature: D4() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. Signature: D5() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. Signature: D6() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. Signature: D7() It is a bidirectional tristate data bus pin= used 0or data trans0er and recei2e. Signature: VBp() It is an electrical pin= connected to anode o0 bac/lighting LE4. Signature: VBn() It is an electrical pin= connected to cathode o0 bac/lighting LE4. Signature: light() LC4*'>#$# e"its light )hen LBp9: is connected at a 2oltage greater that LE4 threshold and LBn9: is connected to ground. Signature: fixing() LC4*'>#$# can be 0i6ed b- a soldering in botto" la-er= or e6ploiting a Connector*16. The ph-sical di"ension o0 this hard)are co"ponent are sho)n in 0igure belo): Vese1.docx - 2014-02-20 - 1:20 PM Pag. 55 of 124 Vese1 root Signature: Open_LCD() : void This 0unction initiali;es the LC4*4ispla- to )or/ in ' bit "ode. Code Body: LCD_RS = 0x00; LCD_E = 0x00; LCD_RW = 0x00; __delay_ms (100); Send_LCD (0,0,1,1); __delay_ms (5); Send_LCD (0,0,1,1); __delay_ms (5); Send_LCD (0,0,1,1); __delay_ms (5); Send_LCD (0,0,1,0); Send_LCD (0,0,1,0); Send_LCD (1,0,0,0); Send_LCD (0,0,0,0); Send_LCD (1,1,1,0); CursorLCD (0,0); ClearLCD (); Signature: Send_LCD(D3 : unsigned char, D2 : unsigned char, D1 : unsigned char, D0 : unsigned char) : void %ccording to ' bit operation "ode o0 LC4*4ispla-= this 0unction send a ' bit co""and to LC4*4ispla- itsel0. Code Body: LCD_D0 = D0; LCD_D1 = D1; LCD_D2 = D2; LCD_D3 = D3; //Enable pulse LCD_E = 1; __delay_ms (1); LCD_E = 0; __delay_ms (1); Signature: Clear_LCD() : void This 0unction allo)s to clear the LC4*4ispla- 0ro" e2er- )ritten char. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 56 of 124 Vese1 root Code Body: Send_LCD (0,0,0,0); Send_LCD (0,0,0,1); Signature: Home_LCD() : void This 0unction "o2e the cursor at the 0irst ro) and 0irst colu"n o0 LC4*4ispla-. Signature: Shift_LCD(direction : char, shift : char) : void This 0unction shi0ts in the right or le0t direction 9according to direction 2alue: the chars )ritten on LC4*'>#$#. The a"ount o0 shi0ting is gi2en b- the 2alue o0 shi0t. direction can assu"e t)o 2alue: $= in order to ha2e a le0t shi0tD 1= in order to ha2e a right shi0t. shi0t speci0ies the nu"ber o0 shi0t operation that ha2e to be done. Code Body: //index of shifting operation char i; for (i=0; i < shift; i++) { Send_LCD (0,0,0,1); Send_LCD (1,direction,0,0); } Signature: ShiftCursor_LCD(direction : char, shift : char) : void E6ploiting this 0unction itKs possible to "o2e the actual position o0 the cursor. The "eaning o0 input para"eters are the sa"e )hich are e6pose in ,hi0t*LC49direction: char= shi0t: char:: 2oid. Code Body: //shifting index char i; for (i=0; i <shift; i++) { Send_LCD (0,0,0,1); Send_LCD (0,direction,0,0); } Signature: Line_LCD(line : char) : void This 0unction locates the LC4*'>#$# cursor on the selected line. line speci0ies the nu"ber o0 the line= and can assu"e the 0ollo)ing 2alue: 1= #= != '. Code Body: switch(line) { case 1: Send_LCD(1,0,0,0); Send_LCD(0,0,0,0); break; case 2: Send_LCD(1,1,0,0); Send_LCD(0,0,0,0); break; case 3: Send_LCD(1,0,0,1); Send_LCD(0,1,0,0); break; case 4: Send_LCD(1,1,0,1); Send_LCD(0,1,0,0); } Signature: WriteChar_LCD(a : unsigned char) : void This 0unction )rites a char to the LC4*'>#$#. The 2alue o0 a speci0ies the char to be sent. The 0unction accept %,CII integer or constants= such as KgK. Code Body: unsigned char D3,D2,D1,D0; LCD_RS = 1; // Splitting of the first nibble D3 = (a & 0b10000000) >> 7; D2 = (a & 0b01000000) >> 6; D1 = (a & 0b00100000) >> 5; D0 = (a & 0b00010000) >> 4; Send_LCD (D3,D2,D1,D0); Vese1.docx - 2014-02-20 - 1:20 PM Pag. 57 of 124 Vese1 root // Splitting of the second nibble D3 = (a & 0b00001000) >> 3; D2 = (a & 0b00000100) >> 2; D1 = (a & 0b00000010) >> 1; D0 = (a & 0b00000001); Send_LCD (D3,D2,D1,D0); LCD_RS = 0; Signature: WriteString_LCD(pointerToString : unsigned char) : void This 0unction )rites a string to the LC4*'>#$#. pointerTo,tring has to be a string= so it should to be inserted in the 0ollo)ing "ode: FstringF. Code Body: while(*pointerToString) { // Write character to LCD WriteChar_LCD(*pointerToString); pointerToString++; } Signature: Writent_LCD(value : unsigned int, digits : char) : void This 0unction )rites an unsigned integer 2alue to the LC4*'>#$#. digits is the nu"ber o0 sho)n digit. It can be assu"e the 0ollo)ing 2alue: $= 1= #= != '= E. I0: eMual to $= the unsigned integer 2alue is sho)n in LC4*'>#$# )ith a le0t 3usti0icationD eMual to 1 B E= the unsigned integer 2alue is sho)n in LC4*'>#$# )ith a right 3usti0ication and a nu"ber o0 digit eMual to digits. Code Body: // The maximum array size is 5 plus end of string \0 unsigned char nt_converted [6] = {0,0,0,0,0,0}; unsigned char i; itoa ((unsigned char*) nt_converted, value,10); if (digits >0 ) { nt_converted[digits] = '\0'; while (!(nt_converted[digits-1] <= '9' && nt_converted[digits-1] >= '0')) { for (i = digits-1; i > 0; i--) { nt_converted[i] = nt_converted[i-1]; nt_converted[i-1] = ' '; } } } writeString_LCD (nt_converted); Class - 'elay-oar# This part o0 circuit contains all the co"ponent used to dri2e the +atering Pu"p. It is co"posed o0: P8P*TransistorD 18'1E$D LE4D ,I4*Iela-D ,eriesIesistor*Iela-: ,M4*Iesistor*$$ED Connected as sho)n in 0igure: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 58 of 124 Vese1 root
Attri%utes Signature -DecouplingCapacitor_Relay : SMD_Electrolytic_Capacitor -SeriesResistor_Relay : SMD_Resistor_0805 -LedResistor_Relay : SMD_Resistor_0805 -relay : SRD_Relay Operations Signature: changeState_Relay() : void This 0unction change the status o0 ,I4*Iela- contacts. Code Body: //save the current status in a temp variable char stato = PORTAbits.RA3; PORTAbits.RA3 = ~stato; Signature: readStatus_Relay() : unsigned char This 0unctions allo)s to read the status o0 ,I4*Iela-. Code Body: return PORTAbits.RA3; Signature: N() This pin is the digital input o0 the Iela-Board. It "ust be dri2en b- MicroPIC*1F'E#$ and= )hen assert it change the status o0 rela-: ,I4*Iela- 0ro" its idle state to the e6cited state. Signature: VCC() This is the suppl- 2oltage pin. It "ust to be connected to LCC. Signature: GND() This is an electrical pin that "ust to be connected to G84 re0erence. Signature: OUT1() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Signature: OUT2() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Signature: OUT3() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Class - SD&@lectrolytic&Capacitor This /ind o0 Capacitor is characteri;ed b- ha2ing a ,M4 pac/age )ith standard 0or alu"inu" electrol-tic. The co"ponent sho)s as belo):
The capacitance 2alue o0 this capacitor is C F. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 59 of 124 Vese1 root 'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2068644 URL http://www.farnell.com/datasheets/1680956.pdf Tagge# (alues anufactorer Value KEMET Series Value KEMET - EDK Series Capacitance Value C [F] Tolerance Value 20% a) Operating (oltage Value 10V Pac0age Value SMD Operating Temperature in Value -40C Operating Temperature a) Value 85C Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 60 of 124 Vese1 root
+here 0or nu"erical di"ensions indicated b- letters re0er to datasheet. Class - SD&Capacitor&/,/A This /ind o0 Capacitor is characteri;ed b- ha2ing a ,M4 pac/age )ith standard $$E. The co"ponent sho)s as belo):
The capacitance 2alue o0 this capacitor is C F. 'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2370726 URL http://www.farnell.com/datasheets/1132289.pdf Tagge# (alues anufactorer Value YAGEO Pro#uct 'ange Value YAGEO - CC Series (alue Value C [F] Capacitance Tolerance Value +80%, -20% Dielectric Vese1.docx - 2014-02-20 - 1:20 PM Pag. 61 of 124 Vese1 root Value Y5V a)1 Operating (oltage Value 25 V a)1 Operating Temperature Value 85C in1 Operating Temperature Value -30C Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Class - SD&Capacitor&/B/8 This /ind o0 Capacitor is characteri;ed b- ha2ing a ,M4 pac/age )ith standard $?$!. The co"ponent sho)s as belo):
The capacitance 2alue o0 this capacitor is C F. 'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2310560 URL http://www.farnell.com/datasheets/1792107.pdf Vese1.docx - 2014-02-20 - 1:20 PM Pag. 62 of 124 Vese1 root Tagge# (alues anufacturer Value MULTCOMP (alue Value C Capacitance Tolerance Value 10 % Dielectric Value X7R a) operati*e *oltage Value 25 V Capacitor Case Style Value 0603 Operating Temperature in Value -55C Operating Temperature a) Value 125C Capacitor Terminals Value SMD Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Class - SD&Capacitor&/5/. This /ind o0 Capacitor is characteri;ed b- ha2ing a ,M4 pac/age )ith standard $$E. The co"ponent sho)s as belo): Vese1.docx - 2014-02-20 - 1:20 PM Pag. 63 of 124 Vese1 root
The capacitance 2alue o0 this capacitor is C F. 'eferences Type (alue URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2310495 URL http://http://www.farnell.com/datasheets/1792107.pdf Tagge# (alues Value MULTCOMP Series Value MULTCOMP - MC Series Tolerance Value 5% Capacitance Value C [V] Dielectric Value C0G / NP0 Capacitor Case Style Value 0402 a)1 Operati*e (oltage Value 50V Operating Temperature in Value -55C Operating Temperature a) Value 125C Pac0age Vese1.docx - 2014-02-20 - 1:20 PM Pag. 64 of 124 Vese1 root Value SMD Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Class - Capacitor Capacitor is a reacti2e electrical co"ponent that can store energ- in an electric 0ield. Is is used in "an- applications= such as 0ilter or decoupling. It can be pac/ed in di00erent "ode= as sho)n in 0igure:
Its principal electrical Muantit- is capacitance OFP. Operations Signature: A() Electrical pin o0 Capacitor. Signature: B() Electrical pin o0 Capacitor. Class - SD&'esistor&/,/A This is a /ind o0 Iesistor characteri;ed b- ha2ing ,M4 pac/age )ith standard $$E. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 65 of 124 Vese1 root 'eferences Type (alue URL http://www.farnell.com/datasheets/1755795.pdf URL http://it.farnell.com/vishay-draloric/crcw08051k00fkeahp/resistore-alimentazione- 0805-1/dp/1738959 URL http://it.farnell.com/te-connectivity/crgh0805f470r/resistore-alimentazione-470r- 0/dp/2332067RL URL http://it.farnell.com/te-connectivity/crgh0805f330r/resistore-alimentazione-330r- 0/dp/2332065RL URL http://it.farnell.com/te-connectivity/crgh0805f220r/resistore-alimentazione-220r- 0/dp/2332063 URL http://it.farnell.com/te-connectivity/crgh0805f100r/resistore-alimentazione-100r- 0/dp/2332058 URL http://it.farnell.com/te-connectivity/crgh0805f1k5/resistore-alimentazione-1k5-0- 33w/dp/2332074 Tagge# (alues anufactorer Value TE CONNECTVTY 'esistance (alue Value R ohm Series Value TE CONNECTVTY - CRG Series Po!er ma)1 Value 330mW 'esistance Tollerance Value 1% Pac0age Value 0805 Temperature Coefficient Value 200ppm/C a)1 Operating (oltage Value 150V in1 Operating Temperature Vese1.docx - 2014-02-20 - 1:20 PM Pag. 66 of 124 Vese1 root Value -55C a)1 Operating Temperature Value 155C Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Class - SD&'esistor&+./B This is a /ind o0 Iesistor characteri;ed b- ha2ing ,M4 pac/age )ith standard 1#$?. 'eferences Type (alue URL http://www.farnell.com/datasheets/1755795.pdf URL http://it.farnell.com/yageo-phycomp/rc1206fr-074k7l/resistore-4-7k-0-25w- 1/dp/9240985 URL http://it.farnell.com/multicomp/mc0125w12061110k/resistore-110k-0-125w-1- 1206-reel/dp/2129812 Tagge# (alues anufactorer Value TE CONNECTVTY 'esistance (alue Value R ohm Vese1.docx - 2014-02-20 - 1:20 PM Pag. 67 of 124 Vese1 root Series Value TE CONNECTVTY - CRG Series Value 330mW 'esistance Tollerance Value 1% Pac0age Value 1206 Temperature Coefficient Value 200ppm/C a)1 Operating (oltage Value 150V in1 Operating Temperature Value -55C a)1 Operating Temperature Value 155C Operations Signature: fixing() Co"ponent is soldered in sur0ace o0 PCB. Its di"ension is sho)n in 0ollo)ing picture: Class - 'esistor Iesistor is an electrical co"ponent )hich has I Q as resistance 2alue. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 68 of 124 Vese1 root Operations Signature: a() It is an electrical pin o0 Iesistor. Signature: b() It is an electrical pin o0 Iesistor. Class - ./6&TrimmingPotentiometer This is a tri""er potentio"eter that can be also used as a 2ariable resistor. The #$5*Tri""ingPotentio"eter presents bet)een %9: and B9:= al)a-s #$5oh" o0 resistance. +hile the resistance that can be see bet)een %9: and +9: or B9: and +9: is a 0unction o0 angle. (ser e6ploiting a scre)dri2er can "odi0- the angle 2alue in order to change the resistance ratio . 'eferences Type (alue URL http://it.farnell.com/bourns/tc33b-1-203e/trimming-potentiometer-20k/dp/1360925 URL http://www.farnell.com/datasheets/1520225.pdf Tagge# (alues anufactorer Value BOURNS Cost Value C 0,20 Farnell Co#e Value 1360925 anufactorer Co#e Value TC33B-1-203E Trac0 'esistance Value 20kohm 'esistance Tolerance Value 25% Temperature coeficient Value 250ppm/C Vese1.docx - 2014-02-20 - 1:20 PM Pag. 69 of 124 Vese1 root a) Po!er Value 10mW Potentiometer ounting Value SMD @n# 'esistance Value 400ohm Operating Temperature a) Value 100C Operating Temperature in Value -40C (oltage 'ating ma) Value 50V Operations Signature: fixing() The co"ponent has to be soldered in top la-er o0 PCB 0ollo)ing the distances sho)n belo): Signature: A() It is the pin associated to one side o0 the internal resistor end. Signature: B() It is the pin associated to one side o0 the internal resistor end. Signature: W() Vese1.docx - 2014-02-20 - 1:20 PM Pag. 70 of 124 Vese1 root It is the pin associated to the )iper o0 #$5*Tri""ingPotentio"eter. Signature: turn(angle) (ser e6ploiting an scre)dri2er can change the angle 2alue in order to change the resistance see bet)een %9:B+9: and B9:B+9:. Class - Connector&+)+B It is a 0e"ale connector 0or PCB )hich has in a ro) si6teen connections. 'eferences Type (alue URL http://it.farnell.com/samtec/bcs-116-l-s-te/contatto-2-54mm-vert-16- vie/dp/1667483 URL http://www.farnell.com/datasheets/81213.pdf Tagge# (alues anufactorer Value SAMTEC Farnell co#e Value 1667483 anufactorer co#e Value BCS-116-L-S-TE Pitc" Spacing Value 2.54mm N1 of 'o!s Value 1 N1 of Contacts Value 16 Value Through Hole Vertical Contact Plating Value gold Vese1.docx - 2014-02-20 - 1:20 PM Pag. 71 of 124 Vese1 root Contact aterial Value Phosphor Bronze a) Current Value 3A @)ternal Wi#t" Value 5.08mm =ea# Spacing Value 2.54mm Operating Temperature a) Value 125C Operating Temperature in Value -55C Operations Signature: pin1() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin2() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin3() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin4() It is a pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin5() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin6() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin7() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin8() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin9() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin10() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin11() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin12() Vese1.docx - 2014-02-20 - 1:20 PM Pag. 72 of 124 Vese1 root It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin13() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin14() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin15() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: pin16() It is an electrical pin o0 connector. It can be connected )ith e2er- other co"ponent through a conducti2e path in PCB= )hich starts 0ro" botto" la-er. Signature: fixing() The Connector*161? is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo): Signature: connect() Class - PC- PCB is a solid and hard "echanical support reali;ed in FIB' on )hich are "ounted and electricall- connected 9as sho)n in the sche"atic: all co"ponents. This PCB is co"posed b- # la-ers= the ,MT co"ponents are soldered in top one= )hile T1T co"ponents in botto" la-er.
and )ith ground plane in both botto" and top la-ers:
% !4BLie) o0 the PCB is also illustrated:
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 75 of 124 Vese1 root Attri%utes Signature -DecouplingCapacitance_uC_1 : SMD_Capacitor_0805 -DecouplingCapacitance_uC_2 : SMD_Capacitor_0805 -BypassCapacitance_uC_1 : SMD_Capacitor_0603 -BypassCapacitance_uC_2 : SMD_Capacitor_0603 -QuartzCapacitance_1 : SMD_Capacitor_0402 -QuartzCapacitance_2 : SMD_Capacitor_0402 -DecouplingCapacitance_Relay : SMD_Electrolytic_Capacitor Class - FlatCa%le FlatCable is a /ind o0 electrical cable that is both 0lat and 0le6ible. ItKs co"posed b- )ires. Operations Signature: connect() This operation allo)s the electrical connection bet)een pins to other e6ternal pins. Class - 6eyPa# 5e-Pad is a '6' /e- "atri6= )hich has output pins to distinguish the pressed /e-.
The beha2ioral o0 this co"ponent is the 0ollo)ing one: )hen the user presses a /e-= the co"ponent reali;es a shortBcircuit bet)een the correspondent colu"n and ro). For e6a"ple: Pressing ,+7= Col!9: and Io)#9: are connected. 'eferences Type (alue URL http://www.farnell.com/datasheets/523847.pdf URL http://it.farnell.com/jsp/search/productdetail.jsp?id=1171224 Tagge# (alues anufaturer Value APEM anufacturer Part Num%er Value AC3561 Cost Value 15.64 C 6eypa# atri) Vese1.docx - 2014-02-20 - 1:20 PM Pag. 77 of 124 Vese1 root Value 4x4 a) DC (oltage Value 30 V a) Current Value 100 mA 2nsulation 'esistance at +//( Value 100 MC a) Attuation Force Value 400 g in Operating Temperature Value -30 C a) Operating Temperature Value 55 C 6eyPa# Dimension Value 95x95 mm 6ey Diameter Value 0 Attri%utes Signature Documentation -KeyPad_Cable2 : FlatCable It is a FlatCable that has one side soldered in 5e-Pad. -SW1 It is a "echanical button o0 5e-Pad. -SW2 It is a "echanical button o0 5e-Pad. -SW3 It is a "echanical button o0 5e-Pad. -SW4 It is a "echanical button o0 5e-Pad. -SW5 It is a "echanical button o0 5e-Pad. -SW6 It is a "echanical button o0 5e-Pad. -SW7 It is a "echanical button o0 5e-Pad. -SW8 It is a "echanical button o0 5e-Pad. -SW9 It is a "echanical button o0 5e-Pad. -SW10 It is a "echanical button o0 5e-Pad. -SW11 It is a "echanical button o0 5e-Pad. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 78 of 124 Vese1 root -SW12 It is a "echanical button o0 5e-Pad. -SW13 It is a "echanical button o0 5e-Pad. -SW14 It is a "echanical button o0 5e-Pad. -SW15 It is a "echanical button o0 5e-Pad. -SW16 It is a "echanical button o0 5e-Pad. Operations Signature: Row1() Electric ter"inal: nor"all- opened and: shorts to Col19: )hen ,+1 is press9,+i:D shorts to Col#9: )hen ,+# is press9,+i:D shorts to Col!9: )hen ,+! is press9,+i:D shorts to Col'9: )hen ,+' is press9,+i:. Signature: Row2()
Electric ter"inal: nor"all- opened and: shorts to Col19: )hen ,+E is press9,+i:D shorts to Col#9: )hen ,+? is press9,+i:D shorts to Col!9: )hen ,+7 is press9,+i:D shorts to Col'9: )hen ,+ is press9,+i:. Signature: Row3()
Electric ter"inal: nor"all- opened and: shorts to Col19: )hen ,+9 is press9,+i:D shorts to Col#9: )hen ,+1$ is press9,+i:D shorts to Col!9: )hen ,+11 is press9,+i:D shorts to Col'9: )hen ,+1# is press9,+i:. Signature: Row4()
Electric ter"inal: nor"all- opened and: shorts to Col19: )hen ,+1! is press9,+i:D shorts to Col#9: )hen ,+1' is press9,+i:D shorts to Col!9: )hen ,+1E is press9,+i:D shorts to Col'9: )hen ,+1? is press9,+i:. Signature: Col1() Electric ter"inal: nor"all- opened and: shorts to Io)19: )hen ,+1 is press9,+i:D shorts to Io)#9: )hen ,+E is press9,+i:D shorts to Io)!9: )hen ,+9 is press9,+i:D shorts to Io)'9: )hen ,+1! is press9,+i:. Signature: Col2() Electric ter"inal: nor"all- opened and: shorts to Io)19: )hen ,+# is press9,+i:D shorts to Io)#9: )hen ,+? is press9,+i:D shorts to Io)!9: )hen ,+1$ is press9,+i:D shorts to Io)'9: )hen ,+1' is press9,+i:. Signature: Col3() Electric ter"inal: nor"all- opened and: shorts to Io)19: )hen ,+! is press9,+i:D shorts to Io)#9: )hen ,+7 is press9,+i:D shorts to Io)!9: )hen ,+11 is press9,+i:D shorts to Io)'9: )hen ,+1E is press9,+i:. Signature: Col4() Electric ter"inal: nor"all- opened and: shorts to Io)19: )hen ,+' is press9,+i:D shorts to Io)#9: )hen ,+ is press9,+i:D shorts to Io)!9: )hen ,+1# is press9,+i:D Vese1.docx - 2014-02-20 - 1:20 PM Pag. 79 of 124 Vese1 root shorts to Io)'9: )hen ,+1? is press9,+i:. Signature: press(SWi) (ser through press9,+i: operation is able to press and release the /e- corresponded to ,+i. +hen ,+i is pressed= the corresponding colu"n and ro) are shortBcircuited. Signature: fixing() : void 5e-Pad 0i6ing9:: 2oid is through a stic/- bac/ sur0ace. Class - icroP2C&+,F5A./ MicroPIC*1F'E#$ is a Bbit "icrocontroller Manu0acturer b- Microchip. It has a MIP, architecture CP( that can "anage his peripherals. Than/s to adc: %4C= it can be used in "i6ed signal s-ste"s.
The pin no"enclature is sho)n in 0ollo)ing picture= in )hich the order o0 pin and peripheral I&7 can be sho)n:
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 80 of 124 Vese1 root 'eferences Type (alue URL http://it.farnell.com/microchip/pic18f4520-i-pt/ic-mcu-8bit-pic18-40mhz- tqfp44/dp/1212703 URL http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf Tagge# (alues anufacturer Value Microchip Farnell Co#e Value 1212703 anufacturer Co#e Value PC18F4520-/PT Vese1.docx - 2014-02-20 - 1:20 PM Pag. 81 of 124 Vese1 root Program emory Si:e Value 32KB 'A emory Si:e Value 1.5KB CPU Spee# a) Value 40 MHz Num%er of 2$O Value 36 Case Style Value TQFP Num%er of Pins Value 44 @m%e##e# 2nterface Type Value EUSART, 2C, PSP, SP Supply (oltage in Value 4.2V Supply (oltage a) Value 5.5V Core Si:e Value 8bit @@P'O emory Si:e Value 256Byte Value 0.5mm Num%er of ADC 2nputs Value 13 Num%er of PW C"annels Value 5 Vese1.docx - 2014-02-20 - 1:20 PM Pag. 82 of 124 Vese1 root Num%er of Timers Value 4 Num%er of %it ADC Value 10 Operating Temperature a) Value 85C Operating Temperature in Value -40C Attri%utes Signature -PortA : ParallelPortA -PortB : ParallelPortB -PortC : ParallelPortC -PortD : ParallelPortD -PortE : ParallelPortE -adc : ADC -2C : 2C_Port_Master Operations Signature: fix() MicroPIC*1F'E#$ has to be 0i6ed on the sur0ace o0 PCB as sho)n in 0igure:
In )hich the distance are:
Vese1.docx - 2014-02-20 - 1:20 PM Pag. 83 of 124 Vese1 root Class - Automatic&Watering&System Attri%utes Signature Documentation -AutoStatus : unsigned char ItKs the 2ariable )hich indicates i0 the %uto"atic*+atering*,-ste" is in acti2e status or not. I0: eMual to $= %uto"atic s-ste" 7FFD eMual to 1= %uto"atic s-ste" 78. -HumidityTH : unsigned char This attribute indicates the 2alue o0 "oisture threshold. I0 the hu"idit- o0 soil is lo)er than 1u"idit-T1: unsigned char= the %uto"atic*+atering*,-ste" has to start the irrigation at gi2en hour. 7ther)ise the %uto"atic*+atering*,-ste" is stalled. -Minutes_Alarm_On : unsigned char -Minutes_Alarm_Off : unsigned char -Hours_Alarm_On : unsigned char -Hours_Alarm_Off : unsigned char Operations Signature: main() : void This 0unction is the core o0 )hole s-ste". ItKs i"ple"ents the 0inite state "achine )hich allo)s the (ser to control the %uto"atic*+atering*,-ste" Code Body: //variable unsigned char key = 20; float moisture = 0; unsigned char TempHours1 = 20; //contains the temp value of hour's tens unsigned char TempHours2 = 20; //contains the temp value of hour's unit unsigned char TempMinutes1 = 20; //contains the temp value of minute's tens unsigned char TempMinutes2 = 20; //contains the temp value of minute's tens unsigned char TempHumidity1 = 20;//contains the temp value of humidity's tens unsigned char TempHumidity2 = 20;//contains the temp value of humidity's tens // impost the direction of each pin drivern_PortA(0xFF); drivern_PortB(0x8F); drivern_PortC(0x7F); drivern_PortD(0x8F); drivern_PortE(0xFF); //ADC initialization init_ADC(); TurnON_ADC(); Vese1.docx - 2014-02-20 - 1:20 PM Pag. 84 of 124 Vese1 root //LCD initialization Open_LCD(); Clear_LCD(); //Enable PortB interrupt enablenterrupt_PortB(); //2C initialization Open2C(); //Turn-on the alarm generated by RTCC enableAlarm_RTCC(); //Turn-on the display Open_LCD(); WriteString_LCD("Welcome to"); Line_LCD(2); WriteString_LCD("Automatic Watering"); Line_LCD(3); WriteString_LCD("Systems"); __delay_ms(250); __delay_ms(250); __delay_ms(250); __delay_ms(250); int stato = 0 while(1) { switch(stato) { case 0 : /* Show the Home*/ Clear_LCD(); WriteString_LCD("A : Start Watering"); Line_LCD(2); WriteString_LCD("B : Stop Watering"); Line_LCD(3); WriteString_LCD("C : View Menu"); Line_LCD(4); WriteString_LCD("D : Show T/H"); key = readPressedButton(); while (key == 20) { key = readPressedButton(); } switch(key()) { case 10 : //f press A (10) then the irrigation is activated stato = 1; break; case 11 : //f press B (11) then the irrigation is deactivated stato = 2; break; case 12 : //f press C (12) then 'll see the control menu stato = 3; break; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 85 of 124 Vese1 root case 13 : //f press D (13) then 'll see the humidity vale and temperature one stato = 4; break; default : //se non premo nulla o altro resto nel mio stato iniziale stato = 0; break; } case 1 : //Avvio il sistema di irrigazione, nel display nulla cambia, solo il //led della rete di condizionamento del relay si accende if(!readStatus_Relay()) //prima controllo che il sistema sia spento changeState_Relay(); //se spento lo accendo stato = 0; //ritorno allo stato di partenza break; case 2: //Spegnimento del sistema di irrigazione, nel display nulla cambia, solo il //led della rete di condizionamento del relay si spegne if(readStatus_Relay()) //prima controllo che il sistema sia acceso changeState_Relay(); //se acceso lo spengo stato = 0; //ritorno allo stato di partenza break; case 3: //Sono nel sistema che controlla l'irrigazione automatica Clear_LCD(); WriteString_LCD("A : Set Time"); Line_LCD(2); WriteString_LCD("B : Auto. Sys. OnOff"); Line_LCD(3); WriteString_LCD("C : Settings"); Line_LCD(4); WriteString_LCD("D : Moisture Th"); key = readPressedButton(); while (key == 20) { key = readPressedButton(); } switch(key()) { case 10 : //se premo A (10) allora si passa al setting del time stato = 5; break; case 11 : //se premo B (11) allora si spegne o si accende il sistema di irrigazione automatico stato = 6; break; case 12 : //se premo C (12) allora vado a visualizzare il menu delle impostazioni stato = 7; break; case 13 : //se premo D (13) allora vado set humidity th. stato = 8; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 86 of 124 Vese1 root break; case 15 : //se premo il cancelletto (15) allora torno al menu di home stato = 0; break; default : //se non premo nulla o altro resto nel mio stato stato = 3; break; } case 4: //Vado a visualizzare l'umidit e la temperatura Clear_LCD(); //pulisco l'LCD WriteString_LCD("Moisture :"); Line_LCD(2); moisture = readMoisture(); WriteString_LCD(Moisture); Line_LCD(3); WriteString_LCD("Temperature :"); Line_LCD(4); ShowTemperature_DS18B20(); key = readPressedButton(); while (key == 20) { key = readPressedButton(); } //Controllo che sia stato o meno premuto il cancelletto (15) if(key() = 15) stato = 0; else stato = 4; break; case 5: //setting del time Clear_LCD(); WriteString_LCD("Setting Time"); Line_LCD(2); WriteString_LCD("HH:MM"); Line_LCD(2); //shift the cursor to the begin of the row TempHours1 = readPressedButton(); while(TempHours1 == 20) //ciclo while serve per aspettare che l'utente { //scriva qualche numero, nota, la funzione di read torna TempHours1 = readPressedButton(); //20 quando non si preme nulla } if(TempHours1 == 15) //controllo che non sia stato cliccato il cancelletto { stato = 3; break; } WritheChar_LCD(TempHours1); TempHours2 = readPressedButton(); while(TempHours2 == 20) { TempHours2 = readPressedButton(); } if(TempHours2 == 15) //controllo che non sia stato premuto il cancelletto { stato = 3; break; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 87 of 124 Vese1 root } WritheChar_LCD(TempHours2); TempMinutes1 = readPressedButton(); while(TempMinutes1 == 20) { TempMinutes1 = readPressedButton(); } if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto { stato = 3; break; } WritheChar_LCD(TempMinutes1); TempMinutes2 = readPressedButton(); while(TempMinutes2 == 20) { TempMinutes2 = readPressedButton(); } if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto { stato = 3; break; } WritheChar_LCD(TempMinutes2); // una volta ricevuti i dati vado a settare l'ora e i minuti TempHours1 = (TempHours1<<4) | TempHours2; setHours_RTCC(TempHours1); TempMinutes1 = (TempMinutes1<<4) | TempMinutes2; setMinutes_RTCC(TempMinutes1); Line_LCD(3); WriteString_LCD("Current Hour"); Line_LCD(4); WriteString_LCD(getTime_RTCC()); //feedback sull'ora corrente while(readPressedButton()!=15) { WriteString_LCD(getTime_RTCC()); //feedback sull'ora corrente } stato = 3; break; case 6: //on-off sistema automatico Clear_LCD(); WriteString_LCD("A : Auto. Sys. ON"); Line_LCD(2); WriteString_LCD("B : Auto. Sys. OFF"); Line_LCD(4); if(AutoStatus) WriteString_LCD("Status ON"); else WriteString_LCD("Status OFF"); key = readPressedButton(); while (key == 20) { key = readPressedButton(); } switch(key()) { case 10 : stato = 9; break; case 11 : stato = 10; break; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 88 of 124 Vese1 root case 15 : stato = 3; break; default : stato = 6; break; } case 7: //menu delle impostazioni Clear_LCD(); WriteString_LCD("A :Watering Time"); Line_LCD(2); WriteString_LCD("B :Watering Duration"); key = readPressedButton(); while (key == 20) { key = readPressedButton(); } switch(key()) { case 10 : stato = 11; break; case 11 : stato = 12; break; case 15 : stato = 3; break; default : stato = 7; break; } case 8: //set humidity th. Clear_LCD(); WriteString_LCD("Setting Moisture"); Line_LCD(2); WriteString_LCD("HH %"); Line_LCD(2); //shift the cursor to the begin of the row TempHumidity1 = readPressedButton(); while(TempHumidity1 == 20) //ciclo while serve per aspettare che l'utente { //scriva qualche numero, nota, la funzione di read torna TempHumidity1 = readPressedButton(); //20 quando non si preme nulla } if(TempHumidity1 == 15) //controllo che non sia stato cliccato il cancelletto { stato = 3; break; } WritheChar_LCD(TempHumidity1); TempHumidity2 = readPressedButton(); while(TempHumidity2 == 20) { TempHumidity2 = readPressedButton(); } if(TempHumidity2 == 15) //controllo che non sia stato premuto il cancelletto { stato = 3; break; } Vese1.docx - 2014-02-20 - 1:20 PM Pag. 89 of 124 Vese1 root WritheChar_LCD(TempHumidity2); TempHumidity1 = (TempHumidity1 << 4) | TempHumidity2; //now humidity threshold is stored in TempHumidity1 in BDC form HumidityTH = (((TempHumidity1 & 0xF0) >> 4) * 10) + (TempHumidity1 & 0x0F); // now humidity threshold is stored in HumidityTH in decimal form Line_LCD(4); WriteString_LCD("Set! "); Writent_LCD(HumidityTH,2); WriteChar_LCD('%'); while(readPressedButton()!=15); stato = 3; break; case 9: //attivo il sistema automatico AutoStatus = 1; Line_LCD(4); WriteString_LCD("Status ON"); __delay_ms(250); //one second of delay __delay_ms(250); __delay_ms(250); __delay_ms(250); stato = 6; break; case 10: //disattivo il sistema automatico AutoStatus = 0; Line_LCD(4); WriteString_LCD("Status OFF"); __delay_ms(250); //one second of delay __delay_ms(250); __delay_ms(250); __delay_ms(250); stato = 6; break; case 11: //Set Watering Time Clear_LCD(); WriteString_LCD("Watering Time"); Line_LCD(2); WriteString_LCD("HH:MM"); Line_LCD(2); //shift the cursor to the begin of the row TempHours1 = readPressedButton(); while(TempHours1 == 20) //ciclo while serve per aspettare che l'utente { //scriva qualche numero, nota, la funzione di read torna TempHours1 = readPressedButton(); //20 quando non si preme nulla } if(TempHours1 == 15) //controllo che non sia stato cliccato il cancelletto { stato = 7; break; } WritheChar_LCD(TempHours1); TempHours2 = readPressedButton(); while(TempHours2 == 20) { TempHours2 = readPressedButton(); } if(TempHours2 == 15) //controllo che non sia stato premuto il cancelletto Vese1.docx - 2014-02-20 - 1:20 PM Pag. 90 of 124 Vese1 root { stato = 7; break; } WritheChar_LCD(TempHours2); TempMinutes1 = readPressedButton(); while(TempMinutes1 == 20) { TempMinutes1 = readPressedButton(); } if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto { stato = 7; break; } WritheChar_LCD(TempMinutes1); TempMinutes2 = readPressedButton(); while(TempMinutes2 == 20) { TempMinutes2 = readPressedButton(); } if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto { stato = 7; break; } WritheChar_LCD(TempMinutes2); // una volta ricevuti i dati vado a settare l'ora e i minuti Hours_Alarm_On = (TempHours1<<4) | TempHours2; if(!readStatus_Realay()) //prima di andare a memorizzare l'ora nell'allarme vado a setHours_Alarm_RTCC(Hours_Alarm_On); //vedere che l'irrigazione non sia gia attiva, in quanto necessita dell'allarme per la durata Minutes_Alarm_On = (TempMinutes1<<4) | TempMinutes2; if(!readStatus_Realay()) setMinutes_Alarm_RTCC(Minutes_Alarm_On); while(readPressedButton()!=15); stato = 7; break case 12: //Set Watering Duration Clear_LCD(); WriteString_LCD("Watering Duration"); Line_LCD(2); WriteString_LCD("HH:MM"); Line_LCD(2); //shift the cursor to the begin of the row TempHours1 = readPressedButton(); while(TempHours1 == 20) //ciclo while serve per aspettare che l'utente { //scriva qualche numero, nota, la funzione di read torna TempHours1 = readPressedButton(); //20 quando non si preme nulla } if(TempHours1 == 15) //controllo che non sia stato cliccato il cancelletto { stato = 7; break; } WritheChar_LCD(TempHours1); TempHours2 = readPressedButton(); while(TempHours2 == 20) { TempHours2 = readPressedButton(); } if(TempHours2 == 15) //controllo che non sia stato premuto il cancelletto Vese1.docx - 2014-02-20 - 1:20 PM Pag. 91 of 124 Vese1 root { stato = 7; break; } WritheChar_LCD(TempHours2); TempMinutes1 = readPressedButton(); while(TempMinutes1 == 20) { TempMinutes1 = readPressedButton(); } if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto { stato = 7; break; } WritheChar_LCD(TempMinutes1); TempMinutes2 = readPressedButton(); while(TempMinutes2 == 20) { TempMinutes2 = readPressedButton(); } if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto { stato = 7; break; } WritheChar_LCD(TempMinutes2); // una volta ricevuti i dati vado a settare l'ora e i minuti Hours_Alarm_Off = (TempHours1<<4) | TempHours2; if(readStatus_Realay()) //prima di andare a memorizzare l'ora nell'allarme vado a setHours_Alarm_RTCC(Hours_Alarm_Off); //vedere che l'irrigazione non sia gia attiva, in quanto necessita dell'allarme per la durata Minutes_Alarm_Off = (TempMinutes1<<4) | TempMinutes2; if(readStatus_Realay()) setMinutes_Alarm_RTCC(Minutes_Alarm_Off); while(readPressedButton()!=15); stato = 7; break } } Signature: high_interrupt() : void This 0unction contains the bod- o0 high le2el interrupt. Because o0 in MicroPIC*1F'E#$ 0a"il-= there is a li"ited place dedicated to this /ind o0 interrupt= this 0unction contains onl- a operation: an unconditional 3u"p to another 0unction 9PortB*interrupt*isr9:: 2oid:. Code Body: _asm GOTO PortB_interrupt_isr _endasm Signature: PortB_interrupt_isr() : void This 0unction contains the beha2ior )hich the MicroPIC*1F'E#$ has to do= )hen an alar" b- ITCC is generated. Code Body: if(checknterrupt_PortB()) { if(PORTBbits.RB0 == 0) //check that interrupt on portB is due to a negative edge in RB0 { disablenterrupt_PortB(); if(AutoStatus) //check if automatic system is set { if(readStatus_Relay()) //if the irrigation is already on { changeState_Relay(); //turn-off the irrigation setHours_Alarm_RTCC(Hours_Alarm_On); setMinutes_Alarm_RTCC(Minutes_Alarm_On); } else //if the irrigation is off { float moisture = readMoisture(); //read the actual value of moisture Vese1.docx - 2014-02-20 - 1:20 PM Pag. 92 of 124 Vese1 root if(moisture < ((float) HumidityTH) //if it is lower than TH { changeState_Relay(); //turn-on the irrigation setHours_Alarm_RTCC(Hours_Alarm_Off); setMinutes_Alarm_RTCC(Minutes_Alarm_Off); } } } } enablenterrupt_PortB(); clearnterrupt_PortB(); } Automatic&Watering&System Vese1.docx - 2014-02-20 - 1:20 PM Pag. 93 of 124 Vese1 root icroP2C&+,F5A./ Class - ParallelPortC ParallelPortC is a ParallelPort )hich has the 0ollo)ing operations: dri2erIn*PortC9pins: unsigned char:: 2oid= to decide the direction o0 each pin belonging to ParallelPortC itsel0. read*PortC9pin: unsigned char:: unsigned char= to read the logic 2alue pro2ided as an input o0 a speci0icpino0 ParallelPortC itsel0. )rite*PortC9pin: unsigned char= pin,tatus: unsigned char:: 2oid= to )rite in the speci0ied pin the 2alue indicates b- pin,tatus Operations Signature: drivern_PortC(pins : unsigned char) : void ,ets pin direction o0 ParallelPortC to be input. Each bit o0 argu"ent pins is associated )ith a pin o0 the ParallelPortCD bit $&1&#.. o0 pins corresponds )ith bit $&1&#... o0 ParallelPortC respecti2el-. The pin is set to input i0 the corresponding bit o0 pins is set to 1D output other)ise. Code Body: TRSC = bits; Signature: read_PortC(pin : unsigned char) : unsigned char Ieturns 1 9respecti2el-= $: i0 the 2alue o0 the pin= )hose inde6 9$ to 7: is gi2en b- argu"ent pin= is 1 9respecti2el- $:. Code Body: switch(pin) { case 0 : return PORTCbits.RC0; break; case 1 : Vese1.docx - 2014-02-20 - 1:20 PM Pag. 94 of 124 Vese1 root return PORTCbits.RC1; break; case 2 : return PORTCbits.RC2; break; case 3 : return PORTCbits.RC3; break; case 4 : return PORTCbits.RC4; break; case 5 : return PORTCbits.RC5; break; case 6 : return PORTCbits.RC6; break; case 7 : return PORTCbits.RC7; break; } Signature: write_PortC(pin : unsigned char, pinStatus : unsigned char) : void +rite the 2alue o0 pin,tatus on pin Code Body: switch(pin) { case 0 : PORTCbits.RC0 = pinStatus; break; case 1 : PORTCbits.RC1 = pinStatus; break; case 2 : PORTCbits.RC2 = pinStatus;; break; case 3 : PORTCbits.RC3 = pinStatus;; break; case 4 : PORTCbits.RC4 = pinStatus;; break; case 5 : PORTCbits.RC5 = pinStatus;; break; case 6 : PORTCbits.RC6 = pinStatus;; break; case 7 : PORTCbits.RC7 = pinStatus;; break; } Class - ParallelPort@ ParallelPortE is a ParallelPort )hich has the 0ollo)ing operations: dri2erIn*PortE9pins: unsigned char:: 2oid= to decide the direction o0 each pin belonging to ParallelPortE itsel0. read*PortE9pin: unsigned char:: unsigned char= to read the logic 2alue pro2ided as an input o0 a speci0ic pin o0 ParallelPortE itsel0. )rite*PortE9pin: unsigned char= pin,tatus: unsigned char:: 2oid= to )rite in the speci0ied pin the 2alue indicates b- pin,tatus Operations Signature: drivern_PortE(pins : unsigned char) : void Vese1.docx - 2014-02-20 - 1:20 PM Pag. 95 of 124 Vese1 root ,ets pin direction o0 ParallelPortE to be input. Each bit o0 argu"ent pins is associated )ith a pin o0 the ParallelPortED bit $&1&#.. o0 pins corresponds )ith bit $&1&#... o0 ParallelPortE respecti2el-. The pin is set to input i0 the corresponding bit o0 pins is set to 1D output other)ise. Code Body: TRSE = bits; Signature: read_PortE(pin : unsigned char) : unsigned char Ieturns 1 9respecti2el-= $: i0 the 2alue o0 the pin= )hose inde6 9$ to 7: is gi2en b- argu"ent pin= is 1 9respecti2el- $:. Code Body: switch(pin) { case 0 : return PORTEbits.RE0; break; case 1 : return PORTEbits.RE1; break; case 2 : return PORTEbits.RE2; break; case 3 : return PORTEbits.RE3; break; case 4 : return PORTEbits.RE4; break; case 5 : return PORTEbits.RE5; break; case 6 : return PORTEbits.RE6; break; case 7 :e return PORTEbits.RE7; break; } Signature: write_PortE(pin : unsigned char, pinStatus : unsigned char) : void +rite the 2alue o0 pin,tatus on pin Code Body: switch(pin) { case 0 : PORTEbits.RE0 = pinStatus; break; case 1 : PORTEbits.RE1 = pinStatus; break; case 2 : PORTEbits.RE2 = pinStatus;; break; case 3 : PORTEbits.RE3 = pinStatus;; break; case 4 : PORTEbits.RE4 = pinStatus;; break; case 5 : PORTEbits.RE5 = pinStatus;; break; case 6 : PORTEbits.RE6 = pinStatus;; break; case 7 : PORTEbits.RE7 = pinStatus;; break; } Vese1.docx - 2014-02-20 - 1:20 PM Pag. 96 of 124 Vese1 root Class - ParallelPortD ParallelPort4 is a ParallelPort )hich has the 0ollo)ing operations: dri2erIn*Port49pins: unsigned char:: 2oid= to decide the direction o0 each pin belonging to ParallelPort4 itsel0. read*Port49pin: unsigned char:: unsigned char= to read the logic 2alue pro2ided as an input o0 a speci0ic pin o0 ParallelPort4 itsel0. )rite*Port49pin: unsigned char= pin,tatus: unsigned char:: 2oid= to )rite in the speci0ied pin the 2alue indicates b- pin,tatus Operations Signature: drivern_PortD(pins : unsigned char) : void ,ets pin direction o0 ParallelPort4 to be input. Each bit o0 argu"ent pins is associated )ith a pin o0 the ParallelPort4D bit $&1&#.. o0 pins corresponds )ith bit $&1&#... o0 ParallelPort4 respecti2el-. The pin is set to input i0 the corresponding bit o0 pins is set to 1D output other)ise. Code Body: TRSD = bits; Signature: read_PortD(pin : unsigned char) : unsigned char Ieturns 1 9respecti2el-= $: i0 the 2alue o0 the pin= )hose inde6 9$ to 7: is gi2en b- argu"ent pin= is 1 9respecti2el- $:. Code Body: switch(pin) { case 0 : return PORTDbits.RD0; break; case 1 : return PORTDbits.RD1; break; case 2 : return PORTDbits.RD2; break; case 3 : return PORTDbits.RD3; break; case 4 : return PORTDbits.RD4; break; case 5 : return PORTDbits.RD5; break; case 6 : return PORTDbits.RD6; break; case 7 : return PORTDbits.RD7; break; } Signature: write_PortD(pin : unsigned char, pinStatus : unsigned char) : void +rite the 2alue o0 pin,tatus on pin Code Body: switch(pin) { case 0 : PORTDbits.RD0 = pinStatus; break; case 1 : PORTDbits.RD1 = pinStatus; break; case 2 : PORTDbits.RD2 = pinStatus;; break; case 3 : PORTDbits.RD3 = pinStatus;; break; case 4 : PORTDbits.RD4 = pinStatus;; break; case 5 : Vese1.docx - 2014-02-20 - 1:20 PM Pag. 97 of 124 Vese1 root PORTDbits.RD5 = pinStatus;; break; case 6 : PORTDbits.RD6 = pinStatus;; break; case 7 : PORTDbits.RD7 = pinStatus;; break; } Class - ParallelPortA ParallelPort% is a ParallelPort )hich has the 0ollo)ing operations: dri2erIn*Port%9pins: unsigned char:: 2oid= to decide the direction o0 each pin belonging to ParallelPort% itsel0. read*Port%9pin: unsigned char:: unsigned char= to read the logic 2alue pro2ided as an input o0 a speci0ic pin o0 ParallelPort% itsel0. )rite*Port%9pin: unsigned char= pin,tatus: unsigned char:: 2oid= to )rite in the speci0ied pin the 2alue indicates b- pin,tatus Operations Signature: drivern_PortA(pins : unsigned char) : void ,ets pin direction o0 ParallelPort% to be input. Each bit o0 argu"ent pins is associated )ith a pin o0 the ParallelPort%D bit $&1&#.. o0 pins corresponds )ith bit $&1&#... o0 ParallelPort% respecti2el-. The pin is set to input i0 the corresponding bit o0 pins is set to 1D output other)ise. Code Body: TRSA = bits; Signature: read_PortA(pin : unsigned char) : unsigned char Ieturns 1 9respecti2el-= $: i0 the 2alue o0 the pin= )hose inde6 9$ to 7: is gi2en b- argu"ent pin= is 1 9respecti2el- $:. Code Body: switch(pin) { case 0 : return PORTAbits.RA0; break; case 1 : return PORTAbits.RA1; break; case 2 : return PORTAbits.RA2; break; case 3 : return PORTAbits.RA3; break; case 4 : return PORTAbits.RA4; break; case 5 : return PORTAbits.RA5; break; case 6 : return PORTAbits.RA6; break; case 7 : return PORTAbits.RA7; break; } Signature: write_PortA(pin : unsigned char, pinStatus : unsigned char) : void +rite the 2alue o0 pin,tatus on pin Code Body: switch(pin) { case 0 : PORTAbits.RA0 = pinStatus; break; case 1 : PORTAbits.RA1 = pinStatus; break; Vese1.docx - 2014-02-20 - 1:20 PM Pag. 98 of 124 Vese1 root case 2 : PORTAbits.RA2 = pinStatus;; break; case 3 : PORTAbits.RA3 = pinStatus;; break; case 4 : PORTAbits.RA4 = pinStatus;; break; case 5 : PORTAbits.RA5 = pinStatus;; break; case 6 : PORTAbits.RA6 = pinStatus;; break; case 7 : PORTAbits.RA7 = pinStatus;; break; } Class - ParallelPort- ParallelPortB is a ParallelPort )hich has the 0ollo)ing operations: dri2erIn*PortB9pins: unsigned char:: 2oid= to decide the direction o0 each pin belonging to ParallelPortB itsel0. read*PortB9pin: unsigned char:: unsigned char= to read the logic 2alue pro2ided as an input o0 a speci0ic pin o0 ParallelPortB itsel0. )rite*PortB9pin: unsigned char= pin,tatus: unsigned char:: 2oid= to )rite in the speci0ied pin the 2alue indicates b- pin,tatus In addiction to those= ParallelPortB has three pin 9B$9:= B19:= and B#9:: that can detect the input e2ent in order to generate an interrupt. To do this= ParallelPortB has the 0ollo)ing operations: enableInterrupt*PortB9:: 2oid to enable this /ind o0 interrupt as high le2el interruptD chec/Interrupt*PortB9:: unsigned char= to chec/ i0 interrupt is in2ol2ed because o0 e2ent on ParallelPortBD clearInterrupt*PortB9:: 2oid= to reset the interrupt 0lag due to e2ent on ParallelPortBD disableInterrupt*PortB9:: 2oid= to disable the interrupt due to e2ent on ParallelPortB. Operations Signature: drivern_PortB(pins : unsigned char) : void ,ets pin direction o0 ParallelPortB to be input. Each bit o0 argu"ent pins is associated )ith a pin o0 the ParallelPortBD bit $&1&#.. o0 pins corresponds )ith bit $&1&#... o0 ParallelPortB respecti2el-. The pin is set to input i0 the corresponding bit o0 pins is set to 1D output other)ise. Code Body: TRSB = bits; Signature: read_PortB(pin : unsigned char) : unsigned char Ieturns 1 9respecti2el-= $: i0 the 2alue o0 the pin= )hose inde6 9$ to 7: is gi2en b- argu"ent pin= is 1 9respecti2el- $:. Code Body: switch(pin) { case 0 : return PORTBbits.RB0; break; case 1 : return PORTBbits.RB1; break; case 2 : return PORTBbits.RB2; break; case 3 : return PORTBbits.RB3; break; case 4 : return PORTBbits.RB4; break; case 5 : return PORTBbits.RB5; break; case 6 : Vese1.docx - 2014-02-20 - 1:20 PM Pag. 99 of 124 Vese1 root return PORTBbits.RB6; break; case 7 : return PORTBbits.RB7; break; } Signature: write_PortB(pin : unsigned char, pinStatus : unsigned char) : void +rite the 2alue o0 pin,tatus on pin Code Body: switch(pin) { case 0 : PORTBbits.RB0 = pinStatus; break; case 1 : PORTBbits.RB1 = pinStatus; break; case 2 : PORTBbits.RB2 = pinStatus;; break; case 3 : PORTBbits.RB3 = pinStatus;; break; case 4 : PORTBbits.RB4 = pinStatus;; break; case 5 : PORTBbits.RB5 = pinStatus;; break; case 6 : PORTBbits.RB6 = pinStatus;; break; case 7 : PORTBbits.RB7 = pinStatus;; break; } Signature: enablenterrupt_PortB() : void This 0unction enables the interrupt generated b- ParallelPortB. In particular= e2er- input e2ent on B$9:= B19:= and B#9: o0 ParallelPortB generates an high le2el interrupt. MicroPIC*1F'E#$ allo)s the nesting interrupt= and has t)o le2el o0 that. Code Body: NTCONbits.RBE = 1; NTCON2bits.RBP = 1; NTCONbits.PEE = 1; Signature: checknterrupt_PortB() : unsigned char This 0unction chec/ i0 interrupt is in2ol2ed because o0 e2ent on ParallelPortB. Code Body: return NTCONbits.RBF; Signature: clearnterrupt_PortB() : void This 0unction reset the interrupt 0lag due to e2ent on ParallelPortB= in order to be read- to ser2e the ne6t interrupt. Code Body: NTCONbits.RBF = 0; Signature: disablenterrupt_PortB() : void This 0unction disable the interrupt due to e2ent on ParallelPortB. Code Body: NTCONbits.RBE = 0; Class - +WirePort&aster It is the "aster side o0 an 1B+ire co""unication. 1B+ire is bus protocol that i"ple"ents bus co""unication using 3ust one port: 7+*Port9:. 1+irePort*Master dri2es this control signal= the operation that it can per0or" are: +riteBit*7+9bit: unsigned char:: 2oid= to trans"it a single bit to sla2e de2iceD +riteB-te*7+9data: unsigned char:: 2oid= to trans"it a single b-te to sla2e de2iceD IesetPulse*7+9:: unsigned char= to trans"it a reset pulse to sla2e de2iceD Iead*7+9:: unsigned char= to con0igure as Input pin and Iead the status o0 7+*Port9:D IeadBit*7+9:: unsigned char= to read a bit sent b- sla2e de2iceD IeadB-te*7+9:: unsigned char= to read a b-te sent b- sla2e de2iceD Vese1.docx - 2014-02-20 - 1:20 PM Pag. 100 of 124 Vese1 root Operations Signature: WriteByte_OW(data : unsigned char) : void This 0unction used to trans"it a co"plete b-te to sla2e de2ice through the 7+*Port9:. Code Body: unsigned char i; for (i = 0; i < 8; i++) { WriteBit_OW(data & 0x01); //Sending LS-bit first data >>= 1; // shift the data byte for the next bit to send } Signature: ResetPulse_OW() : unsigned char Initiali;ation seMuence start )ith reset pulse. IesetPulse*7+9:: unsigned char generates reset seMuence as per the protocol. This 0unctions return an unsigned char )hich indicates i0 the sla2e is tied to 7+*Port9: or not. Code Body: unsigned char presence; Low_OW();
__delay_us(240); // delay 480 microsecond (us) __delay_us(240); High_OW(); // Release the bus __delay_us(70); // delay 70 microsecond (us) presence = Read_OW(); //Sample for presence pulse from slave __delay_us(205); // delay 410 microsecond (us) __delay_us(205); High_OW(); // Release the bus return presence; Signature: ReadByte_OW() : unsigned char This 0unction used to read a co"plete b-te 0ro" the sla2e de2ice through the 7+*Port9:. Code Body: unsigned char i, result=0; for (i = 0; i < 8; i++) { result >>= 1; // shift the result to get it ready for the next bit to receive if (ReadBit_OW()) result |= 0x80; // if result is one, then set MS-bit } return result; Signature: WriteBit_OW(bit : unsigned char) : void This 0unction used to trans"it a single bit to sla2e de2ice through the 7+*Port9:. Code Body: if (bit) { //writing a bit '1' Low_OW(); // Drive the bus low __delay_uc(6); // delay 6 microsecond (us) High_OW (); // Release the bus __delay_uc(64); // delay 64 microsecond (us) } else { //writing a bit '0' Low_OW(); // Drive the bus low __delay_uc(60); // delay 60 microsecond (us) High_OW (); // Release the bus __delay_uc(10); // delay 10 microsecond for recovery (us) } Signature: ReadBit_OW() : unsigned char Vese1.docx - 2014-02-20 - 1:20 PM Pag. 101 of 124 Vese1 root This 0unction used to read a single bit 0ro" the sla2e de2ice through the 7+*Port9:. Code Body: unsigned char bit; //reading a bit Low_OW(); // Drive the bus low __delay_us(6); // delay 6 microsecond (us) High_OW (); // Release the bus __delay_us(9); // delay 9 microsecond (us) bit = Read_OW(); //Read the status of OW_PN __delay_us(55);// delay 55 microsecond (us) return bit; Signature: Low_OW() : void Con0igure the 7+*Port9: as 7utput and dri2e the 7+*Port9: L7+. Code Body: TRSCbits.RC1 = 0; PORTCbits.RC1 = 0; Signature: High_OW() : void Con0igure the 7+*Port9: as 7utput and dri2e the 7+*Port9: 1IG1. Code Body: TRSCbits.RC1 = 0; PORTCbits.RC1 = 1; Signature: Read_OW() : unsigned char Con0igure as Input pin and Iead the status o0 7+*Port9:. Code Body: unsigned char data=0; // OW pin as an input TRSCbits.RC1 = 1; if (1 == PORTCbits.RC1) data = 1; else data = 0; return data; Signature: OW_Port() This is the digital port used as 1+ire co""unication bus. Class - 2.C&Port&aster I#C is a serial protocol used in e"bedded s-ste"s to connect "icrocontroller )ith "an- peripherals= such as other "icrocontrollers= ITCC= sensors and so on. I#C*Port*Master is the "aster side o0 this /ind o0 serial co""unication inter0ace. It uses the 0ollo)ing operations to "anage the sla2e: EEB-te+rite9control: unsigned char= address: unsigned char= data: unsigned char:: signed char= to )rite a single data b-te to sla2eD EEIando"Iead9control: unsigned char= address: unsigned char:: signed int= to read a single data b-te to sla2eD IdleI#C9:: 2oid= to generate )ait condition until I#C bus is IdleD ,tartI#C9:: 2oid= to send I#C bus start conditionD +riteI#C9control: unsigned char:: 2oid= to )rite a single b-te to the I#C busD ,topI#C9:: 2oid= to send I#C bus stop conditionD 8ot%c/I#C9:: 2oid= to initiate 87T %C5 bus conditionD 7penI#C9:: 2oid= to open the I#C*Port*Master as a "aster and sets the trans"ission rate to '$$51;. Co""unication uses t)o di00erent pin: ,4I*,4%9:= serial data busD ,C5*,CL9:= serial cloc/ pro2ided b- "aster to sla2e. Operations Signature: EEByteWrite(control : unsigned char, address : unsigned char, data : unsigned char) : signed char +rite single data b-te to I#C EE "e"or- sla2e de2ice. This routine returns: 1: The b-te has been properl- )ritten B1: Bus Collision error B#: 8ot %c/ error condition Vese1.docx - 2014-02-20 - 1:20 PM Pag. 102 of 124 Vese1 root B!: +rite collision Code Body: dle2C(); // ensure module is idle Start2C(); // initiate START condition while ( SSPCON2bits.SEN ); // wait until start condition is over if ( PR2bits.BCLF ) // test for bus collision { return ( -1 ); // return with Bus Collision error } else // start condition successful { if ( Write2C( control ) ) // write byte - R/W bit should be 0 { Stop2C(); return ( -3 ); // set error for write collision } //dle2C(); // ensure module is idle if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received { if ( Write2C( address ) ) // write word address for EEPROM { Stop2C(); return ( -3 ); // set error for write collision } //dle2C(); // ensure module is idle if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received { if ( Write2C( data ) ) // data byte for EEPROM { Stop2C(); return ( -3 ); // set error for write collision } } else { Stop2C(); return ( -2 ); // return with Not Ack error condition } } else { Stop2C(); return ( -2 ); // return with Not Ack error condition } } //dle2C(); // ensure module is idle Stop2C(); // send STOP condition while ( SSPCON2bits.PEN ); // wait until stop condition is over if ( PR2bits.BCLF ) // test for bus collision { return ( -1 ); // return with Bus Collision error } return ( 0 ); // return with no error Signature: EERandomRead(control : unsigned char, address : unsigned char) : signed int Ieads 1 b-te 0ro" passed address to EE "e"or- sla2e de2ice. Code Body: dle2C(); // ensure module is idle Start2C(); // initiate START condition while ( SSPCON2bits.SEN ); // wait until start condition is over if ( PR2bits.BCLF ) // test for bus collision { return ( -1 ); // return with Bus Collision error } Vese1.docx - 2014-02-20 - 1:20 PM Pag. 103 of 124 Vese1 root else { if ( Write2C( control ) ) // write 1 byte { Stop2C(); return ( -3 ); // return with write collision error } //dle2C(); // ensure module is idle if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition, if received { if ( Write2C( address ) ) // WRTE word address for EEPROM { Stop2C(); return ( -3 ); // return with write collision error } //dle2C(); // ensure module is idle if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition, if received { Restart2C(); // generate 2C bus restart condition while ( SSPCON2bits.RSEN );// wait until re-start condition is over if ( PR2bits.BCLF ) // test for bus collision { return ( -1 ); // return with Bus Collision error }
if ( Write2C( control+1 ) )// write 1 byte - R/W bit should be 1 { Stop2C(); return ( -3 ); // return with write collision error } //dle2C(); // ensure module is idle if ( !SSPCON2bits.ACKSTAT )// test for ACK condition, if received { SSPCON2bits.RCEN = 1; // enable master for 1 byte reception while ( SSPCON2bits.RCEN ); // check that receive sequence is over NotAck2C(); // send ACK condition while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over Stop2C(); // send STOP condition while ( SSPCON2bits.PEN ); // wait until stop condition is over if ( PR2bits.BCLF ) // test for bus collision { return ( -1 ); // return with Bus Collision error } } else { Stop2C(); return ( -2 ); // return with Not Ack error } } else { Stop2C(); return ( -2 ); // return with Not Ack error } } else { Stop2C(); return ( -2 ); // return with Not Ack error Vese1.docx - 2014-02-20 - 1:20 PM Pag. 104 of 124 Vese1 root } } return ( (unsigned int) SSPBUF ); // return with data Signature: dle2C() : void This 0unction generates )ait condition until I#C bus is Idle. Code Body: while ( ( SSPCON2 & 0x1F ) || ( SSPSTATbits.R_W ) ) continue; Signature: Start2C() : void ,end I#C bus start condition. Code Body: SSPCON2bits.SEN = 1; // initiate bus start condition Signature: Write2C(control : unsigned char) : void This routine )rites a single b-te to the I#C bus. Code Body: SSPBUF = data_out; // write single byte to SSPBUF if ( SSPCON1bits.WCOL ) // test if write collision occurred return ( -1 ); // if WCOL bit is set return negative # else { if( ((SSPCON1&0x0F)!=0x08) && ((SSPCON1&0x0F)!=0x0B) ) //Slave mode only { SSPCON1bits.CKP = 1; // release clock line while ( !PR1bits.SSPF ); // wait until ninth clock pulse received if ( ( !SSPSTATbits.R_W ) && ( !SSPSTATbits.BF ) )// if R/W=0 and BF=0, NOT ACK was received { return ( -2 ); //return NACK } else { return ( 0 ); //return ACK } } else if( ((SSPCON1&0x0F)==0x08) || ((SSPCON1&0x0F)==0x0B) ) //master mode only { while( SSPSTATbits.BF ); // wait until write cycle is complete dle2C(); // ensure module is idle if ( SSPCON2bits.ACKSTAT ) // test for ACK condition received return ( -2 ); // return NACK else return ( 0 ); //return ACK } } Signature: Stop2C() : void This 0unction sends I#C bus stop condition. Code Body: SSPCON2bits.PEN = 1; // initiate bus stop condition Signature: NotAck2C() : void This 0unction initiates 87T %C5 bus condition. Code Body: SSPCON2bits.ACKDT = 1; // set acknowledge bit for not ACK SSPCON2bits.ACKEN = 1; // initiate bus acknowledge sequence Signature: Open2C() : void This 0unction per"its to open the I#C*Port*Master as a "aster and sets the trans"ission rate to '$$51;. Code Body: SSPSTAT &= 0x3F; // power on state SSPCON1 = 0x00; // power on state SSPCON2 = 0x00; // power on state SSPCON1 |= 0x08; // select master mode SSPSTAT |= 0x00; // slew rate on 2C_SCL = 1; 2C_SDA = 1; SSPCON1 |= SSPENB; // enable synchronous serial port SSPADD = 12; //transmission rate equal to 400KHz Signature: SD_SDA() Signature: SCK_SCL() Vese1.docx - 2014-02-20 - 1:20 PM Pag. 105 of 124 Vese1 root Class - ADC It is the dri2er 0or internal %4C o0 MicroPIC*1F'E#$. It is used to "anage the con2ersion operation )hich allo)s to ha2e a digital in0or"ation associated to an analog signal. Attri%utes Signature Documentation -NUMBTS : byte const = 10 This attribute indicates the resolution o0 %4C in nu"ber o0 bits. It is eMual to 1$= so the digital in0or"ation )ill be in the range O$= 1$#!P. Operations Signature: init_ADC() : void Initiali;es %4C : to ha2e as 2oltage re0erence the po)er suppl- pro22ided to MicroPIC*1F'E#$D to operate on t)o analog channel 9%8$9: and %819::D to use a le0t 3usti0ication 0or %4C resultD to ha2e the biggest sa"pling ti"e in order to ha2e the best possible con2ersion. Code Body: /* * nitialization of ADC */ // Vdd and Vss as voltages reference ADCON1bits.VCFG0 = 0; ADCON1bits.VCFG1 = 0; //number of analog channel equal to 2 ADCON1bits.PCFG3 = 1; ADCON1bits.PCFG2 = 1; ADCON1bits.PCFG1 = 0; ADCON1bits.PCFG0 = 1; //left justification of ADC result ADCON2bits.ADFM = 0; //samplig time as long as possible ADCON2bits.ACQT2 = 1; ADCON2bits.ACQT1 = 1; ADCON2bits.ACQT0 = 1; ADCON2bits.ADCS2 = 1; ADCON2bits.ADCS1 = 1; ADCON2bits.ADCS0 = 0; Signature: AN0() %8$9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN1() %819: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN2() %8#9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN3() %8!9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN4() %8'9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN5() %8E9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN6() %8?9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN7() %879: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 106 of 124 Vese1 root Signature: AN8() %89: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN9() %899: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN10() %81$9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN11() %8119: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: AN12() %81#9: in the analog input pin. It can be connected to analog source in order to be con2erted in a digital in0or"ation. Signature: TurnON_ADC() : void This 0unction turns on the %4C "odule. Code Body: ADCON0bits.ADON = 1; Signature: SelectChannel_ADC(channel : unsigned char) : void This 0unction allo)s the user to select the channel that has to be used. In particular= channel can assu"e the 2alues 0ro" $ to 1#= each o0 then are associate to %8$9:= %819:= %8#9:= %8!9:= %8'9:= %8E9:= %8?9:= %879:= %89:= %899:= %81$9:= %8119:= %81#9: respecti2el-. Code Body: ADCON0bits.CHS = channel; Signature: Busy_ADC() : char This 0unctions returns 1 i0 the %4C is bus-= other)ise returns $. Code Body: return ADCON0bits.GODONE; Signature: Read_ADC() : unsigned int This 0unction returns the result o0 %4C operation. Code Body: return (((unsigned int)ADRESH)<<8)|(ADRESL); Signature: Convert_ADC() : void This 0unction allo)s to start the con2erting operation. Code Body: ADCON0bits.GODONE = 1; Class - ParallelPort ParallelPort is a /ind o0 general purpose I&7 co"posed b- pin: B$9:= B19:= B#9:= B!9:= B'9:= BE9:= B?9:= and B79:. This ParallelPort allo)s the co""unication )ith "an- peripheral= such as LC4= other "icrocontrollers= LE4= push button and "ore o2er... Operations Signature: B0() B$9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B1() B19: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B2() B#9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B3() B!9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B4() B'9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B5() BE9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B6() B?9: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Signature: B7() B79: is a digital pin o0 ParallelPort= )hich can be set as an input or as an output= and in this last case= it can assu"es onl- t)o 2alues: $ or 1. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 107 of 124 Vese1 root 'elay-oar# Name (alue Documentation Vese1.docx - 2014-02-20 - 1:20 PM Pag. 108 of 124 Vese1 root Class - PNP&Transistor It is an P8P transistor= that can be used to a"pli0- the current )hich enters in its B9:. 'eferences Type (alue URL http://www.digikey.com/product-detail/en/12A02CH-TL-E/12A02CH-TL-E- ND/2796955 URL http://www.onsemi.com/pub_link/Collateral/EN7482-D.PDF Tagge# (alues anufactorer Value ON Semiconductor Digi-6ey Part Num%er Value 12A02CH-TL-E-ND anufacturer Part Num%er Value 12A02CH-TL-E Cost Value 0.07866$ Pac0aging Value Tape & Reel (TR) Vese1.docx - 2014-02-20 - 1:20 PM Pag. 109 of 124 Vese1 root Transistor Type Value PNP Current - Collector 32c4 3a)4 Value 1A (oltage - Collector @mitter -rea0#o!n 3a)4 Value 12V DC Current >ain 3"F@4 3in4 Value 300 @ 10mA, 2V Po!er - a) Value 700mW ounting Type Value Surface Mount Pac0age Value SC-96 Temperature - in Value -55 C Temperature - a) Value 150 C Operations Signature: B() It is the base pin o0 P8P*Transistor. Signature: C() It is the collector pin o0 P8P*Transistor. Signature: E() It is the e"itter pin o0 P8P*Transistor. Signature: fixing() It is reali;ed b- sur0ace soldering. The de2ice di"ensions are sho)n in 0igure: Vese1.docx - 2014-02-20 - 1:20 PM Pag. 110 of 124 Vese1 root Class - +N5+A/ It is a standard diode. In 0irst appro6i"ation 18'1E$ is used as unidirectional conducti2e path. I0 the 2oltage applied to pin %9: is bigger than 2oltage applied to pin 59:= and their di00erence is also higher than 18'1E$ threshold 2oltage= due to depleted region= so a current can 0lo) 0ro" %9: to 59:. 7ther)ise= the beha2ior o0 this co"ponent is eMual to an open circuit. 'eferences Type (alue URL http://www.digikey.com/product-detail/en/1N4150TR/1N4150VSTR-ND/3104055 URL http://www.vishay.com/docs/85522/1n4150.pdf Tagge# (alues anufactorer Value Vishay Semiconductor Digi-6ey Part Num%er Value 1N4150VSTR-ND anufacturer Part Num%er Value 1N4150TR Cost Value 0.024 Dio#e Type Value Standard (oltage - DC 'e*erse 3(r4 3a)4 Value 50V Current - A*erage 'ectifie# 32o4 Value 300mA (DC) (oltage - For!ar# 3(f4 3a)4 C 2f Value 1V @ 200mA 'e*erse 'eco*ery Time 3trr4 Value 4ns Current - 'e*erse =ea0age C (r Vese1.docx - 2014-02-20 - 1:20 PM Pag. 111 of 124 Vese1 root Value 100nA @ 50V ounting Type Value Through Hole Value DO-35 T"ermal 'esistance Value 350C/W Ja Operating Temperature - a) Value 175C Operating Temperature - in Value -55C Ot"er Names Value 1N4150VSTR Operations Signature: A() It is the anode pin o0 18'1E$. Signature: K() It is the anode pin o0 18'1E$. Signature: fixing() The i"age belo) sho)s ho) 18'1E$ can be 0i6ed and its di"ension. The 0i6ing is through round hole. Class - =@D LE4 is an electrical co"ponent that can e"its light )hen %9: is connected at a 2oltage greater than LE4Ks threshold 2oltage. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 112 of 124 Vese1 root 'eferences Type (alue URL http://http://www.newark.com/avago-technologies/hlmp-4740/led-green-t-1-3-4- 5mm-2-3mcd-569nm/dp/40K0082?MER=PPSO_N_P_LEDs_None URL http://www.avagotech.com/docs/AV02-1557EN Tagge# (alues anufacturer Value AVAGO TECHNOLOGES Ne!ar0 Part No1 Value 40K0082 anufacturer Part No Value HLMP-4740 -ul% Si:e Value T-1 3/4 (5mm) For!ar# Current 2f Value 2 mA For!ar# (oltage Value 1.9 V =@D Color Value Green =@D ounting Value Through Hole =ens S"ape Value Round =uminous 2ntensity Value 2.3 mcd Price Value 0.5$ Vese1.docx - 2014-02-20 - 1:20 PM Pag. 113 of 124 Vese1 root Operations Signature: light() LE4 e"its light )hen %9: is connected at a 2oltage greater than LE4Ks threshold 2oltage Signature: A() The anode pin o0 the LE4 Signature: K() The cathode o0 the LE4 Signature: fixing() This co"ponent "ust to be 0i6ed through botto" soldering. The di"ensions o0 co"ponent are the 0ollo)ing: Class - S'D&'elay It is the rela- )hich a EL dri2er can dri2e #!$L load. There are t)o pair o0 high 2oltage pin: I8!9:BI8'9: is the nor"all- open interrupt= )hen a current 0lo)s through I819: and I8#9:= this t)o contacts are shortB circuited. I8'9:BI8E9: is the nor"all- closed interrupt= )hen a current 0lo)s through I819: and I8#9:= this t)o contacts are separated. 'eferences Type (alue URL http://www.songle.com/en/pdf/20084141716341001.pdf URL http://www.cytron.com.my/viewProduct.php?pcode=RE-SO-SRS- 24&name=Songle%20Relay%20SRS%2024VDC-SH Vese1.docx - 2014-02-20 - 1:20 PM Pag. 114 of 124 Vese1 root Tagge# (alues anufactorer Value Songle Cost Value 0.78$ anufactorer Co#e Value Songle Relay SRS 24VDC-SH a) Current Value 10A a) Operating (oltage 3AC4 Value 240VAC a) Operating (oltage 3DC4 Value 28VDC Temperature min Value -25C Temperature ma) Value 70C Conctact 'esistance Value 100 mOhm Operations Signature: N1() It is the EL electrical pin o0 ,I4*Iela-. Signature: N2() It is the EL electrical pin o0 ,I4*Iela-. Signature: N3() It is the #'$Lac electrical pin o0 ,I4*Iela-. Signature: N4() It is the #'$Lac electrical pin o0 ,I4*Iela-. Signature: N5() It is the #'$Lac electrical pin o0 ,I4*Iela-. Signature: fixing() The ,I4*Iela- is soldered in botto" la-er 0ollo)ing the 0igures sho)s belo): Vese1.docx - 2014-02-20 - 1:20 PM Pag. 115 of 124 Vese1 root Class - 'elay-oar# This part o0 circuit contains all the co"ponent used to dri2e the +atering Pu"p. It is co"posed o0: P8P*TransistorD 18'1E$D LE4D ,I4*Iela-D ,eriesIesistor*Iela-: ,M4*Iesistor*$$ED Connected as sho)n in 0igure:
Attri%utes Signature -DecouplingCapacitor_Relay : SMD_Electrolytic_Capacitor -SeriesResistor_Relay : SMD_Resistor_0805 -LedResistor_Relay : SMD_Resistor_0805 -relay : SRD_Relay Operations Signature: changeState_Relay() : void This 0unction change the status o0 ,I4*Iela- contacts. Code Body: //save the current status in a temp variable char stato = PORTAbits.RA3; PORTAbits.RA3 = ~stato; Signature: readStatus_Relay() : unsigned char This 0unctions allo)s to read the status o0 ,I4*Iela-. Code Body: return PORTAbits.RA3; Signature: N() This pin is the digital input o0 the Iela-Board. It "ust be dri2en b- MicroPIC*1F'E#$ and= )hen assert it change the status o0 rela-: ,I4*Iela- 0ro" its idle state to the e6cited state. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 116 of 124 Vese1 root Signature: VCC() This is the suppl- 2oltage pin. It "ust to be connected to LCC. Signature: GND() This is an electrical pin that "ust to be connected to G84 re0erence. Signature: OUT1() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Signature: OUT2() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Signature: OUT3() It is the electrical pin that is associated to high po)er side o0 the rela-: ,I4*Iela-. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 117 of 124 Vese1 root Automatic&Watering&System Name (alue Documentation State - C9@C6 9U2D2TD In this state the F,M chec/ i0 the hu"idit- is under the threshold 9i"posed b- user: or not. State - TU'N&OFF&2''2>AT2ON In this state the F,M turns o00 the irrigation s-ste" State - TU'N&ON&2''2>AT2ON In this state the F,M turns on the irrigation s-ste". State - C9@C6&AUTOSTATUS In this state the F,M chec/ i0 user has asserted the auto"atic )atering s-ste". State - 2D=@ In this state= the F,M do the "ain9: 0unction )aiting 0or e2ent on P7ITB Vese1.docx - 2014-02-20 - 1:20 PM Pag. 118 of 124 Vese1 root Automatic Watering Project 'e;uirements 'e;uirement - Po!er Supply *oltage Requirement D: REQ02 The po)er suppl- 2oltage pro2ided through Connector*16# "ust be EL4C. Constraints: Max thickness, Max length, Max width 'e;uirement - Automatic Watering System ma) temperature Requirement D: REQ03 %uto"atic*+atering*,-ste" "ust )ithstand a "a6 operating te"perature o0 '$GC Constraints: Maximum operating temperature 'e;uirement - Automatic Watering System in Temperature Requirement D: REQ04 %uto"atic*+atering*,-ste" "ust )ithstand a "ini"u" operating te"perature o0 B#EGC. Constraints: Min operating temperature 'e;uirement - Automatic Watering System !ater proof Requirement D: REQ08 %uto"atic*+atering*,-ste" "ust be )ater proo0. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 119 of 124 Vese1 root Automatic Watering System ma) temperature 'e;uirement - Automatic Watering System ma) temperature Requirement D: REQ03 %uto"atic*+atering*,-ste" "ust )ithstand a "a6 operating te"perature o0 '$GC Constraints: Maximum operating temperature 'e;uirement - icrocontroller ma) operating temperature Requirement D: REQ03.REQ008 MicroPIC*1F'E#$ "ust ha2e a "a6 operating te"perature grater than '$GC 'e;uirement - Temperature senspr ma) operatin temperature Requirement D: REQ03.REQ009 4,1B#$ "ust ha2e a "a6 operating te"perature grater than '$GC 'e;uirement - oisture sensor ma) operating temperature Requirement D: REQ03.REQ010 Moisture,ensor "ust ha2e an operating "a6 te"perature grater than '$GC Vese1.docx - 2014-02-20 - 1:20 PM Pag. 120 of 124 Vese1 root 'e;uirement - 'TCC ma) operating temperature Requirement D: REQ03.REQ011 ITCC "ust ha2e an operating "a6 te"perature grater than '$GC Vese1.docx - 2014-02-20 - 1:20 PM Pag. 121 of 124 Vese1 root Automatic Watering System in Temperature 'e;uirement - oisture sensor min temperature Requirement D: REQ03.REQ004 Moisture,ensor "ust ha2e an operating "in te"perature lo)er than B#EGC 'e;uirement - 'TCC min operating temperature Requirement D: REQ03.REQ005 ITCC "ust ha2e an operating "in te"perature lo)er than B#$GC 'e;uirement - Temperature sensor min operating temperature Requirement D: REQ03.REQ006 4,1B#$ "ust ha2e a "in operating te"perature lo)er than B#EGC 'e;uirement - icrocontroller min operating temperature Requirement D: REQ03.REQ007 MicroPIC*1F'E#$ "ust ha2e a "in operating te"perature lo)er than B#EGC Vese1.docx - 2014-02-20 - 1:20 PM Pag. 122 of 124 Vese1 root 'e;uirement - Automatic Watering System in Temperature Requirement D: REQ04 %uto"atic*+atering*,-ste" "ust )ithstand a "ini"u" operating te"perature o0 B#EGC. Constraints: Min operating temperature Vese1.docx - 2014-02-20 - 1:20 PM Pag. 123 of 124 Vese1 root Automatic Watering System !ater proof 'e;uirement - Automatic Watering System !ater proof Requirement D: REQ08 %uto"atic*+atering*,-ste" "ust be )ater proo0. Vese1.docx - 2014-02-20 - 1:20 PM Pag. 124 of 124
Chatlog 2-22-14 To 4 - 27 - 14 - Weekend Performance Tuning - Analyzing With DBA Skillsets - Every Sat - Sun 10 - 00 Am To 5 - 00 PM 2014-04-19 13 - 58