• Nenhum resultado encontrado

Κεφάλαιο 5 Ενιαιοποίηση και Έλεγχος

5.2 Έλεγχος συστήματος

5.2.4 Έλεγχος στάθμης

Σε αυτόν τον έλεγχο δοκιμάστηκε η απόκριση του συστήματος όταν το ενυδρείο

έχει νερό και όταν δεν έχει. Όταν ο αισθητήρας νερού ανιχνεύσει νερό, τότε συνεχίζεται

κανονικά η λειτουργία του ενυδρείου. Για να προσομοιωθεί η απουσία νερού, ο

αισθητήρας αφαιρέθηκε από την γυάλα. Αυτό είχε ως αποτέλεσμα να σταλθεί το

κατάλληλο σήμα από τον αισθητήρα στην κεντρική μονάδα, να ενεργοποιηθεί το κινητό

τηλέφωνο, και να σταλεί σχετικό μήνυμα.

51

Κεφάλαιο 6 Αποτελέσματα – Προτάσεις

Το αυτόματο σύστημα ελέγχου ενυδρείου που δημιουργήθηκε για τις ανάγκες της πτυχιακής εργασίας ανταποκρίνεται στις απαιτήσεις και στις προδιαγραφές που είχαν τεθεί από την αρχή. Έχοντας σαν βάση του συστήματος την πλακέτα ανάπτυξης του μικροελεγκτή AVR ATmega8515 της ATMEL και τα απαραίτητα περιφερειακά υποσυστήματα και αισθητήρια, δημιουργήθηκε ένα σύστημα με τις παρακάτω δυνατότητες:

 Αυτόματος έλεγχος ταίσματος

 Αυτόματη ενεργοποίηση/απενεργοποίηση εσωτερικού φωτισμού ανάλογα με τις συνθήκες φωτισμού του δωματίου

 Σύστημα ψύξης όταν η θερμοκρασία στο ενυδρείο ξεπερνά κατά 6°C την επιθυμητή μέση θερμοκρασία

 Σύστημα θέρμανσης όταν η θερμοκρασία στο ενυδρείο είναι μικρότερη κατά 6°C της επιθυμητής μέσης θερμοκρασίας

 Ειδοποίηση με μήνυμα sms στο κινητό του χρήστη όταν η θερμοκρασία του ενυδρείου είναι 10°C μεγαλύτερη από την μέση θερμοκρασία

 Ειδοποίηση με μήνυμα sms στο κινητό του χρήστη όταν η θερμοκρασία του ενυδρείου είναι 10°C μικρότερη από την μέση θερμοκρασία

 Μέτρηση της στάθμης νερού και ειδοποίηση όταν αυτή πέσει κάτω από το επιτρεπτό όριο.

Με αυτές τις λειτουργίες καλύπτονται σε μεγάλο ποσοστό οι ανάγκες που μπορεί

να έχει η συντήρηση ενός ενυδρείου. Η αυτοματοποίηση κάποιων διαδικασιών οδήγησε

στην δημιουργία ενός συστήματος με δύο βασικά πλεονεκτήματα: α) να υπάρχει η

μικρότερη δυνατή ανάγκη για επιτόπιο έλεγχο από τον ιδιοκτήτη του ενυδρείου, αλλά και

β) να υπάρχει έγκαιρη ειδοποίηση σε περίπτωση δυσλειτουργίας έτσι ώστε να γίνουν

έγκαιρα οι απαραίτητες διορθωτικές ενέργειες.

52

Βιβλιογραφία

1) http://www.atmel.com/

2) http://www.avr-tutorials.com/

3) http://www.avrfreaks.com/

4) Πογαρίδης Δ. (2003), «Σχεδίαση Ψηφιακών Συστημάτων», Εκδόσεις Ίων.

5) Πογαρίδης Δ. (2006), «Σχεδίαση Συστημάτων Μικροεπεξεργαστών», Εκδόσεις Γκιούρδας.

6) Αλεβίζος Θ. (2002), «Προγραμματισμός με τη Γλώσσα C++ Μέρος Α», Τ.Ε.Ι Καβάλας.

