티스토리 뷰





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
#include <io.h>
#include <mega128.h>
#include <delay.h>
 
void main(){
    unsigned char type = 0x00;
    unsigned char i = 0b00000001;
 
    DDRB = 0xff;
    DDRD = 0x00;
    
 
    while(1){           
        PORTB = ~i;
        delay_ms(300); 
        if(type == 0x01){
            i = i << 1;  
            if(i == 0x00){
                i = 0b00000001;
            } 
        }
        if(type == 0x02){
            i = i >> 1;
            if(i == 0x00){
                i = 0b10000000;
            } 
        }
        if(type == 0x03){
            i = i<<1;
            if(i == 0b10000000){
                i = 0b10000001;
            }
            else if(i == 0b00000010){
                i = 0b00000011;
            } 
        }
        if(type == 0x04){
            if(i == 0b00001111){
                i = 0b11110000;
            }
            else if(i == 0b11110000){
                i = 0b00001111;
            } 
        }
                
        if(PIND.0 == 0){
            type = 0x01;
            i = 0b00000001;
        }
        if(PIND.1 == 0){
            type = 0x02;
            i = 0b10000000;
        }
        if(PIND.2 == 0){
            type = 0x03;
            i = 0b00000011;
        }
        if(PIND.3 == 0){
            type = 0x04;
            i = 0b00001111;
        }  
    }
                
}
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
글 보관함