我正在使用 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、...、RB5。
我该如何优化这段代码,而内存是我最关心的问题。
更新::
来自 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;
我可以使用头文件中的这些值来使函数在循环中包含几行代码吗?