PDA

View Full Version : Button



savnik
- 26th May 2007, 21:01
if PORTB.5 = 1 and PORTB.7 = 1 then
WRITE W1, TMP_LO
WRITE W1+1, TMP_HI
LCDOUT $FE, 1, " STORE "
PAUSE 1000
menu = 2
GOTO MAIN
endif

GOTO MAIN

When PORTB.5 = 1 go to main and if PORTB.5 = 1 and PORTB.7 = 1
write to the memory and after go to main.
Now, i want if PORTB.5 = 1 for pause = 100 to go to to main and if
PORTB.5 = 1 for long time and if PORTB.7 = 1 go to write.

mister_e
- 26th May 2007, 21:18
OK let's see if i understand your requirement.

When ONLY PORTB.5 = 1 this should go to main
if PORTB.5 = 1 and PORTB.7 = 1, this should write to the memory and after go to main.


but you lost me with the pause 100... i may think you want to perform another operation if PORTB.1 have been hold more than 100 mSec... but not sure.

savnik
- 26th May 2007, 22:27
OK let's see if i understand your requirement.

When ONLY PORTB.5 = 1 this should go to main
if PORTB.5 = 1 and PORTB.7 = 1, this should write to the memory and after go to main.


but you lost me with the pause 100... i may think you want to perform another operation if PORTB.1 have been hold more than 100 mSec... but not sure.
I have two buttons . One to portb.5 and another to portb.7
Yes ,when i press momentarily the button1 then go to main, and when i press button1 for a long time and when afterwards press button2, then write to the memory.
Sorry fo my bad english.

mister_e
- 26th May 2007, 23:21
Don't worry about your English Savnik. I understand how hard it is to explain something when English is not your native language. I'm French... but Canadian :D

OK let's see one method to do that... yeah the saturday pm one solution ;)


PORTB = 0
TRISB=%10100000
EEPROMWriteMode VAR PORTB.0
WriteToEEPROM var PORTB.1
MainLed var PORTB.2

Delay var word

Main:
MainLed = 1
if PORTB.5 = 1 THEN GOSUB P_B_sub
goto main

P_B_Sub:
mainled = 0
delay = 0
while (PORTB.5 = 1) and (Delay<1000)
pause 1
delay=delay+1
wend
if delay<1000 then return

eepromwritemode=1
delay = 0
while (PORTB.7 = 0) and (DELAY<1000)
pause 1
delay=delay+1
wend

if (delay<1000) then
writetoeeprom =1
endif

pause 1000
eepromwritemode =0
writetoeeprom = 0
return

there's still the Timer Interrupt solution...

savnik
- 27th May 2007, 13:41
Thank you.Your code help me to solve my problem.
I use this code:

if PORTB.5 = 1 then
while (PORTB.5 = 1) and (Delay < 1000)
menu = 6
pause 1
delay = delay + 1
wend
if delay < 1000 then
delay = 0
GOTO MAIN
else
delay = 0
WRITE W1, TMP_LO
WRITE W1+1, TMP_HI
LCDOUT $FE, 1, " STORE "
PAUSE 1000
menu = 2
GOTO MAIN
endif
endif

mister_e
- 27th May 2007, 16:52
Good, enjoy!

and mmm... παρακαλώ! ;)