7) Αλεβίζος Θ. (2000), «Προγραμματισμός με τη Γλώσσα C++ Μέρος Β», Τ.Ε.Ι Καβάλας.

8) Μαρινάγη Α. (2005), «Τεχνολογία Λογισμικού ΙΙ», Τ.Ε.Ι Καβάλας.

9) Νικολαρόπουλος Ε. (2007), «Τεχνολογία Συστημάτων Βασισμένων Σε Υπολογιστές»,

Τ.Ε.Ι Καβάλας.

53

ΠΑΡΑΡΤΗΜΑ Ι.

Σε αυτό το παράρτημα παρατίθεται ο κώδικας του λογισμικού του συστήματος.

#include <mega8515.h>

// 1 Wire Bus functions

#asm

.equ __w1_port=0x1B ;PORTA .equ __w1_bit=7

#endasm

#include <1wire.h>

// DS1820 Temperature Sensor functions

#include <ds18b20.h>

// maximum number of DS1820 devices // connected to the 1 Wire bus

#define MAX_DEVICES 8

// number of DS1820 devices // connected to the 1 Wire bus

// DS1820 devices ROM code storage area, // 9 bytes are used for each device

// (see the w1_search function description in the help) unsigned char rom_code[MAX_DEVICES][9];

// Alphanumeric LCD Module functions

#asm

.equ __lcd_port=0x15 ;PORTC

#endasm

#include <lcd.h>

#include <delay.h>

#include <stdio.h>

#include <string.h>

char lcd_buffer[33];

//emfanizei tous arithmous apo 0-9 stin othoni void show_int(int x)

{

switch (x) {

case 0: lcd_putsf("O");

break;

case 1: lcd_putsf("1");

break;

case 2: lcd_putsf("2");

break;

case 3: lcd_putsf("3");

break;

case 4: lcd_putsf("4");

break;

case 5: lcd_putsf("5");

break;

case 6: lcd_putsf("6");

break;

case 7: lcd_putsf("7");

54

break;

case 8: lcd_putsf("8");

break;

case 9: lcd_putsf("9");

break;

} }

//emfanizei arithmous mexri kai xiliades kai 1 dekadiko void show_num(float x,short int y)

{

int tmp;

unsigned short int tmp2=0;

//ean o arithmos pros emfanisei einai arnitikos if (x<0)

{

//kanton thetiko kai emfanise ena "-" stin othoni x=-x;

lcd_putsf("-");

}

//apothikevoume ton arithmo mas se mia prosorini metavliti gia na kratisoume tin timi tou

tmp=x;

//ean o arithmos einai pano apo xilia if (x>=1000 || tmp2==1)

{

//emfanise tis xiliades kai aferese tes apo ton arithmo mas tmp2=1;

tmp=tmp/1000;

show_int(tmp);

tmp=tmp*1000;

x=x-tmp;

tmp=x;

}

//ean einai panw apo ekato i an eixe xiliades if (x>=100 || tmp2==1)

{

//emfanise tis ekatontades kai aferese tes apo ton arithmo mas tmp2=1;

tmp=tmp/100;

show_int(tmp);

tmp=tmp*100;

x=x-tmp;

tmp=x;

}

//ean einai panw apo deka i an eixe ekatontades i xiliades if ((x>=10 && x<100) || tmp2==1)

{

//emfanise tis dekades kai aferese tes apo ton arithmo mas tmp2=1;

tmp=tmp/10;

show_int(tmp);

tmp=tmp*10;

x=x-tmp;

tmp=x;

}

55

else

//ean den itan apo ena kai panw emfanise 0 show_int(0);

if (x<10 || tmp2==1) show_int(tmp);

//ean theloume na efmanisoume dekadikous arithmous if (y==1)

{

// afairese to akeraio meros tou arithmou x=x-tmp;

//ean iparxei dekadikos if (x>0)

{

//emfanise ton lcd_putsf(".");

x=x*10;

tmp=x;

x-=tmp;

show_int(tmp);

}

//alliws emfanise to 0 else

{

lcd_putsf(".");

show_int(0);

} } }

