当前位置:首页 > 单片机 > 单片机
[导读]好吧,不得不承认,我使用飞思卡尔的XS128单片机已经非常之习惯了,结果一上手atmega8,最令我反感的就是atmega8不能对IO引脚进行操作,非要用些繁琐的位操作。我就不,我就要像飞思卡尔那样操作。。。于是。。。。。

好吧,不得不承认,我使用飞思卡尔的XS128单片机已经非常之习惯了,结果一上手atmega8,最令我反感的就是atmega8不能对IO引脚进行操作,非要用些繁琐的位操作。我就不,我就要像飞思卡尔那样操作。。。


于是。。。。。


把我写的下面这个头文件塞到winavr目录的include/avr中,并在io.h头文件的最后包含这个头文件。


嘿嘿,一切变得是那么的亲切与熟悉。。。。。。


/***********************************************************

* 函数库说明:ATMEGE8

* 版本: v1.0

*

************************************************************

*注意: 无

***********************************************************/


#ifndef _BIT_

#define _BIT_

//定义一个8字节的位段 bit0~7是每个位段名称 1代表一位 PBIT就是整个位段的名称

typedef struct

{

unsigned bit0 : 1 ;

unsigned bit1 : 1 ;

unsigned bit2 : 1 ;

unsigned bit3 : 1 ;

unsigned bit4 : 1 ;

unsigned bit5 : 1 ;

unsigned bit6 : 1 ;

unsigned bit7 : 1 ;

}PBIT;

//强制转换

#define PORTABIT (*(volatile PBIT *)0x3B)

#define DDRABIT (*(volatile PBIT *)0x3A)

#define PINABIT (*(volatile PBIT *)0x39)

#define PORTBBIT (*(volatile PBIT *)0x38)

#define DDRBBIT (*(volatile PBIT *)0x37)

#define PINBBIT (*(volatile PBIT *)0x36)

#define PORTCBIT (*(volatile PBIT *)0x35)

#define DDRCBIT (*(volatile PBIT *)0x34)

#define PINCBIT (*(volatile PBIT *)0x33)

#define PORTDBIT (*(volatile PBIT *)0x32)

#define DDRDBIT (*(volatile PBIT *)0x31)

#define PINDBIT (*(volatile PBIT *)0x30)

//继续封装

#define PORTA_PA0 PORTABIT.bit0

#define PORTA_PA1 PORTABIT.bit1

#define PORTA_PA2 PORTABIT.bit2

#define PORTA_PA3 PORTABIT.bit3

#define PORTA_PA4 PORTABIT.bit4

#define PORTA_PA5 PORTABIT.bit5

#define PORTA_PA6 PORTABIT.bit6

#define PORTA_PA7 PORTABIT.bit7

#define PORTB_PB0 PORTBBIT.bit0

#define PORTB_PB1 PORTBBIT.bit1

#define PORTB_PB2 PORTBBIT.bit2

#define PORTB_PB3 PORTBBIT.bit3

#define PORTB_PB4 PORTBBIT.bit4

#define PORTB_PB5 PORTBBIT.bit5

#define PORTB_PB6 PORTBBIT.bit6

#define PORTB_PB7 PORTBBIT.bit7

#define PORTC_PC0 PORTCBIT.bit0

#define PORTC_PC1 PORTCBIT.bit1

#define PORTC_PC2 PORTCBIT.bit2

#define PORTC_PC3 PORTCBIT.bit3

#define PORTC_PC4 PORTCBIT.bit4

#define PORTC_PC5 PORTCBIT.bit5

#define PORTC_PC6 PORTCBIT.bit6

#define PORTC_PC7 PORTCBIT.bit7

#define PORTD_PD0 PORTDBIT.bit0

#define PORTD_PD1 PORTDBIT.bit1

#define PORTD_PD2 PORTDBIT.bit2

#define PORTD_PD3 PORTDBIT.bit3

#define PORTD_PD4 PORTDBIT.bit4

#define PORTD_PD5 PORTDBIT.bit5

#define PORTD_PD6 PORTDBIT.bit6

#define PORTD_PD7 PORTDBIT.bit7

//**********************

#define DDRA_DDRA0 DDRABIT.bit0

#define DDRA_DDRA1 DDRABIT.bit1

#define DDRA_DDRA2 DDRABIT.bit2

#define DDRA_DDRA3 DDRABIT.bit3

#define DDRA_DDRA4 DDRABIT.bit4

#define DDRA_DDRA5 DDRABIT.bit5

#define DDRA_DDRA6 DDRABIT.bit6

#define DDRA_DDRA7 DDRABIT.bit7

#define DDRB_DDRB0 DDRBBIT.bit0

#define DDRB_DDRB1 DDRBBIT.bit1

#define DDRB_DDRB2 DDRBBIT.bit2

#define DDRB_DDRB3 DDRBBIT.bit3

#define DDRB_DDRB4 DDRBBIT.bit4

#define DDRB_DDRB5 DDRBBIT.bit5

#define DDRB_DDRB6 DDRBBIT.bit6

#define DDRB_DDRB7 DDRBBIT.bit7

#define DDRC_DDRC0 DDRCBIT.bit0

#define DDRC_DDRC1 DDRCBIT.bit1

#define DDRC_DDRC2 DDRCBIT.bit2

#define DDRC_DDRC3 DDRCBIT.bit3

