您的位置:首页 > 其它

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

2013-04-12 23:40 423 查看
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_ */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