Debian Codegraph @

examples/copy-bit.c

raw symbols SCIP
1
2 #include <avr/io.h> // Include file for I/O operations
3
4 #define BITVAL(bit) (1 << (bit))
5 #define CLRBIT(sfr, bit) (_SFR_BYTE(sfr) &= ~BITVAL(bit))
6 #define SETBIT(sfr, bit) (_SFR_BYTE(sfr) |= BITVAL(bit))
7 #define GETBIT(sfr, bit) (_SFR_BYTE(sfr) & BITVAL(bit))
8
9 int main (void)
10 {
11 uint8_t val;
12 DDRA = 0; // Port A as Input
13 PORTA = 1; // Enable pullup on PORTA, bit 0
14 DDRB = 1; // Pin 0 of Port B as output
15
16 for(;;)
17 {
18 val = GETBIT(PINA, 0);
19 if (val != 0)
20 SETBIT(PORTB, 0);
21 else
22 CLRBIT(PORTB, 0);
23 }
24
25 }