James Wages
2017-08-23 02:56:24 UTC
I've discovered something unusual while programming a PIC16F18854 in Assembly.
I have PORTB set to be all DIGITAL INPUTS. (In the case of the 16F18854, PORTB is RB0 through RB7.) Normally on other PICs, the following code works just fine to read such inputs:
banksel PORTB ; [Bank 0]
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM (0x077, RAM common to all banks)
The problem is that when I use to above code, RB5 (pin 26) is misread. It is misread even when I use this code (repetition, just for a test):
banksel PORTB ; [Bank 0]
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
nop
nop
nop
nop
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
nop
nop
nop
nop
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
But when I manually check the state of every pin in PORTB, nothing is misread and the problem is solved:
banksel PORTB ; [Bank 0]
clrf RAMa
btfsc PORTB, RB0
bsf RAMa, 7
btfsc PORTB, RB1
bsf RAMa, 6
btfsc PORTB, RB2
bsf RAMa, 5
btfsc PORTB, RB3
bsf RAMa, 4
btfsc PORTB, RB4
bsf RAMa, 3
btfsc PORTB, RB5
bsf RAMa, 2
btfsc PORTB, RB6
bsf RAMa, 1
btfsc PORTB, RB7
bsf RAMa, 0
I'm pleased I have a solution, but I don't understand why moving the entire PORT to W and then to RAM causes a misread pin. Do any of you know? (And again, PORTB is setup via TRISB to be all INPUTS, ANSELB is cleared, making the pins DIGITAL.)
Thanks.
I have PORTB set to be all DIGITAL INPUTS. (In the case of the 16F18854, PORTB is RB0 through RB7.) Normally on other PICs, the following code works just fine to read such inputs:
banksel PORTB ; [Bank 0]
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM (0x077, RAM common to all banks)
The problem is that when I use to above code, RB5 (pin 26) is misread. It is misread even when I use this code (repetition, just for a test):
banksel PORTB ; [Bank 0]
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
nop
nop
nop
nop
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
nop
nop
nop
nop
movf PORTB, W ; Move state of PORTB input pins to W register.
movwf RAMa ; Save W in RAM
But when I manually check the state of every pin in PORTB, nothing is misread and the problem is solved:
banksel PORTB ; [Bank 0]
clrf RAMa
btfsc PORTB, RB0
bsf RAMa, 7
btfsc PORTB, RB1
bsf RAMa, 6
btfsc PORTB, RB2
bsf RAMa, 5
btfsc PORTB, RB3
bsf RAMa, 4
btfsc PORTB, RB4
bsf RAMa, 3
btfsc PORTB, RB5
bsf RAMa, 2
btfsc PORTB, RB6
bsf RAMa, 1
btfsc PORTB, RB7
bsf RAMa, 0
I'm pleased I have a solution, but I don't understand why moving the entire PORT to W and then to RAM causes a misread pin. Do any of you know? (And again, PORTB is setup via TRISB to be all INPUTS, ANSELB is cleared, making the pins DIGITAL.)
Thanks.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist