×

IAR-C中实现IO端口直接位定义操作的一个示例资料下载

消耗积分:2 | 格式:pdf | 大小:52.4KB | 2021-04-08

分享资料个

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)

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !