PDA

View Full Version : On_Off



Leonardo
- 1st July 2006, 04:04
Hello to all,

I want to make the following thing:

I have a 16f84 and I want that when pulsing in RB0 on a led in RB1 and if I press the same one again off the led.

Somebody can help me.

Greetings

schu4647
- 1st July 2006, 05:54
I am very tired and drunk and am just writing this without trying it but here it goes.

flag var bit
flag = 0

start:
If portb.0 = 1 and flag=0 then
portb.1 = 1
flag = 1
pause 1000
end if

if portb.0 = 1 and flag=1 then
portb.1=0
flag = 0
pause 1000
endif
goto start

The flag is a way for the micro to keep track of which state is currently on. The pause allows the user to remove there finger from the button so the LED is constantly flashing. This may neet to be adjusted. This will be 1000 ms.

schu4647
- 1st July 2006, 06:03
flag var bit
flag = 0

start:
If portb.0 = 1 and flag=0 then
portb.1 = 1
flag = 1
pause 1000
endif

if portb.0 = 1 and flag=1 then
portb.1=0
flag = 0
pause 1000
endif
goto start

The endif should not have had a space in it. I also didn't meand the LED would flash. The pause is so it won't flash.

mister_e
- 1st July 2006, 09:36
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=390&d=1122866228">from what i understand...


IF PORTB.0=0 then
TOGGLE PORTB.1
WHILE PORTB.0=0 : Wend : pause 50
ENDIF

schu4647
- 1st July 2006, 16:15
That is good and simple, but does it debounce the switch.

schu4647
- 1st July 2006, 16:31
I didn't even realize that toggle command was in there. I that case I could change my code to:

input portb.0

start:
If portb.0 = 1 then
toggle portb.1
pause 1000
endif
goto start

I still think you need the pause of at least a second. Otherwise the light will pulse when you are holding the button. You need a delay to allow the user to remove there finger.

mister_e
- 1st July 2006, 22:41
both will work, mine just sit there until the button is release, then it allow a 50mSec of debouncing delay.

Leonardo
- 3rd July 2006, 00:34
Hello friends,

What I want is this:

If RB0 is 0 RB1 is ON and IF RB0 is 1 RB0 is off , every time that presses the led it should change state.

Thank you


both will work, mine just sit there until the button is release, then it allow a 50mSec of debouncing delay.

mister_e
- 3rd July 2006, 00:41
PORTB.1=~PORTB.0

in a loop it have to work.

Leonardo
- 3rd July 2006, 22:08
Hello mister and,

Can give me an example about this please. PORTB.1=~PORTB.0

Thank you

Leonard






PORTB.1=~PORTB.0

in a loop it have to work.