-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCode
More file actions
270 lines (221 loc) · 7.12 KB
/
Copy pathCode
File metadata and controls
270 lines (221 loc) · 7.12 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <tiny2313.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x1B ;PORTA
.equ __sda_bit=1
.equ __scl_bit=0
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// 1 Wire Bus functions
//#asm
// .equ __w1_port=0x12 ;PORTD
// .equ __w1_bit=6
//#endasm
//#include <1wire.h>
// DS1820 Temperature Sensor functions
//#include <ds18b20.h>
#include <delay.h>
int t1,t2,t3,t4;
int t,h,r,f,j;
int e1,e2,e3,e;
unsigned char hour,min,sek;
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
TCNT1H=0x00;
TCNT1L=0x00;
// Place your code here
h++;
if(h==2){h=0;};
rtc_get_time(&hour,&min,&sek);
t1=hour/10;
t2=hour%10;
t3=min/10;
t4=min%10;
if (j==1) { f++;};
if(f<40){ if(f>9){ if(f%2==1){t1=t2=11;} if(PIND.0==0){hour++; if (hour>23) {hour=00; }; rtc_set_time(hour,00,00); }}}
if(f<110){ if(f>40){if(f%2==1){t3=t4=11;} if(PIND.0==0){min++; if (min>59) {min=00; }rtc_set_time(hour,min,00); }}}
if (f>107) {j=0; f=0; };
if (f==7) {j=0; f=0; };
e++;
if (e>100) {e=90; };
//};
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0xFF;
// Port D initialization
// Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
// State6=T State5=0 State4=0 State3=0 State2=0 State1=P State0=T
PORTD=0x02;
DDRD=0x3C;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 7,813 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x0F;
OCR1AL=0x42;
OCR1BH=0x00;
OCR1BL=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
// 1 Wire Bus initialization
//w1_init();
// Global enable interrupts
#asm("sei")
PORTD=1;
// rtc_set_time(20,44,00);
while (1)
{
// Place your code here
if(e>2){ if(PIND.0==0){j=1;}; }
if(f==1){if(PIND.0==0){j=0; f=0;}}
if(f>2){if(f<6){ if(PIND.0==0){f=8;} if(f%2==1){t1=t2=t3=t4=11;} } }
PORTD=0b11101111;
switch(t1) {
case 0: {PORTB=0b01111110; break; }
case 1: {PORTB=0b01010000;break; }
case 2: {PORTB=0b00111011; break; }
case 3: {PORTB=0b01110011; break; }
case 4: {PORTB=0b01010101; break; }
case 5: {PORTB=0b01100111;break; }
case 6: {PORTB=0b01101111;break; }
case 7: {PORTB=0b01010010; break; }
case 8: {PORTB=0b01111111; break; }
case 9: {PORTB=0b01110111;break; }
case 11: {PORTB=0b00000000;break; }
};
delay_ms(1);
// h=sek%2;
if (h==0) {
PORTD=0b11011111;
switch(t2) {
case 0: {PORTB=0b01111110; break; }
case 1: {PORTB=0b01010000;break; }
case 2: {PORTB=0b00111011; break; }
case 3: {PORTB=0b01110011; break; }
case 4: {PORTB=0b01010101; break; }
case 5: {PORTB=0b01100111;break; }
case 6: {PORTB=0b01101111;break; }
case 7: {PORTB=0b01010010; break; }
case 8: {PORTB=0b01111111; break; }
case 9: {PORTB=0b01110111;break; }
case 11: {PORTB=0b00000000;break; }
};
delay_ms(1);
} else {
PORTD=0b11011111;
switch(t2) {
case 0: {PORTB=0b11111110; break; }
case 1: {PORTB=0b11010000;break; }
case 2: {PORTB=0b10111011; break; }
case 3: {PORTB=0b11110011; break; }
case 4: {PORTB=0b11010101; break; }
case 5: {PORTB=0b11100111;break; }
case 6: {PORTB=0b11101111;break; }
case 7: {PORTB=0b11010010; break; }
case 8: {PORTB=0b11111111; break; }
case 9: {PORTB=0b11110111;break; }
case 11: {PORTB=0b00000000;break; }
};
delay_ms(1);
};
PORTD=0b11110111;
switch(t3) {
case 0: {PORTB=0b01111110; break; }
case 1: {PORTB=0b01010000;break; }
case 2: {PORTB=0b00111011; break; }
case 3: {PORTB=0b01110011; break; }
case 4: {PORTB=0b01010101; break; }
case 5: {PORTB=0b01100111;break; }
case 6: {PORTB=0b01101111;break; }
case 7: {PORTB=0b01010010; break; }
case 8: {PORTB=0b01111111; break; }
case 9: {PORTB=0b01110111;break; }
case 11: {PORTB=0b00000000;break; }
};
delay_ms(1);
PORTD=0b11111011;
switch(t4) {
case 0: {PORTB=0b01111110; break; }
case 1: {PORTB=0b01010000;break; }
case 2: {PORTB=0b00111011; break; }
case 3: {PORTB=0b01110011; break; }
case 4: {PORTB=0b01010101; break; }
case 5: {PORTB=0b01100111;break; }
case 6: {PORTB=0b01101111;break; }
case 7: {PORTB=0b01010010; break; }
case 8: {PORTB=0b01111111; break; }
case 9: {PORTB=0b01110111;break; }
case 11: {PORTB=0b00000000;break; }
};
delay_ms(1);
};
}