//ipologizei tous disektous xronous short int leapyear(int y)

{

return (y%400==0) || (y%100!=4 && y%4==0);

}

//ipologizei to poses meres exei o minas

unsigned short int lastday (short int y, short int m) {

short int fv;

if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) fv=31;

else

if (m==4 || m==6 || m==8 || m==11) fv=30;

else

//ean einai disektos o fevrouarios exei 29 if (leapyear(y))

fv=29;

//alliws exei 28 else

fv=28;

return fv;

}

56

//counter gia ta defterolepta/2 pou perasan int

counter=0,h=23,m=0,s,counter2=0,hpf=0,tmphpf,tmpavtmp=20,avtmp=20,tmph=0 ,tmpm=0,tmps=0,nfh=0;

//counter : o metritis twn defteroleptwn/2 //hpf : ana poses wres tha taizei ta psaria

//tmphpf : prosorini metavliti gia to ana poses wres tha taizei ta psaria etsi

// wste na min pirazoume tin kanoniki mexri na apothikefsoume tis allages

//avtmp : mesi thermokrasia pou theloume to enidrio mas

//tmpavtmp : prosorini metavliti gia tin mesi thermokrasia pou theloume to enidrio mas

//npf : i epomeni wra taismatos

unsigned short int

year=2011,month=12,day=30,tmpyear=2011,tmpmonth=1,tmpday=1,nfday,nfmonth ,nfyear,tmpquan,quan;

//nfday : i epomeni mera taismatos //nfmonth : o epomenos minas taismatos //nfyear : o epomenos xronos taismatos //quan : i posotita taismatos

//minima kaloswrismatos xristi void WelcomeScreen()

{

lcd_gotoxy(5,0);

lcd_putsf("Welcome to");

lcd_gotoxy(1,2);

lcd_putsf("*** AquaSenses ***");

delay_ms(6000);

lcd_clear();

lcd_gotoxy(5,1);

lcd_putsf("A project");

lcd_gotoxy(5,2);

lcd_putsf("made by :");

delay_ms(2000);

lcd_clear();

lcd_gotoxy(2,1);

lcd_putsf("Grigoriou Thomas");

lcd_gotoxy(5,2);

lcd_putsf("AEM : 1391");

delay_ms(3000);

lcd_clear();

lcd_gotoxy(0,1);

lcd_putsf("Tzifopoulos Dimitris");

lcd_gotoxy(5,2);

lcd_putsf("AEM : 1517");

delay_ms(3000);

}

//elegxos fwtismou enidriou void LightCheck(short int x) {

57

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Check :");

lcd_gotoxy(0,2);

lcd_putsf("Light check");

//anavoume gia 5" to fws kai to svinoume PORTD.7=1;

if (x!=2)

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

x++;

if (x==1)

LightCheck(2);

if (x==1) {

lcd_gotoxy(0,3);

lcd_putsf("OK");

delay_ms(1000);

PORTD.7=0;

} }

//elegxos psiksis enidriou void FanCheck(short int x) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Check :");

lcd_gotoxy(0,2);

lcd_putsf("Fan check");

//anavoume gia 5" ta anemistirakia kai ta svinoume PORTD.5=1;

if (x!=2)

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

x++;

if (x==1)

FanCheck(2);

if (x==1) {

lcd_gotoxy(0,3);

lcd_putsf("OK");

delay_ms(1000);

PORTD.5=0;

} }

58

//elegxos thermansis enidriou void HeatCheck(short int x) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Check :");

lcd_gotoxy(0,2);

lcd_putsf("Heater check");

//anavoume gia 5" ton thermostati kai ton svinoume PORTD.6=1;

if (x!=2)

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

lcd_putsf(".");

delay_ms(1000);

x++;

if (x==1)

HeatCheck(2);

if (x==1) {

lcd_gotoxy(0,3);

lcd_putsf("OK");

delay_ms(1000);

PORTD.6=0;

} }

//ektelei olous tous elegxous void AllChecks()

{

LightCheck(0);

FanCheck(0);

HeatCheck(0);

}

