AVR Interface

#1623650
Lesenswert?

1
#include <avr/io.h>
2
/********************** Macro definitions *******************************/
3

4
//                      Access bits like variables:
5
struct bits {
6
  uint8_t b0:1;
7
  uint8_t b1:1;
8
  uint8_t b2:1;
9
  uint8_t b3:1;
10
  uint8_t b4:1;
11
  uint8_t b5:1;
12
  uint8_t b6:1;
13
  uint8_t b7:1;
14
} __attribute__((__packed__));
15
#define SBIT_(port,pin) ((*(volatile struct bits*)&port).b##pin)
16
#define SBIT(x,y)       SBIT_(x,y)
17

18

19
/********************** Hardware dependencies ***************************/
20

21
#define LED             SBIT( PORTB, PB0 )
22
#define LED_DDR         SBIT( DDRB,  PB0 )
23
#define BUTTON_PULLUP   SBIT( PORTB, PB1 )
24
#define BUTTON_PIN      SBIT( PINB,  PB1 )
25

26

27
/********************** Code ********************************************/
28

29
int main( void )
30
{
31
  BUTTON_PULLUP = 1;
32
  LED_DDR = 1;
33

34
  for(;;){
35
    LED = BUTTON_PIN;
36
  }
37
}


Peter

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren