C Language Development Kit/Functions/GetSystemTime

From OptiWiki

Jump to: navigation, search
Description This function returns the current value of the system timer. This timer continuously

increments every timer tick and doesn't have to be started and it also doesn't stop like a time-out timer. This function makes it possible to create multiple timed processes that run simultaneously in an application.

Syntax
unsigned long GetSystemTime(void);
Arguments None
Returns Returns the current value of the system timer. The duration of 1 timer tick depends

on the type of terminal. The duration of 1 timer tick depends on the type of terminal.

  • 1 timer tick on the PHLxxxx takes 10 milliseconds.
  • 1 timer tick on the OPH100x, OPL97xx and DCL153x takes 20 milliseconds.

For example, 1 seconds on an OPH100x, OPL97xx or DCL153x takes 50 timer ticks, while 1 second on a PHLxxx takes 100 timer ticks.

The system timer has a range of 0 to 4294967295, which means the timer can almost run for about 1000 days on a OPH100x, OPL97xx or DCL153x and about 500 days on a PHLxxxx, before it resets to zero.

Remarks The system timer can be (re)set with the SetSystemTime() function.

Resetting the system timer doesn't affect the time or date of the operating system in any way.

When only 1 timer is needed in your application, it's better to use the starttimer() function.

Example
#include "lib.h"
#include <stdio.h>
 
#define HIGH_DELAY      13 * 5       //Note that these are prime numbers
#define MEDIUM_DELAY    23 * 5
#define LOW_DELAY       37 * 5
 
void main( void )
{
    unsigned long current_time;
    unsigned long next_high_time;
    unsigned long next_medium_time;
    unsigned long next_low_time;
 
    SetSystemTime(0);      //Reset system timer to zero
 
    next_high_time = HIGH_DELAY;
    next_medium_time = MEDIUM_DELAY;
    next_low_time = LOW_DELAY;
 
    setfont(SMALL_FONT, NULL);
    printf("\f3 independent\ntimers using\nGetSystemTime");
 
    while( 1 )
    {
        current_time = GetSystemTime();
 
        if(current_time>=next_low_time)
        {
            sound( TSTANDARD, VSTANDARD, SLOW, 0);
            goodreadled(RED,10);
            next_low_time += LOW_DELAY;
        }
 
        if(current_time>=next_medium_time)
        {
            sound( TSTANDARD, VSTANDARD, SMEDIUM, 0);
            goodreadled(ORANGE,10);
            next_medium_time += MEDIUM_DELAY;
        }
 
        if(current_time>=next_high_time)
        {
            sound( TSTANDARD, VSTANDARD, SHIGH, 0);
            goodreadled(GREEN,10);
            next_high_time += HIGH_DELAY;
        }
 
        idle();
    }
}


Views
Personal tools