完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
IAR-C有着强大的软件仿真功能,但其中的寄存器位操作定义却十分烦琐,并且编译后生成的ASM代码冗余较多,针对该问题,版主自已定义一个位操作定义的方法,初学者可参考定义,并且该种方法可应用于所有寄存器位操作定义。
共实现置位--Set_Bit, 清位--Clr_Bit,取反位Com_Bit,测试位Test_Bit四种位操作功能,并且每条位操作定义仅需一条3字节的ASM指令序列即可,简便直接。 //***************************************************** //P00位操作定义 #define Set_P00 (P0 = P0 | 0x1) #define Clr_P00 (P0 = P0 & ~0x1) #define Com_P00 (P0 = P0 ^ 0x1) #define Test_P00 (P0 & 0x1) //P01位操作定义 #define Set_P01 (P0 = P0 | 0x2) #define Clr_P01 (P0 = P0 & ~0x2) #define Com_P01 (P0 = P0 ^ 0x2) #define Test_P01 (P0 & 0x2) //P02位操作定义 #define Set_P02 (P0 = P0 | 0x4) #define Clr_P02 (P0 = P0 & ~0x4) #define Com_P02 (P0 = P0 ^ 0x4) #define Test_P02 (P0 & 0x4) //P03位操作定义 #define Set_P03 (P0 = P0 | 0x8) #define Clr_P03 (P0 = P0 & ~0x8) #define Com_P03 (P0 = P0 ^ 0x8) #define Test_P03 (P0 & 0x8) //P04位操作定义 #define Set_P04 (P0 = P0 | 0x10) #define Clr_P04 (P0 = P0 & ~0x10) #define Com_P04 (P0 = P0 ^ 0x10) #define Test_P04 (P0 & 0x10) //P05位操作定义 #define Set_P05 (P0 = P0 | 0x20) #define Clr_P05 (P0 = P0 & ~0x20) #define Com_P05 (P0 = P0 ^ 0x20) #define Test_P05 (P0 & 0x20) //P06位操作定义 #define Set_P06 (P0 = P0 | 0x40) #define Clr_P06 (P0 = P0 & ~0x40) #define Com_P06 (P0 = P0 ^ 0x40) #define Test_P06 (P0 & 0x40) //P07位操作定义 #define Set_P07 (P0 = P0 | 0x80) #define Clr_P07 (P0 = P0 & ~0x80) #define Com_P07 (P0 = P0 ^ 0x80) #define Test_P07 (P0 & 0x80) //************************************* //P1端口操作位定义 //P10位操作定义 #define Set_P10 (P1 = P1 | 0x1) #define Clr_P10 (P1 = P1 & ~0x1) #define Com_P10 (P1 = P1 ^ 0x1) #define Test_P10 (P1 & 0x1) //P11位操作定义 #define Set_P11 (P1 = P1 | 0x2) #define Clr_P11 (P1 = P1 & ~0x2) #define Com_P11 (P1 = P1 ^ 0x2) #define Test_P11 (P1 & 0x2) //P12位操作定义 #define Set_P12 (P1 = P1 | 0x4) #define Clr_P12 (P1 = P1 & ~0x4) #define Com_P12 (P1 = P1 ^ 0x4) #define Test_P12 (P1 & 0x4) //P13位操作定义 #define Set_P13 (P1 = P1 | 0x8) #define Clr_P13 (P1 = P1 & ~0x8) #define Com_P13 (P1 = P1 ^ 0x8) #define Test_P13 (P1 & 0x8) //P14位操作定义 #define Set_P14 (P1 = P1 | 0x10) #define Clr_P14 (P1 = P1 & ~0x10) #define Com_P14 (P1 = P1 ^ 0x10) #define Test_P14 (P1 & 0x10) //P15位操作定义 #define Set_P15 (P1 = P1 | 0x20) #define Clr_P15 (P1 = P1 & ~0x20) #define Com_P15 (P1 = P1 ^ 0x20) #define Test_P15 (P1 & 0x20) //P16位操作定义 #define Set_P16 (P1 = P1 | 0x40) #define Clr_P16 (P1 = P1 & ~0x40) #define Com_P16 (P1 = P1 ^ 0x40) #define Test_P16 (P1 & 0x40) //P17位操作定义 #define Set_P17 (P1 = P1 | 0x80) #define Clr_P17 (P1 = P1 & ~0x80) #define Com_P17 (P1 = P1 ^ 0x80) #define Test_P17 (P1 & 0x80) //************************************* //P2端口操作位定义 //P20位操作定义 #define Set_P20 (P2 = P2 | 0x1) #define Clr_P20 (P2 = P2 & ~0x1) #define Com_P20 (P2 = P2 ^ 0x1) #define Test_P20 (P2 & 0x1) //P21位操作定义 #define Set_P21 (P2 = P2 | 0x2) #define Clr_P21 (P2 = P2 & ~0x2) #define Com_P21 (P2 = P2 ^ 0x2) #define Test_P21 (P2 & 0x2) //P22位操作定义 #define Set_P22 (P2 = P2 | 0x4) #define Clr_P22 (P2 = P2 & ~0x4) #define Com_P22 (P2 = P2 ^ 0x4) #define Test_P22 (P2 & 0x4) //P23位操作定义 #define Set_P23 (P2 = P2 | 0x8) #define Clr_P23 (P2 = P2 & ~0x8) #define Com_P23 (P2 = P2 ^ 0x8) #define Test_P23 (P2 & 0x8) //P24位操作定义 #define Set_P24 (P2 = P2 | 0x10) #define Clr_P24 (P2 = P2 & ~0x10) #define Com_P24 (P2 = P2 ^ 0x10) #define Test_P24 (P2 & 0x10) //P25位操作定义 #define Set_P25 (P2 = P2 | 0x20) #define Clr_P25 (P2 = P2 & ~0x20) #define Com_P25 (P2 = P2 ^ 0x20) #define Test_P25 (P2 & 0x20) //P26位操作定义 #define Set_P26 (P2 = P2 | 0x40) #define Clr_P26 (P2 = P2 & ~0x40) #define Com_P26 (P2 = P2 ^ 0x40) #define Test_P26 (P2 & 0x40) //P27位操作定义 #define Set_P27 (P2 = P2 | 0x80) #define Clr_P27 (P2 = P2 & ~0x80) #define Com_P27 (P2 = P2 ^ 0x80) #define Test_P27 (P2 & 0x80) //************************************* //P3端口操作位定义 //P30位操作定义 #define Set_P30 (P3 = P3 | 0x1) #define Clr_P30 (P3 = P3 & ~0x1) #define Com_P30 (P3 = P3 ^ 0x1) #define Test_P30 (P3 & 0x1) //P31位操作定义 #define Set_P31 (P3 = P3 | 0x2) #define Clr_P31 (P3 = P3 & ~0x2) #define Com_P31 (P3 = P3 ^ 0x2) #define Test_P31 (P3 & 0x2) //P32位操作定义 #define Set_P32 (P3 = P3 | 0x4) #define Clr_P32 (P3 = P3 & ~0x4) #define Com_P32 (P3 = P3 ^ 0x4) #define Test_P32 (P3 & 0x4) //P33位操作定义 #define Set_P33 (P3 = P3 | 0x8) #define Clr_P33 (P3 = P3 & ~0x8) #define Com_P33 (P3 = P3 ^ 0x8) #define Test_P33 (P3 & 0x8) //P34位操作定义 #define Set_P34 (P3 = P3 | 0x10) #define Clr_P34 (P3 = P3 & ~0x10) #define Com_P34 (P3 = P3 ^ 0x10) #define Test_P34 (P3 & 0x10) //P35位操作定义 #define Set_P35 (P3 = P3 | 0x20) #define Clr_P35 (P3 = P3 & ~0x20) #define Com_P35 (P3 = P3 ^ 0x20) #define Test_P35 (P3 & 0x20) //P36位操作定义 #define Set_P36 (P3 = P3 | 0x40) #define Clr_P36 (P3 = P3 & ~0x40) #define Com_P36 (P3 = P3 ^ 0x40) #define Test_P36 (P3 & 0x40) //P37位操作定义 #define Set_P37 (P3 = P3 | 0x80) #define Clr_P37 (P3 = P3 & ~0x80) #define Com_P37 (P3 = P3 ^ 0x80) #define Test_P37 (P3 & 0x80) //************************************* //P4端口操作位定义 //P40位操作定义 #define Set_P40 (P4 = P4 | 0x1) #define Clr_P40 (P4 = P4 & ~0x1) #define Com_P40 (P4 = P4 ^ 0x1) #define Test_P40 (P4 & 0x1) //P41位操作定义 #define Set_P41 (P4 = P4 | 0x2) #define Clr_P41 (P4 = P4 & ~0x2) #define Com_P41 (P4 = P4 ^ 0x2) #define Test_P41 (P4 & 0x2) //P42位操作定义 #define Set_P42 (P4 = P4 | 0x4) #define Clr_P42 (P4 = P4 & ~0x4) #define Com_P42 (P4 = P4 ^ 0x4) #define Test_P42 (P4 & 0x4) //P43位操作定义 #define Set_P43 (P4 = P4 | 0x8) #define Clr_P43 (P4 = P4 & ~0x8) #define Com_P43 (P4 = P4 ^ 0x8) #define Test_P43 (P4 & 0x8) //P44位操作定义 #define Set_P44 (P4 = P4 | 0x10) #define Clr_P44 (P4 = P4 & ~0x10) #define Com_P44 (P4 = P4 ^ 0x10) #define Test_P44 (P4 & 0x10) //P45位操作定义 #define Set_P45 (P4 = P4 | 0x20) #define Clr_P45 (P4 = P4 & ~0x20) #define Com_P45 (P4 = P4 ^ 0x20) #define Test_P45 (P4 & 0x20) //P46位操作定义 #define Set_P46 (P4 = P4 | 0x40) #define Clr_P46 (P4 = P4 & ~0x40) #define Com_P46 (P4 = P4 ^ 0x40) #define Test_P46 (P4 & 0x40) //P47位操作定义 #define Set_P47 (P4 = P4 | 0x80) #define Clr_P47 (P4 = P4 & ~0x80) #define Com_P47 (P4 = P4 ^ 0x80) #define Test_P47 (P4 & 0x80) //***************************************************** |
|
|
|
只有小组成员才能发言,加入小组>>
843 浏览 1 评论
1022 浏览 1 评论
12451 浏览 0 评论
5892 浏览 3 评论
17683 浏览 6 评论
1000浏览 1评论
980浏览 1评论
845浏览 1评论
4030浏览 1评论
1022浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 14:00 , Processed in 0.969543 second(s), Total 81, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号