I'm using mikroC to program pic16f84a, and i have the following function
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;
}
this function, take each bit from d (8 bits) and output it to port pin RA3, RA4, RB0, ... , RB5.
how could I optimize this code,, and memory is my first concern.
Update::
from 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;
can i use these values from the header file,, to make the function a few lines of code inside a loop ?