
182
CHAPTER 8 16-BIT TIMER/EVENT COUNTERS 00, 01
User
’
s Manual U14260EJ3V1UD
8.5.5 PPG output
/******************************************************************************/
/* */
/* Timer 00 PPG mode setting example */
/* Cycle set to 130 as intervalTM00 */
/* Active period set to 65 as active_time */
/* Array ppgdata prepared as data area for rewriting */
/* [0]: Active period (0000: no change, 0xffff: stop) */
/* [1]: Cycle (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 */
#define active_time 65
/* Initial value data of CR010 */
#pragma interrupt INTTM000 ppgint rb2
unsigned int ppgdata[2];
/* Data area to be set to timer 00 */
void main(void)
{
PCC = 0x0;
ppgdata[0] = 0;
ppgdata[1] = 0;
/* Set high-speed operation mode */
/* Set port */
/* Clear P70 */
/* Set P70 to output */
/* Set interrupt */
/* Cancel INTTM000 interrupt mask */
/* Set timer 00 */
/* Count clock is fx/2^6 */
/* Set CR000 and CR010 to compare register */
/* Set initial value of cycle */
/* Set initial value of active period */
/* Inverted on match between CR000 and CR010,
initial value L */
/* Clear & start on match between TM00 and CR000 */
P7 = 0b11111110;
PM7.0 = 0;
TMMK000 = 0;
PRM00 = 0b00000010;
CRC00 = 0b00000000;
CR000 = intervalTM00;
CR010 = active_time;
TOC00 = 0b00010111;
TMC00 = 0b00001100;
EI();
while(1);
}
/* Timer 00 interrupt function */
void ppgint()
{
unsigned int work;
work = ppgdata[0];
if (work != 0)
{
CR010 = work;
ppgdata[0] = 0;
if (work == 0xffff)
{
TMC00 = 0b00000000;
}
}
work = ppgdata[1];
if (work != 0)
{
CR000 = work;
ppgdata[1]=0;
}
}
/* Stop timer */