티스토리 뷰

프로그래밍/C

마이크로프로세서 0517

대싕:) 2018. 5. 24. 15:33





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
#include <io.h>
#include <mega128.h>
#include <delay.h>
#define sei() {#asm("sei")}
unsigned char led = 0b00000000;
int status = 0;
interrupt [2void int0_func(){   // INT.0의 인터럽트 벡터는 2
    if(status == 2){}
    else if(status == 3){
        led = (led>>1)&led; 
    }else{
        led = 0b00000001;
    }
    status = 1;
}
interrupt [3void int1_func(){   // INT.1의 인터럽트 벡터는 3
    if(status == 1){}
    else if(status == 3){
        led = (led>>1)&led; 
    }else{
        led = 0b10000000;
    }
    status = 2;
}
interrupt [4void int2_func(){   // INT.2의 인터럽트 벡터는 4
    if(status == 1 && status == 2){
        led = (led>>1)|led;
    }
    else{
        led = 0b00000011;
    } 
    status = 3;
}
interrupt [5void int3_func(){   // INT.3의 인터럽트 벡터는 5
    led = 0b11110000;
    status = 4;
}
void main(){
    EIMSK = 0b00001111;
    EICRA = 0b00000000;
    SREG |= 0x80;
    DDRB = 0xff;
    DDRD = 0x00;
    led = 0b00000000;
    status = 0;
    while(1){
        PORTB = ~led;
        if(status == 1){
            if(led == 0b10000000){
                led = 0b00000001;
                delay_ms(300);
            }
            else {
                led = led<<1;
                delay_ms(300);
            }
                 
        }
        else if(status == 2){
            if(led == 0b00000001){
                led = 0b10000000;
                delay_ms(300);
            }
            else {
                led = led>>1;
                delay_ms(300);
            }       
        }
        else if(status == 3){
            if(led == 0b10000001){
                led = 0b11000000;
                delay_ms(300);
            }
            else if(led == 0b00000011){
                led = 0b10000001;
                delay_ms(300);
            }
            else {
                led = led>>1;
                delay_ms(300);
            }    
        }
        else if(status == 4){
            if(led == 0b11110000){
                led = 0b00001111;
                delay_ms(300);
            }
            else {
                led = 0b11110000;
                delay_ms(300);
            }  
        }
        else {
            led = 0b00000000;
        }
                  
    }
}
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/01   »
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
글 보관함