I still have the same questions I asked above:
There seems to be code missing.
What are the config bits?
What does the adc_read(2) function do?
What are the values for
adcon0 register?
What is the acquisition delay time?
Have you written code that just blinks the LED?This ensures that the PIC is wired correctly and actually runs. If this doesn't work then there could be hardware issues that code will not fix.
adc_read(2) should make the pic read analog input 2 AN2
"Should" but does it? What does the code look like.
One point in your code:
if (firstvalue==adc_read (2))
May never become true since ADC values can jump around a bit due to noise.
It would be better to test on a 'greater than' or a 'less than' this way it is ensured that the test does became true.