'-------------------------------------------------------------------------------
Option Explicit

' This program illustrates how to use Timer1 as a stopwatch.

'-------------------------------------------------------------------------------
Public Sub Main()

    Dim Key As Byte
    Dim Success As Boolean
    Dim ElapsedTime As Single

    Const AsciiCr As Byte = 13

    Call OpenSerialPort(1, 19200)

    ' The maximum value is about 9.102 s.
    Call InitializeTimer(5)

    Call NewLine

    Do
        Call PutLine("Press <CR> to start stopwatch")
        Do        
            Call GetByte(Key, Success)
        Loop Until (Success) and (Key = AsciiCr)

        Call StartTimer

        Call PutLine("Press <CR> to stop stopwatch")
        Call NewLine
        Do        
            Call GetByte(Key, Success)
        Loop Until (Success) and (Key = AsciiCr)

        Call PutStr("Elapsed time: ")

        If (TimerHasOverflowed) Then
            Call PutLine("Overflow")
        Else
            Call GetTimerValue(ElapsedTime)
            Call PutStr( CStr(ElapsedTime) )
            Call PutLine(" s")
        End If

        Call NewLine
    Loop

End Sub
'-------------------------------------------------------------------------------
