Availability | All terminals |
Description | This function returns the number of timer ticks that have occurred since the startup of the operating system. If the timer reaches 65535 ticks it automatically resets back to 0. This function makes it possible to create multiple timed processes that run "simultaneously" in an application. |
Syntax | unsigned int GetTickCount( void ); |
Arguments | None |
Returns |
Returns the number of timer ticks that have occured since the startup of the operating system. The duration of one timer tick is 20ms. For example, 1 second takes 50 timer ticks. |
Remarks |
The timer tick counter can (re)set to a specific value for some terminals. See the function SetTickCount. When only 1 timer is needed in your application, it's better to use the StartTimer() function. |
Example |
#include <stdio.h> #include "lib.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; current_time = GetTickCount(); next_high_time = current_time + HIGH_DELAY; next_medium_time = current_time + MEDIUM_DELAY; next_low_time = current_time + LOW_DELAY; printf("\n3 independent\ntimers using\nGetTickCount"); for(;;) { //Detect timer reset after 655535 ticks if(current_time > GetTickCount()) { next_high_time = HIGH_DELAY; next_medium_time = MEDIUM_DELAY; next_low_time = LOW_DELAY; } current_time = GetTickCount(); 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(); } } |