PDA

View Full Version : one button-two operations



savnik
- 15th July 2006, 21:58
I have a button and I want when I push it to go to labelone and when push again it to go to labeltwo , and so on.

BGreen
- 15th July 2006, 22:04
Just use a routine that sets a counter and then resets the next time. Branch depending on if the counter is 1 or 0. Put a time limit for the second if you want and have it reset at the expiration.

savnik
- 15th July 2006, 22:08
Just use a routine that sets a counter and then resets the next time. Branch depending on if the counter is 1 or 0. Put a time limit for the second if you want and have it reset at the expiration.
And how to make this;

BGreen
- 15th July 2006, 23:30
I would do it by interupting the pic and have an if statement:

if c1 = 0 then
do whatever
resume (whatever your base routine is)
do whatever else
c1 = 0
resume (whatever your base routine is)

in your base routine you could put the pic to sleep for a defined period of time and if it had not been interupted within that time make c1 = 0. That way if it were 1 it would clear it.

mister_e
- 16th July 2006, 02:30
CounterA Var Byte
CounterA=0
Start:
If PORTB.0=0 then
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0
endif
endif
While PORTB.0=0 : Wend : pause 50
BRANCHL CounterA,[LabelOne,LabelTwo,LabelThree]
'
' stuf and other
'
Goto Main

LabelOne:
' Stuff
goto Main

LabelTwo:
' Stuff
goto Main

LabelThree:
' Stuff
goto Main


The use of an internal Counter may reduce the code size too... look for RA4/T0CKI. Just read the TMR0 register and play with.

savnik
- 16th July 2006, 08:24
I have this code in my programm:

LOOP:
Button CH,0,255,0,b3,1,UHF 'b3 var BYTE
Button CH,1,255,0,b3,1,VHF 'CH var PORTB.5
PAUSE 100
GoSub POSTING
GoTo LOOP

UHF:.................
.................
GoTo LOOP

VHF:.................
.................
GoTo LOOP

I want if push one time the button and release to go to UHF and if push again and release to go to VHF and if push again and release to go to UHF , and so on

mister_e
- 16th July 2006, 09:22
did you at least tried the previous?

savnik
- 16th July 2006, 09:33
did you at least tried the previous?
Yes , but not compile

If PORTB.0=0 then ' ERROR Line 133: IF without a matching ENDIF. (TUNER.bas)
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0

mister_e
- 16th July 2006, 09:36
Doh! corrected now.

peterdeco1
- 16th July 2006, 10:31
Hi Savnik. Assuming you have your pushbutton on porta.0, you can toggle the variable "pushbutton" either 0 or 1 by making it a bit variable.

PUSHBUTTON VAR BIT

START:
IF PORTA.0 = 1 THEN START
IF PORTA.0 = 0 THEN LET PUSHBUTTON = PUSHBUTTON + 1
GOSUB WAITFORRELEASE
IF PUSHBUTTON = 0 THEN UHF
IF PUSHBUTTON = 1 THEN VHF
GOTO START

WAITFORRELEASE:
PAUSE 25
IF PORTA.0 = 0 THEN WAITFORRELEASE
RETURN

Acetronics2
- 16th July 2006, 15:30
as title says ... you could find, between others, melanie's sweet words ...

Alain

savnik
- 17th July 2006, 11:12
Thank you mister_e and peterdeco1.
Both files are working

Leonardo
- 17th July 2006, 16:14
Hello,

I want to do the following thing, I have 2 pulsers one in rb0 and another one in rb1 and a LED in rb2 and rb3. I Need to on and off with the same pulser in rb0 the LED in rb2 and want to on and off with the same pulser in rb1 the LED in rb3.

Since I can do it. Thanks










CounterA Var Byte
CounterA=0
Start:
If PORTB.0=0 then
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0
endif
endif
While PORTB.0=0 : Wend : pause 50
BRANCHL CounterA,[LabelOne,LabelTwo,LabelThree]
'
' stuf and other
'
Goto Main

LabelOne:
' Stuff
goto Main

LabelTwo:
' Stuff
goto Main

LabelThree:
' Stuff
goto Main


The use of an internal Counter may reduce the code size too... look for RA4/T0CKI. Just read the TMR0 register and play with.

Leonardo
- 20th July 2006, 02:24
Hello,

I want to do the following thing, I have 2 pulsers one in rb0 and another one in rb1 and a LED in rb2 and rb3. I Need to on and off with the same pulser in rb0 the LED in rb2 and want to on and off with the same pulser in rb1 the LED in rb3.

Since I can do it. Thanks




Thank you mister_e and peterdeco1.
Both files are working