@Mr.Richard : Tried to figure out how your soft work ... But in Proteus nothing happens.
I do something wrong ? I "addapted" the "elseif" command, since is not present in PBP 2.6 (?).
Thanks in advance for support !
Code:;pic12f683 DEFINE OSC 8 include "dt_ints-14.bas" include "REENTERPBP.bas" @timer1 =TMR1L wsave VAR BYTE $20 SYSTEM ' location for W if in bank0 wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _chk_sw, PBP, yes endm INT_CREATE ENDASM long_press_threshold con 200 ;1 sec 200*5( time const)=1000mS short_press_threshold con 5 btn_tol con 25 ;ADC READING TOLORACE number_of_buttons con 3 ;MAX 7 ;4K7 TO 5V ' 3k3 / ' ___ /\ /\ /\ ___/ ^____ btn1 ' | \/ \/ \/ \/ | ' 5v 4k7 | 2k2 / | ' ___ /\ /\ /\ ___!___ /\ /\ /\ ___/ ^____!btn2 ' \/ \/ \/ \/ | \/ \/ \/ \/ | ' | 1k / | ' ____________________!___ /\ /\ /\ ___/ ^____!btn3 ' an3 gpio4 \/ \/ \/ \/ | ' | ' ________________________________________________! ' gnd | ' ___________|\|__led_____________________________| ' gpio2 |/| OSCCON=$70 CMCON0 = 7 TRISIO = %111011 ANSEL = %01011000 ;fosc/16 ,an3 btn_adc var word[number_of_buttons] b_cnt var byte[number_of_buttons] b_state var byte[number_of_buttons] ;0 not pressed ,1 short ,2 long button_index var byte ;which button led var gpio.2 ;led btn_flg var byte abp var BIT adcr var WORD ;adc reading timer1 VAR WORD EXT tmp var word FLASH_ON VAR WORD ;led FLASH_OFF VAR WORD ;led FLASH_DUTY VAR WORD ;led led = 0 clear btn_adc[0]=209 ;adc read for buttons btn_adc[1]=327 ;adc read for buttons btn_adc[2]=422 ;adc read for buttons timer1=55543 ;5mS time const T1CON=1 @ INT_ENABLE TMR1_INT FLASH_OFF=200 FLASH_On=0 ADCON0 = %10001101 ;warm up the adc ,right shift ,an3 ADCON0.1 = 1 ' Start a conversion Main: Pause 5 ;loop time const IF ABP THEN button_index= 0 tmp=20 while abp if B_STATE[button_index]=2 then FLASH_OFF= tmp abp=0 led=0 FLASH_DUTY=0 else if B_STATE[button_index]=1 then FLASH_On=tmp abp=0 led=0 FLASH_DUTY=0 endif endif tmp=tmp+100 B_STATE[button_index]=0 button_index=button_index+1 if button_index= number_of_buttons then abp=0 ;clr error if req wend ENDIF IF FLASH_ON THEN IF FLASH_DUTY=0 THEN led = ! LED ; flash led IF LED THEN FLASH_DUTY = FLASH_ON ELSE FLASH_DUTY = FLASH_OFF ENDIF ELSE FLASH_DUTY=FLASH_DUTY-1 ENDIF ENDIF Goto Main chk_sw: T1CON.0=0 timer1=timer1+55543 T1CON.0=1 ;ADCON0 = %10001101 ; NO NEED since ch never changes and ADC is left ON ;Pauseus 50 ' aqusition time if req ;ADCON0.1 = 1 ' Start conversion ;While ADCON0.1=1:Wend ' Wait for conversion adcr.HighByte = ADRESH ' Read variable from ADC adcr.LowByte = ADRESL FOR button_index = 0 TO 2 if ! B_STATE[button_index] then IF abs (adcr- btn_adc[button_index] )< btn_tol then if btn_flg.0[button_index] THEN IF b_cnt[button_index] < 250 THEN b_cnt[button_index]=b_cnt[button_index]+1 ELSE ;FIRST PRESS FOR THIS BUTTON b_cnt[button_index]=0 btn_flg.0[button_index]=1 ENDIF ELSE IF btn_flg.0[button_index] THEN ; HAD THIS BUTTON BEEN PRESSED ? IF b_cnt[button_index] > long_press_threshold THEN B_STATE[button_index]=2 abp=1 ELSE IF b_cnt[button_index] > short_press_threshold THEN B_STATE[button_index] =1 abp=1 ENDIF endif btn_flg.0[button_index]=0 ENDIF ENDIF endif next ADCON0.1 = 1 ' Start conversion for next pass @ INT_RETURN![]()




Bookmarks