1 | //B2 Taster K?ltebad
|
2 | //B3 Taster W?rmebad
|
3 |
|
4 |
|
5 |
|
6 | #include <avr/io.h>
|
7 | #include <avr/interrupt.h>
|
8 | #define F_CPU 2000000
|
9 | #include <util/delay.h>
|
10 | #include <inttypes.h>
|
11 | #include <stdint.h>
|
12 |
|
13 | #define TRUE 1
|
14 | #define FALSE 0
|
15 |
|
16 | // Anchlussbelegung:
|
17 |
|
18 | #define KTEMP_DDR DDRD //Temperatur Input vom Kältebad
|
19 | #define WTEMP_DDR DDRC //Temperatur Input vom Wärmebad
|
20 | #define PTEMP_DDR DDRA //Temperatur Input von Probe
|
21 |
|
22 | #define MOTOR_DDR DDRB //Datenrichtung zum Motor-Steuer-Atmega festlegen
|
23 | #define MOTOR_OUT PORTB //Ausgänge zum Motor-Steuer-Atmega
|
24 | #define MOTOR_IN PINB
|
25 |
|
26 | //#define WTEMP_IN PINC //Wärmebad abfragen
|
27 | //#define KTEMP_IN PIND //Kältebad abfragen
|
28 | //#define PTEMP_IN PINA //Probentemperatur abfragen
|
29 |
|
30 | #define CW PB0 //Motor cw richtung Kältebad
|
31 | #define CCW PB1 //Motor ccw richtung Wärmebad
|
32 | #define KB PB2 //Taster Kältebad abfragen
|
33 | #define WB PB3 //Taster Wärmebad abfragen
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | int main(void)
|
43 | {
|
44 | uint8_t w_temp = 0; //Variable zum speichern der Zustände vom Wärmebad
|
45 | uint8_t k_temp = 0; //Variable zum speichern der Zustände vom Kältebad
|
46 | uint8_t p_temp = 0; //Variable zum speichern der Zustände von der Probe
|
47 |
|
48 | const uint16_t pause = 200;
|
49 | const uint16_t pause_2 =80;
|
50 |
|
51 |
|
52 | KTEMP_DDR = 0x00; //Eing?nge D
|
53 | WTEMP_DDR = 0x00; //Eing?nge C
|
54 | PTEMP_DDR = 0x00; //Eing?nge A
|
55 | //B0 un B1 als Ausgänge, B2 und B3 als Eingänge:
|
56 | MOTOR_DDR = DDRB = (1 << DDB0) | (1 << DDB1) | (0 << DDB2) | (0 << DDB3);
|
57 |
|
58 |
|
59 |
|
60 | //Pause für 20 Sekunden damit alles andere initialisieren kann
|
61 | //for(int a=0; a<10; a++){_delay_ms( 1000 )};
|
62 |
|
63 |
|
64 |
|
65 | do
|
66 | {
|
67 | k_temp = 0;
|
68 | p_temp = 0;
|
69 | w_temp = 0;
|
70 | //k_temp = KTEMP_IN; //Temp vom Kältebad abholen
|
71 | //p_temp = PTEMP_IN; //Temp der Probe abholen
|
72 | //w_temp = WTEMP_IN; //Temp vom Wärmebad abholen
|
73 |
|
74 | if ( PINA & (1<<PINA0) ) {p_temp = p_temp + 1}
|
75 | if ( PINA & (1<<PINA1) ) {p_temp = p_temp + 2}
|
76 | if ( PINA & (1<<PINA2) ) {p_temp = p_temp + 4}
|
77 | if ( PINA & (1<<PINA3) ) {p_temp = p_temp + 8}
|
78 | if ( PINA & (1<<PINA4) ) {p_temp = p_temp + 10}
|
79 | if ( PINA & (1<<PINA5) ) {p_temp = p_temp + 20}
|
80 | if ( PINA & (1<<PINA6) ) {p_temp = p_temp + 40}
|
81 | if ( PINA & (1<<PINA6) ) {p_temp = p_temp + 80}
|
82 |
|
83 | if ( PINC & (1<<PINC0) ) {w_temp = w_temp + 1}
|
84 | if ( PINC & (1<<PINC1) ) {w_temp = w_temp + 2}
|
85 | if ( PINC & (1<<PINC2) ) {w_temp = w_temp + 4}
|
86 | if ( PINC & (1<<PINC3) ) {w_temp = w_temp + 8}
|
87 | if ( PINC & (1<<PINC4) ) {w_temp = w_temp + 10}
|
88 | if ( PINC & (1<<PINC5) ) {w_temp = w_temp + 20}
|
89 | if ( PINC & (1<<PINC6) ) {w_temp = w_temp + 40}
|
90 | if ( PINC & (1<<PINC6) ) {w_temp = w_temp + 80}
|
91 |
|
92 | if ( PIND & (1<<PIND0) ) {k_temp = k_temp + 1}
|
93 | if ( PIND & (1<<PIND1) ) {k_temp = k_temp + 2}
|
94 | if ( PIND & (1<<PIND2) ) {k_temp = k_temp + 4}
|
95 | if ( PIND & (1<<PIND3) ) {k_temp = k_temp + 8}
|
96 | if ( PIND & (1<<PIND4) ) {k_temp = k_temp + 10}
|
97 | if ( PIND & (1<<PIND5) ) {k_temp = k_temp + 20}
|
98 | if ( PIND & (1<<PIND6) ) {k_temp = k_temp + 40}
|
99 | if ( PIND & (1<<PIND6) ) {k_temp = k_temp + 80}
|
100 |
|
101 | //Wenn Taster vom K?ltebad an (d.h. Probe ist im Kältebad)
|
102 | if((PINB & (1<<KB)))
|
103 | {
|
104 | //Motor erst mal grundlegend ausschalten, um einen definierten Startwert zu haben
|
105 | PORTB &= ~ (1<<CCW); //Motor aus
|
106 | PORTB &= ~ (1<<CW); //Motor aus
|
107 |
|
108 |
|
109 | if((p_temp <= k_temp + 1)) //fals Probentemp gleich Kältebadtemp ist
|
110 | {
|
111 | //Pause um damit Probe die Temp vom Kältebad vollständig annehmen kann
|
112 | // for(int a=0; a<20; a++){_delay_ms( 1000 );}
|
113 |
|
114 | //ins Wärmebad fahren)
|
115 | PORTB &= ~ (1<<CCW);
|
116 | PORTB |= (1<<CW);
|
117 |
|
118 | //Pause für 20 Sekunden
|
119 | //for(int a=0; a<20; a++){_delay_ms( 1000 );}
|
120 | }
|
121 | }
|
122 |
|
123 | //Wenn Taster vom Wärmebad an (d.h. Probe ist im Wärmebad)
|
124 | if((PINB & (1<<WB)))
|
125 | {
|
126 | //Motor erst mal grundlegend ausschalten, um einen definierten Startwert zu haben
|
127 | PORTB &= ~ (1<<CCW); //Motor aus
|
128 | PORTB &= ~ (1<<CW); //Motor aus
|
129 |
|
130 |
|
131 | if((p_temp >= w_temp - 1))// fals Probentemp gleich Wärmebadtemp ist
|
132 | {
|
133 | //Pause um damit Probe die Temp vom Wärmebad vollständig annehmen kann
|
134 | //for(int a=0; a<20; a++){_delay_ms( 1000 );}
|
135 |
|
136 | //ins Kältebad fahren
|
137 | PORTB &= ~ (1<<CW);
|
138 | PORTB |= (1<<CCW);
|
139 |
|
140 | }
|
141 | }
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | } //ENDE do
|
149 | while(1);
|
150 |
|
151 | } //ENDE main
|