automatic clownfish hatchery

81
:  . . . .     2011

Upload: klause-paulino

Post on 02-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Automatic Clownfish Hatchery

    1/81

    :

    .

    .

    .

    .

    2011

  • 8/10/2019 Automatic Clownfish Hatchery

    2/81

    .

    A..................................................................................................................... 1

    I. I ...................................................................................................................... 2

    II. B ....................................................................................................................... 3

    R ............................................................................................................................ 8

    A. M T ...................................................................................................................... 8

    B. L K T ...................................................................................................... 10

    C. P S ................................................................................................. 11

    D. R S .............................................................................................................. 13

    E. P L M ..................................................................................... 14

    F. O U ....................................................................................................... 14

    III. D .............................................................................................................................. 15

    A. A C H S D ............................................................ 15

    B. T D .................................................................................................................. 18

    C. S ......................................................................................................................... 22

    D. C ............................................................................................................. 22

    E. C ................................................................................................................ 23

    F. PCB .................................................................................................................... 27

    IV. C .................................................................................................................... 28

    A. T C ........................................................................................................ 28

    B. PCB C ......................................................................................................... 31

    V. T ............................................................................................................................. 34

  • 8/10/2019 Automatic Clownfish Hatchery

    3/81

    A. C ............................................................................................................ 34

    B. C ......................................................................................................................... 34

    C. S ......................................................................................................................... 34

    D. P ........................................................................................................................... 38

    E. C S ......................................................................................................... 39

    VI. C R ............................................................................... 40

    VII. B .................................................................................................................... 41

    VIII. A A: S ................................................................................................. 42

    IX. A B: P L, C, T S A .......................................... 48

    A. P L C ........................................................................................................ 48

    B. T S A G C ................................................................. ........ 50

    X. A C: P C B A .................................................................... 51

    XI. A D: B P L ................................................................................. 55

    A. ACHMC. ............................................................................................ 55

    B. P. .................................................................................................................... 57

    C. B. ........................................................................................................................ 62

    D. W. ............................................................................................................. 65

    E. ADC. ........................................................................................................................... 66

    F. ACHADC. ................................................................................................................... 67

    G. MC2. .................................................................................................. 69

  • 8/10/2019 Automatic Clownfish Hatchery

    4/81

    F 1: C L ("F L C.") ....................................................................... 5

    F 2: N P ("R.) ....................................................... 6

    F 3: R U 100 M ("R M I R.") ............ 7

    F 4: E K T(M B A) ........................................... 7

    F 5: T L S D .......................................................................................... 15

    F 6: M C ................................................................................... 16

    F 7: G K D ......................................................................................... 20

    F 8: P T D ..................................................................................... 21

    F 9: E D V R C ......................................................... 24

    F 10: E S I L D C ................................................. 25

    F 11: E S S I A ..................................................... 26

    F 12: S O B A F ................................................................ 26

    F 13: E R C ..................................................................................... 27

    F 14: L C C A ................................................................................... 28

    F 15: K T ............................................................................................................ 29

    F 16: L C T R T ........................................................... 29

    F 17: R T ............................................................................................................ 30

    F 18: P D () S () .................................................... 30

    F 19: R T PCB .................................................................................. 32

    F 20: T PCB ..................................................................................................... 32

    F 21: E H S G............................................................... 35

    F 22: G L D G LED R.............................................................. 36

  • 8/10/2019 Automatic Clownfish Hatchery

    5/81

    F 23: D R U R R C L S ............... 37

    F 24: D P U G R C L S 37

    F 25: M D P ....................................................................................... 38

    F 26: F 12VDC M D P ................................................. 38

    F 27: C C S ...................................................................................... 39

  • 8/10/2019 Automatic Clownfish Hatchery

    6/81

    1

    I

    . T J O, ,

    . T J C,

    . T , M C Q,

    . T J R, ,

    I .

    W .

  • 8/10/2019 Automatic Clownfish Hatchery

    7/81

    2

    .

    M I ,

    . M

    . T

    ,

    . T

    .

    F I . I

    ,

    . D .

    C

    . T

    .

    T

    .

    T , I , ,

    . T ,

    , , .

    D I , ,

    .

    M . O

    . B

    ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    8/81

    3

    .

    O 90%

    . O

    (L 1). C

    .

    T . W ,

    . W . T

    (W). T

    . I

    ,

    ,

    . T 90%

    . T

    (C R O W). T

    .

    T ,

    (W). T

    , , . M

    . T ,

    .

    T , ,

    . T , ,

  • 8/10/2019 Automatic Clownfish Hatchery

    9/81

    4

    , . C 40

    . T

    . S

    .

    T . C

    . O ,

    . T

    . T

    . S

    .

    W

    . T . N

    , , .

    C . T 4

    . I

    , ,

    (W). T 1 .

  • 8/10/2019 Automatic Clownfish Hatchery

    10/81

    5

    1: (" .")

    W

    . O ,

    .

    A .

    I

    . T

    . T 315

    2 5 .

    H 5 12

    .

    E

    L

    J

    A

  • 8/10/2019 Automatic Clownfish Hatchery

    11/81

    6

    O . I

    . T

    . I

    (W).

    F

    . L

    . T .

    P , , 212

    . T . T

    . T

    (H).

    A 2

    .

    2: (".)

  • 8/10/2019 Automatic Clownfish Hatchery

    12/81

    7

    150 500

    . T

    (H). R

    3.

    3: 100 (" .")

    O K . I

    (W). F 4

    K .

    4: ( A)

  • 8/10/2019 Automatic Clownfish Hatchery

    13/81

    8

    .

    T . I

    , ,

    .

    1.

    T 14 . T

    .

    2.

    T , , ( ). A

    .

    3.

    T 3 15 2 5

    L . T

    .

    4.

    T 50/50 6500/420. T

    .

    L 8 .

  • 8/10/2019 Automatic Clownfish Hatchery

    14/81

    9

    5.

    M 10 L/ 400 L/

    . T

    .

    M .

    T .

    T

    .

    A

    .

    6.

    T , ,

    .

    C CP.

    B 14

    .

    M .

    7.

    T P 7.9 8.3. T

    .

    A .

  • 8/10/2019 Automatic Clownfish Hatchery

    15/81

    10

    8.

    S()

    .

    A H H .

    T .

    .

    T K

    .

    1.

    T K 12 . T

    .

    2.

    T PVC . B

    .

    T

    . T

    .

    I K . T

    , ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    16/81

    11

    3.

    T

    .

    4.

    L ,

    .

    5.

    A K.

    T .

    6.

    T

    7.

    F .

    .

    T

    ()

    .

    1.

    T 4+ . T

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    17/81

    12

    2.

    T 4+ .

    T ;

    .

    T .

    T

    .

    3.

    20 40 L

    .

    E .

    4.

    2 C F 6000

    .

    L 16 .

    5.

    N . T

    7

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    18/81

    13

    .

    T

    .

    1.

    T 4+

    .

    2.

    T 1+ .

    I ,

    .

    T .

    T

    .

    3.

    T 200500

    2 5

    .

    4.

    L .

    5.

    N .

    W .

  • 8/10/2019 Automatic Clownfish Hatchery

    19/81

    14

    .

    T

    .

    M

    .

    M .

    .

    T

    .

    LCD .

    T .

    O

    .

    A .

    T , LCD

    77 81 .

    B B .

  • 8/10/2019 Automatic Clownfish Hatchery

    20/81

    15

    .

    T A C H:

    , , . T

    . F 5 .

    .

    5:

  • 8/10/2019 Automatic Clownfish Hatchery

    21/81

    16

    T

    . T LED

    . B ,

    , , .

    6:

  • 8/10/2019 Automatic Clownfish Hatchery

    22/81

    17

    A 6 ,

    A C H. F

    . T , ,

    , , I/O . M

    . A

    . T PIC, NXP,

    .

    T AT2313

    . T

    , 11 I/O, UART ,

    SPI .

    T AT48A ADC ADC

    . T AT

    . A I2C ADC AT48A

    ADC . E

    I2C . T

    6 ADC , UART , SPI. O

    .

    T AT8A

    . T

    AT328P. T 328P

    . A 168A

    8A, . T

    I2C, UART , SPI, 9 .

    I ,

    . D

  • 8/10/2019 Automatic Clownfish Hatchery

    23/81

    18

    AT8A. B

    (ADC, TWI,).

    .

    T : , ,

    . E

    .

    1.

    T

    . A

    ,

    ,

    .

    M . T

    . I

    K

    A . I

    . A ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    24/81

    19

    A 10

    .

    F 14

    , .

    H K, ,

    14 . T 14

    . T 1014 K,

    .

    2.

    T K G. I

    . T 7

    . F ,

    . T

    . T . T

    .

    T . T

    ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    25/81

    20

    7:

    3.

    T .

    F 2 . A 7

    .

    T ,

    , ,

    .

    T

    1/2 8

    . T

    . E 1

    . T

  • 8/10/2019 Automatic Clownfish Hatchery

    26/81

    21

    .

    A .

    8:

    4.

    F . T

    ,

    . T

    .

    T

    1/3 . T

    ,

    CNC . T

    16 29.

    A . I

    ,

  • 8/10/2019 Automatic Clownfish Hatchery

    27/81

    22

    . T

    .

    .

    U LED 565

    . O LED LED

    . T

    .

    S LED ,

    . T

    . T LED IR

    .

    T A ADJDS371Q999

    . T

    , ,

    ( ). B

    . F

    . T

    () .

    .

    U S A R T (USART)

    . D

    ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    28/81

    23

    O USART A328P USART

    . T

    .

    T (I2C)

    . I2C

    (SDA SCL). T

    6 16.

    .

    1.

    T ,

    : LM317 (), LM11175, LM11173.3. T

    12V

    5 . A

    9 .

    T LM317

    . T

    LM317

    (ESR). T LM317 ESR

    .

    T LM1117 . T

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    29/81

    24

    O , LM317

    12V ( ). O LM317

    22V 24V . T

    24V. T LM11175 5V .

    T ADC LM317 7V

    LM11175 .

    T LM11175 LM1117

    3.3 .

    9:

    2.

    T I .

    E ,

    , LED . T

    . A

    10 .

  • 8/10/2019 Automatic Clownfish Hatchery

    30/81

    25

    W 5V ,

    VCC

    . W 5V ,

    EMF . T

    LED

    .

    10:

    3.

    I 05V ADC,

    2.5V . A

    11 . T ADC .

  • 8/10/2019 Automatic Clownfish Hatchery

    31/81

    26

    11: A

    4.

    A B 12

    . F

    PCB.

    12: A

    5.

    T 13

    120V . T 5V

    BJT

    , (NO)

    120V . T LED

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    32/81

    27

    13:

    .

    A PCB ECAD . ECAD PCB

    100 160. F

    , ,

    . T : AT328P ,

    ( 22

    ), AT2313 , (

    ), , AT48A ADC , UART ,

    , LED , . S

    AT 328P.

  • 8/10/2019 Automatic Clownfish Hatchery

    33/81

  • 8/10/2019 Automatic Clownfish Hatchery

    34/81

    29

    15:

    T R . A CNC

    . O 3/8 3/4

    . T 3/8

    . T

    . T

    . T

    17 . T 16.

    16:

  • 8/10/2019 Automatic Clownfish Hatchery

    35/81

    30

    17:

    T P 5 . T

    3 . E

    1

    . T CNC .

    P . T

    18 .

    18: () ()

  • 8/10/2019 Automatic Clownfish Hatchery

    36/81

    31

    .

    T PCB. T

    :

    1. P

    T

    . I

    .

    2. C FR4

    U

    .

    3. H

    P . U

    . O

    .

    4.

    P

    T

    .

    5. E

    A . U ,

    . F 30 1 .

    M .

    6.

    D

    U ,

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    37/81

    32

    7. T R

    R . F 19

    .

    19:

    8. T ()

    P

    . L 3 5

    . F 20 .

    20:

    9. T

    T . T .

    10.

    S

    S .

  • 8/10/2019 Automatic Clownfish Hatchery

    38/81

    33

    M

    ,

    , . I

    . M

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    39/81

    34

    .

    .

    T USART I2C

    . U ET AT128

    AT48A LCD . T

    LCD .

    .

    T , , LT.

    P

    . F PCB

    .

    .

    T LED . F

    . A

    . T 22 34.

    T , ,

    C P S L O. T O S

    N R

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    40/81

    35

    21:

    A , 21 ,

    . I

    . A

    .

    T

    ( 21) . T

    . D ,

    , ,

    . O

    . T

    .

    F FR . A

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    41/81

    36

    22:

    T

    . F 10 40

    10 . T 100

    750. F 3 ( 1 5 )

    5 5 10 . T 100

    1600. C

    189 470 . T

    23 24.

  • 8/10/2019 Automatic Clownfish Hatchery

    42/81

    37

    23:

    24:

  • 8/10/2019 Automatic Clownfish Hatchery

    43/81

    38

    .

    25:

    M 25

    12V DC . T 26

    .

    26: 12

  • 8/10/2019 Automatic Clownfish Hatchery

    44/81

    39

    .

    T LED . B

    . T 27.

    27:

  • 8/10/2019 Automatic Clownfish Hatchery

    45/81

    40

    .

    T A C H

    . T

    .

    E ,

    . T , : ,

    / , ,

    .

    I

    . I

    . O

    . T

    , .

    T ADC

    . T

    LED .

    F , PCB

    . U ECAD ,

    ECAD,

    AT8A ( ) .

    A CNC ,

    . T

    . T CNC

    .

    O ;

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    46/81

    41

    .

    "F L C." , , . N..,

    .. W. 10 J 2011. .

    "CORAL REEF DESTRUCTION AND CONSERVATION C R O W."

    . N.., .. W. 9 J 2011.

    .

    "F A F." . N.., .. W. 10 A. 2011. .

    H, F H., T W. S. . 6 . D C, F.: F

    A F, 2004. P.

    L, D . "C M F I." 26.1

    (2010): 12. P.

    "M B A, C." , . N.., .. W.

    14 J 2011. .

    "R M I R." &

    . N.., .. W. 1 J 2011. .

    "R.: W R B I P PP." !. N..,

    .. W. 2 J 2011. .

    W, M L.. '

    . N C, NJ: T.F.H. P ;, 2007. P.

  • 8/10/2019 Automatic Clownfish Hatchery

    47/81

    42

    . :

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    48/81

    43

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    49/81

    44

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    50/81

    45

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    51/81

    46

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    52/81

    47

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    53/81

    48

    . : , ,

    .

    MCU AVR 8K FLASH 16MH 32TQFP D ATMEGA8AAUND 1 3.2100 3.21

    DIODE SCHOTTK 1A 20V POWERMITE1 D UPS5817E3CTND 1 0.2150 0.22

    CONN HEADER FEMALE 16POS.1" TIN D S7014ND 3 1.1200 3.36

    LED SS 5MM 570NM GREEN WTR CLR D 7541262ND 4 0.1300 0.52

    RES 1K OHM 1/8W 5% 0805 SMD D RMCF0805JT1K00CTND 100 0.0032 0.32

    PCB COPPER CLAD 3 X 4.5" 1 SIDE D PC5ND 2 3.5300 7.06

    PCB COPPER CLAD 3X4.5" 2 SIDE D PC74ND 2 4.8400 9.68

    IC RTC SERIAL 2WIRE LP 8DIP D DS1337+ND 1 2.7300 2.73

    CRSTAL 32.768 KH 6PF CL D 3008301ND 1 0.2800 0.28

    IC REG LDO 1.0A 3.3V SOT223 D AP1117E33GDICTND 1 0.5600 0.56

    IC REG LDO 1.0A 5.0V SOT223 D AP1117E50GDICTND 4 0.5600 2.24

    IC MCU AVR 4K FLASH 28PDIP D ATMEGA48APUND 2 2.5800 5.16

    CONN SOCKET BNC R/A 50 OHM PCB D A97555ND 1 2.3000 2.30HEADER,ST MALE,1RW,40PIN J 160882 10 0.4900 4.90

    PCB,BLANK,SNGL SIDED,PHENOLIC, J 169296 1 9.9500 9.95

    PCB,BLANK,DBL SIDED,PHENOLIC, J 169325 1 19.9500 19.95

    SMD, 1206, GRN, 569NM, CLR, J 697741 10 0.1000 1.00

    C, C, SMT, 0805, 1F, J 1858914 100 0.0100 1.00

    SMD LED,0805 SU THIN,ELLW J 2075639 10 0.0700 0.70

    CONN,TERMINAL BLOCK,2 POSITION J 2120647 40 0.2500 10.00

    SOCKET,IC,20 PIN,3902616, J 526221 2 0.1600 0.32

    IC,MCU,ATTIN2313V10PU,8BIT J 689039 2 2.2500 4.50

    CONN,TERMINAL BLOCK,2 POSITION J 2120647 40 0.2500 10.00

    HEADER,LP SHROUD,4PIN J 152726 1 0.55 0.55

    CONNECTOR,.1",1RW,4PIN HSG J 152734 1 0.45 0.45

    @CONNECTOR,PIN,FEM,SQ POST TIN J 181673 4 0.04 0.16BATTER HOLDER FOR CR2032, J 355434 1 0.79 0.79

    @RESISTOR,SMT,1206,10K OHM, J 2078848 100 0.008 0.80

    RELA,SPDT,6VDC,10A J 2077378 3 1.49 4.47

    F C M 5904154L 1 28.95 28.95

    L T M 590421500ML 1 33.38 33.38

    10 M 5179740110 5 1.47 7.35

    T C S SMD 35 1F

    20%M 80B45196H6105M109 10 0.22 2.20

    S (D & R) 1A 40 V M 625LL101C 12 0.05 0.60

    MOSFET P TAPE13 PWRMOS M 771BUK9815055A/T3 12 0.21 2.52

    T R SMD 5K S 3

    S M 81PVG3A502C01R00 4 0.83 3.32

    T F R SMD 1/4 240

    5% M 660RK73B2BTTD241J 10 0.05 0.50

    M C C (MLCC)

    SMD/SMT 50 0.1F 5U 20%M 80C1206C104M5U7210 10 0.03 0.30

    L R S 3 T A. P. M 595LM317DCR 4 0.79 3.16

    T F R SMD 1/8WATT 110OHMS M 290110RC 4 0.05 0.20

    T F R SMD 1/8WATT

    8.25KOHMSM 2908.25KRC 4 0.05 0.20

    T F R SMD 1/8WATT M 29031.6KRC 4 0.05 0.20

  • 8/10/2019 Automatic Clownfish Hatchery

    54/81

    49

    31.6KOHMS

    T R SMD 3MM 20KOHMS 25%

    0.1 WATT OPEN FRMM 652TC33X2203E 2 0.18 0.36

    O A D G P JFET M 511TL082ACD 4 0.44 1.76

    T F R SMD 1/8WATT 1.5KOHMS M 2901.5KRC 10 0.05 0.50

    T F R SMD 56K 5% M 652CR1206JW563ELF 4 0.05 0.20

    T R SMD 3MM 100KOHMS 25%

    0.1 WATT OPEN FRM M 652TC33X2104E 3 0.2 0.60

    T F R SMD 10K 1% M 652CR1206FX1002ELF 50 0.03 1.50

    T F R SMD 4.7KOHM 1/4 WATT

    5%M 652CR1206JW472GLF 10 0.05 0.50

    O A S G P JFET M 511TL081CD 1 0.4 0.40

    T R SMD 10K OHM 3MM ST

    CERMM 85835WR10KLFTR 2 0.13 0.26

    D D S 5.6V 1%

    250W 3PM 771BX84A5V6,215 1 0.19 0.19

    P L C (50., ) GE 76530 1 7.88 7.88

    M L C P 10 P GE 26133 1 3.64 3.64

    C A S 1824.093 O MC05 6 7.98 47.88

    V T 5/8"OD 1/2"ID 20' 1 7.26 7.26

    V T 1/2"OD 3/8"ID 10' 1 4.15 4.151/2" B T BT50 1 2.49 2.49

    1/2" I L S O V D328 3 2.76 8.28

    1/4" B T H828 1 4.79 4.79

    1/4" I L S O V D33A 3 1.98 5.94

    1/2" 10' PVC40 PE P 1 1.55 1.55

    A S 12241/8 US P 44449 2 9.85 19.7

    1 3/4" 12" C A P H US P 44111 1 1.21 1.21

    3" OD 2 3/4" 6' ID A T US P 44037 1 21.78 21.78

    3/8" OD 1/4" 6' ID A T US P 44019 1 1.08 1.08

    MAXI CULTURE KIT, FOR MICROALGAE AND ROTIFERS F A F GAMACK 1 103.5 103.50

    A S K 15 G T F 1 64.98 64.98

    12VDC 3W M 100/ CXDF H10 10 11.28 112.8

    615.24

  • 8/10/2019 Automatic Clownfish Hatchery

    55/81

    50

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    56/81

    51

    . :

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    57/81

    52

    .

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    58/81

    53

    .

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    59/81

    54

    .

    .

  • 8/10/2019 Automatic Clownfish Hatchery

    60/81

    55

    . :

    .

    .

    T I S R

    ADC

    ACH.

    #include #include #include #include #include #include #include

    #include "ADC.h"#include "operators.h"#include "usart.h"

    #include "waterchange.h"#include "plankton.h"#include "babies.h"#include "motor_control_com.h"#include "ds1337.h"

    ////////////////////////////////////////////// USART Application Specific Constants// Rate: 38.4kHz////////////////////////////////////////////#define MASTER_ADDRESS 0x0A#define SENSOR_CONTROLLER 0x03

    ////////////////////////////////////////////// Master Modes////////////////////////////////////////////#define PLANKTON 0

    #define BABIES 1#define WATERCHANGE 2

    ////////////////////////////////////////////// Master input pins////////////////////////////////////////////#define MASTER_INPUT_0 0#define MASTER_INPUT_1 1#define MASTER_INPUT_2 2#define MASTER_INPUT_3 3#define MASTER_INPUT_4 6#define MASTER_INPUT_5 7

    ////////////////////////////////////////////// Color Light Sensor Parameters//////////////////////////////////////////////Integration Time

    #define RED_INT 750#define GREEN_INT 1600

    ////////////////////////////////////////////// Global Variables//////////////////////////////////////////////This variable will be 1 if this device is selected on the usart.volatile unsigned char usart_selected = 0;

    //This variable denotes the data sequence of the current USART transmission.

  • 8/10/2019 Automatic Clownfish Hatchery

    61/81

    56

    unsigned char usart_sequence = 0;

    int main(void){

    //Initialize local variablesunsigned char mode = 1;

    //Set port status

    LCD_PORT_DDR = OUTPUT; //Set LCD port (PortB) as output

    //Designate external pins on PortCDDRC = (0

  • 8/10/2019 Automatic Clownfish Hatchery

    62/81

    57

    //Signal the end of the data Rxelse if(data == 0xFF){

    if(exit_counter == 0){

    exit_counter++;}

    else if(exit_counter == 1){

    exit_counter = 0;usart_adc_seq = 0;

    }}

    sei();}/* EOF ACH_Master_Controller.c */

    . .

    T A C H. I

    ,

    .

    #ifndef __PLANKTON_H

    #define __PLANKTON_H

    #include

    #include

    #include

    #include

    #include

    #include "motor_control_com.h"

    #include "usart.h"

    #include "ds1337.h"

    #include "ADC.h"

    #include "Time_Functions.h"

    #include "babies.h"

    #define MAIN_TANK_DAY_HOUR 10 //10:00 AM

    #define MAIN_TANK_NIGHT_HOUR 18 //06:00 PM

    #define PLANKTON_DAY_HOUR 7 //07:00 AM

    #define PLANKTON_NIGHT_HOUR 23 //11:00 PM

    #define PLANKTON_NEW_H20 4 //Add water every 4 hours

    #define ROTIFER_H20_CHANGE_HOUR 9 //9:02 AM

    #define ROTIFER_H20_CHANGE_MINUTE 2

    //Number of days between waterchanges

    #define ROTIFER_PERIOD 4

    #define ORGANISM_DENSITY 18 //Low density

  • 8/10/2019 Automatic Clownfish Hatchery

    63/81

    58

    //Master Input Signals

    #define ROTIFER_FLOAT1 0x01

    #define ROTIFER_FLOAT1_PORT PINC

    #define ROTIFER_FLOAT2 0

    #define ROTIFER_FLOAT2_PORT PINC

    //Switch mode

    #define BABY_MODE 0x80#define BABY_MODE_PORT PIND

    //Function Prototypes

    void ACH(unsigned char* mode);

    void ACH(unsigned char* mode)

    {

    //Set LCD variables

    char LCD_Temp[4], LCD_ph[4];

    //Set RTC variables

    unsigned char Day, Hour, Minute, Second;

    unsigned char pm_flag;

    //Rotifer day of next water changeunsigned char Rotifer_day = 5;

    unsigned char Rotifer_top_off = 0;

    //Plankton time of next water addition

    unsigned char Plankton_water = PLANKTON_DAY_HOUR;

    unsigned char Plankton_density_reading = 0;

    unsigned char Plankton_density_value = 0;

    //Flags

    unsigned char Relay1_on = 0; //Plankton Light

    unsigned char Relay3_on = 0; //Main Tank Light

    lcd4_init();

    //Setup the Plankton mode display

    lcd4_ClearDisplay();

    lcd4_Command(HOME);

    //Display mode format

    lcd4_putstr("Phytoplankton 00:00");

    lcd4_pos_xy(0,2);

    //lcd4_putstr("Temp: F pH: ");

    lcd4_putstr("GreenLED Red Green");

    //lcd4_pos_xy(7,2);

    //lcd4_putchar(DEGREES);

    Display_Time();

    //Disable opens the normally closed ocntactUSART_motor_controller(MOTOR_CONTROLLER_2, RELAY_2, DISABLE, 100);

    sei(); //Enable interrupts

    //Main while loop of Plankton. Exit comes with menu choice or //timed interrupt.

    while(1)

    {

    //Get time

  • 8/10/2019 Automatic Clownfish Hatchery

    64/81

    59

    RTC_Get_Time(RTC_ADDRESS, 1, &Second, &Minute, &Hour);

    pm_flag = Get_AMPM();

    RTC_Get_Day(RTC_ADDRESS, &Day);

    //24 Hour mode

    if(pm_flag == 1)

    {Hour = Hour + 12;

    }

    //Display Time

    Display_Time();

    //Calculate Temp Value

    Temp = (ADC_values[0] * 100) * V_STEP;

    //Format Temp Value

    itoa(Temp, LCD_Temp, 10);

    //Display Temp

    //lcd4_pos_xy(5,2);

    //lcd4_putstr(LCD_Temp);

    //Calculate pH value

    pH = ( ( (ADC_values[5] - PH_OFFSET) * V_STEP ) * PH_STEP ) + 7;

    //Format pH value

    dtostrf(pH, 3, 1, LCD_ph);

    //Display pH

    lcd4_pos_xy(17,2);

    lcd4_putstr(LCD_ph);

    //Turn on Relay 1 (Plankton Light) if within the //appropriate time window

    if((Hour >= PLANKTON_DAY_HOUR) && (Hour > PLANKTON_NIGHT_HOUR))

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, RELAY_1, DISABLE, 100);

    Relay1_on = 1;

    }

    else

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, RELAY_1, ENABLE, 100);

    Relay1_on = 0;

    }

    //Turn on Relay 3 (Main Tank Light) if within the //appropriate time window

    if((Hour >= MAIN_TANK_DAY_HOUR) && (Hour < MAIN_TANK_NIGHT_HOUR))

    {USART_motor_controller(MOTOR_CONTROLLER_2, RELAY_3, DISABLE, 100);

    Relay3_on = 1;

    }

    else

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, RELAY_3, ENABLE, 100);

  • 8/10/2019 Automatic Clownfish Hatchery

    65/81

    60

    Relay3_on = 0;

    }

    //Perform Rotifer Waterchange

    if((Day == Rotifer_day) && (Hour == ROTIFER_H20_CHANGE_HOUR) && (Minute ==

    ROTIFER_H20_CHANGE_MINUTE))

    {//Perform Rotifer water change

    Rotifer_Waterchange(&Minute);

    //Calculate next waterchange day

    Rotifer_day = Day + ROTIFER_PERIOD;

    if(Rotifer_day > 7)

    {

    Rotifer_day = Rotifer_day - 7;

    }

    }

    //Add new water to phytoplankton every 4 hours.

    if((Hour == Plankton_water) && (Minute < 2))

    {USART_motor_controller(MOTOR_CONTROLLER_2, MOTOR_CHANNEL_1, ENABLE,

    60);

    }

    else if((Hour == Plankton_water) && (Minute >=2))

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, MOTOR_CHANNEL_1, DISABLE,

    60);

    Plankton_water = Plankton_water + PLANKTON_NEW_H20;

    if(Plankton_water > PLANKTON_NIGHT_HOUR)

    {

    Plankton_water = PLANKTON_DAY_HOUR;

    }

    }

    //Monitor Plankton density

    itoa(ADC_values[2], LCD_Temp, 10);

    lcd4_pos_xy(0,3);

    lcd4_putstr(" ");

    lcd4_pos_xy(3,3);

    lcd4_putstr(LCD_Temp);

    Plankton_density_value = ADC_values[2];

    if( ((Hour >= PLANKTON_DAY_HOUR) && (Hour ORGANISM_DENSITY) && (Minute ==

    Plankton_density_reading)){

    Plankton_density_reading = Plankton_density_reading + 10;

    if(Plankton_density_reading > 59)

    {

    Plankton_density_reading = 0;

    }

  • 8/10/2019 Automatic Clownfish Hatchery

    66/81

    61

    USART_motor_controller(MOTOR_CONTROLLER_2, MOTOR_CHANNEL_3, ENABLE,

    100);

    }

    else if(Minute > Plankton_density_reading - 10)

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, MOTOR_CHANNEL_3, DISABLE,

    100);}

    //Rotifer water input pump

    if((ROTIFER_FLOAT1_PORT & FLOAT1) != 1)

    {

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_3, ENABLE,

    100);

    Rotifer_top_off = 1;

    }

    else if(Rotifer_top_off == 1)

    {

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_3, DISABLE,

    100);

    Rotifer_top_off = 0;

    }

    //If baby mode switch is toggled high, exit phytoplankton //mode and enter

    baby mode

    if(((BABY_MODE_PORT & BABY_MODE) == 0) && (*mode == 1))

    {

    *mode = 2;

    lcd4_pos_xy(0,0);

    lcd4_putstr(" ");

    lcd4_pos_xy(0,0);

    lcd4_putstr("Baby mode");

    }

    else if(((BABY_MODE_PORT & BABY_MODE) == BABY_MODE) && (*mode == 2))

    {

    *mode = 1;

    lcd4_pos_xy(0,0);

    lcd4_putstr(" ");

    lcd4_pos_xy(0,0);

    lcd4_putstr("Phytoplankton");

    }

    if(*mode == 2)

    {

    Babies(&Day, &Hour, &Minute, &Second, MAIN_TANK_DAY_HOUR,MAIN_TANK_NIGHT_HOUR);

    }

    }//End while loop

    }

    #endif

  • 8/10/2019 Automatic Clownfish Hatchery

    67/81

    62

    .

    .

    T B

    A C H. I

    .

    #ifndef __BABIES_H#define __BABIES_H

    #include

    #include

    #include

    #include

    #include

    #include "plankton.h"

    #include "ADC.h"

    #include "ADJD-S371.h"

    #include "motor_control_com.h"

    #include "Time_Functions.h"

    #include "usart.h"

    #include "ds1337.h"

    #define RED_SET_POINT 220 //Color Light Sensor Red compare value for 10 Rotifer/ml

    #define GREEN_SET_POINT 480 //Color Light Sensor Green comp. value for 3M

    Phytoplankton/ml

    #define CLS_SAMPLES 50

    #define PH_LOWER_SET_POINT 8.0 //pH should not fall below this range

    #define PH_UPPER_SET_POINT 8.3 //pH should not be above this point

    //Samples are taken and adjustments made

    #define PLANKTON_DENSITY_FREQ 5

    //Samples are taken and adjustments made

    #define ROTIFER_DENSITY_FREQ 5

    #define PH_SENSE_FREQ 1 //Take samples every hour

    //Global Variables

    //Main Tank Phytoplankton

    volatile unsigned char plankton_density = 0;

    volatile unsigned char rotifer_density = 0;

    //pH Control variables

    //Repeat this every hour

    volatile unsigned char pH_sense_time = 6;

    //Stop the pump after 30 sec

    volatile unsigned char pH_sense_stop = 30;

    volatile unsigned int red_total = 0, green_total = 0;

    volatile unsigned int red_average = 0, green_average = 0;volatile unsigned char Cls_counter = 0;

    //Function prototype

    void Babies(unsigned char* Day, unsigned char* Hour, unsigned char* Minute, unsigned char*

    Second, unsigned char main_tank_day_hour, unsigned char main_tank_night_hour);

    //Babies function definition.

  • 8/10/2019 Automatic Clownfish Hatchery

    68/81

    63

    void Babies(unsigned char* Day, unsigned char* Hour, unsigned char* Minute, unsigned char*

    Second, unsigned char main_tank_day_hour, unsigned char main_tank_night_hour)

    {

    unsigned int Color_light_green, Color_light_red;

    char lcd_red[6], lcd_green[6];

    //Take color light sensor reading

    ADJD_S371_TakeSensorReading();

    //Get Red and Green color values

    Color_light_red = ADJD_S371_GetRegisterData(DATA_RED_LO) |

    (ADJD_S371_GetRegisterData(DATA_RED_HI) = main_tank_day_hour) && (*Hour GREEN_SET_POINT) && (*Minute == plankton_density))

    {

    USART_motor_controller(MOTOR_CONTROLLER_2, MOTOR_CHANNEL_2, ENABLE, 60);}

    else if((*Hour >= main_tank_day_hour) && (*Hour

  • 8/10/2019 Automatic Clownfish Hatchery

    69/81

    64

    //then set the minute to 0.

    plankton_density = plankton_density + PLANKTON_DENSITY_FREQ;

    if(plankton_density > 59)

    {

    plankton_density = 0;

    }

    }

    //Main Tank Rotifer Density

    if((*Hour >= main_tank_day_hour) && (*Hour

    RED_SET_POINT) && (*Minute == rotifer_density))

    {

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_2, ENABLE, 100);

    }

    else if((*Hour >= main_tank_day_hour) && (*Hour 59)

    {

    rotifer_density = 0;

    }

    }

    //Compare pH value with pH set point and add chemical //accordingly.

    if((*Hour >= main_tank_day_hour) && (*Hour

    PH_UPPER_SET_POINT) || (pH < PH_LOWER_SET_POINT)) && (*Minute == pH_sense_time))

    {

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_1, ENABLE, 60);

    }

    else if((*Hour >= main_tank_day_hour) && (*Hour main_tank_night_hour)

    {

    pH_sense_time = main_tank_day_hour;

    }

    }}

    #endif

  • 8/10/2019 Automatic Clownfish Hatchery

    70/81

    65

    .

    .

    T

    .

    #ifndef __WATERCHANGE_H

    #define __WATERCHANGE_H

    #include

    #include

    #include

    #include

    #include "motor_control_com.h"

    #include "Time_Functions.h"

    #include "ds1337.h"

    #define FLOAT1 0x01

    #define FLOAT1_PORT PINC

    #define FLOAT2 0x02

    #define FLOAT2_PORT PINC#define FLOAT3 0x04

    #define FLOAT3_PORT PINC

    #define FLOAT4 0x08

    #define FLOAT4_PORT PINC

    //Function Prototypes

    void Rotifer_Waterchange(unsigned char* Minute_start);

    void Rotifer_Waterchange(unsigned char* Minute_start)

    {

    unsigned char hour, minute = *Minute_start, second;

    //Turn off Rotifer air pump

    USART_motor_controller(MOTOR_CONTROLLER_2, RELAY_2, DISABLE, 100);

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_3, DISABLE, 100);

    I2C_WriteRegister(RTC_ADDRESS, MINUTES, 0x17);

    while(minute < *Minute_start + 15)

    {

    RTC_Get_Time(RTC_ADDRESS, 1, &second, &minute, &hour);

    Display_Time();

    _delay_ms(100);

    }

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_4, ENABLE, 100);

    while((FLOAT3_PORT & FLOAT3) != FLOAT3)

    {

    RTC_Get_Time(RTC_ADDRESS, 1, &second, &minute, &hour);

    Display_Time();

    _delay_ms(100);

    }

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_4, DISABLE, 100);

  • 8/10/2019 Automatic Clownfish Hatchery

    71/81

    66

    USART_motor_controller(MOTOR_CONTROLLER_1, MOTOR_CHANNEL_3, ENABLE, 100);

    while((FLOAT1_PORT & FLOAT1) != FLOAT1)

    {

    RTC_Get_Time(RTC_ADDRESS, 1, &second, &minute, &hour);

    Display_Time();

    _delay_ms(100);}

    }

    #endif

    .

    .

    T ACHMC.. I

    ADC .

    #ifndef __ADC_H

    #define __ADC_H

    #include

    #include #include

    #include

    ////////////////////////////////////////////

    // ADC Constants

    ////////////////////////////////////////////

    #define VREF 4.971 //Measured Reference Voltage

    #define V_STEP (VREF / 256) //ADC voltage increment

    ////////////////////////////////////////////

    // Sensor Constants

    ////////////////////////////////////////////

    #define PH_STEP -0.414

    #define PH_OFFSET 128

    ////////////////////////////////////////////

    // ADC Variables

    ////////////////////////////////////////////

    volatile unsigned char ADC_values[6] = {0,0,0,0,0,0};

    volatile unsigned char ADC_limit_high[6] = {200, 100, 100, 100, 100, 255};

    volatile unsigned char ADC_limit_low[6] = { 0, 0, 0, 0, 0, 0};

    ////////////////////////////////////////////

    // Sensor Variables

    ////////////////////////////////////////////

    volatile char Temp;

    volatile float pH;

    ////////////////////////////////////////////// ADC USART Variables

    ////////////////////////////////////////////

    volatile unsigned char exit_counter = 0;

    volatile unsigned char usart_adc_seq = 0;

    volatile unsigned char adc_channel = 0;

    #endif //End ADC.h

  • 8/10/2019 Automatic Clownfish Hatchery

    72/81

    67

    .

    .

    T ADC

    A C H. T

    .

    #include #include #include

    #include "usart.h"

    // UART Constants#define MYADDRESS 0x03#define USART_EXIT 0xFF

    // ADC Constants#define NUM_SAMPLES 20#define NUM_CHANNELS 6

    //Global ADC Variablesvolatile unsigned char sample_complete = 0;

    /***********************************/// Interrupt Service Routines/***********************************/ISR(ADC_vect){

    // This event causes the main program to continue// after the ADC sample is complete.

    sample_complete = 1;}

    /***********************************/// Function Definitions/***********************************/void ADC_init(void){

    //Set Reference voltage to AREF

    //ADLAR: 1 - define 8-bit ADC modeADMUX = (0

  • 8/10/2019 Automatic Clownfish Hatchery

    73/81

    68

    //Wait for conversion to completewhile (sample_complete == 0)

    //Capture ADC resultADC_result = ADCH;

    //Format result for function output

    //ADC_sample = (ADC_high

  • 8/10/2019 Automatic Clownfish Hatchery

    74/81

    69

    //Send end of TxUSART_Transmit(USART_EXIT);USART_Transmit(USART_EXIT);

    //Process delay value. (Delay * NUM_CHANNELS = Total Delay)_delay_ms(10);

    }

    } //End of main while loop

    return(0); //main return value (Code will never reach this)} //End of ACH_ADC main

    .

    2.

    T

    A C H. T #2

    #1 .

    #include #include

    #include "usart.h"#include "operators.h"

    //Define Delay parameters#define F_CPU 8000000UL

    //Auto Clownfish Hatchery Device Address# define MYADDRESS 0x02

    //Non-PWM motor frequency#define PWM_TOP 10

    //Timer Variables

    #define TIMER0_TOP 0xFF#define TIMER0_BOTTOM 0x00#define TIMER1_TOP 0xC8#define TIMER1_BOTTOM 0x00

    /******************************* Channel Definitions *******************************///Channel 1#define CH1_PORT PORTD#define CH1_BIT 5

    //Channel 2#define CH2_PORT PORTB#define CH2_BIT 0

    //Channel 3

    #define CH3_PORT PORTB#define CH3_BIT 1

    //Channel 4#define CH4_PORT PORTB#define CH4_BIT 2

    //channel 5#define CH5_PORT PORTB#define CH5_BIT 3

  • 8/10/2019 Automatic Clownfish Hatchery

    75/81

    70

    //Channel 6#define CH6_PORT PORTB#define CH6_BIT 4

    //Channel EXT_1#define CH_EXT1_PORT PORTD#define CH_EXT1_BIT 4

    //Channel EXT_2#define CH_EXT2_PORT PORTD#define CH_EXT2_BIT 3

    //Channel EXT_3#define CH_EXT3_PORT PORTD#define CH_EXT3_BIT 2

    //channel EXT_4#define CH_EXT4_PORT PORTA#define CH_EXT4_BIT 1

    //Channel EXT_5#define CH_EXT5_PORT PORTA#define CH_EXT5_BIT 0

    //Function Prototypesvoid USART_Init(unsigned int ubrr);void USART_Transmit( unsigned char data );unsigned char USART_Receive( void );void Timer0_init(void);void Timer1_init(void);

    /////////////////////////////////////////Global Variables/////////////////////////////////////////USART Variablesvolatile unsigned char usart_select = 0;volatile unsigned char usart_data_sequence = 0;volatile unsigned char usart_endoftx = 0;volatile unsigned char channel = 0;

    // Values of 0, 1: 0 = Disable, 1 = Enable

    volatile unsigned char channel_enable = 1;volatile unsigned char channel_DC = 0;

    //Status Variablesvolatile unsigned char CH1_Status = 0;volatile unsigned char CH2_Status = 0;volatile unsigned char CH3_Status = 0;

    //Duty Cycle Variablesvolatile unsigned char CH1_DC = 5;volatile unsigned char CH2_DC = 5;volatile unsigned char CH3_DC = 5;

    int main(void){

    char Duty_cycle = 0;

    DDRA = (1

  • 8/10/2019 Automatic Clownfish Hatchery

    76/81

    71

    Timer1_init();USART_Init(MYUBRR);

    sei();

    while(1){

    //Channel 1 waveform

    if((CH1_Status == 1) & (CH1_DC >= Duty_cycle)){SETBIT(CH1_PORT,CH1_BIT);

    }

    else{

    CLEARBIT(CH1_PORT,CH1_BIT);}

    //Channel 2 waveformif((CH2_Status == 1) & (CH2_DC >= Duty_cycle)){

    SETBIT(CH2_PORT,CH2_BIT);}

    else

    { CLEARBIT(CH2_PORT,CH2_BIT);}

    //Channel 3 waveformif((CH3_Status == 1) & (CH3_DC >= Duty_cycle)){

    SETBIT(CH3_PORT,CH3_BIT);}

    else{

    CLEARBIT(CH3_PORT,CH3_BIT);}

    //Non-PWM waveform period controlif(Duty_cycle >= PWM_TOP)

    {Duty_cycle = 0;

    }

    else{

    Duty_cycle++;}

    }

    return(0);}

    ISR(USART_RX_vect){

    cli();

    char data;

    data = USART_Receive();

    //Look for address bitif(usart_select == 0){

    if(data == MYADDRESS){

    usart_select = 1;

  • 8/10/2019 Automatic Clownfish Hatchery

    77/81

    72

    //usart_data_sequence should be 1 at this pointusart_data_sequence++;usart_endoftx = 0;

    }}

    else if(data == 0xFF)

    { usart_endoftx++;

    if(usart_endoftx == 2){

    usart_data_sequence = 0;usart_select = 0;usart_endoftx = 0;

    }}

    //Perform operation if slave selectedelse if(usart_select == 1){

    switch(usart_data_sequence){

    case 1: channel = data;usart_data_sequence++;usart_endoftx = 0;

    break;

    case 2: channel_enable = data;usart_data_sequence++;usart_endoftx = 0;break;

    case 3: channel_DC = data;

    switch(channel){

    case 1: CH1_Status = channel_enable;CH1_DC = (((unsigned int)channel_DC) *

    ((unsigned int)PWM_TOP))/100;

    break;

    case 2: CH2_Status = channel_enable;CH2_DC = (((unsigned int)channel_DC) *

    ((unsigned int)PWM_TOP))/100;break;

    case 3: CH3_Status = channel_enable;CH3_DC = (((unsigned int)channel_DC) *

    ((unsigned int)PWM_TOP))/100;break;

    case 4: if(channel_enable == 0){CLEARBIT(TCCR0A,COM0A1);}

    else{SETBIT(TCCR0A,COM0A1);

    OCR0A = (((unsignedint)channel_DC) * ((unsigned int)TIMER0_TOP))/100;

    }

    break;

  • 8/10/2019 Automatic Clownfish Hatchery

    78/81

  • 8/10/2019 Automatic Clownfish Hatchery

    79/81

    74

    CLEARBIT(CH_EXT4_PORT,CH_EXT4_BIT);}

    else{SETBIT(CH_EXT4_PORT,CH_EXT4_BIT);}

    break;

    case 11: if(channel_enable == 0){CLEARBIT(CH_EXT5_PORT,CH_EXT5_BIT);}

    else{SETBIT(CH_EXT5_PORT,CH_EXT5_BIT);}

    break;

    default: break;}

    usart_select = 0;usart_data_sequence = 0;usart_endoftx = 0;break;

    //If the code gets this far, there is an error. Reset USART //sequencevariables.default: usart_select = 0;

    usart_data_sequence = 0;usart_endoftx = 0;break;

    }}

    sei();}

    //Channel 4 Waveformvoid Timer0_init(void){

    //(COM0A1 = 1, COM0A0 = 0) To turn on Channel 4TCCR0A = (0

  • 8/10/2019 Automatic Clownfish Hatchery

    80/81

    75

    TCCR1B = (0

  • 8/10/2019 Automatic Clownfish Hatchery

    81/81