Yes, I NEED to use ADC instead "usual" button(s).
Yes, I NEED to use ADC instead "usual" button(s).
just my two cents ..
remove the Quartz and capacitors
an use the internal oscillator if you don't need a precison time ..
I love to use those small 12F675 ..
Take care at programmation time you have datas (2 bytes) at the end of the eprom.
read it before programming
Francois
I have used 'for loop' to test for switch press duration as such....you would use your adc reading instead of GPIO check
Code:if GPIO.1= 1 then start ' gpio is 1 for no press, 0 for pressed....or do 1 adc read and check ..about 100 microseconds FOR B5= 1 TO 100 '1 SECOND FOR TIMER PAUSE 10 if GPIO.1= 1 then start 'or do 1 adc read and check ..about 100 microseconds NEXT B5 '''' switch still pressed ...continue to 2 second press check FOR B5 = 1 TO 100 '2 SECONDS FOR 6 HR PAUSE 10 if GPIO.1=1 then TIMER 'press is greater than 1 second in this loop... up to 2 second NEXT B5 continuing here if switch still pressed !!!!
Thank you all for the support !
Code from Mr.Richard (Thanks !), see post #3, works just fine.
But now I'm stuck again ...
For accurate reading of ADC I use bubble-sort algoritm, how it's presented on this forum.
The code works amazing, almost no error ... for different value of ADC, I can do different tasks.Code:Main: nr=1 for nr = 1 to 2 For CounterA=0 to 8 ADCON0 = %10000001 Pauseus 50 ' Wait for channel to setup ADCON0.1 = 1 ' Start conversion While ADCON0.1=1:Wend ' Wait for conversion DataW.HighByte=ADRESH ' Read variable from ADC and save DataW.LowByte=ADRESL RawData(CounterA)=DataW Next CounterA CounterA=0 Gosub Getsort next nr if adca=adcb then gosub efectuez goto main ;============================================================================ GetSort: If RawData(CounterA+1) < RawData(CounterA) then DataW=RawData(CounterA) RawData(CounterA)=RawData(CounterA+1) RawData(CounterA+1)=DataW If CounterA>0 then CounterA=CounterA-2 endif CounterA=CounterA+1 If CounterA<9 then goto GetSort DataW=0 For CounterA=3 to 6 DataW=DataW+RawData(CounterA) Next CounterA ADCValue=DataW>>2 if nr = 1 then adca = adcvalue else adcb = adcvalue endif Return ;============================================================================
BUT ... I can not figure out how to use the procedure of short/long press in this code... since even a short press makes the code to jump to "efectuez" (where I have different commands defined).
I tried to use the same procedure as in post #3 ; I tried to put it into different places of the code, but without result ! Whatever I do, it's like pressing the button for a short time.
can you explain what you are trying to achieve , and maybe another schematic .
at this stage I can't see how an array sorting routine is useful for detecting button presses long or short .
post the code for what have you tried
In the schematic posted in #1, R4 have different values ... for different commands.
The code above is for reading accurate ADC ; works very, very fine.
Tried to read short/long press of button ... but no succes. No matter what I do, I always have same result, as pressed "short".
Sorry for my poor english, I use g...translate for many words.
Bookmarks