· 6 years ago · Jun 29, 2019, 04:40 AM
1#include <avr/io.h>
2#include <stdio.h>
3
4int main(void)
5{
6 DDRA = 0x00; //PORTA = 0x00;
7 DDRB = 0xFF; //PORTB = 0x00;
8
9 typedef enum {
10 firstkey,
11 secondkey,
12 dooropens,
13 }doorstate;
14
15 doorstate state = firstkey;
16 char secretkey;
17 while (1)
18 {
19 switch(state)
20 {
21 case firstkey:
22 scanf("%c", secretkey); //?????
23 if (secretkey == '#') {
24 PORTA == 0x01 << 3;
25 state = secondkey;
26 }
27 else
28 state = firstkey;
29 break;
30 case secondkey:
31 scanf("%c", secretkey);//?????
32 if (secretkey == 'Y') {
33 PORTA = PORTA | 0x02;
34 state = dooropens;
35 }
36 else
37 state = firstkey;
38 break;
39 case dooropens:
40 PORTB = 0x01;
41 if (PORTA == 0x80) {
42 state = firstkey;
43 PORTB = 0x00;
44 }
45 break;
46 default:
47 state = firstkey;
48 }
49 }
50}