//ipologizei tin wra kai tin imerominia tou epomenou taismatos void nextfeed()

{

int temph;

temph=h+hpf;

nfday=day;

nfmonth=month;

nfyear=year;

//ean i epomeni wra taismatos einai panw apo 48 wres if (temph>48)

{

//ean eimaste stin teleftaia mera tou mina if (lastday(nfyear,nfmonth)==nfday)

{

//pame ston epomeno mina month++;

//ean eimastan ston teleftaio mina if (month==13)

{

59

//pame ston prwto mina kai stin epomeni xronia month=1;

year++;

}

//pame stin defteri mera tou mina day=2;

}

//alliws ean eimaste stin proteleftaia mera tou mina else

if (lastday(nfyear,nfmonth)==nfday+1) {

//pame ston epomeno mina nfmonth++;

//ean eimastan ston teleftaio mina if (nfmonth==13)

{

//pame ston prwto mina kai stin epomeni xronia nfmonth=1;

nfyear++;

}

//pame stin prwti mera tou mina nfday=1;

}

//alliws pame stin methepomeni mera else

{

nfday=nfday+2;

}

//afairoume 48wres apo tis wres tou epomenou taismatos nfh=temph-48;

}

//alliws ean i epomeni wra taismatos einai panw apo 24 wres else

if (temph>24) {

//ean eimaste stin teleftaia mera tou mina if (lastday(nfyear,nfmonth)==nfday)

{

//pame ston epomeno mina nfmonth++;

//ean eimastan ston teleftaio mina if (nfmonth==13)

{

//pame ston prwto mina kai stin epomeni xronia nfmonth=1;

nfyear++;

}

//pame stin prwti mera tou mina nfday=1;

}

//alliws pame stin epomeni mera else

{

nfday++;

}

//afairoume 24 wres apo tis wres tou epomenou taismatos nfh=temph-24;

} else {

//apothikevoume tin wra epomenou taismatos

60

nfh=temph;

} }

//rithmisi wras short int TimeConf() {

int tmp=1,tmp2=1;

short int rv=1;

while (tmp2<4) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Time Manage :");

lcd_gotoxy(0,2);

lcd_putsf("Select Time :");

lcd_gotoxy(0,3);

//ean epilegoume defterolepta if (tmp2==3)

lcd_putsf("Seconds :");

//ean epilegoume lepta else

if (tmp2==2)

lcd_putsf("Minutes :");

//ean epilegoume wres else

if (tmp2==1)

lcd_putsf("Hours :");

show_num(tmph,0);

lcd_putsf(":");

show_num(tmpm,0);

lcd_putsf(":");

show_num(tmps,0);

tmp=counter+1;

while (tmp>counter) {

//ean patithei enter i deksia if ( PINA.0==0 || PINA.5==0 ) {

//pame sto epomeno menu delay_ms(500);

tmp2++;

}

//ean patithei to velaki aristera if ( PINA.3==0 )

{

//pame ena menu pisw delay_ms(500);

if (tmp2>1) tmp2--;

else

{ delay_ms(500);

lcd_clear();

return 1;

}

61

}

//ean patithei esc vgainoume teleiws apo to menu if ( PINA.4==0 )

{ delay_ms(500);

lcd_clear();

return 2;

}

//ean patithei to panw if ( PINA.1==0)

{ delay_ms(500);

//ean eimaste sta defterolepta prosthetoume ena defterolepto

if (tmp2==3) {

//ean ftasame ta 60 midenizoume ton metriti tmps++;

if (tmps>=60) tmps=0;

}

//ean eimaste sta lepta prosthetoume ena lepto if (tmp2==2)

{

//ean ftasame ta 60 midenizoume ton metriti tmpm++;

if (tmpm>=60) tmpm=0;

}

//ean eimaste stis wres prosthetoume mia wra if (tmp2==1)

{

//ean ftasame tis 24 midenizoume ton metriti tmph++;

if (tmph>=24) tmph=0;

} }

//ean patithei to katw if ( PINA.2==0)

