Clamp diodes for higher input voltages
Sometimes we're faced with higher input voltages than the VCC powered to an mcu such as in model railroads.
A simple and effective option to deal with higher pin input voltages is to make use of the clamp diodes. ScienceProg has a good summary on how clamp diodes work.
Basically clamp diodes or ESD protection diodes protect the mcu from over- and under-voltage. By putting a resistor in series to input pins, we can allow higher voltages.
The resistor is calculated as follows: R = (Vin - VCC - 0.7) / 1mA
(Assuming the forward voltage of the clamp diode is 0.7v and they accept 1mA)
Example for DCC: (24 - 3.3 - 0.7) / 1mA = 20kΩ