November 22, 2024, 10:22:54 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Long Delays (> 65 seconds)

Started by JonnyMac, September 28, 2008, 01:37:52 PM

Previous topic - Next topic

JonnyMac

September 28, 2008, 01:37:52 PM Last Edit: September 28, 2008, 01:40:04 PM by JonnyMac
The maximum duration for PAUSE is 65535 which means the longest delay we can do with one PAUSE instruction is 65.5 seconds.  We can either stack PAUSE instructions or create a subroutine for longer delays.  For the latter, this little demo will help; it has a subroutine called Delay_Seconds that when called will create a delay by the number of seconds specified in the variable timer.  If using a byte for timer this means you can have delays from 1 second to 255 seconds (4 mins, 15 secs).

' =========================================================================
'
'   File...... Long_Delays.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = B2


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00111111                              ' make P0-P5 outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  ' prop code here

  timer = 90                                    ' set for 1.5 minutes 
  GOSUB Delay_Seconds                           ' delay now

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Put number of seconds to delay in "timer" (1 to 255)
' -- "timer" is cleared to zero by routine

Delay_Seconds:
  IF timer = 0 THEN Delay_Exit
    PAUSE 1000
    timer = timer - 1
    GOTO Delay_Seconds

Delay_Exit:
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office