Yes, I have pull up resistor enabled on input and initial state = "1"
It works perfect when running on debugger but when I program the part it does not.
I have never had this issue with reading IO pins to date.
The micro restarts ok. I can get it to flash some leds on boot to make sure it is running. But does not read correct state of input pin.
Please add some delay prior to get the MyID like
CyDelay(1000); myID = SW1_Read();
This solution is effective if the settling time of the input port is too long
Try another pin for testing purpose. It may happen that pin is blown already if it accidentally was set to "strong drive" or "open drain drive high" mode.
I cannot put a long delay before read because another device polls this one on power up (around 200ms after power up). It works on all previous versions of the project ok.
The problem seems to occur after power up of hardware.
If the hardware is already powered and I re-program it, the input works ok.
If I switch power off and back on and then program the hardware, it does NOT work. The switch gets read on power up and sets ID but I cannot change the ID by changing switch position.
If I run in debug mode then I can change channel ok, system reads switch fine.
This occurs even if I add 1000 ms delay before switch read.
I constructed a new board with only the PSU, micro and Hex switch and it works fine after programming and removal and reapplying power.
The original boards were potted with silicon compound, I suspect the compound has leached up into the switches and and pushed the contacts apart.