If you connect 12V to an analog input you will kill the input. No amount of software will prevent that. You must reduce the voltage to be no more than Vcc + 0.5V to prevent harm to the input and no more than Vcc to be able to convert the voltage with the ADC with any accuracy (defalut Vref).