On the 16F1946/1947, most PBP commands will not work on PORTF or PORTG.
The issue is in the way the library tries to locate the TRIS bits.
It does so (in many locations) by setting bit-7 of the address to the PORT.
This works fine when the PORT is in BANK0
PORTA = $00C, set bit-7 and you get $08C which is the address of TRISA.
But with PORTF = $28C, bit-7 is already set.
It tries to set bit-7, which has no effect since it's already 1. Then changes the PORTx bit instead of the TRISx bit.
When it tries to go back to the PORT, it clears bit-7 which puts it in the bank previous to where the PORT is ... $20C which is unimplemented.
When using PORTG, it ends up reading/changing WPUB instead of the PORT.
The problem is prevalent throughout the 14e library.
And it comes in several different forms.
For instance, in the PULSIN command, it sets/clears bit-7 directly.
The above is the most common in the library.
This is from the SHIFTIN command where it OR's $80 with the address, and the same technique is found in several other commands.
The LCDOUT command assumes ALL TRIS registers are in BANK1, and all PORTS are in BANK0. It doesn't even try to add $80 to the PORT.
Every PBP command that automatically sets the TRIS bit has this problem.
A great deal of work is required to fix all of them.
The issue is in the way the library tries to locate the TRIS bits.
It does so (in many locations) by setting bit-7 of the address to the PORT.
This works fine when the PORT is in BANK0
PORTA = $00C, set bit-7 and you get $08C which is the address of TRISA.
But with PORTF = $28C, bit-7 is already set.
It tries to set bit-7, which has no effect since it's already 1. Then changes the PORTx bit instead of the TRISx bit.
When it tries to go back to the PORT, it clears bit-7 which puts it in the bank previous to where the PORT is ... $20C which is unimplemented.
When using PORTG, it ends up reading/changing WPUB instead of the PORT.
The problem is prevalent throughout the 14e library.
And it comes in several different forms.
For instance, in the PULSIN command, it sets/clears bit-7 directly.
Code:
LIST PULSINT movwf RM1 ; Save bit mask [COLOR="red"]bsf FSR0L, 7 ; Point to TRIS[/COLOR] iorwf INDF0, F ; Set bit to input [COLOR="red"]bcf FSR0L, 7 ; Point back to port[/COLOR]
This is from the SHIFTIN command where it OR's $80 with the address, and the same technique is found in several other commands.
Code:
[COLOR="red"] movf RS1, W ; Get data port movwf FSR1H ; Put it into FSR1 movf RR1, W iorlw 80h ; Point to TRIS[/COLOR] movwf FSR1L movf RM1, W ; Get data bit mask iorwf INDF1, F ; Set data to input bcf FSR1L, 7 ; Point back to port
The LCDOUT command assumes ALL TRIS registers are in BANK1, and all PORTS are in BANK0. It doesn't even try to add $80 to the PORT.
Code:
bcf LCD_RSREG, LCD_RSBIT ; Set command register select bcf LCD_RWREG, LCD_RWBIT ; Set RW low (write) [COLOR="red"]movlb 1 ; Point to TRISes [/COLOR] bcf LCD_EREG, LCD_EBIT ; Set E to output bcf LCD_RSREG, LCD_RSBIT ; Set RS to output bcf LCD_RWREG, LCD_RWBIT ; Set RW to output if ((LCD_BITS) == 8) clrf LCD_DREG ; Set port to all output else if ((LCD_DBIT) == 0) movlw 0f0h else movlw 0fh endif andwf LCD_DREG, F ; Set proper half of port to output endif [COLOR="red"]movlb 0 ; Point back to ports[/COLOR] movf R3 + 1, W ; Get back char
A great deal of work is required to fix all of them.
Comment