This function returns the number of timer ticks that have occurred since the startup of the operating system.

Syntax

unsigned int GetTickCount(void);

Parameters

None

Return value

Returns the tick count that represents 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 tick count starts from 0 and increases by 1 every 20 msec to 0xFFFFFFFF (maximum value of unsigned int type), and then wraps around to 0 after 0xFFFFFFFF.
Even if it wraps around to 0, the elapsed time up to 0xFFFFFFFF can be calculated correctly in 20msec units by subtracting the past tick count held by the unsigned int type from the current tick count.

Note:

  • Since the tick count is initialized to 0 when the operating system is restarted, it is not suitable for calculating the number of elapsed days or elapsed time based on the date and time. Use the GetDate function and GetTime function to calculate them.

Requirements

Header file:
lib.h
Library file:
libSTARTUPOPH5000.a

Sample

#include <stdio.h>
#include "lib.h"

void main(void)
{
    unsigned int startTick;
    int event;
    int elapsedSeconds;
    int prev_elapsedSeconds;

    while(1){
        printf("\n Press [ENT] to start\n");
        while(1){
            if (kbhit()){
                if (getchar() == ENT_KEY){
                    break;
                }
            }
            Idle();
        }
        printf(" Press [F1] within 10\n seconds.\n\n");
        event = FALSE;
        prev_elapsedSeconds = -1;

        startTick = GetTickCount();
        while(GetTickCount() - startTick < 10000/20){ // Wait for 10 seconds
            if (kbhit()){
                if (getchar() == F1_KEY){
                    event = TRUE;
                    break;
                }
            }
            elapsedSeconds = (GetTickCount() - startTick) / 5; // 5 ticks = 0.1 secconds
            if (elapsedSeconds != prev_elapsedSeconds ){
                printf(" Elapsed:%2d.%d\r", elapsedSeconds/10, elapsedSeconds%10);
                prev_elapsedSeconds = elapsedSeconds;
            }
            Idle();
        }

        if (event){
            printf(" Good!        \r\n");
        }else{
            printf(" Timeout!     \r\n");
        }
    }
}

Last updated: 2021/02/04