Program using the HC12 pulse accumulator in gated time accumulation mode to determine the length of time (in 8 microsecond intervals) a signal applied to Pin 7 of Port T is high.
/* Program to count the number of clock edges while input
 * on PT7 is high 
 */
#include "hc12.h"
#include "DBug12.h"

main()
{
    unsigned int count;

    TSCR = 0x80;                 /* Enable timer */
    PACTL = 0x40;                /* Enable PACTL */
    PACTL = PACTL | 0x20;        /* Go into gated time acc. mode */
    PACTL = PACTL & ~0x10;       /* Count while gate high */
    PACNT = 0;                   /* Clear PACNT register */
    PAFLG = 0x01;                /* Clear Input Edge Flag */
    
    while ((PFLAG&0x01) == 0) ;  /* Wait for gate to go low */
    count = PACNT;

    DBug12FNP->printf("%u clocks while gate high",count);
}