{ delay_ms(500);

//ean eimaste sta defterolepta afairoume ena defterolepto

if (tmp2==3) {

//ean ftasame sto 0 kanoume 59 ton metriti tmps--;

if (tmps<0) tmps=59;

}

//ean eimaste sta lepta afairoume ena lepto if (tmp2==2)

{

//ean ftasame sto 0 kanoume 59 ton metriti tmpm--;

if (tmpm<0) tmpm=59;

}

62

//ean eimaste stis wres afairoume mia wra if (tmp2==1)

{

//ean ftasame sto 0 kanoume 23 ton metriti tmph--;

if (tmph<0) tmph=23;

} }

delay_ms(100);

}

lcd_gotoxy(10,3);

}

return 0;

}

rithmisi imerominias short int DateConf() {

int tmp=1,tmp2=1;

short int rv=1;

//gia oso den exoume oloklirwsei tin rithmisi imerominias while (rv==1)

{

//gia 3 epanalipseis(mia gia tin mera mia gia ton mina mia gia tin xronia)

while (tmp2<4) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Date Manage :");

lcd_gotoxy(0,2);

lcd_putsf("Select Date :");

lcd_gotoxy(0,3);

//ean epilegoume xronia if (tmp2==1)

lcd_putsf("Year :");

else //ean epilegoume mina if (tmp2==2)

lcd_putsf("Month :");

else

//ean epilegoume mera if (tmp2==3)

lcd_putsf("Day :");

show_num(tmpday,0);

lcd_putsf(":");

show_num(tmpmonth,0);

lcd_putsf(":");

show_num(tmpyear,0);

tmp=counter+1;

while (tmp>counter) {

//ean patithei enter i deksia if ( PINA.0==0 || PINA.5==0 )

63

{

//pame sto epomeno menu delay_ms(500);

tmp2++;

}

//ean patithei to velaki aristera if ( PINA.3==0 )

{

//pame ena menu pisw delay_ms(500);

if (tmp2>1) tmp2--;

else

{

delay_ms(500);

lcd_clear();

return 1;

} }

//ean patithei esc vgainoume teleiws apo to menu if ( PINA.4==0 )

{ delay_ms(500);

lcd_clear();

return 2;

}

//ean patithei to panw if ( PINA.1==0)

{

delay_ms(500);

//ean eimaste stin mera prosthetoume mia mera if (tmp2==3)

{

tmpday++;

//ean eimaste stin teleftaia tou mina pame stin prwti

if (tmpday-1==lastday(tmpyear,tmpmonth)) tmpday=0;

}

//ean eimaste ston mina prosthetoume ena mina if (tmp2==2)

{

tmpmonth++;

//ean eimaste ston teleftaio pame ston prwto if (tmpmonth>=12)

tmpmonth=0;

}

//ean eimaste stin xronia prosthetoume mia xronia if (tmp2==1)

{

tmpyear++;

} }

//ean patithei to katw if ( PINA.2==0)

{ delay_ms(500);

//ean eimaste stin mera afairoume mia mera if (tmp2==3)

{

tmpday--;

64

//an eimaste stin prwti tou mina, pame stin teleftaia

if (tmpday<=0)

tmpday=lastday(tmpyear,tmpmonth);

}

//ean eimaste ston mina afairoume ena mina if (tmp2==2)

{

tmpmonth--;

//ean eimaste ston prwto pame ston teleftaio if (tmpmonth<=0)

tmpmonth=12;

}

//ean eimaste stin xronia afairoume mia xronia if (tmp2==1)

{

tmpyear--;

} }

delay_ms(100);

}

lcd_gotoxy(10,3);

} delay_ms(500);

//kaloume tin sinartisi rithmisis wra rv=TimeConf();

//an mas epistrepsei -1 ksanarithizoume xronia if (rv==1)

tmp2--;

//ean mas epistrepsei 2 vgainoume teleios apo to menou xwris na apothikefsoume tipota

if (rv==2) return 2;

}

//s=counter*2;

return 0;

}

