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_ */
#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_ */
相关文章推荐
- Fuhome推出FuIP3.0专为单片机联网的协议栈 51 stm32 avr 都可以,采用ENC28J60
- 单片机引脚与端口操作
- 在关闭网页之前可以进行的一些操作
- 模板方法模式(Template Method)-定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。
- __attribute__编绎属性、关于__init、__initdata、__exit、__exitdata及类似的宏、关于initcall的一些宏定义、__setup宏的来源及使用
- UIView回调方法(可以在添加子视图等,做一些额外操作)
- Kotlin通过Id操作View,Adapter和动态加载Xml文件也可以类似操作
- 51单片机引脚详解
- Python Numpy的一些操作可以极大的加快你的code运行速度
- AVR 单片机与GCC 编程之存储器操作(转载)
- Android中可以作为Log开关的一些操作及安全性详解
- 用CoreText实现类似微博那样可以点击的Label
- jQuery可以操作的一些元素属性
- 基于proteus的51单片机仿真实例十三、51单片机的C语言宏定义应用实例
- js判断页面滚动到底部的时候,可以执行一些操作
- Linux有时候执行了 rm -rf 等操作误删了文件绝对是一件可怕的事情,好在有一些解决的办法可以临时救急。这时我们就要用到一款叫做extundelete的工具了。
- AVR单片机端口设置
- AVR 单片机与GCC 编程之存储器操作
- __attribute__编绎属性、关于__init、__initdata、__exit、__exitdata及类似的宏、关于initcall的一些宏定义、__setup宏的来源及使用
- python中的shelve模块,可以提供一些简单的数据操作