177
CHAPTER 8 16-BIT TIMER/EVENT COUNTERS 00, 01
User
’
s Manual U14260EJ3V1UD
8.5.1 Interval timer
/*******************************************************************************/
/* */
/* Setting example of timer 00 interval timer mode */
/* Cycle set to 130 as intervalTM00 (at 8.38 MHz for 1 ms) */
/* Variable ppgdata prepared as rewrite data area */
/* : Cycle (if 0000, no change) */
/* ppgdata to be checked at every INTTM000, and changed if required. */
/* Therefore, if change is required, set the change data in ppgdata. */
/* When changed, ppgdata cleared to 0000. */
/* */
/*******************************************************************************/
#pragma sfr
#pragma EI
#pragma DI
#define intervalTM00 130
/* Cycle data to be set to CR000 */
#pragma interrupt INTTM000 intervalint rb2
unsigned int ppgdata;
/* Data area to be set to timer 00 */
void main(void)
{
PCC = 0x0;
ppgdata = 0;
/* Set high-speed operation mode */
/* Set port */
/* Set the following to output */
/* Clear P70 */
/* Set P70 as output */
/* Set interrupt */
/* Cancel INTTM000 interrupt mask */
/* Set timer 00 */
/* Count clock is fx/2^6 */
/* Set CR000 and CR010 to compare register */
/* Set cycle initial value to CR000 */
/* Invert on match with CR000, initial value L */
/* Clear & start on match between TM00 and CR000 */
P7 = 0b11111110;
PM7.0 = 0;
TMMK000 = 0;
PRM00 = 0b00000010;
CRC00 = 0b00000000;
CR000 = intervalTM00;
TOC00 = 0b00000111;
TMC00 = 0b00001100;
EI();
while(1);
/* Loop as dummy here */
}
/* Timer 00 interrupt function */
void intervalint()
{
unsigned int work;
/***************************************************/
/* */
/* Define variables required for interrupt here */
/* */
/***************************************************/
work = ppgdata;
if (work != 0)
{
CR000 = work;
ppgdata = 0;
if (work == 0xffff)
{
TMC00 = 0b00000000;
}
}
/***********************************************************/
/* */
/* Describe processing required for interrupt below */
/* */
/***********************************************************/
}
/* Stop timer */