我使用 mikroC 程序 pic16f84a, 并有以下函数
volatile unsigned short d; // global variable
void put_data(){
RA3_bit = d & 1;
d >>= 1;
RA4_bit = d & 1;
d >>= 1;
PORTB.B0 = d & 1;
d >>= 1;
PORTB.B1 = d & 1;
d >>= 1;
PORTB.B2 = d & 1;
d >>= 1;
PORTB.B3 = d & 1;
d >>= 1;
PORTB.B4 = d & 1;
d >>= 1;
PORTB.B5 = d & 1;
}
此函数, 从 d (8 位元) 中取取每位元, 并将其输出为 RA3 、 RA4 、 RB0 、... 、 RB 5 端口针 。
我怎样才能优化这个代码 记忆是我关心的首要问题
<强> 更新日期: 强>
来自pic16f84a.h:
volatile unsigned char PORTA @ 0x005;
// bit and bitfield definitions
volatile bit RA0 @ ((unsigned)&PORTA*8)+0;
volatile bit RA1 @ ((unsigned)&PORTA*8)+1;
volatile bit RA2 @ ((unsigned)&PORTA*8)+2;
volatile bit RA3 @ ((unsigned)&PORTA*8)+3;
volatile bit RA4 @ ((unsigned)&PORTA*8)+4;
volatile unsigned char PORTB @ 0x006;
// bit and bitfield definitions
volatile bit RB0 @ ((unsigned)&PORTB*8)+0;
volatile bit RB1 @ ((unsigned)&PORTB*8)+1;
volatile bit RB2 @ ((unsigned)&PORTB*8)+2;
volatile bit RB3 @ ((unsigned)&PORTB*8)+3;
volatile bit RB4 @ ((unsigned)&PORTB*8)+4;
volatile bit RB5 @ ((unsigned)&PORTB*8)+5;
volatile bit RB6 @ ((unsigned)&PORTB*8)+6;
volatile bit RB7 @ ((unsigned)&PORTB*8)+7;
我可以使用信头文件中的这些值, 使该函数在循环中成为几行代码?