org 000h
goto main
org 200h
main
nop
banksel trisb
movlw h'ff'
movwf trisb
banksel portb
clrf portb
goto $
end
I just wanted to clear Portb before getting ready for receiving input.
I checked and double checked with the code and couldn't find anything I might have missed, but no matter what, I couldn't find out why the portb register is not setting all of its bits. I checked the data sheet to see if in case port b has any special requirements or something. Couldn't find anything there. Am I wrong somewhere?
You configured all pins of PORTB as inputs. The value of each bit of the PORTB register depends on the external voltage you apply to each pin.
Clearing the PORTB register does not affect the state of the output pins.
Im using the simulator available in MP-LAB. And when I step through the code, the port b register never seems to clear. Atleast that is what the simulator shows.
You configured all pins of PORTB as inputs. The value of each bit of the PORTB register depends on the external voltage you apply to each pin.
Clearing the PORTB register does not affect the state of the output pins.
Im using the simulator available in MP-LAB. And when I step through the code, the port b register never seems to clear. Atleast that is what the simulator shows.
You don't need to clear the port B latch register. It is not like other processors where you have to write 1 to enable input. Just write 0xff to the TRIS register and the port will be input.
Also the ports are not fully implemented in the simulator and hence you will not see change on the port. There is some method of designing a stimulus file but I never cared for it. Sure someone else can assist with this.
To simulate inputs in MPLAB Sim, you need to use the Stimulus Controller. You assign actions to the pins you want and click the "fire" button when you want the action to occur. I find the toggle option to be the most useful:
You don't need to clear the port B latch register. It is not like other processors where you have to write 1 to enable input. Just write 0xff to the TRIS register and the port will be input.
Lets assume all the bits in trisb are set and therefore portb is now input. But a few bits in my portb latch are already set from some insignificant previous instruction.
Wouldn't that be considered an input signal to the controller even though the signal did not originate externally?
Also the ports are not fully implemented in the simulator and hence you will not see change on the port. There is some method of designing a stimulus file but I never cared for it. Sure someone else can assist with this.
Lets assume all the bits in trisb are set and therefore portb is now input. But a few bits in my portb latch are already set from some insignificant previous instruction.
Wouldn't that be considered an input signal to the controller even though the signal did not originate externally?
When you read from a port, it always returns what is on the pins. Even if the port is set to output, reading it returns the value on the pin. This can sometimes cause a problem if the pin is highly loaded, it will read back as a zero even though the latch is set high. This is (sometimes) the cause of the RMW problem with the 16 series pic chips.
When you read from a port, it always returns what is on the pins. Even if the port is set to output, reading it returns the value on the pin. This can sometimes cause a problem if the pin is highly loaded, it will read back as a zero even though the latch is set high. This is (sometimes) the cause of the RMW problem with the 16 series pic chips.
So conclusively, what you're saying is, if my tris register is configured for input, it doesn't matter whether portb latch bits are set or not, cos the input will always be read from the pins and not the latch bits.
You are correct. But remember, if your port is configured as output it will still read the pins. A highly loaded output pin with it's latch bit set can still read back zero.
You are correct. But remember, if your port is configured as output it will still read the pins. A highly loaded output pin with it's latch bit set can still read back zero.