C Language Development Kit/Functions/StartTimer

From OptiWiki

Jump to: navigation, search
Description This function starts the time-out timer. This function can be used to implement time-outs in an application. When the timer is started, endtimer() can be used to check if the specified time has elapsed.
Syntax
void starttimer(unsigned int timevalue);
Arguments
unsigned int timevalue
This is the time in steps of 20 milliseconds. For example, time = 50 refers to one second.
Returns None
Remarks Use endtimer() to check if the specified time has elapsed.

Use timervalue() to find out how much time is left before the timer elapses. The maximum time-out value that can be set is about 22 minutes (65535*20ms).

Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    while( 1 )
    {
        printf("\fTick off 5 sec");
        starttimer( 255 );
        while( !endtimer())
        {
            printf("\nTime left %d s", timervalue()/50);
            sound( TSTANDARD, VSTANDARD, SMEDIUM, 0);
            delay( 50 );
        }
 
        printf("\nDone");
        resetkey();
        while( !kbhit())
            idle();
    }
}


Views
Personal tools