-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrowave.c
316 lines (279 loc) · 9.78 KB
/
Microwave.c
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "Tiva.h"
#include "Switch.h"
#include "Buzzer.h"
#include "keypad.h"
#include "LCD.h"
#include "Timer.h"
#include "LED.h"
#include "Switch.h"
#include "defines.h"
#include <inttypes.h>
#include "Interrupt.h"
#include <stdbool.h>
char time[]={'0','0',':','0','0','\0'};
void microwave_Init(void){
System_Init();
buzzer_Init();
keypad_Init();
LCD_Init();
LED_Init();
SW1_Init();
SW2_Init();
SW3_Init();
interrupt_Init();
}
/*pause time on LCD*/
void pause(void){
START =0; // reset start flag
SW1_Press_Counts = 1;
LCD_Clear_Display(); //clear LCD
LCD_Show(time); //display on LCD
while(1)
{
WhiteOn(); // turns leds on
Systick_Wait_ms(500); // wait 0.5 second
LED_Clear(); // clear LCD
Systick_Wait_ms(500); // wait 0.5 second
if((SW3_Input() != 0x04) && (START ==1) ) //check if sw2 and sw3 pressed together
{
LCD_Clear_Display(); //clear LCD
LCD_Show("Close The Door"); //display on LCD
START =0; // reset start flag
}
if(((SW3_Input() == 0x04) && START ==1) || (RESET == 1 ))//check if sw2 pressed and sw3 not pressed or reset flag is set
{
SW1_Press_Counts = 0; // reset count flag
LCD_Clear_Display(); // clear LCD
break;
}
}
PAUSE =0; // reset pause flag
}
/*reset timer array */
void reset(void){
time[0] = '0';
time[1] = '0';
time[3] = '0';
time[4] = '0';
LED_Clear(); // clear LCD
RESET=0; // Reset the flag
}
/*check if the input is vaild or not */
bool Check_Invalid(void){
if( time[0]>'3' ) // check if tens of mins is more than 3
{
return true;
}
if( time[0]=='3' && ( time[1]!='0' || time[3] !='0' || time[4] !='0') )// check if time is more than 30 min
{
return true;
}
if( time[3]>'5' ) // check if tens of seconds is more than five
{
return true;
}
if(time[0]=='0' && time[1] =='0') //check if time is less than 1 min
{
return true;
}
else
{
return false;
}
}
void End_Operation(){
int i;
START=0; // reset the value of flags
Start_Cook_Time = 0;
SW1_Press_Counts=0;
LCD_Clear_Display(); // clear LCD
LCD_Show("End"); // display end on LCD
for(i=0; i<3; i++){
beep(); // turn buzzer on
WhiteOn(); // turn leds on
Systick_Wait_ms(500); // wait 0.5 second
LED_Clear(); // clear LCD
stop_Beep(); //turn buzzer off
Systick_Wait_ms(500); //wait 0.5 second
}
LCD_Clear_Display(); //clear LCD
}
/* disply the countdown timer on LCD*/
void Time_Display(char time[]){
LCD_Clear_Display();
while(time[0]!='0' || time[1]!='0' || time[3]!='0' || time[4]!='0') //check the timer is not equal zero
{
WhiteOn(); // turn leds on
LCD_Clear_Display(); //clear LCD
LCD_Show(time); // display time on LCD
if((PAUSE == 1) || (SW3_Input() !=0x04)){ //check if SW1 pressed or the door opened
pause(); // pause time on LCD
}
if(RESET == 1){ // check if sw1 pressed twice
reset(); // reset the timer array
break;
}
Systick_Wait_ms(1000); //wait 1 second
if(time[4]!='0' ) // check if units of seconds not equal zero
{
time[4]--; //decrease the units of seconds
}
else if(time[4]=='0' && time[3]!='0') //check if tens of seconds not equal zero and units of seconds equal zero
{
time[4]='9'; //units of seconds equal nine
time[3]--; //decrease the tens of seconds
}
else if(time[4]=='0' && time[3]=='0' && time[1]!='0') //check if seconds equal zero and units of mins not equal zero
{
time[4]='9'; //units of seconds equal nine
time[3]='5'; //tens of seconds equal five
time[1]--;//decrease the units of mins
}
else if(time[4]=='0' && time[3]=='0' && time[1]=='0' && time[0]!='0')//check if seconds equal zero and tens of mins not equal zero
{
time[4]='9'; //units of seconds equal nine
time[3]='5'; //tens of seconds equal five
time[1]='9'; //units of mins equal nine
time[0]--; //decrease the tens of mins
}
LCD_Clear_Display(); //clear LCD
}
End_Operation();
}
/*start countdown of timer*/
void start(void){
RESET=0;
PAUSE =0;
Time_Display(time);
}
/* take time from user*/
void Cook_Time(void){
char x;
int i ;
bool invalid= false;
Cook_Time_f = 1; // set flag (get in function cook time)
time[4]='0'; // reset the time array
time[3]='0';
time[1]='0';
time[0]='0';
LCD_Show("Cooking Time?");
Systick_Wait_ms(1000); //wait 1 second
for(i=4;i>0;i--)
{
x= KeyScan(); // take input from user
LCD_Clear_Display();
if(Cook_Time_Again || Start_Cook_Time){ // check if SW2 or SW1 pressed
LCD_Clear_Display(); //clear LCD
break;
}
if( x<'0' || x>'9' ) //check if the input is among 0 to 9
{
invalid= true; // set the invaild flag
break;
}
time[0]=time[1]; // make shift left to timer array
time[1]=time[3];
time[3]=time[4];
time[4]=x;
LCD_Show(time); // display time on LCD
Systick_Wait_ms(500); //wait 0.5 seconds
}
while(1)
{
if(Cook_Time_Again == 1 || Start_Cook_Time == 1 || invalid == 1 ){ //check if SW2 or SW1 pressed
LCD_Clear_Display(); //clear LCD
break;
}
}
Cook_Time_f = 0; // reset flag (get out from function cook time)
if((Check_Invalid() || invalid )&& (!Cook_Time_Again)) // check if input is not valid or time is reset
{
LCD_Clear_Display(); // clear LCD
LCD_Show("Invalid value"); //display on LCD
Systick_Wait_ms(2000); //wait 2 seconds
LCD_Clear_Display(); //clear LCD
Start_Cook_Time = 0; //reset the flag
Cook_Time(); //back again to function until input is valid
}
}
/* to convert char to integer */
int Char_to_int(char x){
int number = x-'0'; //to get the number that is between 0 and 9
return number;
}
/* to convert integer to char and get tens*/
char IntToChar_Tens(int x){
int Tens= x/10; // to get tens
char required;
required = Tens +'0'; //convert to char
return required;
}
/* to convert integer to char and get units*/
char IntToChar_Units(int x){
int Units= x%10; //to get ones
char required;
required = Units +'0'; //convert to char
return required;
}
void cook_Popcorn(void){
time[1]='1'; // to make time equal 1 min
LCD_Show("Popcorn"); // show popcorn in lcd
Systick_Wait_ms(1000); // wait 1 second
LCD_Clear_Display(); // clear display
LCD_Show(time); // show time on LCD
}
/*take num of kilos and count time to display*/
void cook_Beef_or_Chicken(char choice){
int minutes;
int seconds;
double TimeInMinutes_d;
char No_kilos;
int no_kilos ;
if(choice ==beef) // check if the choose is B
{
LCD_Show("Beef weight?"); // display on LCD
Systick_Wait_ms(500); //wait 0.5 second
LCD_Clear_Display(); // clear LCD
}
else if(choice ==chicken) // check if the choose is C
{
LCD_Show("Chicken weight?"); // display on LCD
Systick_Wait_ms(500); //wait 0.5 second
LCD_Clear_Display(); // clear LCD
}
do
{
LCD_Show("Kilos? 1 to 9"); // display on LCD
Systick_Wait_ms(300); // wait 0.3 second
No_kilos =KeyScan(); // take input from kaypad
LCD_Clear_Display(); // clear LCD
if(No_kilos<'1' || No_kilos>'9' ) //check if num of kilos not is between 1 and 9
{
LCD_Show("Err"); // display on LCD
Systick_Wait_ms(2000); // wait 2 seconds
LCD_Clear_Display(); // clear LCD
}
}
while(No_kilos<'1' || No_kilos>'9'); // wait until num of kilos is between 1 and 9
LCD_Show("Weight is "); //display on LCD
LCD_Write(No_kilos); //writes char on LCD
Systick_Wait_ms(500); //wait 0.5 second
if (choice ==beef) // check if the choose is B
{
no_kilos=Char_to_int(No_kilos); // convert char to int
TimeInMinutes_d=0.5*no_kilos ; // count time
}
else if(choice == chicken) // check if the choose is C
{
no_kilos=Char_to_int(No_kilos); // convert char to int
TimeInMinutes_d=0.2*no_kilos; // count time
}
minutes= (int)TimeInMinutes_d; // count the num of mins
seconds= (TimeInMinutes_d-minutes) * 60; // count the num of seconds
time[0]=IntToChar_Tens(minutes); // convert int to char to display it on LCD
time[1]=IntToChar_Units(minutes);
time[3]=IntToChar_Tens(seconds);
time[4]=IntToChar_Units(seconds);
LCD_Clear_Display(); //clear LCD
LCD_Show(time); //display on LCD
}