-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
235 lines (177 loc) · 4.08 KB
/
Copy pathmain.c
File metadata and controls
235 lines (177 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
* GccApplication8.c
*
* Created: 12/1/2017 4:25:21 PM
* Author : Raffique
*/
/*
* GccApplication4.c
*
* Created: 11/10/2017 7:29:55 AM
* Author : Raffique
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
//#include <asf.h>
int seconds = 0, As0 = 10, As1 = 10, As2 = 10, As3 = 10, As4 = 10, As5 = 10, As6 = 10;
int limit = 20;
int shut_off = 9, check_others = 9;
const int d_time = 700;
int main()
{
DDRB = 0xFF;
DDRD = 0x00;
// Buttons
PORTD |= (1<<6);
PORTD |= (1<<5);
PORTD |= (1<<4);
PORTD |= (1<<3);
PORTD |= (1<<2);
PORTD |= (1<<1);
PORTD |= (1<<0);
/* EICRA &= ~(1 << ISC00); // set INT0 to trigger on ANY logic change
EIMSK |= (1 << INT0); // Turns on INT0 */
// Set the Timer Mode to CTC
// Set the Timer Mode to CTC
OCR1A = 0x3CF;
TCCR1B |= (1 << WGM12);
// Mode 4, CTC on OCR1A
TIMSK |= (1 << OCIE1A);
//Set interrupt on compare match
TCCR1B |= (1 << CS12) | (1 << CS10);
// set prescaler to 1024 and start the timer
sei();
//light relays
PORTB |= (1<<7);
PORTB |= (1<<6);
PORTB |= (1<<5);
PORTB |= (1<<4);
PORTB |= (1<<3);
PORTB |= (1<<2);
PORTB |= (1<<1);
// this is for the chime
PORTB |= (1<<0);
while (1)
{
//-------------------------------------------------button 1
if( (!(PIND & (1<<0))) )
{
As0 = 0;
PORTB &= ~(1<<1);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
/*
//--------------------------------------------------- button 2
if( (!(PIND & (1<<1))) )
{
As1 = 0;
//PORTB &= ~(1<<2);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
//---------------------------------------------------- button 3
if( (!(PIND & (1<<2))) )
{
As2 = 0;
PORTB &= ~(1<<3);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
//----------------------------------------------------- button 4
if( (!(PIND & (1<<3))) )
{
As3 = 0;
PORTB &= ~(1<<4);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
//----------------------------------------------------- button 5
if( (!(PIND & (1<<4))) )
{
As4 = 0;
PORTB &= ~(1<<5);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
//----------------------------------------------------- button 6
if( (!(PIND & (1<<5))) )
{
As5 = 0;
PORTB &= ~(1<<6);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
//----------------------------------------------------- button 7
if( (!(PIND & (1<<6))) )
{
As6 = 0;
PORTB &= ~(1<<7);
PORTB &= ~(1<<0);
_delay_ms(d_time);
PORTB |= (1<<0);
}
*/
//----------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------//
if(As0>shut_off) { PORTB |= (1<<1); }
if(As1>shut_off) { PORTB |= (1<<2); }
if(As2>shut_off) { PORTB |= (1<<3); }
if(As3>shut_off) { PORTB |= (1<<4); }
if(As4>shut_off) { PORTB |= (1<<5); }
if(As5>shut_off) { PORTB |= (1<<6); }
if(As6>shut_off) { PORTB |= (1<<7); }
}
/*-------------------------------------------------------------------------------------------------------------*/
}
ISR (TIMER1_COMPA_vect)
{
As0++; As1++; As2++; As3++; As4++; As5++; As6++;
/*
if(As0<shut_off) { PORTB ^= (1<<1); }
if(As1<shut_off) { PORTB ^= (1<<2); }
if(As2<shut_off) { PORTB ^= (1<<3); }
if(As3<shut_off) { PORTB ^= (1<<4); }
if(As4<shut_off) { PORTB ^= (1<<5); }
if(As5<shut_off) { PORTB ^= (1<<6); }
if(As6<shut_off) { PORTB ^= (1<<7); }
*/
if(As0 > limit)
{
As0 = limit;
}
if(As1 > limit)
{
As1 = limit;
}
if(As2 > limit)
{
As2 = limit;
}
if(As3 > limit)
{
As3 = limit;
}
if(As4 > limit)
{
As4 = limit;
}
if(As5 > limit)
{
As5 = limit;
}
if(As6 > limit)
{
As6 = limit;
}
}
// && (As1>check_others) && (As2>check_others) && (As3>check_others) && (As4>check_others) && (As5>check_others) && (As6>check_others)