short int AverTemp() {

int tmp=1;

short int rv=1;

//mexri na ginoun oi rithmiseis while (rv==1)

{

//mexri na patithei enter i deksia while (PINA.0==1 && PINA.5==1) {

//rithmizoume tin mesi thermokrasia lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Auto Temp :");

lcd_gotoxy(0,2);

65

lcd_putsf("Select Average :");

lcd_gotoxy(0,3);

lcd_putsf("Temperature :");

show_num(tmpavtmp,0);

tmp=counter+1;

while (tmp>counter) {

//ean patithei to velaki aristera if ( PINA.3==0 )

{

//pame ena vima pisw sto menu delay_ms(500);

lcd_clear();

return 1;

}

//ean patithei to esc if ( PINA.4==0 ) {

//vgainoume apo to menu xwris na apothikefsoume tipota

delay_ms(500);

lcd_clear();

return 2;

}

//ean patithei to epanw velaki if ( PINA.1==0)

{

//prosthetoume 1 stin thermokrasia delay_ms(500);

tmpavtmp++;

}

//ean patithei to katw velaki if ( PINA.2==0)

{

//afairoume 1 stin thermokrasia delay_ms(500);

tmpavtmp--;

}

//dinoume oria apo 15-35 vathmous if (tmpavtmp>35)

tmpavtmp=35;

if (tmpavtmp<15) tmpavtmp=15;

delay_ms(100);

}

lcd_gotoxy(10,3);

delay_ms(100);

} delay_ms(500);

//kaloume tin rithmisi imerominias rv=DateConf();

//ean epistrepsei 2 den apothikevoume tipota kai vgainoume apo to menu

if (rv==2) return 2;

}

return 0;

66

}

//emfanisei keimenou menu posotitas void ShowQuant(int x)

{

if (x==1)

lcd_putsf("Low");

else if (x==2)

lcd_putsf("Medium");

else if (x==3)

lcd_putsf("High");

}

short int FeederQuant() {

int tmp;

short int rv=1;

tmpquan=1;

while (rv==1) {

while (PINA.0==1 && PINA.5==1 ) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Automatic Feeder :");

lcd_gotoxy(0,2);

lcd_putsf("Select Quantity :");

lcd_gotoxy(0,3);

lcd_putsf("Quantity :");

ShowQuant(tmpquan);

tmp=counter+1;

while (tmp>counter) {

//ean patithei to velaki aristera if ( PINA.3==0 )

{

//vgainoume apo to menu xwris na apothikefsoume tipota

delay_ms(500);

lcd_clear();

return 1;

}

//ean patithei to esc if ( PINA.4==0 ) {

//vgainoume apo to menu xwris na apothikefsoume tipota

delay_ms(500);

lcd_clear();

return 2;

}

//ean patithei to epanw velaki if ( PINA.1==0)

{

//prosthetoume 1 stin posotita taismatos

67

delay_ms(500);

tmpquan++;

}

//ean patithei to epanw velaki if ( PINA.2==0)

{

//afairoume 1 apo tin posotita taismatos delay_ms(500);

tmpquan--;

}

//dinoume oria apo 1-3 fores if (tmpquan>3)

tmpquan=3;

if (tmpquan<1) tmpquan=1;

delay_ms(100);

}

lcd_gotoxy(10,3);

delay_ms(100);

} delay_ms(500);

//kaloume tin rithmisi mesis thermokrasias rv=AverTemp();

//ean epistrepsei 2 den apothikevoume tipota kai vgainoume apo to menu

if (rv==2) return 2;

}

counter=0;

return 0;

}

//menu ana poses wres taisma short int FeederConf()

