Both “Temp = PortB” and “PortB = i” read the Port . Both allow for a chance of missing a change and therefore an interrupt. Steve is right in that preserving the state of the upper four pins does not appear necessary since it does not change the input values when the port is written – just the latched values should the pin directions be changed from inputs to outputs. Go with #5.