Chapter 3 Register Setup of Each Function
69
/* Register address declaration */
#define
TM2BC_adr
0x3F58
#define
TM2BC
(*(volatile unsigned char *)TM2BC_adr)
#define
TM2OC_adr
0x3F5A
#define
TM2OC
(*(volatile unsigned char *)TM2OC_adr)
#define
TM2MD_adr
0x3F5C
#define
TM2MD
(*(volatile unsigned char *)TM2MD_adr)
#define
CK2MD_adr
0x3F5E
#define
CK2MD
(*(volatile unsigned char *)CK2MD_adr)
/* Setting program */
CK2MD = TM2PSC;
/* Set prescaler */
TM2OC = TIME;
/* Set timer value */
TM2MD = TM2MOD | TM2PWM | TM2EN | TM2CK;
This sample is stored in the CD.
Stored directory: Sample\chapter3,4\Initial\ASM\TIMER\Sclock\
Stored directory: Sample\chapter3,4\Initial\C\TIMER\Sclock\
The simple pulse width measurement uses timer count to measure the pulse width when the interrupt input
signal stays "Low". 3 timers, timers 0, 2, and 4, are available for the simple pulse width measurement.
The following section describes a sample program.
/* Control data declaration */
#define
TM0MOD
0x20
/* 0b00100000 Pulse width measurement */
#define
TM0PWM
0x00
/* 0b00000000 Timer operation */
#define
TM0EN
0x08
/* 0b00001000 Count operation */
/* Determine time for interval timer */
#define
TIME
0xFF
/* Timer count value, maximum value */
/* Register address declaration */
#define
TM0BC_adr
0x3F50
#define
TM0BC
(*(volatile unsigned char *)TM0BC_adr)
#define
TM0OC_adr
0x3F52
#define
TM0OC
(*(volatile unsigned char *)TM0OC_adr)
#define
TM0MD_adr
0x3F54
#define
TM0MD
(*(volatile unsigned char *)TM0MD_adr)
#define
CK0MD_adr
0x3F56
#define
CK0MD
(*(volatile unsigned char *)CK0MD_adr)
/* Setting program */
TM0OC = TIME;
/* Set timer value (counter clear) */
TM0MD = TM0MOD | TM0PWM | TM0EN | TM0CK;
This sample is stored in the CD.
Stored directory: Sample\chapter3,4\Initial\ASM\TIMER\PLUSE8\
Stored directory: Sample\chapter3,4\Initial\C\TIMER\PLUSE8\