{ int tmp;

short int rv=1;

tmphpf=0;

while (rv==1) {

lcd_clear();

lcd_gotoxy(1,0);

lcd_putsf("*** AquaSenses ***");

lcd_gotoxy(0,1);

lcd_putsf("Automatic Feeder :");

lcd_gotoxy(0,2);

lcd_putsf("Select Hours/Feed :");

lcd_gotoxy(0,3);

lcd_putsf("Hours : ");

//mexri na patithei enter i deksia while (PINA.0==1 && PINA.5 ==1 ) {

show_num(tmphpf,0);

tmp=counter+1;

68

while (tmp>counter) {

//ean patithei aristera i esc if (PINA.3==0 || PINA.4==0) {

//prosthetoume stin wra mas tin wra pou den metrousame

oso eimastan sto menu (defterolepta,lepta,wres,meres,mines kai xronia) m+=(counter/2)/60;

if (m>60) {

h++;

if (h>23) {

if (day==lastday(year,month)) {

day=0;

if (month==12) {

month=0;

year++;

} } else {

day++;

} } m-=60;

}

counter=counter%120;

return;

delay_ms(500);

return;

}

//ean patithei to panw velaki if ( PINA.1==0)

{

//prosthetoume mia wra sto ana poses wres tha taizei delay_ms(500);

tmphpf++;

}

//ean patithei to katw velaki if ( PINA.2==0)

{

//afairoume mia wra sto ana poses wres tha taizei delay_ms(500);

tmphpf--;

}

//vazoume oria 0-48 wres if (tmphpf>48)

tmphpf=0;

if (tmphpf<0) tmphpf=48;

delay_ms(100);

}

lcd_gotoxy(8,3);

} delay_ms(500);

//kaloume tin rithisi posotitas taismatos

69

rv=FeederQuant();

//ean mas epistrepsei 2 prosthetoume stin wra mas tin wra pou den metrousame oso

//eimastan sto menu (defterolepta,lepta,wres,meres,mines kai xronia)

if (rv==2) {

lcd_clear();

m+=(counter/2)/60;

if (m>60) {

h++;

if (h>23) {

if (day==lastday(year,month)) {

day=0;

if (month==12) {

month=0;

year++;

} } else {

day++;

} } m-=60;

}

counter=counter%120;

return;

} }

//apothikevoume tis prosorines mas metavlites stis kiries metavlites s=tmps;

m=tmpm;

h=tmph;

day=tmpday;

month=tmpmonth;

year=tmpyear;

avtmp=tmpavtmp;

hpf=tmphpf;

quan=tmpquan;

counter=s*2;

delay_ms(1000);

}

//apostoli minimatos kinitou void sms(int sms)

{

PORTD.2=1;

delay_ms(2000);

PORTD.2=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

70

PORTD.1=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

//ean prokeite gia xamili thermokrasia if (sms==1)

{

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

}

//alliws ean prokeite gia ipsili thermokrasia else

if (sms==2) {

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

}

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.0=1;

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.0=1;

71

delay_ms(200);

PORTD.0=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.1=1;

delay_ms(200);

PORTD.1=0;

delay_ms(200);

PORTD.1=1;

delay_ms(100);

PORTD.1=0;

delay_ms(10000);

PORTD.2=1;

delay_ms(2000);

PORTD.2=0;

delay_ms(200);

PORTD.2=1;

delay_ms(2000);

PORTD.2=0;

delay_ms(200);

}

void feed() {

int i=0;

//gia toses fores oso i posotita pou epileksame while (i<quan)

{

PORTD.4=1;

delay_ms(200);

PORTD.4=0;

delay_ms(7000);

i++;

} }

//afksanei ton counter kata 1 kathe miso defterolepto // Timer 1 overflow interrupt service routine

interrupt [TIM1_OVF] void timer1_ovf_isr(void) {

// Reinitialize Timer 1 value TCNT1H=0xF8;

TCNT1L=0xFB;

// Place your code here counter++;

}

// Declare your global variables here

72

