I'm writing the code for a microcontroller to control an ROV for a school competition and I've come into and interesting problem.
I'm getting serial data from a laptop (or another chip in my case) and the packets are sending fine. So then I want to set ports based on that data.
Anyway I've got a integer called 'packet' it contains: ##000000 00000000 00000000 10000101
Now I've got the following two lines of code:
What's weird is that the 2nd bit of port B is not being set (seeing as the light doesn't turn on...but the 5th and 3rd bit pins do turn on as expected. If I comment out the second line the the first line works as expected.
Also the generated assembly for those two lines are as follows:
If you might know why this is happening or a good solution it would be greatly appreciated. (Also the tristate for Port B has been entirely set to output and there is nothing special about those pins).
Thanks,
Trevor
I'm getting serial data from a laptop (or another chip in my case) and the packets are sending fine. So then I want to set ports based on that data.
Anyway I've got a integer called 'packet' it contains: ##000000 00000000 00000000 10000101
Now I've got the following two lines of code:
Rich (BB code):
PORTB = ((packet & 0x00C0) >> 6); /* Turn on the correct direction */
PORTB |= ((packet & 0x000F) << 2);
Also the generated assembly for those two lines are as follows:
Rich (BB code):
; .line 97; "receive.c" PORTB = ((packet & 0x00C0) >> 6); /* Turn on the correct direction */
MOVLW 0xc0
ANDWF r0x1001,W
MOVWF r0x1002
CLRF r0x1003
SWAPF r0x1002,W
ANDLW 0x0f
MOVWF r0x1004
SWAPF r0x1003,W
MOVWF r0x1005
ANDLW 0xf0
IORWF r0x1004,F
XORWF r0x1005,F
MOVLW 0xf0
BTFSC r0x1005,3
IORWF r0x1005,F
;shiftRight_Left2ResultLit:6080: shCount=1, size=2, sign=1, same=1, offr=0
BCF STATUS,0
BTFSC r0x1005,7
BSF STATUS,0
RRF r0x1005,F
RRF r0x1004,F
;shiftRight_Left2ResultLit:6080: shCount=1, size=2, sign=1, same=1, offr=0
BCF STATUS,0
BTFSC r0x1005,7
BSF STATUS,0
RRF r0x1005,F
RRF r0x1004,F
MOVF r0x1004,W
BANKSEL _PORTB
MOVWF _PORTB
; .line 105; "receive.c" PORTB = ((packet & 0x000F) << 2) | PORTB;
MOVLW 0x0f
BANKSEL r0x1001
ANDWF r0x1001,F
CLRF r0x1000
MOVF r0x1001,W
MOVWF r0x1002
BCF STATUS,0
RLF r0x1002,W
MOVWF r0x1001
BCF STATUS,0
RLF r0x1001,F
BANKSEL _PORTB
MOVF _PORTB,W
BANKSEL r0x1002
MOVWF r0x1002
IORWF r0x1001,W
BANKSEL _PORTB
MOVWF _PORTB
GOTO _00105_DS_
Thanks,
Trevor