#define DDRC_DDRC4 DDRCBIT.bit4

#define DDRC_DDRC5 DDRCBIT.bit5

#define DDRC_DDRC6 DDRCBIT.bit6

#define DDRC_DDRC7 DDRCBIT.bit7

#define DDRD_DDRD0 DDRDBIT.bit0

#define DDRD_DDRD1 DDRDBIT.bit1

#define DDRD_DDRD2 DDRDBIT.bit2

#define DDRD_DDRD3 DDRDBIT.bit3

#define DDRD_DDRD4 DDRDBIT.bit4

#define DDRD_DDRD5 DDRDBIT.bit5

#define DDRD_DDRD6 DDRDBIT.bit6

#define DDRD_DDRD7 DDRDBIT.bit7

//*****************

#define PINA_PA0 PINABIT.bit0

#define PINA_PA1 PINABIT.bit1

#define PINA_PA2 PINABIT.bit2

#define PINA_PA3 PINABIT.bit3

#define PINA_PA4 PINABIT.bit4

#define PINA_PA5 PINABIT.bit5

#define PINA_PA6 PINABIT.bit6

#define PINA_PA7 PINABIT.bit7

#define PINB_PB0 PINBBIT.bit0

#define PINB_PB1 PINBBIT.bit1

#define PINB_PB2 PINBBIT.bit2

#define PINB_PB3 PINBBIT.bit3

#define PINB_PB4 PINBBIT.bit4

#define PINB_PB5 PINBBIT.bit5

#define PINB_PB6 PINBBIT.bit6

#define PINB_PB7 PINBBIT.bit7

#define PINC_PC0 PINCBIT.bit0

#define PINC_PC1 PINCBIT.bit1

#define PINC_PC2 PINCBIT.bit2

#define PINC_PC3 PINCBIT.bit3

#define PINC_PC4 PINCBIT.bit4

#define PINC_PC5 PINCBIT.bit5

#define PINC_PC6 PINCBIT.bit6

#define PINC_PC7 PINCBIT.bit7

#define PIND_PD0 PINDBIT.bit0

#define PIND_PD1 PINDBIT.bit1

#define PIND_PD2 PINDBIT.bit2

#define PIND_PD3 PINDBIT.bit3

#define PIND_PD4 PINDBIT.bit4

#define PIND_PD5 PINDBIT.bit5

#define PIND_PD6 PINDBIT.bit6

#define PIND_PD7 PINDBIT.bit7

#endif


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

特朗普集团近日取消了其新推出的T1智能手机“将在美国制造”的宣传标语,此举源于外界对这款手机能否以当前定价在美国本土生产的质疑。

关键字: 特朗普 苹果 AI

美国总统特朗普在公开场合表示,他已要求苹果公司CEO蒂姆·库克停止在印度建厂,矛头直指该公司生产多元化的计划。

关键字: 特朗普 苹果 AI

4月10日消息,据媒体报道,美国总统特朗普宣布,美国对部分贸易伙伴暂停90天执行新关税政策,同时对中国的关税提高到125%,该消息公布后苹果股价飙升了15%。这次反弹使苹果市值增加了4000多亿美元,目前苹果市值接近3万...

关键字: 特朗普 AI 人工智能 特斯拉

3月25日消息,据报道,当地时间3月20日,美国总统特朗普在社交媒体平台“真实社交”上发文写道:“那些被抓到破坏特斯拉的人,将有很大可能被判入狱长达20年,这包括资助(破坏特斯拉汽车)者,我们正在寻找你。”

关键字: 特朗普 AI 人工智能 特斯拉

1月22日消息,刚刚,新任美国总统特朗普放出重磅消息,将全力支持美国AI发展。

关键字: 特朗普 AI 人工智能

特朗普先生有两件事一定会载入史册,一个是筑墙,一个是挖坑。在美墨边境筑墙的口号确保边境安全,降低因非法移民引起的犯罪率过高问题;在中美科技产业之间挖坑的口号也是安全,美国企业不得使用对美国国家安全构成威胁的电信设备,总统...

关键字: 特朗普 孤立主义 科技产业

据路透社1月17日消息显示,知情人士透露,特朗普已通知英特尔、铠侠在内的几家华为供应商,将要撤销其对华为的出货的部分许可证,同时将拒绝其他数十个向华为供货的申请。据透露,共有4家公司的8份许可被撤销。另外,相关公司收到撤...

关键字: 华为 芯片 特朗普

曾在2018年时被美国总统特朗普称作“世界第八奇迹”的富士康集团在美国威斯康星州投资建设的LCD显示屏工厂项目,如今却因为富士康将项目大幅缩水并拒绝签订新的合同而陷入了僵局。这也导致富士康无法从当地政府那里获得约40亿美...

关键字: 特朗普 富士康

今年5月,因自己发布的推文被贴上“无确凿依据”标签而与推特发生激烈争执后,美国总统特朗普签署了一项行政令,下令要求重审《通信规范法》第230条。

关键字: 谷歌 facebook 特朗普

众所周知,寄往白宫的所有邮件在到达白宫之前都会在他地进行分类和筛选。9月19日,根据美国相关执法官员的通报,本周早些时候,执法人员截获了一个寄给特朗普总统的包裹,该包裹内包含蓖麻毒蛋白。

关键字: 美国 白宫 特朗普
关闭