void main(void) {

// Declare your local variables here unsigned char i,j,devices,i2;

float tmp;

short int done=0,lsmsd=0,hsmsd=0,levsmsd=0,ft=0;

//lsmsd=low(temperature) sms done //hsmsd=high(temperature) sms done //levsmsd=level(water) sms done

// Input/Output Ports initialization // Port A initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x7F;

DDRA=0x00;

// Port B initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0xFF;

DDRB=0x00;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0x00;

DDRD=0xFf;

// Port E initialization

// Func2=In Func1=In Func0=In // State2=T State1=T State0=T PORTE=0xff ;

DDRE=0x00;

// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh

// OC0 output: Disconnected TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 3,600 kHz

73

// Mode: Normal top=FFFFh // OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge // Timer 1 Overflow Interrupt: On // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00;

TCCR1B=0x05;

TCNT1H=0xF8;

TCNT1L=0xFB;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// External Interrupt(s) initialization // INT0: Off

// INT1: Off // INT2: Off MCUCR=0x00;

EMCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x80;

// Analog Comparator initialization // Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80;

// Determine the number of DS1820 devices // connected to the 1 Wire bus devices=w1_search(0xf0,rom_code);

// LCD module initialization lcd_init(20);

// Global enable interrupts

#asm("sei")

lcd_clear();

WelcomeScreen();

AllChecks();

FeederConf();

done=0;

nextfeed();

lcd_clear();

while (1) {

// Place your code here

74

//tin prwti fora pou trexei to programa isagoume mia kathisterisi 5" logo rithmisewn

if (ft==0) {

delay_ms(5000);

ft=1;

}

//ean den iparxei fws anapse ton eswteriko fwtismo PORTD.7=PINA.6;

//ean patithei to koumpi gia na anoiksei/kleisei to kinito na ektelestei i entoli

if (PINE.0==0) {

PORTD.3=1;

delay_ms(3000);

PORTD.3=0;

delay_ms(1000);

}

//ean patithei to enter na anoiksei to menu taismatos twn psariwn

if (PINA.5==0) {

lcd_clear();

delay_ms(1000);

FeederConf();

nextfeed();

}

//ipologizoume ta defterolepta s=counter/2;

//ean einai 60 if (s>=60) {

//afksanoume ta lepta m++;

//ean ta lepta einai 60 if (m==60)

{

//afksanoume tin wra h++;

//ean oi wres einai 24 if (h==24)

{

//midenizoume tis wres h=0;

//ean i mera einai i teleftaia tou mina if (day==lastday(year,month))

{

//tin kanoume prwti day=1;

//ean o minas den einai o teleftaios if (month<12)

{

//pame ston epomeno month++;

}

75

//alliws ean einai o teleftaios else

{

//pame stin epomeni xronia kai ston prwto mina

year++;

month=1;

} } else {

//pame stin epomeni mera day++;

} }

//midenizoume ta lepta m=0;

}

//midenizoume ta defterolepta counter=0;

//ean exoume energopoiisei to aftomato taizma if (hpf>0)

//ean irthe i wra taismatos

if (nfh==h && nfday==day && nfmonth==month &&

nfyear==year) {

//taizoume kai ipologizoume tin epomeni wra/mera taismatos

feed();

nextfeed();

} }

if (m%5==0) {

if (done==0) {

lcd_clear();

counter+=4;

done=1;

} } else

done=0;

if (s!=0)

if (s%10!=0) {

//ean to aisthitirio xamilis stathmis energopoiithei if (PINE.1==0)

{

//ean den exoume idi steilei minima tote stelnoume if ( levsmsd==0 )

{

sms(0);

levsmsd=1;

} } else

76

{

levsmsd=0;

}

//diavazoume tin thermokrasia tmp=ds18b20_temperature(&rom_code[0][0]);

//ean einai xamiloteri kata 6 vathmous apo tin epithimiti anavoume ton thermostati

if (tmp<avtmp-6) {

PORTD.6=1;

}

//alliws ton kleinoume else

{

PORTD.6=0;

}

//ean einai xamiloteri kata 10 vathmous apo tin epithimiti timi

if (tmp<avtmp-10 ) {

//ean den exoume idi steilei minima, stelnoume if ( lsmsd==0 )

{

sms(2);

lsmsd=1;

} } else {

lsmsd=0;

}

//ean einai ipsiloteri kata 6 vathmous apo tin epithimiti timi, energopoioume ta anemistirakia

if (tmp>avtmp+6) {

PORTD.5=1;

} else {

PORTD.5=0;

}

//ean einai ipsiloteri kata 10 vathmous apo tin epithimiti timi

if (tmp>avtmp+10 ) {

//ean den exoume idi steilei minima, stelnoume if ( hsmsd==0)

{

sms(1);

hsmsd=1;

} } else {

Documentos relacionados