i am so disapointed because it doesn't work on test real card and works on simu.
strange...
i have microcode studio with 15 days trial .(compiler 3.0.0.1)

TRISA = %00001111 ' RA0 et RA1 en entrée

TRISB = 255 ' Disconnect all resistor from the circuit (Haute impédance)

PORTB = 0 '

'

' ADC

' ---

DEFINE ADC_BITS 10 ' Set number of bits in result

DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)

DEFINE ADC_SAMPLEUS 50 ' Set sampling time in

ADCON1 = %10000010 ' RA0 à RA3 and RIGHT JUSTIFIED



'

' Software Variable

' =================

ADCRes VAR WORD ' ADC Reading

btn var byte ' Data to be scan

i VAR BYTE '

j var bit

ADCChannel VAR byte '

ADCButton VAR word [3]'

'

' Software constant

' =================

j = 0

ADCSafety CON 10 ' min/max range for ADC Reading

'

ADCNone CON 814 - ADCSafety '

ADCButton[0] = 90 ' button 1,7 or 4,10

ADCButton[1] = 164 ' button 2,8 or 5,11

ADCButton[2] = 270 ' button 3,9 or 6,12



Start:

TRISB = 255

ADCIN ADCChannel,ADCRes ' Read ADC

'

if (ADCRes < ADCNone) Then ' Any button down?!?

' - Yes!

FOR i = 2 TO 0 STEP -1 ' Loop through all 3 calculated posibilities

' Test against calculated ADCresult

' and allow a range of +/- ADCSafety

IF (ADCRes > (ADCButton[i]-ADCSafety)) AND (ADCRes < (ADCButton[i]+ADCSafety)) THEN

' Valid ADC result, clear the coresponding I/O

btn = ((DCD i) << (ADCChannel*3)) ^255

if (ADcchannel = 3 and btn = 255) then btn = ((btn - (3*adcchannel)) << i)

gosub choix

pause 200

i=0 ' and getOut of here

ENDIF '

NEXT '

else ' - NO!

ADCChannel = ADCChannel + 1 'Switch to the other ADC channel

if ADCchannel = 4 then adcchannel = 0

ENDIF

GOTO Start

choix:

select case btn

' premier bloc de 6 boutons
case %11111011 ' AN0-270 --- 47k and 5k = 4.6k

TRISB.0 = 0 ' 5k and 5k = 2.5k

TRISB.1 = 0

case %11111101 ' AN0-164 --- 47k and 10k = 8.2k

TRISB.1 = 0 ' 5k and 5k = 2.5k

TRISB.2 = 0 ' 47k and 47k = 22k

case %11111110 ' AN0-90 --- 47k and 22k = 15k

TRISB.2 = 0

TRISB.3 = 0 ' 10k and 10k = 5k

case %11011111 ' AN1-270 --- 47k and 2.2k = 2.1k

TRISB.3 = 0 ' 47k and 15k = 11.3k

case %11101111 ' AN1-164 --- 100k and 22k = 18k

TRISB.4 = 0 '

TRISB.0 = 0 '

case %11110111 ' AN1-90

TRISB.5 = 0

TRISB.1 = 0

TRISB.3 = 0

' deuxième bloc de boutons

case %11111111 ' AN2-270 --- 47k and 5k = 4.6k

TRISB.7 = 0 ' 5k and 5k = 2.5k

TRISB.6 = 0

case %01111111 ' AN2-164 --- 47k and 10k = 8.2k

TRISB.5 = 0 ' 5k and 5k = 2.5k

TRISB.4 = 0 ' 47k and 47k = 22k

case %10111111 ' AN2-90 --- 47k and 22k = 15k

TRISB.2 = 0

TRISB.3 = 0 ' 10k and 10k = 5k

case %11011000 ' AN3-270 --- 47k and 2.2k = 2.1k

TRISB.7 = 0 ' 47k and 15k = 11.3k

case %11101100 ' AN3-164 --- 100k and 22k = 18k

TRISB.5 = 0 '

TRISB.0 = 0 '

case %11110110 ' AN3-90

TRISB.5 = 0

TRISB.7 = 0

TRISB.3 = 0

end select

return