avr的一些宏定义,可以类似51单片机那样按位对端口引脚操作

来源:互联网 发布:影视制作的软件 编辑:程序博客网 时间:2024/05/16 23:54

avr的一些宏定义,可以类似51单片机那样按位对端口引脚操作,方便操作!

 

#ifndef INCFILE1_H_
#define INCFILE1_H_

#include<avr/io.h>

// Macro to access bits like variables:
struct bits {
  uint8_t b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1;
} __attribute__((__packed__));
#define SBIT_(port,pin) ((*(volatile struct bits*)&port).b##pin)
#define SBIT(x,y)       SBIT_(x,y)


//#define KEY0_PIN        SBIT( PINB,  PB0 )      // Input
//#define KEY1_PIN        SBIT( PINB,  PB1 )
//
//#define LED0            SBIT( PORTB, PB2 )      // Output
//#define LED0_DDR        SBIT( DDRB,  PB2 )      // Direction
//
//
//int main()
//{
  //LED0 = 0;
  //LED0_DDR = 1;                         // output
//
  //for(;;){
    //LED0 = KEY0_PIN                     // Key0 = on
         //| (LED0 & !KEY1_PIN);          // Key1 = off
  //}
//}
//

 

#endif /* INCFILE1_H_ */

原创粉丝点击