Thanks for suport !
@Tumbleweed : I used code from this post : http://www.picbasic.co.uk/forum/show...207#post123207
@Jerson : Tried already ...no improvement !
Code:
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_ON
DEFINE OSC 4
CMCON = 7
ADCON0 = 0
ADCON1 = 0
ANSEL = 0
VRCON = 0
TRISA = %00000100
PORTA = %00000000
TRISC = %11111111
PORTC = %00000000
MI VAR PORTA.1
SCK VAR PORTA.2
CSN VAR PORTA.0
adc_RES var Word
last_b_level var byte
b_level var byte
b_cnt var byte
b_act var byte
CSN = 1
main:
TRISC = %11111111
CSN = 0
SHIFTIn MI, SCK, 4, [adc_RES\16]
CSN = 1
if adc_RES < 2600 then
IF adc_RES > 300 AND adc_RES < 320 THEN b_level=1
IF adc_RES > 560 AND adc_RES < 590 THEN b_level=2
IF adc_RES > 890 AND adc_RES < 910 THEN b_level=3
IF adc_RES > 1280 AND adc_RES < 1300 THEN b_level=4
IF adc_RES > 1790 AND adc_RES < 1820 THEN b_level=5
IF adc_RES > 2420 AND adc_RES < 2440 THEN b_level=6
if b_level=last_b_level then
b_cnt=b_cnt+1
pauseus 500
if b_cnt > 10 then
TRISc = %11111111
gosub comenzi
else
b_cnt= 0
endif
endif
last_b_level=b_level
serout2 porta.5, 84, [ dec adc_RES, " ", dec b_level, " ", dec b_cnt, 13] ; to see ADC values
endif
pauseus 100
goto main
;============================================================================
comenzi:
IF b_level=1 THEN gosub VoldN
IF b_level=2 THEN gosub Volup
IF b_level=3 THEN gosub Mute
IF b_level=4 THEN gosub SeekUp
IF b_level=5 THEN gosub SeekDn
IF b_level=6 THEN gosub Source
last_b_level=0
b_cnt=0
Return
;============================================================================
voldn:
TRISC = %11111011
pause 100
TRISC = %11111111
return
volup:
TRISC = %11111101
pause 100
TRISC = %11111111
return
seekup:
TRISC = %11011111
pause 250
TRISC = %11111111
return
seekdn:
TRISC = %11111110
pause 250
TRISC = %11111111
return
source:
TRISC = %11110111
pause 200
TRISC = %11111111
return
mute:
TRISC = %11101111
pause 200
TRISC = %11111111
return
END
Bookmarks