
181
CHAPTER 7
8-BIT TIMER/EVENT COUNTERS 50, 51
User’s Manual U12790EJ2V0UD
7.5 Program List
Caution
The following sample program is shown as an example to describe the operation of semiconductor
products and their applications. Therefore, when applying the following information to your
devices, design the devices after performing evaluation on your own responsibility.
7.5.1 Interval timer (8-bit)
/*************************************************************************************/
/*
*/
/*
Timer 50 operation sample
*/
/*
Interval timer setting example (frequency change by interrupt processing)
*/
/*
data[0]: Data set flag (value changed when other than 00)
*/
/*
data[1]: Set data
*/
/*
*/
/*************************************************************************************/
#pragma sfr
#pragma EI
#pragma DI
#pragma interrupt INTTM50 intervalint rb2
unsigned char data[2];
/* Data area */
void main(void)
{
PCC = 0x0;
/* Set high-speed operation mode */
data[0] = 0;
/* Clear data area */
data[1] = 0;
/* Set port
*/
P13 = 0b11111110;
/* Clear P130 when using TO50 */
/* Set interrupt
*/
TMMK50 = 0;
/* Clear INTTM50 interrupt mask */
/* Set timer 50
*/
TMC50 = 0b00000111;
/* Clear & start mode, initial value L */
CL50 = 0b00000101;
/* Both rising and falling edges */
/* Count clock is fx/2^6 */
CR50 = 98;
/* Set interval to 1 ms as initial value */
TCE50 = 1;
/* Timer start */
EI();
while(1);
/* Dummy loop */
}
/* INTTM50 interrupt function */
void intervalint()
{
if(data[0] != 0)
{
CR50 = data[1];
/* Set new set value */
data[0] = 0;
/* Clear request flag */
}