-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperations.h
243 lines (206 loc) · 6.04 KB
/
operations.h
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
#include "TM4C123.h"
#include "stdio.h"
#include "Io.h"
#include "delays.h"
#include "keypad.h"
#include "lcd.h"
#include "switches.h"
#include "stdlib.h"
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
void start_reading(unsigned char key);
void beef_cooking(unsigned char weight);
void chicken_cooking(unsigned char weight);
enum States {idle, prep, cooking, finish} mystate;
void RGB_Init(void);
void RGB_Output(unsigned char data);
void Blink (void);
enum States countdown(int min, int sec);
enum States cooking_time(void);
void SW3_Init(void);
unsigned sw3_Input(void);
unsigned char button_in;
unsigned char door_button;
unsigned char key;
unsigned char weight;
int seconds;
int minutes;
char c;
int min;
int sec;
void RGB_Init()
{
SYSCTL_RCGCGPIO_R |= 0x20; //for all bits in port f
while((SYSCTL_PRGPIO_R &= 0x20)== 0){} //delay
GPIO_PORTF_LOCK_R = 0x4C4F434B;
GPIO_PORTF_CR_R |= 0x0E;
GPIO_PORTF_AMSEL_R &=~ 0x0E;
GPIO_PORTF_AFSEL_R &=~ 0x0E;
GPIO_PORTF_DIR_R |= 0x0E;
GPIO_PORTF_DEN_R |= 0x1F;
GPIO_PORTF_PCTL_R &=~0x0000FFF0;
GPIO_PORTF_DATA_R &=~0x0E;
}
void RGB_Output(unsigned char data)
{
GPIO_PORTF_DATA_R &=~ 0x0E;
GPIO_PORTF_DATA_R |= data;
}
void Blink (void){
RGB_Output(0x0E);
delayMs(1000);
RGB_Output(0x00);
delayMs(1000);
}
int8_t i;
void start_reading(unsigned char key)
{
LCD_command(0x80); /* LCD cursor location */
switch (key)
{
case ('A'):
LCD_command(0x01);//clearing lcd
LCD_String("Popcorn");
delayMs(2000);//delay 2 seconds
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
break;
case ('B')://miffro -->case B
LCD_String ("Beef");
delayMs(2000);//delay 2 seconds
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
break;
case ('C'):
LCD_String ("chicken");
delayMs(2000);//delay 2 seconds
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
break;
case('D'):
LCD_String("Cooking Time?");
delayMs(2000);
LCD_command(0xC0);
mystate =cooking;
break;
}
return;
}
void beef_cooking(unsigned char weight){
if(weight== 'A'||weight=='B'||weight=='C'||weight=='D'||weight=='*'||weight=='#'||weight=='0'){
LCD_command(0x01);//clearing lcd
LCD_String("Err");
delayMs(2000);
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
}
else{
int x = weight -48;
x=x*30;
minutes = x/60;
seconds = x-(minutes *60);
mystate=countdown( minutes, seconds);
}
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
}
void chicken_cooking(unsigned char weight){
if(weight== 'A'||weight=='B'||weight=='C'||weight=='D'||weight=='*'||weight=='#'||weight=='0'){
LCD_command(0x01);//clearing lcd
LCD_String("Err");
delayMs(2000);
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
}
else{
int x = weight -48;
x=x*12;
minutes = x/60;
seconds = x-(minutes *60);
mystate=countdown( minutes, seconds);
}
LCD_command(0x01);//clearing lcd
LCD_command(0x02);//returing cursor to its initial position
}
enum States cooking_time(void){
char arr[4]= {'0','0','0','0'};
int j;
LCD_command(0x01);
LCD_String("00:00");
while(1){
while (keypad_getkey() == 0xFF && sw_Input() != 0x11){};//waiting to enter a char or pressing a switch
if (keypad_getkey() != 0xFF){
c = keypad_getkey();//taking characters from user
if(c== 'A'||c=='B'||c=='C'||c=='D'||c=='*'||c=='#'){//if input is not a number display an error
LCD_command(0x01);//clearing lcd
LCD_String("Err");
delayMs(2000);
LCD_command(0x02);
mystate =idle;//returing cursor to its initial position
}
else{
for( j=0; j<3 ; j++){//taking numbers from user and store it in an array
arr[j] = arr[j+1];
}
arr[3] = c;
min = ((arr[0])-48)*10+ (arr[1]-48);//calculating minutes from 1st 2 elements in the array
sec = ((arr[2])-48)*10+ (arr[3]-48);//calculating secondes from 2nd 2 elements in the array
LCD_Display(min, sec);
//mystate=cooking;
}
}
delayMs(2000);
while(sw_Input()== 0x01 ){
LCD_command(0x01);//clearing lcd
return idle;
}
while (sw_Input() == 0x10){ //switch 2 is pressed
if((min == 30 && sec == 0)|| (min<30 && sec <= 59 && sec > 0)) // check input time conditions
{
mystate=countdown(min,sec ); //start countdown
if(mystate==idle)return idle;
else {
LCD_command(0x01);//clearing lcd
return finish;}
}
else{
LCD_command(0x01);//clearing lcd
LCD_String("Err");
delayMs(2000);
LCD_command(0x02);//returing cursor to its initial position
return idle;
}
}
}
}
enum States countdown(int min, int sec){
while (min != -1){
RGB_Output(0x0E);
LCD_Display(min,sec);//displays minutes and secondes on lcd
delayMs(290);
sec--;
while(sw3_Input()==1){ Blink();}//While door open pause
while(1){
while(sw_Input()==0x01){//switch 1 pressed for 1st time and pause
delayMs(3000);
while(sw_Input()!=0x10){//switch 2 pressed after switch 1 (continue cooking)
Blink();
if(sw_Input()==0x01){//switch 1 pressed for 2nd time clear lcd
LCD_command(0x01);
LCD_String("lcd clear!");
delayMs(500);
LCD_command(0x01);
return idle;
}
}
}
break;
}
if(sec == -1){
min--;
sec = 59;
}
}
return finish;
}