November 22, 2024, 07:31:05 AM

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:48:43 PM

Previous topic - Next topic

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.BS2
'   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 BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN


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

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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed


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

timer           VAR     Byte


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

Reset:
  OUTS = $0000                                  ' clear all outputs
  DIRS = $0FFF                                  ' make P0-P11 outputs


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for 0.1 sec input
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * Trigger                 ' update timer
  LOOP

  ' 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 destroyed by routine

Delay_Seconds:
  DO WHILE (timer > 0)
    PAUSE 1000
    timer = timer - 1
  LOOP
  RETURN


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


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