-
Notifications
You must be signed in to change notification settings - Fork 1
/
bomb clock countdown.txt
284 lines (266 loc) · 7.04 KB
/
bomb clock countdown.txt
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Program to make a clock with time setting functionality.
#include<reg51.h>
sbit dig_ctrl_4=P0^0; //Declare the control pins of the seven segment
sbit dig_ctrl_3=P0^1;
sbit dig_ctrl_2=P0^2;
sbit dig_ctrl_1=P0^3;
sbit reset=P1^4; // Reset pin to reset the clock.
sbit start=P1^7; //Start pin to start the clock after the time is set.
sbit incr=P1^6; //Increment pin to increase the digits during time setting.
sbit set=P1^5; // Set pin to set the time.
sbit beep=P3^0;
int sel_seg_to_incr=0;
int ret_seg_to_incre=0;
int recnt_incr_seg;
unsigned char dig_disp=0;
int min2=0;
int min1=0;
int sec2=0;
int sec1=0;
char dig_val[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67}; // to store values corresponding to digits 0 to 9
void delay(int a) // Function to provide a time delay of approx. 1 second using Timer1.
{
int i;
for(i=0;i<a;i++)
{
TL1=0xFD;
TH1=0x4B;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
}
int setfn() // Function to select minute and seconds digit to be set.
{
while(set==0)
{
switch(recnt_incr_seg)
{
case 1:
if(set==0) //select the min2 digit
{
dig_ctrl_4=1;
dig_ctrl_3=0;
dig_ctrl_2=0;
dig_ctrl_1=0;
recnt_incr_seg=1;
ret_seg_to_incre=1;
P2=dig_val[min2];
delay(20);
}
case 2:
if(set==0) // Select the min1 digit
{
dig_ctrl_4=0;
dig_ctrl_3=1;
dig_ctrl_2=0;
dig_ctrl_1=0;
recnt_incr_seg=2;
ret_seg_to_incre=2;
P2=dig_val[min1];
delay(20);
}
case 3:
if(set==0) //Select the sec 2 digit
{
dig_ctrl_4=0;
dig_ctrl_3=0;
dig_ctrl_2=1;
dig_ctrl_1=0;
recnt_incr_seg=3;
ret_seg_to_incre=3;
P2=dig_val[sec2];
delay(20);
}
case 4:
if(set==0) //Select the sec1 digit
{
recnt_incr_seg=1;
dig_ctrl_4=0;
dig_ctrl_3=0;
dig_ctrl_2=0;
dig_ctrl_1=1;
ret_seg_to_incre=4;
P2=dig_val[sec1];
delay(20);
recnt_incr_seg=1;
}
}
}
return(ret_seg_to_incre);
}
void increase(int a) //Function to set the minute or seconds digit
{
while(incr==0)
{
switch(a)
{
case 1: // To set the min2 digit.
P2=dig_val[min2]; //Display the value of min2
delay(15);
min2++;
if(min2==6)
min2=0;
P2=dig_val[min2];
delay(5);
break;
case 2: //To set the min1 digit.
P2=dig_val[min1];
delay(15);
min1++;
if(min1==10)
min1=0;
P2=dig_val[min1];
delay(5);
break;
case 3: // To set the sec2 digit.
P2=dig_val[sec2];
delay(15);
sec2++;
if(sec2==6)
sec2=0;
P2=dig_val[sec2];
delay(5);
break;
case 4: //To set the sec1 digit.
P2=dig_val[sec1];
delay(15);
sec1++;
if(sec1==10)
sec1=0;
P2=dig_val[sec1];
delay(5);
break;
}
}
}
void resetfn() // This function brings the clock to reset or set mode.
{
IE=0x80; //Disable timer0 interrupt to stop the display of the clock
sel_seg_to_incr=1;
recnt_incr_seg=1;
dig_ctrl_4=1;
dig_ctrl_3=0;
dig_ctrl_2=0;
dig_ctrl_1=0;
P2=dig_val[min2];
delay(5);
while(1)
{
if(start==0) //check if start pin is pressed
{
TMOD=0x11; //reset the timer0
TL0=0xf6;
TH0=0xFf;
IE=0x82; //enabling again the timer0 interrupt to start displaying of the clock
TR0=1;
break; // break loop and return to main program
}
if(set==0) //if set pin is pressed call set function
sel_seg_to_incr=setfn();
if(incr==0) // if incr pin is pressed call incr function
increase(sel_seg_to_incr);
}
}
void display() interrupt 1 // function to display the values on seven segmnet. For more details refer seven segment multiplexing.
{
TL0=0x36; //reloading timer0
TH0=0xf6;
P2=0xFF;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0;
dig_disp++;
dig_disp=dig_disp%4;
switch(dig_disp)
{
case 0:
P2=dig_val[sec1];
dig_ctrl_1 = 1;
break;
case 1:
P2= dig_val[sec2];
dig_ctrl_2 = 1;
break;
case 2:
P2= dig_val[min1];
dig_ctrl_3 = 1;
break;
case 3:
P2= dig_val[min2];
dig_ctrl_4 = 1;
break;
}
}
void main() //main function the programs begins from here
{
set=1; //delaring set, reset, start and incr as input pins
reset=1;
start=1;
incr=1;
TMOD=0x11; //enabling timer0
TL0=0xf6; //loading timer0
TH0=0xFf;
IE=0x82; //initialize timer0 interrupt
TR0=1; //triggering timer0
min2=0;
min1=0;
sec2=0;
sec1=0;
beep=1;
while(1) //forward counting of clock
{
while(min2>=0)
{ if(min2==0 && min1 ==0 && sec2==0 && sec1 == 0)
{
break;
}
while(min1>=0)
{
while(sec2>=0)
{
while(sec1>=0)
{
if(reset==0)
resetfn();
if(min2==0 && min1 ==0 && sec2==0 && sec1==0)
{
beep=0;
delay(10);
beep=1;
delay(10);
beep=0;
delay(10);
beep=1;
delay(10);
beep=0;
delay(10);
beep=1;
delay(10);
beep=0;
delay(10);
beep=1;
}
delay(20);
sec1--;
}
sec1=9;
sec2--;
}
sec1=9;
sec2=5;
min1--;
}
sec1=9;
sec2=5;
min1=9;
min2--;
}
min2=0;
min1=0;
sec2=0;
sec1=0;
beep=1;
if(reset==0)
resetfn();
}
}