Bitwise shifts on assignments to ports shouldn't be applied to port registers, as they may not be able to set/read some of they bits.
On pic16f877, PORTE register has only 3 bits (RE3:RE0), the rest (RE7:RE4) are non-writable, readed as 0.
On attached exaple program, compiled this way:
sdcc -mpic14 -p16f877a -V --debug -c shifted.c
The C code:
unsigned char tmp;
tmp = PORTA;
PORTE = tmp >> 6;
Gets compiled to .asm code:
Wich gets a wrong value in PORTE, for example:
if tmp = 0xff; tmp>>6 shoud be 0x03. but with that code:
SWAPF r0x1001,W ; W = 0xff
ANDLW 0x0f; W = 0x0f
MOVWF _PORTE ; PORTE = 0x07!! as RE7:RE3 are non-writable!!
RRF _PORTE,F ; PORTE = 0x03
RRF _PORTE,F; PORTE = 0x01!! should be 0x03!!
Log in to post a comment.