-
Notifications
You must be signed in to change notification settings - Fork 0
/
taror002_lab4_part3.c
113 lines (91 loc) · 1.58 KB
/
taror002_lab4_part3.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
/*
* taror002_lab4_part3'.c
*
* Created: 4/19/2018 7:59:21 AM
* Author : tanish
*/
#include <avr/io.h>
enum LA_States { LA_SMStart, init, init_wait, display, wait, display1, wait1} LA_State;
#define A0 (~PINA & 0x01)
unsigned char tmp = 0x00;
void TickFct_LED()
{
switch(LA_State) { // Transitions
case LA_SMStart: // Initial transition
LA_State = init;
break;
case init:
if(A0){
LA_State = init;
}else{
LA_State = init_wait;
}
break;
case init_wait:
if(!A0){
LA_State = init_wait;
}else{
LA_State = display;
}
break;
case display:
if(!A0){
LA_State = wait;
}else{
LA_State = display;
}
break;
case wait:
if(!A0){
LA_State = wait;
}else{
LA_State = display1;
}
break;
case display1:
if(!A0){
LA_State = wait1;
}else{
LA_State = display1;
}
break;
case wait1:
if(!A0){
LA_State = wait1;
}else{
LA_State = init;
}
break;
default:
LA_State = LA_SMStart;
break;
} // Transitions
switch(LA_State) { // State actions
case init:
PORTC = 0x00;
break;
case init_wait:
break;
case display:
PORTC = 0xAA;
break;
case display1:
PORTC = 0x55;
break;
case wait:
break;
case wait1:
break;
default:
break;
} // State actions
}
int main(void) {
DDRA=0x00; PORTA=0xFF;
DDRC=0xFF; PORTC=0x00;
PORTC = 0x00; // Initialize outputs
LA_State = LA_SMStart; // Indicates initial call
while(1) {
TickFct_LED();
}
}