I think that you need to understand the banking on 18F processors better.
There are 16 banks of registers allowed for, 0 - 15. Each is 256 bytes.
The special function registers are in the top half of bank 15
All operations that involve registers (including special function registers) will access whichever bank the bank select register (BSR) is set to.
So to read or write to the file registers in bank 0 you need to set the BSR to 0
To set a bit in a port (which is a special function register) you need to set the BSR to 15
However, there is also another way of getting to some of the file registers and all of the special function registers. Each command has a flag that selects either the bank that the BSR is pointing to or the access registers. The access registers are the bottom half of bank 0 and the top half of bank 15, which is where the special function registers are.
For example:-
will:-
add w to 0x010 if the BSR is 0,
add w to 0x110 if the BSR is 1,
add w to 0x210 if the BSR is 2
etc
will always:-
add w to 0x010, whatever is in the BSR
MPLAB makes this flag select the access registers for all commands that use the access registers, if you simply miss out the last argument (0 or 1)
Where you wrote:-
the final "1" made the command use whatever bank the BSR was set to. That is wrong for PORTD, because PORTD is within the access registers.
If you had written:-
then MPLAB would have used the access registers and it would have worked, as it did when you used:-
Had you written:-
that would also have failed because it would have needed the BSR set correctly.