C program to determine the time elapsed between two rising edges using the HC12 input capture subsystem

/* Program to determine time elapsed between two rising edges using the HC12
 * input capture subsystem.
 * First rising edge connected to pint PT1 of Port T
 * Second rising edge connected to pint PT2 of Port T
 */
#include "hc12.h"

unsigned int first, second, time;

main()
{
    TSCR = 0x80;                     /* Turn on timer subsystem */
    TMSK2 = 0x05;                    /* Set prescaler for divide by 32 */

    /* Setup for IC1 */
    TIOS = TIOS & ~0x02;             /* IOC1 set for Input Capture */
    TCTL4 = (TCTL4 | 0x04) & ~0x08;  /* Capture Rising Edge */
    TFLG1 = 0x02;                    /* Clear IC1 Flag */

    /* Setup for IC2 */
    TIOS = TIOS & ~0x04;             /* IOC2 set for Input Capture */
    TCTL4 = (TCTL4 | 0x10) & ~0x20;  /* Capture Rising Edge */
    TFLG1 = 0x04;                    /* Clear IC2 Flag */

    while ((TFLG1 & 0x02) == 0) ;  /* Wait for 1st rising edge; */
    first = TC1;                   /* Read time of 1st edge;    */

    while ((TFLG1 & 0x04) == 0) ;  /* Wait for 2nd rising edge; */
    second = TC2;                  /* Read time of 2nd edge;    */

    time = second - first;         /* Calculate total time */
}