请教一个傻问题..

[复制链接]
2494|2
 楼主| keer_zu 发表于 2007-3-24 15:08 | 显示全部楼层 |阅读模式

以下代码如何用GET_PORT()定义成一个宏?


        unsigned char t;
        t = PINA;
        s_port |= ((int)t&0x00ff);          
        t = PINE;
        s_port |= (((int)t&0x0007) << 8);  
        t = PINC;
        s_port |= ((int)(t&(BIT(7))) << 4);     
        s_port |= ((int)(t&(BIT(6))) << 6);     
        s_port |= ((int)(t&(BIT(5))) << 8);     
        s_port |= ((int)(t&(BIT(4))) << 10);    
        s_port |= ((int)(t&(BIT(3))) << 12);    
 楼主| keer_zu 发表于 2007-3-24 15:45 | 显示全部楼层

这样定义可以吗?

#define  GET_PORT()        unsigned char t;
        t = PINA;  
        s_port |= ((int)t&0x00ff);            
        t = PINE;                           
        s_port |= (((int)t&0x0007) << 8);    
        t = PINC;                             
        s_port |= ((int)(t&(BIT(7))) << 4);     
        s_port |= ((int)(t&(BIT(6))) << 6);     
        s_port |= ((int)(t&(BIT(5))) << 8);     
        s_port |= ((int)(t&(BIT(4))) << 10);    
        s_port |= ((int)(t&(BIT(3))) << 12);  
        
ayb_ice 发表于 2007-3-24 15:48 | 显示全部楼层

随便说说

unsigned char t;
t最好定义成全局变量,否则调用宏时大部分会出错...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1488

主题

12949

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部