/*
 * Copyright(C) Paul und Scherer (mct.de/mct.net)
 *
 * This example demonstrates how to...
 *
 *  ... use a timer to trigger periodic
 *      events with no interrupt active.
 */

#include <target.h>

/*
 * When the counter has reached the value in MR2, MAT0.2
 * (=P0.16 =LED) is toggled, and the counter reset to 0.
 *
 * The prescaler is set, so that the counter increments
 * every millisecond. A value of 500 (-1) for MR2 resets
 * the counter every 500ms, thus making the LED blink at
 * intervals of 1 second (50% duty cycle).
 *
 * No interrupt is needed for this action.
 */
int
main(void)
{
	Intern_t0pr     = _PCLK/1000-1;		// inc every ms
	Intern_t0mr2    = 500-1;		// set MR2 [ms]
	Intern_t0mcr   |= 0x80;			// reset on MR2
	Intern_t0emr   |= 0x300;		// MAT0.2 toggle
	Intern_pinsel1 |= 2;			//        enable
	Intern_t0tcr    = 1;			// go...

	return 0;
}
