include avr io include avr delay static void avr_init void int main vo

 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
#include <avr/io.h>
#include <avr/delay.h>
static void avr_init(void);
int main(void)
{
avr_init();
unsigned char tmp;
PORTB=0b00000100;
_delay_ms(100);
PORTB=0b00000000;
_delay_ms(100);
PORTB=0b00000100;
_delay_ms(100);
PORTB=0b00000100;
for(;;)
{
tmp=PINB&0b00011000;
switch (tmp)
{
case 0b00011000:
PORTB=0b00000100;
break;
case 0b00010000:
PORTB=0b00000110;
break;
case 0b00001000:
PORTB=0b00000101;
break;
case 0b00000000:
PORTB=0b00000100;
break;
}
}
return(0);
}
static void avr_init(void)
{
DDRB=0b00000111;
PORTB=0b00000000;
return;
}