The Renesas Embedded Application Programming Interface (API) is a unified API for
the microcomputers made by Renesas Technology Corporation.
Rev.1.00 2007.11.1
REC10B0002-0100
5
2. Driver
2.1 Overview
The library described herein provides a peripheral facility control program (peripheral
driver) for microcomputers. Use of the Renesas API permits the peripheral driver to be
built into a user program.
2.2 Driver Features
The library described herein has the following features available as a peripheral driver.
(1) Serial I/O control feature
It comprises a serial interface driver, which sets or clears the conditions of serial
communication, as well as controls and manages the transmission/reception of
communication data.
(2) Timer control feature
It comprises a timer driver, which sets or clears the operating conditions of timers,
as well as controls the timer operation.
(3) I/O port control feature
It comprises an I/O port driver, which sets or clears the usage conditions of I/O ports, as
well as control data read/write operation.
(4) External interrupt control feature
It comprises an external interrupt driver, which sets or clears the usage conditions of
external interrupts, as well as controls interrupt operation.
(5) A/D converter control feature
It comprises an A/D converter driver, which sets or clears the usage conditions of A/D
converters, as well as controls A/D converter operation.
Rev.1.00 2007.11.1
REC10B0002-0100
6
2.3 Serial Interface Driver
The serial interface driver sets serial communication, clears settings, transmit/receives
data, and controls the status of serial communication.
There are two kinds of serial interface driver: a single-data transmission/reception API
and a multi-data transmission/reception API.
Rev.1.00 2007.11.1
REC10B0002-0100
7
2.4 Timer Driver
The timer driver sets the timer, clears timer settings, controls timer operation, and
acquires a counter value with respect to the following modes:
• Timer mode
• Event counter mode
• Pulse width modulation mode (PWM mode)
• Pulse period measurement mode
• Pulse width measurement mode
2.4.1 Timer Mode
In this mode, the timer counts the internally generated count source. When an
underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.2 Event Counter Mode
In this mode, the timer counts the external signal fed in from an input pin or an
overflow or underflow from other timer. When an underflow or an overflow interrupt
occurs, it calls a preset callback function.
2.4.3 Pulse Width Modulation Mode (PWM Mode)
In this mode, the timer outputs pulses in a given width successively. When an
underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.4 Pulse Period Measurement Mode
In this mode, the timer measures the pulse period of an external signal fed in from an
input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback
function.
2.4.5 Pulse Width Measurement Mode
In this mode, the timer measures the pulse width of an external signal fed in from an
input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback
function.
Rev.1.00 2007.11.1
REC10B0002-0100
8
2.5 I/O Port Driver
The I/O port driver sets the I/O port for input or output, writes data to the I/O port, and
reads data from the I/O port.
Rev.1.00 2007.11.1
REC10B0002-0100
9
2.6 External Interrupt Driver
The external interrupt driver sets external interrupts, controls external interrupts,
acquires the status of external interrupt flags, and clears external interrupt flags.
Rev.1.00 2007.11.1
REC10B0002-0100
10
2.7 A/D Converter Driver
The A/D converter driver sets the A/D converter, controls the A/D converter, clears
settings of the A/D converter, acquires the A/D converter value, acquires the status of the
A/D converter, and clears the status of the A/D converter.
Rev.1.00 2007.11.1
REC10B0002-0100
11
3. Standard Types
This section describes the standard types defined in the library. For details about the
set values, refer to the description of each API.
Standard type Description
Boolean
Voi dF un cNo ti fy
The Boolean type represents the enum-type data that indicates
whether successful (RAPI_TRUE (= 1)) or failed (RAPI_FALSE (=
0)).
The VoidFuncNotify type represents the type of the notification
function to be registered.
Rev.1.00 2007.11.1
REC10B0002-0100
12
4. Library Reference
4.1 API List by Peripheral Facility
The table below lists the Renesas Embedded APIs classified by peripheral facility.
Opens serial port
Closes serial port
Sets serial communication
Receives 1 data
Transmits 1 data
Reads receive status
Reads transmit status
Stops reception
Stops transmission
Opens serial port
Closes serial port
Registers notification function
Sets serial communication
Sets transmit/receive interrupt
Starts reception
Starts transmission
Stops reception
Stops transmission
Receives by polling
Transmits by polling
Sets timer mode
Controls timer mode operation
Clears timer mode setting
Sets event counter mode
Controls operation of event counter
mode
Clears setting of event counter
mode
Gets event counter mode counter
value
Sets pulse width modulation mode
Controls operation of pulse width
modulation mode
Clears setting of pulse width
modulation mode
Sets pulse period measurement
mode
Controls operation of pulse period
measurement mode
Clears setting of pulse width
measurement mode
Acquires measured value of pulse
period measurement mode
Sets pulse width measurement
mode
Controls operation of pulse width
measurement mode
Clears setting of pulse width
measurement mode
Acquires measured value of pulse
width measurement mode
Sets timer register
Controls operation of timer register
Clears timer register
Gets timer register value
Sets I/O port
Reads from I/O port
Writes to I/O port
Sets I/O port register
Reads from I/O port register
Writes to I/O port register
Sets external interrupt
Controls external interrupt
Gets flag status of external interrupt
Clears flag of external interrupt
Sets A/D converter
Controls operation of A/D converter
Discards settings of A/D converter
Gets A/D conversion value (register
specified)
Gets A/D conversion value (all
registers)
Rev.1.00 2007.11.1
REC10B0002-0100
14
4.2 Description of Each API
This section describes each API and explains how to use them, showing a program
example for each.
The description of each API is divided into the following items.
• Synopsis
• Description
• Return value
• Functionality
• Reference
• Remark
• Program example
: Outlines the content of processing performed by the function. It
also shows the syntax of the function, followed by a brief
explanation of arguments.
: Describes the function and how to use it in detail.
: Explains the returned value of the function.
: Indicates the functional classification of the function.
: Indicates the related functions.
: Describes the precautions to be taken when using the API.
: Presents a program showing how to use the function.
Rev.1.00 2007.11.1
REC10B0002-0100
15
4.2.1 Serial I/O
__BasicOpenSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
Program example
<Open a serial port>
Boolean __BasicOpenSerialDriver(unsigned long data)
For serial communication mode, the following values can be set.
(UART0, UART1, UART2)
RAPI_SM_SYNC
RAPI_SM_ASYNC
(SI/O3, SI/O4)
RAPI_SIO_SM_SYNC
For the data length format of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_BIT_7 Transfer data length 7 bitsRAPI_BIT_8 Transfer data length 8 bits
RAPI_BIT_9 Transfer data length 9 bits
For the clock source of serial communication, the following values can be set.
(UART0, UART1, UART2)
RAPI_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_CKDIR_EXT External clock is used as the clock source of serial communication.
(SI/O3, SI/O4)
RAPI_SIO_CKDIR_INTInternal clock is used as the clock source of serial communication.
RAPI_SIO_CKDIR_EXTExternal clock is used as the clock source of serial communication.
For the stop bit length of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_STPB_1 1 stop bit RAPI_STPB_2 2 stop bits
For the parity bit of clock asynchronous serial communication, the following values can
be set.
Clock synchronous serial communication mode
Clock asynchronous serial communication mode
Clock synchronous serial communication mode
Rev.1.00 2007.11.1
REC10B0002-0100
18
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_PARITY_NONNo parity bit RAPI_PARITY_EVEN Even parity bit
RAPI_PARITY_ODDOdd parity bit
For the clock polarity of serial communication, the following values can be set.
If the API is used in clock asynchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_DPOL_NON Polarity not invertedRAPI_DPOL_INV Polarity inverted
(SI/O3, SI/O4)
RAPI_SIO_DPOL_NONPolarity not invertedRAPI_SIO_DPOL_INV Polarity inverted
For the count source of the built-in baud rate generator, the following values can be set.
(UART0, UART1, UART2)
For the _CTS/_RTS function, the following values can be set.
If the internal clock is selected for use in clock synchronous serial communication
mode, the _RTS function has no effect.
(UART0, UART1, UART2)
RAPI_CTSRTS_DIS _CTS/_RTS functions are not used.
RAPI_CTS_SEL _CTS function is selected.
RAPI_RTS_SEL _RTS function is selected.
For the transfer format, the following values can be set.
If the data length selected for use in clock asynchronous serial communication mode is
7 or 9 bits long, do not set these values.
(UART0, UART1, UART2)
RAPI_LSB_SEL LSB first RAPI_MSB_SEL MSB first
(SI/O3, SI/O4)
RAPI_SIO_LSB_SEL LSB first RAPI_SIO_MSB_SEL MSB first
For serial data logic switchover, the following values can be set.
(UART0, UART1, UART2)
RAPI_LOGIC_NO_REV
RAPI_LOGIC_REV The value written in the transmit buffer register is inverted before
Return value
[data2]
Sets the divide-by-N value of a communication speed.
The value written in the transmit buffer register does not have its
logic inverted.
being transmitted.
Rev.1.00 2007.11.1
REC10B0002-0100
19
Functionality
Reference
Remark
If serial communication was successfully set, RAPI_TRUE is returned; if settings failed,
RAPI_FALSE is returned.
Serial I/O
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
Boolean func( void )
{
/* Set the data of RAPI_COM1 to serial driver */
Return _BasicSetSerialFormat(RAPI_COM1 | RAPI_SM_SYNC | RAPI_CKDIR_INT
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Serial I/O
__OpenSerialDriver
If an undefined value is specified in the argument, operation of the API cannot be
•
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void )
{
/* Close serial driver */
return __CloseSerialDriver( RAPI_COM1 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
28
0
__ConfigSerialDriverNotify
Synopsis
Description
The function to be registered in func must be supplied to the serial I/O driver by the
The serial I/O driver calls the function registered in func.
The serial I/O driver notifies the user of the transmit/receive status by an argument.
The type of the function to be registered is shown below.
void “any function name” (unsigned char notify);
The argument is detailed below.
(UART0, UART1, UART2)
<Register a notification function>
Boolean __ConfigSerialDriverNotify(unsigned long data, VoidFuncNotify *func)
data Setup data
func Function pointer to be registered
Registers the notification function necessary to get various transmit/receive information
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Rev.1.00 2007.11.1
REC10B0002-0100
32
Functionality
Reference
Remark
Serial I/O
If an undefined value is specified in the argument, operation of the API cann ot be
•
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
Boolean func( void )
{
/* Set interrupt of RAPI_COM1 to serial driver */
return __SetSerialInterrupt( RAPI_COM1 | RAPI_INT_TX_LV_1 |
}
RAPI_INT_RX_LV_2 );
Rev.1.00 2007.11.1
REC10B0002-0100
33
__StartSerialReceiving
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Start reception>
Boolean __StartSerialReceiving(unsigned long data, unsigned char wordNum,
unsigned int *RcvDtBuf)
data Setup data
wordNum Number of words received
RcvDtBuf Pointer to the buffer in which received data is stored
Starts reception of serial communication and gets received data by a specified number
of words. When acquisition of received data is complete, this API calls a notification
function (if a notification function is registered).
If reception of serial communication was successfully started, RAPI_TRUE is returned;
if failed, RAPI_FALSE is returned.
Serial I/O
__ConfigSerialDriverNotify, __StopSerialReceiving
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
unsigned int buffer[10];
void func( void )
{
/* Get 5 word data received in serial communication */
__StartSerialReceiving( RAPI_COM1, 5, buffer );
}
Rev.1.00 2007.11.1
REC10B0002-0100
34
__StartSerialSending
Synopsis
data Setup data
wordNum Number of words transmitted
SndDtBuf Pointer to the transmit data
Description
For data, the following values can be set.
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2 RAPI_COM4 SI/O3
RAPI_COM5 SI/O4
Return value
Functionality
Reference
Remark
<Start transmission>
Boolean __StartSerialSending(unsigned long data, unsigned char wordNum,
unsigned int *SndDtBuf)
Starts transmission of serial communication and writes transmit data to the transmit
buffer by a specified number of words. When transmission of all transmit data is
complete, this API calls a notification function (if a notification function is registered).
[data]
If transmission of serial communication was successfully started, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__ConfigSerialDriverNotify, __StopSerialSending
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include ”ra pi_sif_m16c_62p”
unsigned int buffer[10];
void func( void )
{
/* Set 5 word data to transmit buffer of serial communication */
__StartSerialSending( RAPI_COM1, 5, buffer );
}
Rev.1.00 2007.11.1
REC10B0002-0100
35
__StopSerialReceiving
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop reception>
Boolean __StopSerialReceiving(unsigned long data)
data Setup data
Stops reception of serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2
If reception of serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__StartSerialReceiving
For the M16C SI/03 and SI/04, this API cannot be used.
•
If an undefined value is specified in the argument, operation of the API cannot be
•
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void )
{
/* Stop receiving data in serial communication */
__StopSerialReceiving ( RAPI_COM1 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
36
__StopSerialSending
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop transmission>
Boolean __StopSerialSending(unsigned long data)
data Setup data
Stops transmission of serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2
If transmission of serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__StartSerialReceiving
For the M16C SI/03 and SI/04, this API cannot be used.
•
When operating in clock synchronous serial communicatio n mode, data reception is
•
stopped at the same time by this API.
If an undefined value is specified in the argument, operation of the API cann ot be
•
guaranteed.
Program example
#include ”ra pi_sif_m16c_62p”
void func( void )
{
/* Stop sending data in serial communication */
__StopSerialSending ( RAPI_COM1 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
37
__PollingSerialReceiving
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Polling reception>
Boolean __PollingSerialReceiving(unsigned long data)
data Setup data
Performs reception of serial communication by polling. This API gets received data by
an amount specified by __StartSerialReceiving. When acquisition of received data is
complete, it calls a notification function (if a notification function is registered).
Boolean __PollingSerialSending(unsigned long data)
data Setup data
Performs transmission of serial communication by polling. This API sends transmit data
by an amount specified by __StartSerialSending from the transmit data buffer specified
by __StartSerialSending. When transmission of all transmit data is complete, it calls a
notification function (if a notification function is registered).
Boolean __CreateTimer(unsigned long data1, unsigned int data2, unsigned int
data3, unsigned int data4, void* func)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
data4 Setup data 4
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified timer to timer mode.
[data1]
For data1, the following definition values can be set. T o set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_A0 Uses timer A channel 0.
RAPI_TIMER_A1 Uses timer A channel 1.
RAPI_TIMER_A2 Uses timer A channel 2.
RAPI_TIMER_A3 Uses timer A channel 3.
RAPI_TIMER_A4 Uses timer A channel 4.
RAPI_TIMER_B0 Uses timer B channel 0.
RAPI_TIMER_B1 Uses timer B channel 1.
RAPI_TIMER_B2 Uses timer B channel 2.
RAPI_TIMER_B3 Uses timer B channel 3.
RAPI_TIMER_B4 Uses timer B channel 4.
RAPI_TIMER_B5 Uses timer B channel 5.
RAPI_F1 Selects f1 for the count source.
RAPI_F2 Selects f2 for the count source.
RAPI_F8 Selects f8 for the count source.
RAPI_F32 Selects f32 for the count source.
RAPI_FC32 Selects f
RAPI_TIMER_ON Sets the timer to start operating in __CreateTimer.
RAPI_TIMER_OFF Sets the timer to stop operating in __CreateTimer.
RAPI_GATE_L Selects a gate facility that counts a period during which input at
RAPI_GATE_H Selects a gate facility that counts a period during which input at
RAPI_PULSE_ON Selects that pulses are output from TA
RAPI_PULSE_OFF Selects that no pulses are output from TA
• Specifiable definition values when timer A is used (RAPI_TIMER_A0 to
RAPI_TIMER_A4 specified)
for the count source.
c32
pin remains low.
TA
iIN
pin remains high.
TA
iIN
pin.
iIN
iIN
pin.
Rev.1.00 2007.11.1
REC10B0002-0100
40
Return value
Functionality
Reference
Remark
(Count source) Specify one from { RAPI_F1, RAPI_F2, RAPI_F8, RAPI_F32,
(Operating states set) Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The
(Pulse output state) Specify one from { RAPI_PULSE_ON, RAPI_PULSE_OFF }. The
(Gate facility) Specify one from { RAPI_GATE_L, RAPI_GATE_H }. If omitted,
• Specifiable definition values when timer B is used (RAPI_TIMER_B0 to
RAPI_TIMER_B5 specified)
(Count source) Specify one from { RAPI_F1, RAPI_F2, RAPI_F8, RAPI_F32,
(Operating states set) Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
[data3]
Specify the value to be set in the timer register in 16 bits.
[data4]
Specify 0.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
Timer (timer mode)
__EnableTimer, __DestroyTimer
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void TimerIntFunc( void ){}
void func( void )
{
/* Set up timer A0 as timer mode */
__CreateTimer( RAPI_TIMER_A0|RAPI_TIMER_ON|RAPI_F8, 5, 0x80, 0,
}
RAPI_FC32 }. The default value is RAPI_F2.
default value is RAPI_TIMER_OFF.
default value is RAPI_PULSE_OFF.
“No gate facility” is set.
RAPI_FC32 }. The default value is RAPI_F2.
default value is RAPI_TIMER_OFF.
TimerIntFunc );
Rev.1.00 2007.11.1
REC10B0002-0100
41
__EnableTimer
Synopsis
Description
<Control operation of timer mode>
Boolean __EnableTimer(unsigned long data)
data Setup data
Controls operation of the timer that is set to specified timer mode by starting or
stopping it.
[data]
For data, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_A0
RAPI_TIMER_A1
RAPI_TIMER_A2
RAPI_TIMER_A3
RAPI_TIMER_A4
RAPI_TIMER_B0
RAPI_TIMER_B1
RAPI_TIMER_B2
RAPI_TIMER_B3
RAPI_TIMER_B4
RAPI_TIMER_B5
RAPI_TIMER_ONSets the timer that is set to timer mode to start operating.
RAPI_TIMER_OFF Sets the timer that is set to timer mode to stop operating.
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Timer (timer mode)
__CreateTimer, __DestroyTimer
If an undefined value is specified in the argument, oper ation of the API cannot be
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Selects timer B channel 0.
Selects timer B channel 1.
Selects timer B channel 2.
Selects timer B channel 3.
Selects timer B channel 4.
Selects timer B channel 5.
Rev.1.00 2007.11.1
REC10B0002-0100
42
__DestroyTimer
Synopsis
Description
<Discard settings of timer mode>
Boolean __DestroyTimer(unsigned long data)
data Setup data
Discards settings of the timer that is set to specified timer mode.
[data]
For data, the following definition values can be set.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
Timer (timer mode)
__CreateTimer, __EnableTimer
If an undefined value is specified in the argument, oper ation of the API cannot be
•
guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
/* Destroy the setting of timer A2 as timer mode */
__DestroyTimer( RAPI_TIMER_A2 );
}
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2
Selects timer A channel 3.
Selects timer A channel 4.
Selects timer B channel 0.
Selects timer B channel 1.
Selects timer B channel 2.
Selects timer B channel 3.
Selects timer B channel 4.
Selects timer B channel 5.
Rev.1.00 2007.11.1
REC10B0002-0100
43
__CreateEventCounter
Synopsis
Description
<Set event counter mode>
Boolean __CreateEventCounter(unsigned long data1, unsigned int data2,
unsigned int data3, unsigned int data4, void* func)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
data4 Setup data 4
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified timer to event counter mode.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_A0
RAPI_TIMER_A1
RAPI_TIMER_A2
RAPI_TIMER_A3
RAPI_TIMER_A4
RAPI_TIMER_B0
RAPI_TIMER_B1
RAPI_TIMER_B2
RAPI_TIMER_B3
RAPI_TIMER_B4
RAPI_TIMER_B5
RAPI_EV_EXTERNAL Selects the external signal input to TA
RAPI_EV_TIMER_AJ Selects overflow or underflow of timer Aj (j = i-1, however j = 4 if i =
RAPI_EV_TIMER_AK Selects overflow or underflow of timer Ak (k = i+1, however k = 0 if i
RAPI_EV_TIMER_B2 Selects overflow or underflow of timer B2 for the count source.
RAPI_EV_TIMER_BJ Selects overflow or underflow of timer Bj (j = i – 1, however j = 2 if i
RAPI_TIMER_ON Sets the timer to start operating in __CreateEventCounter.
RAPI_TIMER_OFF Sets the timer to stop operating in __CreateEventCounter.
RAPI_PULSE_ON Selects that pulses are output from TA
RAPI_PULSE_OFF Selects that no pulses are output from TA
RAPI_AUTO_RELOADSelects reload type for the count type.
RAPI_FREE_RUN Selects free-run type for the count type.
Uses timer A channel 0.
Uses timer A channel 1.
Uses timer A channel 2.
Uses timer A channel 3.
Uses timer A channel 4.
Uses timer B channel 0.
Uses timer B channel 1.
Uses timer B channel 2.
Uses timer B channel 3.
Uses timer B channel 4.
Uses timer B channel 5.
or TB
pin (when using timer Bi) for the count source.
iIN
0) for the count source.
= 4) for the count source.
= 0, j = 5 if i = 3 ) for the count source.
pin (when using timer Ai)
iIN
pin.
iIN
pin.
iIN
Rev.1.00 2007.11.1
REC10B0002-0100
44
RAPI_UP_COUNT Selects up-count for the count operation.
RAPI_DOWN_COUNT Selects down-count for the count operation.
RAPI_UDF_REGISTERSelects the UDF register for the cause of up/down switching.
RAPI_TAIOUT Selects the input signal at TA
switching.
RAPI_RISING Selects the rising edge of count source as active edge.
RAPI_FALLING Selects the falling edge of count source as active edge.
RAPI_BOTH Selects both rising and falling edges of count source as active
edges.
• Specifiable definition values when timer A is used (RAPI_TIMER_A0 to RAPI_TIMER_A4
specified)
(Count source) Specify one from { RAPI_EV_EXTERNAL, RAPI_EV_TIMER_AJ,
RAPI_EV_TIMER_AK, RAPI_EV_TIMER_B2 }. The default value is
RAPI_EV_EXTERNAL.
(Operating
states set)
(Pulse output
facility)
(Gate facility) Specify one from { RAPI_GATE_L, RAPI_GATE_H }. If omitted, “No gate
(Count type) Specify one from { RAPI_AUTO_RELOAD, RAPI_FREE_RUN }. The
(Count
direction)
(Count direction
switching)
(Count edge) Specify one from { RAPI_RISING, RAPI_FALLING }. The default value is
• Specifiable definition values when timer B is used (RAPI_TIMER_B0 to R API_TIMER_B4
specified)
(Count source) Specify one from { RAPI_EV_EXTERNAL, RAPI_EV_TIMER_BJ }. The
(Operating
states set)
(Count edge) Specify one from { RAPI_RISING, RAPI_FALLING, RAPI_BOTH }. The
Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The default
value is RAPI_TIMER_OFF.
Specify one from { RAPI_PULSE_ON, RAPI_PULSE_OFF }. The default
value is RAPI_PULSE_OFF.
facility” is set.
default value is RAPI_AUTO_RELOAD.
Specify one from { RAPI_UP_COUNT, RAPI_DOWN_COUNT }. The
default value is RAPI_DOWN_COUNT . The count direction can only be set
when the UDF register is used.
Specify one from { RAPI_UDF_REGISTER, RAPI_TAIOUT }. The default
value is RAPI_UDF_REGISTER.
RAPI_FALLING.
default value is RAPI_EV_EXTERNAL.
Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The default
value is RAPI_TIMER_OFF.
default value is RAPI_FALLING.
pin for the cause of up/down
iOUT
Specify the value to be set in the timer register in 16 bits.
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
[data3]
Rev.1.00 2007.11.1
REC10B0002-0100
45
[data4]
Specify 0.
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Selects timer B channel 0.
Selects timer B channel 1.
Selects timer B channel 2.
Selects timer B channel 3.
Selects timer B channel 4.
Selects timer B channel 5.
Sets the timer that is set to event counter mode to start
operating.
Sets the timer that is set to event counter mode to stop
operating.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the argument, oper ation of the API cannot be
•
guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
/* Destroy the setting of timer B2 as event counter mode */
__DestroyEventCounter( RAPI_TIMER_B2 );
}
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Selects timer B channel 0.
Selects timer B channel 1.
Selects timer B channel 2.
Selects timer B channel 3.
Selects timer B channel 4.
Selects timer B channel 5.
Rev.1.00 2007.11.1
REC10B0002-0100
48
__GetEventCounter
Synopsis
Description
<Get event counter mode counter value>
Boolean __GetEventCounter(unsigned long data1, unsigned int *data2)
data1
data2
Gets the counter value of the timer that is set to specified event counter mode.
[data1]
For data, the following definition values can be set.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
unsigned int data[2];
/* Get the counter of timer B3 as event counter mode */
__GetEventCounter(RAPI_TIMER_B3, data );
}
Setup data 1
Pointer to the buffer in which counter value is stored
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Selects timer B channel 0.
Selects timer B channel 1.
Selects timer B channel 2.
Selects timer B channel 3.
Selects timer B channel 4.
Selects timer B channel 5.
Rev.1.00 2007.11.1
REC10B0002-0100
49
__CreatePulseWidthModulationMode
Synopsis
Description
<Set pulse width modulation mode>
Boolean __CreatePulseWid thModula tionM ode(unsigne d long da t a 1, uns igned int
data2, unsigned int* data3, void* data4)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified timer to pulse width modulation mode.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_A0 Uses timer A channel 0.
RAPI_TIMER_A1 Uses timer A channel 1.
RAPI_TIMER_A2 Uses timer A channel 2.
RAPI_TIMER_A3 Uses timer A channel 3.
RAPI_TIMER_A4 Uses timer A channel 4.
RAPI_F1 Selects f1 for the count source.
RAPI_F2 Selects f2 for the count source.
RAPI_F8 Selects f8 for the count source.
RAPI_F32 Selects f32 for the count source.
RAPI_FC32 Selects f
RAPI_TIMER_ONSets the timer to start operating in __CreatePulseWidthModulationMode.
RAPI_TIMER_OFF Sets the timer to stop operating in __CreatePulseWidthModulationMode.
RAPI_TG_TAIIN Selects external trigger input from TA
RAPI_EV_
TIMER_AJ
RAPI_EV_TIMER_
AK
RAPI_EV_TIMER_
B2
RAPI_TG_TAIS Only writing 1 to the TAiS bit of the TABSR register causes the timer to
RAPI_PULSE_ONSelects that pulses are output from TA
RAPI_PULSE_OFF Selects that no pulses are output from TA
RAPI_PWM_16 Selects operation as a 16-bit pulse width modulator.
RAPI_PWM_8 Selects operation as an 8-bit pulse width modulator.
RAPI_RISING Selects the rising edge of TA
Selects overflow or underflow of timer Aj (j = i – 1, however j = 4 if i = 0)
as the trigger for the timer to start counting.
Selects overflow or underflow of timer Ak (k = i + 1, however k = 0 if i =
4) as the trigger for the timer to start counting.
Selects overflow or underflow of timer B2 as the trigger for the timer to
start counting.
start counting.
Ai is used.
timer Ai is used.
for the count source.
C32
pin for the count start condition.
iIN
pin. Selectable only when timer
iIN
pin. Selectable only when
iIN
pin input signal as active edge.
iIN
Rev.1.00 2007.11.1
REC10B0002-0100
50
RAPI_FALLING Selects the falling edge of TA
• Specifiable definition values when timer A is used (RAPI_TIMER_A0 to
RAPI_TIMER_A4 specified)
(Count source) Specify one from { RAPI_F1, RAPI_F2, RAPI_F32, RAPI_FC32 }.
(Operating states set) Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The
(Count start condition) Specify one from { RAPI_TG_TAIS, RAPI_TG_TAIIN,
(Pulse output facility) Specify one from { RAPI_PULSE_ON, RAPI_PULSE_OFF }. The
(Modulator) Specify one from { RAPI_PWM_16, RAPI_PWM_8 }. The default
(TA
pin input) Specify one from { RAPI_RISING, RAPI_FALLING }. The default
iIN
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
[data3]
Specify a pointer to the 16-bit variable in which the set value for the timer register is
The default value is RAPI_F2.
default value is RAPI_TIMER_OFF.
RAPI_EV_TIMER_AJ, RAPI_EV_TIMER_AK,
RAPI_EV_TIMER_B2 }. The default value is RAPI_TG_TAIIN.
default value is RAPI_PULSE_OFF.
value is RAPI_PWM_16.
value is RAPI_FALLING. The active edge of TA
be set when RAPI_TG_TAIIN is selected.
pin input signal as active edge.
iIN
stored.
For 16-bit PWM, specify the value of ‘n’ in “high-level width n/fj, period 65535/fj” in
16 bits.
For 8-bit PWM, specify the values of ‘n’ and ‘m’ in “high-level width n (m + 1)/f,
period 255 (m + 1)/fj” in the 8 high-order bits and the 8 low-order bits, respectively.
Return value
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the argument, operation of the API cannot be
•
guaranteed.
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Sets the timer that is set to pulse width modulation mode to
start operating.
Sets the timer that is set to pulse width modulation mode to
stop operating.
If an undefined value is specified in the argument, oper ation of the API cannot be
•
guaranteed.
Selects timer A channel 0.
Selects timer A channel 1.
Selects timer A channel 2.
Selects timer A channel 3.
Selects timer A channel 4.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
/* Destroy the setting of timer A1 as pulse width modulation mode */
__DestroyPulseWidthModulationMode( RAPI_TIMER_A1 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
54
__CreatePulsePeriodMeasurementMode
Synopsis
Description
<Set pulse period measurement mode>
Boolean __CreatePulsePeriodMeasureme ntMode(unsigned long data1,
unsigned int data2, unsigned int data3, unsigned int data4, void* func)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
data4 Setup data 4
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified timer to pulse period measurement mode.
[data1]
For data1, the following definition values can be set. To set multiple definition values
at the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_B0Uses timer B channel 0.
RAPI_TIMER_B1Uses timer B channel 1.
RAPI_TIMER_B2Uses timer B channel 2.
RAPI_TIMER_B3Uses timer B channel 3.
RAPI_TIMER_B4Uses timer B channel 4.
RAPI_TIMER_B5Uses timer B channel 5.
RAPI_F1 Selects f
RAPI_F2 Selects f
RAPI_F8 Selects f
RAPI_F32 Selects f
RAPI_FC32 Selects f
RAPI_TIMER_ON
RAPI_TIMER_OFF
RAPI_RISING_
RISING
RAPI_FALLING_
FALLING
• Specifiable definition values when timer B is used (RAPI_TIMER_B0 to
RAPI_TIMER_B5 specified)
(Count source) Specify one from { RAPI_F1, RAPI_F2, RAPI_F8, RAPI_F32,
(Operating
states set)
(Measurement
pulse)
Sets the timer to start operating in __CreateP u ls eP eriodMeasurementMode.
Sets the timer to stop operating in __CreatePulsePeriodMeasurementMode.
Selects measurement of an interval from the rise to the next rise of a
measurement pulse.
Selects measurement of an interval from the fall to the next fall of a
measurement pulse.
RAPI_FC32 }. The default value is RAPI_F2.
Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The default
value is RAPI_TIMER_OFF.
Specify one from { RAPI_RISING_RISING, RAPI_FALLING_FALLING }.
The default value is RAPI_FALLING_FALLING.
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
for the count source.
1
for the count source.
2
for the count source.
8
for the count source.
32
for the count source.
C32
Rev.1.00 2007.11.1
REC10B0002-0100
55
[data3]
Specify 0.
[data4]
Specify 0.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise,
If an undefined value is specified in the first argument, operation of the API
•
cannot be guaranteed.
#include "rapi_timer_m16c_62p.h"
void TimerIntFunc( void ){}
void func( void )
{
/* Set up timer B0 as pulse period measurement mode */
__CreatePulsePeriodMeasurementMode(
RAPI_TIMER_B0|RAPI_TIMER_ON|RAPI_FALLING_FALLING|RAPI_F8,
5, 0, 0, TimerIntFunc);
}
Rev.1.00 2007.11.1
REC10B0002-0100
56
__EnablePulsePeriodMeasurementMode
Synopsis
Description
For data, the following defi nition values can be set. To set multiple definition values at
Return value
Functionality
Reference
__GetPulsePeriodMeasurementMode
Remark
<Control operation of pulse period measurement mode>
Boolean __EnablePulsePeriodMeasurementMode(unsigned long data)
data Setup data
Controls operation of the timer that is set to specified pulse period measurement mode
by starting or stopping it.
[data]
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_B0 Selects timer B channel 0.
RAPI_TIMER_B1 Selects timer B channel 1.
RAPI_TIMER_B2 Selects timer B channel 2.
RAPI_TIMER_B3 Selects timer B channel 3.
RAPI_TIMER_B4 Selects timer B channel 4.
RAPI_TIMER_B5 Selects timer B channel 5.
RAPI_TIMER_ONSets the timer that is set to pulse period measurement mode to start
operating.
RAPI_TIMER_OFF Sets the timer that is set to pulse period measurement mode to stop
operating.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
unsigned int data[2];
/* Get the measured value of timer B3 as pulse period measurement mode
*/
__GetPulsePeriodMeasurementMode( RAPI_TIMER_B3, data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
59
__CreatePulseWidthMeasurementMode
Synopsis
Description
<Set pulse width measurement mode>
Boolean __CreatePulseWidthMeasurementMode(unsigned long data1, unsigned
int data2, unsigned int data3, unsigned int data4, void* func)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
data4 Setup data 4
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified timer to pulse with measurement mode.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_B0 Uses timer B channel 0.
RAPI_TIMER_B1 Uses timer B channel 1.
RAPI_TIMER_B2 Uses timer B channel 2.
RAPI_TIMER_B3 Uses timer B channel 3.
RAPI_TIMER_B4 Uses timer B channel 4.
RAPI_TIMER_B5 Uses timer B channel 5.
RAPI_F1 Selects f1 for the count source.
RAPI_F2 Selects f2 for the count source.
RAPI_F8 Selects f8 for the count source.
RAPI_F32 Selects f32 for the count source.
RAPI_FC32 Selects f
RAPI_TIMER_ONSets the timer to start operating in
__CreatePulseWidthMeasurementMode.
RAPI_TIMER_OFF Sets the timer to stop operating in
__CreatePulseWidthMeasurementMode.
• Specifiable definition values when timer B is used (RAPI_TIMER_B0 to
RAPI_TIMER_B2 specified)
(Count source) Specify one from { RAPI_F1, RAPI_F2, RAPI_F8, RAPI_F32, RAPI_FC32 }.
The default value is RAPI_F2.
(Operating
states set)
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
[data3]
Specify 0.
Specify one from { RAPI_TIMER_ON, RAPI_TIMER_OFF }. The default
value is RAPI_TIMER_OFF.
for the count source.
C32
Rev.1.00 2007.11.1
REC10B0002-0100
60
Return value
Functionality
Reference
__GetPulseWidthMeasurementMode
Remark
[data4]
Specify 0.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void TimerIntFunc( void ){}
void func( void )
{
/* Set up timer B4 as pulse width measurement mode */
__CreatePulseWidthMeasurementMode(
RAPI_TIMER_B4|RAPI_TIMER_ON|RAPI_RISING_FALLING|RAPI_F8,
5, 0, 0, TimerIntFunc);
}
Rev.1.00 2007.11.1
REC10B0002-0100
61
__EnablePulseWidthMeasurementMode
Synopsis
Description
For data, the following defi nition values can be set. To set multiple definition values at
Return value
Functionality
Reference
__GetPulseWidthMeasurementMode
Remark
<Control operation of pulse width measurement mode>
Boolean __EnablePulseWidthMeasurementMode(unsigned long data)
data Setup data
Controls operation of the timer that is set to specified pulse width measurement mode.
[data]
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_B0 Selects timer B channel 0.
RAPI_TIMER_B1 Selects timer B channel 1.
RAPI_TIMER_B2 Selects timer B channel 2.
RAPI_TIMER_B3 Selects timer B channel 3.
RAPI_TIMER_B4 Selects timer B channel 4.
RAPI_TIMER_B5 Selects timer B channel 5.
RAPI_TIMER_ONSets the timer that is set to pulse width measurement mode to start
operating.
RAPI_TIMER_OFF Sets the timer that is set to pulse width measurement mode to stop
operating.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void )
{
unsigned int data[2];
/* Get th e measured value of timer B1 as pulse width measurement mode
*/
__GetPulseWidthMeasurementMode( RAPI_TIMER_B1, data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
64
__SetTimerRegister
Synopsis
data1 Setup data 1
data2 Pointer to the buffer in which register value is stored
Description
For data, the following definition values can be set.
RAPI_TIMER_A0 Selects timer A channel 0.
RAPI_TIMER_A1 Selects timer A channel 1.
RAPI_TIMER_A2 Selects timer A channel 2.
RAPI_TIMER_A3 Selects timer A channel 3.
RAPI_TIMER_A4 Selects timer A channel 4.
RAPI_TIMER_B0 Selects timer B channel 0.
RAPI_TIMER_B1 Selects timer B channel 1.
RAPI_TIMER_B2 Selects timer B channel 2.
[0]: Specify the set value for the timer Ai mode register (i = 0–4).
[1]: Specify the set value for the timer Ai register (i = 0–4).
[2]: Specify the set value for the up/down flag register.
[3]: Specify the set value for the one-shot start flag register.
[4]: Specify the set value for the trigger select register.
[5]: Specify the set value for the time-clock prescaler reset register.
[6]: Specify the set value for the count start flag register.
[0]: Specify the set value for the timer Bi mode register (i = 0–5).
[1]: Specify the set value for the timer Bi register (i = 0–5).
[3]: Specify the set value for the time-clock prescaler reset register.
[4]: Specify the set value for the count start flag register.
Return value
Functionality
Reference
Remark
<Set timer register>
Boolean __SetTimerRegister(unsigned long data1, unsigned int *data2)
Sets the registers of a specified timer.
[data1]
[data2]
The content of a pointer to the buffer in which the register value is stored must be specified
as described below . The value is set in each register in order of buffer pointer elements.
• When using timer A (RAPI_TIMER_A0 to RAPI_TIMER_A4 specified)
• When using timer B (RAPI_TIMER_B0 to RAPI_TIMER_B5)
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
/* Set up timer A0 register */
__SetTimerRegister( RAPI_TIMER_A0, data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
66
__EnableTimerRegister
Synopsis
Description
<Control operation of timer register>
Boolean __EnableTimerRegister(unsigned long data)
data Setup data
Controls operation of a specified timer by starting or stopping it.
[data]
For data, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value.
RAPI_TIMER_A0 Selects timer A channel 0.
RAPI_TIMER_A1 Selects timer A channel 1.
RAPI_TIMER_A2 Selects timer A channel 2.
RAPI_TIMER_A3 Selects timer A channel 3.
RAPI_TIMER_A4 Selects timer A channel 4.
RAPI_TIMER_B0 Selects timer B channel 0.
RAPI_TIMER_B1 Selects timer B channel 1.
RAPI_TIMER_B2 Selects timer B channel 2.
RAPI_TIMER_B3 Selects timer B channel 3.
RAPI_TIMER_B4 Selects timer B channel 4.
RAPI_TIMER_B5 Selects timer B channel 5.
RAPI_TIMER_ONSets the selected timer to start operating.
RAPI_TIMER_OFF Sets the selected timer to stop operating.
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the argument, operation of the API cannot be
•
guaranteed.
Program example
#include " rapi_timer_m16c_62p.h"
void func( void )
{
/* Clear the setting of timer A2 */
__ClearTimerRegister( RAPI_TIMER_A2 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
68
__GetTimerRegister
Synopsis
Description
<Get timer register value>
Boolean __GetTimerRegister(unsigned long data1, unsigned int *data2)
data1 Setup data
data2 Pointer to the buffer in which register value is stored
Gets the counter value of a specified timer.
[data]
For data, the following definition values can be set.
RAPI_TIMER_A0 Selects timer A channel 0.
RAPI_TIMER_A1 Selects timer A channel 1.
RAPI_TIMER_A2 Selects timer A channel 2.
RAPI_TIMER_A3 Selects timer A channel 3.
RAPI_TIMER_A4 Selects timer A channel 4.
RAPI_TIMER_B0 Selects timer B channel 0.
RAPI_TIMER_B1 Selects timer B channel 1.
RAPI_TIMER_B2 Selects timer B channel 2.
RAPI_TIMER_B3 Selects timer B channel 3.
RAPI_TIMER_B4 Selects timer B channel 4.
RAPI_TIMER_B5 Selects timer B channel 5.
[data2]
Specify a pointer to the array in which the acquired register value is stored.
The content of the array is described below.
• When using timer A (RAPI_TIMER_A0 to RAPI_TIMER_A4 specified)
[0]: Store the value of timer Ai mode register (i = 0–4).
[1]: Store the value of timer Ai register (i = 0–4).
[2]: Store the value of the up/down flag register.
[3]: Store the value of the one-shot start flag register.
[4]: Store the value of the trigger select register.
[5]: Store the value of the time-clock prescaler reset flag register.
[6]: Store the value of the count start flag register.
• When using timer B (RAPI_TIMER_B0 to RAPI_TIMER_B5 specified)
[0]: Store the value of timer Bi mode register (i = 0–5).
[1]: Store the value of timer Bi register (i = 0–5).
[2]: Store the value of the time-clock prescaler reset flag register.
[3]: Store the value of the count start flag register.
Return value
Functionality
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_timer_m16c_62p.h"
void func( void )
{
unsigned int data[7];
/* Get the value of timer A3 registers */
__GetTimerRegister( RAPI_TIMER_A3, data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
70
4.2.3 I/O Port
__SetIOPort
Synopsis
Description
<Set I/O port>
Boolean __SetIOPort(unsigned long data1, unsigned int data2)
data1 Setup data 1
data2 Setup data 2
Sets the operating conditions of a specified I/O port.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value. Note, however, that
multiple ports cannot be specified at the same time.
The definition values corresponding to each I/O port are listed below.
RAPI_PORT_0_0 Port P00 RAPI_PORT_0_1 Port P01
RAPI_PORT_0_2 Port P02 RAPI_PORT_0_3 Port P03
RAPI_PORT_0_4 Port P04 RAPI_PORT_0_5 Port P05
RAPI_PORT_0_6 Port P06 RAPI_PORT_0_7 Port P07
RAPI_PORT_1_0 Port P10 RAPI_PORT_1_1 Port P11
RAPI_PORT_1_2 Port P12 RAPI_PORT_1_3 Port P13
RAPI_PORT_1_4 Port P14 RAPI_PORT_1_5 Port P15
RAPI_PORT_1_6 Port P16 RAPI_PORT_1_7 Port P17
RAPI_PORT_2_0 Port P20 RAPI_PORT_2_1 Port P21
RAPI_PORT_2_2 Port P22 RAPI_PORT_2_3 Port P23
RAPI_PORT_2_4 Port P24 RAPI_PORT_2_5 Port P25
RAPI_PORT_2_6 Port P26 RAPI_PORT_2_7 Port P27
RAPI_PORT_3_0 Port P30 RAPI_PORT_3_1 Port P31
RAPI_PORT_3_2 Port P32 RAPI_PORT_3_3 Port P33
RAPI_PORT_3_4 Port P34 RAPI_PORT_3_5 Port P35
RAPI_PORT_3_6 Port P36 RAPI_PORT_3_7 Port P37
RAPI_PORT_4_0 Port P40 RAPI_PORT_4_1 Port P41
RAPI_PORT_4_2 Port P42 RAPI_PORT_4_3 Port P43
RAPI_PORT_4_4 Port P44 RAPI_PORT_4_5 Port P45
RAPI_PORT_4_6 Port P46 RAPI_PORT_4_7 Port P47
RAPI_PORT_5_0 Port P50 RAPI_PORT_5_1 Port P51
RAPI_PORT_5_2 Port P52 RAPI_PORT_5_3 Port P53
RAPI_PORT_5_4 Port P54 RAPI_PORT_5_5 Port P55
RAPI_PORT_5_6 Port P56 RAPI_PORT_5_7 Port P57
RAPI_PORT_6_0 Port P60 RAPI_PORT_6_1 Port P61
RAPI_PORT_6_2 Port P62 RAPI_PORT_6_3 Port P63
RAPI_PORT_6_4 Port P64 RAPI_PORT_6_5 Port P65
RAPI_PORT_6_6 Port P66 RAPI_PORT_6_7 Port P67
RAPI_PORT_7_0 Port P70 RAPI_PORT_7_1 Port P71
Rev.1.00 2007.11.1
REC10B0002-0100
71
RAPI_PORT_7_2 Port P72 RAPI_PORT_7_3 Port P73
RAPI_PORT_7_4 Port P74 RAPI_PORT_7_5 Port P75
RAPI_PORT_7_6 Port P76 RAPI_PORT_7_7 Port P77
RAPI_PORT_8_0 Port P80 RAPI_PORT_8_1 Port P81
RAPI_PORT_8_2 Port P82 RAPI_PORT_8_3 Port P83
RAPI_PORT_8_4 Port P84 RAPI_PORT_8_5 Port P85
RAPI_PORT_8_6 Port P86 RAPI_PORT_8_7 Port P87
RAPI_PORT_9_0 Port P90 RAPI_PORT_9_1 Port P91
RAPI_PORT_9_2 Port P92 RAPI_PORT_9_3 Port P93
RAPI_PORT_9_4 Port P94 RAPI_PORT_9_5 Port P95
RAPI_PORT_9_6 Port P96 RAPI_PORT_9_7 Port P97
RAPI_PORT_10_0 Port P100 RAPI_PORT_10_1 Port P101
RAPI_PORT_10_2 Port P102 RAPI_PORT_10_3 Port P103
RAPI_PORT_10_4 Port P104 RAPI_PORT_10_5 Port P105
RAPI_PORT_10_6 Port P106 RAPI_PORT_10_7 Port P107
RAPI_PORT_11_0 Port P110 RAPI_PORT_11_1 Port P111
RAPI_PORT_11_2 Port P112 RAPI_PORT_11_3 Port P113
RAPI_PORT_11_4 Port P114 RAPI_PORT_11_5 Port P115
RAPI_PORT_11_6 Port P116 RAPI_PORT_11_7 Port P117
RAPI_PORT_12_0 Port P120 RAPI_PORT_12_1 Port P121
RAPI_PORT_12_2 Port P122 RAPI_PORT_12_3 Port P123
RAPI_PORT_12_4 Port P124 RAPI_PORT_12_5 Port P125
RAPI_PORT_12_6 Port P126 RAPI_PORT_12_7 Port P127
RAPI_PORT_13_0 Port P130 RAPI_PORT_13_1 Port P131
RAPI_PORT_13_2 Port P132 RAPI_PORT_13_3 Port P133
RAPI_PORT_13_4 Port P134 RAPI_PORT_13_5 Port P135
RAPI_PORT_13_6 Port P136 RAPI_PORT_13_7 Port P137
RAPI_PORT_14_0 Port P140 RAPI_PORT_14_1 Port P141
The definition values related to port settings are described below.
RAPI_PORT_INPUT Sets a selected port for input.
RAPI_PORT_OUTPUT Sets a selected port for output.
RAPI_PULLED_HIGH Sets a selected port to be pulled high.
RAPI_NOT_PULLED
_HIGH
RAPI_LATCH Sets a selected port to read the port latch regardless of whether it
[data2]
Specify 0.
Return value
If the I/O port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Sets a selected port not to be pulled high.
is set for input or output. Specifiable only when port P1 is used.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
/* Set up port P03 as input port */
__SetIOPort(RAPI_PORT_0_3| RAPI_PORT_INPUT| RAPI_PULLED_HIGH, 0 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
73
__ReadIOPort
Synopsis
Description
<Read from I/O port>
Boolean __ReadIOPort(unsigned long data1, unsigned int *data2)
data1 Setup data 1
data2 Pointer to the variable in which the value read from I/O port is stored.
Gets the value of a specified I/O port.
[data1]
Specify an I/O port from which data is read. The definition values corresponding to
each I/O port are listed below.
RAPI_PORT_0_0 Port P00 RAPI_PORT_0_1 Port P01
RAPI_PORT_0_2 Port P02 RAPI_PORT_0_3 Port P03
RAPI_PORT_0_4 Port P04 RAPI_PORT_0_5 Port P05
RAPI_PORT_0_6 Port P06 RAPI_PORT_0_7 Port P07
RAPI_PORT_1_0 Port P10 RAPI_PORT_1_1 Port P11
RAPI_PORT_1_2 Port P12 RAPI_PORT_1_3 Port P13
RAPI_PORT_1_4 Port P14 RAPI_PORT_1_5 Port P15
RAPI_PORT_1_6 Port P16 RAPI_PORT_1_7 Port P17
RAPI_PORT_2_0 Port P20 RAPI_PORT_2_1 Port P21
RAPI_PORT_2_2 Port P22 RAPI_PORT_2_3 Port P23
RAPI_PORT_2_4 Port P24 RAPI_PORT_2_5 Port P25
RAPI_PORT_2_6 Port P26 RAPI_PORT_2_7 Port P27
RAPI_PORT_3_0 Port P30 RAPI_PORT_3_1 Port P31
RAPI_PORT_3_2 Port P32 RAPI_PORT_3_3 Port P33
RAPI_PORT_3_4 Port P34 RAPI_PORT_3_5 Port P35
RAPI_PORT_3_6 Port P36 RAPI_PORT_3_7 Port P37
RAPI_PORT_6_0 Port P60 RAPI_PORT_6_1 Port P61
RAPI_PORT_6_2 Port P62 RAPI_PORT_6_3 Port P63
RAPI_PORT_6_4 Port P64 RAPI_PORT_6_5 Port P65
RAPI_PORT_6_6 Port P66 RAPI_PORT_6_7 Port P67
RAPI_PORT_7_0 Port P70 RAPI_PORT_7_1 Port P71
RAPI_PORT_7_2 Port P72 RAPI_PORT_7_3 Port P73
RAPI_PORT_7_4 Port P74 RAPI_PORT_7_5 Port P75
RAPI_PORT_7_6 Port P76 RAPI_PORT_7_7 Port P77
RAPI_PORT_8_0 Port P80 RAPI_PORT_8_1 Port P81
RAPI_PORT_8_2 Port P82 RAPI_PORT_8_3 Port P83
RAPI_PORT_8_4 Port P84 RAPI_PORT_8_5 Port P85
RAPI_PORT_8_6 Port P86 RAPI_PORT_8_7 Port P87
RAPI_PORT_9_0 Port P90 RAPI_PORT_9_1 Port P91
RAPI_PORT_9_2 Port P92 RAPI_PORT_9_3 Port P93
RAPI_PORT_9_4 Port P94 RAPI_PORT_9_5 Port P95
Rev.1.00 2007.11.1
REC10B0002-0100
74
RAPI_PORT_9_6 Port P96 RAPI_PORT_9_7 Port P97
RAPI_PORT_10_0 Port P100 RAPI_PORT_10_1 Port P101
RAPI_PORT_10_2 Port P102 RAPI_PORT_10_3 Port P103
RAPI_PORT_10_4 Port P104 RAPI_PORT_10_5 Port P105
RAPI_PORT_10_6 Port P106 RAPI_PORT_10_7 Port P107
RAPI_PORT_11_0 Port P110 RAPI_PORT_11_1 Port P111
RAPI_PORT_11_2 Port P112 RAPI_PORT_11_3 Port P113
RAPI_PORT_11_4 Port P114 RAPI_PORT_11_5 Port P115
RAPI_PORT_11_6 Port P116 RAPI_PORT_11_7 Port P117
RAPI_PORT_12_0 Port P120 RAPI_PORT_12_1 Port P121
RAPI_PORT_12_2 Port P122 RAPI_PORT_12_3 Port P123
RAPI_PORT_12_4 Port P124 RAPI_PORT_12_5 Port P125
RAPI_PORT_12_6 Port P126 RAPI_PORT_12_7 Port P127
RAPI_PORT_13_0 Port P130 RAPI_PORT_13_1 Port P131
RAPI_PORT_13_2 Port P132 RAPI_PORT_13_3 Port P133
RAPI_PORT_13_4 Port P134 RAPI_PORT_13_5 Port P135
RAPI_PORT_13_6 Port P136 RAPI_PORT_13_7 Port P137
RAPI_PORT_14_0 Port P140 RAPI_PORT_14_1 Port P141
Return value
Functionality
Reference
__WriteIOPortRegister
Remark
If the I/O port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
/* Get the value of port P12 */
__ReadIOPort(RAPI_PORT_1_2, &data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
75
__WriteIOPort
Synopsis
Description
<Write to I/O port>
Boolean __WriteIOPort(unsigned long data1, unsigned int data2)
data1 Setup data 1
data2 Data to be written to I/O port
Writes data to a specified I/O port.
[data1]
Specify an I/O port to which data is written. The definition values corresponding to each
I/O port are listed below.
RAPI_PORT_0_0 Port P00 RAPI_PORT_0_1 Port P01
RAPI_PORT_0_2 Port P02 RAPI_PORT_0_3 Port P03
RAPI_PORT_0_4 Port P04 RAPI_PORT_0_5 Port P05
RAPI_PORT_0_6 Port P06 RAPI_PORT_0_7 Port P07
RAPI_PORT_1_0 Port P10 RAPI_PORT_1_1 Port P11
RAPI_PORT_1_2 Port P12 RAPI_PORT_1_3 Port P13
RAPI_PORT_1_4 Port P14 RAPI_PORT_1_5 Port P15
RAPI_PORT_1_6 Port P16 RAPI_PORT_1_7 Port P17
RAPI_PORT_2_0 Port P20 RAPI_PORT_2_1 Port P21
RAPI_PORT_2_2 Port P22 RAPI_PORT_2_3 Port P23
RAPI_PORT_2_4 Port P24 RAPI_PORT_2_5 Port P25
RAPI_PORT_2_6 Port P26 RAPI_PORT_2_7 Port P27
RAPI_PORT_3_0 Port P30 RAPI_PORT_3_1 Port P31
RAPI_PORT_3_2 Port P32 RAPI_PORT_3_3 Port P33
RAPI_PORT_3_4 Port P34 RAPI_PORT_3_5 Port P35
RAPI_PORT_3_6 Port P36 RAPI_PORT_3_7 Port P37
RAPI_PORT_6_0 Port P60 RAPI_PORT_6_1 Port P61
RAPI_PORT_6_2 Port P62 RAPI_PORT_6_3 Port P63
RAPI_PORT_6_4 Port P64 RAPI_PORT_6_5 Port P65
RAPI_PORT_6_6 Port P66 RAPI_PORT_6_7 Port P67
RAPI_PORT_7_0 Port P70 RAPI_PORT_7_1 Port P71
RAPI_PORT_7_2 Port P72 RAPI_PORT_7_3 Port P73
RAPI_PORT_7_4 Port P74 RAPI_PORT_7_5 Port P75
RAPI_PORT_7_6 Port P76 RAPI_PORT_7_7 Port P77
RAPI_PORT_8_0 Port P80 RAPI_PORT_8_1 Port P81
RAPI_PORT_8_2 Port P82 RAPI_PORT_8_3 Port P83
RAPI_PORT_8_4 Port P84 RAPI_PORT_8_5 Port P85
RAPI_PORT_8_6 Port P86 RAPI_PORT_8_7 Port P87
RAPI_PORT_9_0 Port P90 RAPI_PORT_9_1 Port P91
RAPI_PORT_9_2 Port P92 RAPI_PORT_9_3 Port P93
RAPI_PORT_9_4 Port P94 RAPI_PORT_9_5 Port P95
Rev.1.00 2007.11.1
REC10B0002-0100
76
RAPI_PORT_9_6 Port P96 RAPI_PORT_9_7 Port P97
RAPI_PORT_10_0 Port P100 RAPI_PORT_10_1 Port P101
RAPI_PORT_10_2 Port P102 RAPI_PORT_10_3 Port P103
RAPI_PORT_10_4 Port P104 RAPI_PORT_10_5 Port P105
RAPI_PORT_10_6 Port P106 RAPI_PORT_10_7 Port P107
RAPI_PORT_11_0 Port P110 RAPI_PORT_11_1 Port P111
RAPI_PORT_11_2 Port P112 RAPI_PORT_11_3 Port P113
RAPI_PORT_11_4 Port P114 RAPI_PORT_11_5 Port P115
RAPI_PORT_11_6 Port P116 RAPI_PORT_11_7 Port P117
RAPI_PORT_12_0 Port P120 RAPI_PORT_12_1 Port P121
RAPI_PORT_12_2 Port P122 RAPI_PORT_12_3 Port P123
RAPI_PORT_12_4 Port P124 RAPI_PORT_12_5 Port P125
RAPI_PORT_12_6 Port P126 RAPI_PORT_12_7 Port P127
RAPI_PORT_13_0 Port P130 RAPI_PORT_13_1 Port P131
RAPI_PORT_13_2 Port P132 RAPI_PORT_13_3 Port P133
RAPI_PORT_13_4 Port P134 RAPI_PORT_13_5 Port P135
RAPI_PORT_13_6 Port P136 RAPI_PORT_13_7 Port P137
RAPI_PORT_14_0 Port P140 RAPI_PORT_14_1 Port P141
Return value
Functionality
Reference
Remark
If the I/O port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
unsigned int data;
/* Set the data to port P05 */
__WriteIOPort( RAPI_PORT_0_5, 0 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
77
__SetIOPortRegister
<Set I/O port register>
Synopsis
Boolean __SetIOPortRegister(unsigned long da ta1, unsigned int data2, unsigned
int data3, unsigned int data4)
data1 Setup data 1
data2 Setup data 2
data3 Setup data 3
data4 Setup data 4
[data1]
Description
Set the operating condition of a specified I/O port in each relevant register.
The definition values corresponding to each I/O port register are listed below.
RAPI_PORT_0 Port P0register RAPI_PORT_1 Port P1 register
RAPI_PORT_2 Port P2 register RAPI_PORT_3 Port P3 register
RAPI_PORT_4 Port P4 register RAPI_PORT_5 Port P5 register
RAPI_PORT_6 Port P6 register RAPI_PORT_7 Port P7 register
RAPI_PORT_8 Port P8 register RAPI_PORT_9 Port P9 register
RAPI_PORT_10 Port P10 register RAPI_PORT_11 Port P11 register
RAPI_PORT_12 Port P12 register RAPI_PORT_13 Port P13 register
RAPI_PORT_14 Port P14 register
The definition values related to port settings are described below.
RAPI_LATCH Set to read the port latch regardl ess of whether the port is set for input or
Return value
Functionality
Reference
Remark
[data2]
S pecify the set value for the port direction register corresponding to a selected port.
[data3]Specify the set value for the pullup control register corresponding to a selected port.
[data4]
Specify 0.
If the I/O port register specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
If an undefined value is specified in the first argument, operation of the API cannot
be guaranteed.
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
/* Set inputs/outputs of port P1 register */
__SetIOPortRegister(RAPI_PORT_1, 0xAA, 0, 0 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
79
__ReadIOPortRegister
Synopsis
Description
<Read from I/O port register>
Boolean __ReadIOPortRegister(unsigned long data1, unsigned int *data2)
data1 Setup data 1
data2 Pointer to the variable in which the value read from I/O port register is stored.
Gets the value of a specified I/O port from each relevant register.
[data1]
Specify an I/O port register from which data is read. The definition values
corresponding to each I/O port register are listed below.
RAPI_PORT_0 Port P0register RAPI_PORT_1 Port P1 register
RAPI_PORT_2 Port P2 register RAPI_PORT_3 Port P3 register
RAPI_PORT_4 Port P4 register RAPI_PORT_5 Port P5 register
RAPI_PORT_6 Port P6 register RAPI_PORT_7 Port P7 register
RAPI_PORT_8 Port P8 register RAPI_PORT_9 Port P9 register
RAPI_PORT_10 Port P10 register RAPI_PORT_11 Port P11 register
RAPI_PORT_12 Port P12 register RAPI_PORT_13 Port P13 register
RAPI_PORT_14 Port P14 register
Return value
Functionality
Reference
Remark
If the I/O port register specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
unsigned int data;
/* Get the value of port P1 register */
__ReadIOPortRegister( RAPI_PORT_1, &data );
}
Rev.1.00 2007.11.1
REC10B0002-0100
80
__WriteIOPortRegister
Synopsis
Description
<Write to I/O port register>
Boolean __WriteIOPortRegister(unsigned long data1, unsigned int data2)
data1 Setup data 1
data2 Data to be written to I/O port register
Writes the value for a specified I/O port to each relevant register.
[data1]
Specify an I/O port register to which data is written. The definition values
corresponding to each I/O port register are listed below.
RAPI_PORT_0 Port P0register RAPI_PORT_1 Port P1 register
RAPI_PORT_2 Port P2 register RAPI_PORT_3 Port P3 register
RAPI_PORT_4 Port P4 register RAPI_PORT_5 Port P5 register
RAPI_PORT_6 Port P6 register RAPI_PORT_7 Port P7 register
RAPI_PORT_8 Port P8 register RAPI_PORT_9 Port P9 register
RAPI_PORT_10 Port P10 register RAPI_PORT_11 Port P11 register
RAPI_PORT_12 Port P12 register RAPI_PORT_13 Port P13 register
RAPI_PORT_14 Port P14 register
Return value
Functionality
Reference
Remark
If the I/O port register specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_io_port_m16c_62p.h"
void func( void )
{
/* Set the data to port P2 register */
__WriteIOPortRegister( RAPI_PORT_2, 0xFF );
}
Rev.1.00 2007.11.1
REC10B0002-0100
81
4.2.4 External interrupt
__SetInterrupt
Synopsis
Description
<Set external interrupt>
Boolean __SetInterrupt(unsigned long data1, unsigned int data2, void* func)
data1 Setup data 1
data2 Setup data 2
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets a specified external interrupt.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value. Note, however, that
multiple external interrupts cannot be specified at the same time.
RAPI_INT0 Uses _INT0 interrupt.
RAPI_INT1 Uses _INT1 interrupt.
RAPI_INT2 Uses _INT2 interrupt.
RAPI_INT3 Uses _INT3 interrupt.
RAPI_INT4 Uses _INT4 interrupt.
RAPI_INT5 Uses _INT5 interrupt.
RAPI_KEY Uses key input interrupt.
RAPI_INT_RISING Specifies a rising edge for the active edge of a selected external
RAPI_INT_FALLINGSpecifies a falling edge for the active edge of a selected external
RAPI_INT_BOTH Specifies both edges for the active edge of a selected external
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include " rapi_interrupt_m16c_62p.h"
void func( void )
{
/* Clear status of _INT0 interrupt */
__ClearInterruptFlag( RAPI_INT0 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
86
4.2.5 A/D converter
__CreateADC
Synopsis
Description
<Set A/D converter>
Boolean __CreateADC(unsigned long data1, unsigned int data2, unsigned int
data3, void* func)
data1 Setup data 1
data2 Number of analog input pins used by A/D converter
data3 Setup data 3
func Callback function pointer
(Specify 0 if no callback functions are set.)
Sets the A/D converter to specified mode and operating condition.
[data1]
For data1, the following definition values can be set. To set multiple definition values at
the same time, use the symbol “|” to separate each specified value. Note, ho wever,
that multiple analog input pin symbols cannot be specified at the same time.
RAPI_ONE_SHOT Selects one-shot mode.
RAPI_REPEAT Selects repeat mode.
RAPI_SINGLE_SWEEP Selects single sweep mode.
RAPI_REPEAT_SWEEP0 Selects repeat sweep mode 0.
RAPI_REPEAT_SWEEP1 Selects repeat sweep mode 1.
RAPI_AN0 Uses AN0 pin for the analog input pin.
RAPI_AN1 Uses AN1 pin for the analog input pin.
RAPI_AN2 Uses AN2 pin for the analog input pin.
RAPI_AN3 Uses AN3 pin for the analog input pin.
RAPI_AN4 Uses AN4 pin for the analog input pin.
RAPI_AN5 Uses AN5 pin for the analog input pin.
RAPI_AN6 Uses AN6 pin for the analog input pin.
RAPI_AN7 Uses AN7 pin for the analog input pin.
RAPI_AN00 Uses AN00 pin for the analog input pin.
RAPI_AN01 Uses AN01 pin for the analog input pin.
RAPI_AN02 Uses AN02 pin for the analog input pin.
RAPI_AN03 Uses AN03 pin for the analog input pin.
RAPI_AN04 Uses AN04 pin for the analog input pin.
RAPI_AN05 Uses AN05 pin for the analog input pin.
RAPI_AN06 Uses AN06 pin for the analog input pin.
RAPI_AN07 Uses AN07 pin for the analog input pin.
RAPI_AN20 Uses AN20 pin for the analog input pin.
RAPI_AN21 Uses AN21 pin for the analog input pin.
RAPI_AN22 Uses AN22 pin for the analog input pin.
RAPI_AN23 Uses AN23 pin for the analog input pin.
RAPI_AN24 Uses AN24 pin for the analog input pin.
RAPI_AN25 Uses AN25 pin for the analog input pin.
RAPI_AN26 Uses AN26 pin for the analog input pin.
Rev.1.00 2007.11.1
REC10B0002-0100
87
RAPI_AN27 Uses AN27 pin for the analog input pin.
RAPI_P0_GROUP Uses port P0 group for the analog input pin.
RAPI_P10_GROUP Uses port P10 group for the analog input pin.
RAPI_P2_GROUP Uses port P2 group for the analog input pin.
RAPI_FAD Sets the AD converter’s operating frequency to fAD.
RAPI_FAD2
RAPI_FAD3
RAPI_FAD4
RAPI_FAD6
RAPI_FAD12
RAPI_10BIT Sets the AD converter’s resolution to 10 bits.
RAPI_8BIT Sets the AD converter’s resolution to 8 bits.
RAPI_AD_ON Sets the AD converter to start operating.
RAPI_AD_OFF Sets the AD converter to stop operating.
RAPI_WITH_SAMPLE_HOLD Specifies that sample-and-hold action is applied.
RAPI_WITHOUT_SAMPLE_
HOLD
RAPI_SOFTWARE_TRIGGER Selects software trigger.
RAPI_EXTERNAL_TRIGGER Selects external trigger.
RAPI_ANEX_UNUSED ANEX0 and ANEX1 are not used
RAPI_ANEX0 ANEX0 input is A/D converted
RAPI_ANEX1 ANEX1 input is A/D converted
RAPI_EXTERNAL_OP_AMP External op-amp connection mode
• Specifiable definition values when one-shot mode is used (RAPI_ONE_SHOT specified)
(Input pin)
(Operating
frequency)
(Resolution) Specify one from { RAPI_10BIT, RAPI_8BIT }. The default value is
(Operating
states set)
(Conversion
method)
(Trigger) Specify one from { RAPI_SOFTWARE_TRIGGER,
(External
Op-Amp
Connection)
• Specifiable definition values when repeat mode is used (RAPI_REPEAT specified)
Specify one from { RAPI_AN0, RAPI_AN1, RAPI_AN2, RAPI_AN3, RAPI_AN4,
RAPI_AN5, RAPI_AN6, RAPI_AN7, RAPI_AN00, RAPI_AN01, RAPI_AN02,
RAPI_AN03, RAPI_AN04, RAPI_AN05, RAPI_AN06, RAPI_AN07, RAPI_AN20,
RAPI_AN21, RAPI_AN22, RAPI_AN23, RAPI_AN24, RAPI_AN25, RAPI_AN26,
RAPI_AN27, RAPI_ANEX0, RAPI_ANEX1 }. The defau lt is RAPI_AN0.
Specify one from { RAPI_FAD, RAPI_FAD2, RAPI_FAD3, RAPI_FAD4,
RAPI_FAD6, RAPI_FAD12 }. The default value is RAPI_FAD4.
RAPI_8BIT.
Specify one from { RAPI_AD_ON, RAPI_AD_OFF }. The default value is
RAPI_AD_OFF.
Specify one from { RAPI_WITH_SAMPLE_HOLD,
RAPI_WITHOUT_SAMPLE_HOLD }. The default value is
RAPI_WITHOUT_SAMPLE_HOLD.
RAPI_EXTERNAL_TRIGGER }.
The default value is RAPI_SOFTWARE_TRIGGER.
Specify one from { RAPI_ANEX_UNUSED, RAPI_EXTERNAL_OP_AMP }.
The default value is RAPI_ANEX_UNUSED.
Sets the AD converter ’s operating frequency to fAD divided by 2.
Sets the AD converter ’s operating frequency to fAD divided by 3.
Sets the AD converter ’s operating frequency to fAD divided by 4.
Sets the AD converter ’s operating frequency to fAD divided by 6.
Sets the AD converter ’s operating frequency to fAD divided by 12.
Specifies that sample-and-hold action is not applied.
Rev.1.00 2007.11.1
REC10B0002-0100
88
(Input pin)
(Operating
frequency)
(Resolution) Specify one from { RAPI_10BIT, RAPI_8BIT }. The default value is
(Operating
states set)
(Conversion
method)
(Trigger)
(External
Op-Amp
Connection)
• Specifiable definition values when single sweep mode is used
(RAPI_SINGLE_SWEEP specified)
(Input pin) Specify one from { RAPI_P0_GROUP, RAPI_P10_GROUP,
(Operating
frequency)
(Resolution) Specify one from { RAPI_10BIT, RAPI_8BIT }. The default value is
(Operating
states set)
(Conversion
method)
(Trigger)
(External
Op-Amp
Connection)
• Specifiable definition values when repeat sweep mode 0 is used
(RAPI_REPEAT_SWEEP0 specified)
(Input pin) Specify one from { RAPI_P0_GROUP, RAPI_P10_GROUP,
(Operating
frequency)
(Resolution) Specify one from { RAPI_10BIT, RAPI_8BIT }. The default value is
Specify one from { RAPI_AN0, RAPI_AN1, RAPI_AN2, RAPI_AN3, RAPI_AN4,
RAPI_AN5, RAPI_AN6, RAPI_AN7, RAPI_AN00, RAPI_AN01, RAPI_AN02,
RAPI_AN03, RAPI_AN04, RAPI_AN05, RAPI_AN06, RAPI_AN07, RAPI_AN20,
RAPI_AN21, RAPI_AN22, RAPI_AN23, RAPI_AN24, RAPI_AN25, RAPI_AN26,
RAPI_AN27, RAPI_INEX0, RAPI_ANEX1 }. The default is RAPI_AN0.
Specify one from { RAPI_FAD, RAPI_FAD2, RAPI_FAD3, RAPI_FAD4,
RAPI_FAD6, RAPI_FAD12 }. The default value is RAPI_FAD4.
RAPI_8BIT.
Specify one from { RAPI_AD_ON, RAPI_AD_OFF }. The default value is
RAPI_AD_OFF.
Specify one from { RAPI_WITH_SAMPLE_HOLD,
RAPI_WITHOUT_SAMPLE_HOLD }.
The default value is RAPI_WITHOUT_SAMPLE_HOLD.
Specify one from { RAPI_SOFTWARE_TRIGGER,
RAPI_EXTERNAL_TRIGGER }.
The default value is RAPI_SOFTWARE_TRIGGER.
Specify one from { RAPI_ANEX_UNUSED, RAPI_EXTERNAL_OP_AMP }.
The default value is RAPI_ANEX_UNUSED.
Specify one from { RAPI_ANEX_UNUSED, RAPI_EXTERNAL_OP_AMP }.
The default value is RAPI_ANEX_UNUSED.
RAPI_P2_GROUP }. The default value is RAPI_P10_GROUP.
Specify one from { RAPI_FAD, RAPI_FAD2, RAPI_FAD3, RAPI_FAD4,
RAPI_FAD6, RAPI_FAD12 }. The default value is RAPI_FAD4.
RAPI_8BIT.
Specify one from { RAPI_AD_ON, RAPI_AD_OFF }. The default value is
RAPI_AD_OFF.
Specify one from { RAPI_WITH_SAMPLE_HOLD,
RAPI_WITHOUT_SAMPLE_HOLD }.
The default value is RAPI_WITHOUT_SAMPLE_HOLD.
Specify one from { RAPI_SOFTWARE_TRIGGER,
RAPI_EXTERNAL_TRIGGER }.
The default value is RAPI_SOFTWARE_TRIGGER.
RAPI_P2_GROUP }. The default value is RAPI_P10_GROUP.
Specify one from { RAPI_FAD, RAPI_FAD2, RAPI_FAD3, RAPI_FAD4,
RAPI_FAD6, RAPI_FAD12 }. The default value is RAPI_FAD4.
RAPI_8BIT.
Rev.1.00 2007.11.1
REC10B0002-0100
89
(Operating
states set)
(Conversion
method)
(Trigger)
(External
Op-Amp
Connection)
• Specifiable definition values when repeat sweep mode 1 is used
(RAPI_REPEAT_SWEEP1 specified)
(Input pin) Specify one from { RAPI_P0_GROUP, RAPI_P10_GROUP,
(Operating
frequency)
(Resolution) Specify one from { RAPI_10BIT, RAPI_8BIT }. The default value is
(Operating
states set)
(Conversion
method)
(Trigger)
(External
Op-Amp
Connection)
Specify one from { RAPI_ANEX_UNUSED, RAPI_EXTERNAL_OP_AMP }.
The default value is RAPI_ANEX_UNUSED.
Specify one from { RAPI_ANEX_UNUSED, RAPI_EXTERNAL_OP_AMP }.
The default value is RAPI_ANEX_UNUSED.
[data2]
The set value differs with the A/D conversion mode used.
One-shot mode Specify 1.
Repeat mode
Single sweep mode Specify 2, 4, 6, or 8.
Repeat sweep mode 0
Repeat sweep mode1 Specify 1, 2, 3, or 4.
[data3]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
Return value
Functionality
Reference
If A/D converter was successfully set, RAPI_TRUE is returned; if failed, RAPI_FALSE
is returned.
A/D converter
__EnableADC, __DestroyADC, __GetADC, __GetADCAll
Specify one from { RAPI_AD_ON, RAPI_AD_OFF }. The default value is
RAPI_AD_OFF.
Specify one from { RAPI_WITH_SAMPLE_HOLD,
RAPI_WITHOUT_SAMPLE_HOLD }. The default value is
RAPI_WITHOUT_SAMPLE_HOLD.
Specify one from { RAPI_SOFTWARE_TRIGGER,
RAPI_EXTERNAL_TRIGGER }. The default value is
RAPI_SOFTWARE_TRIGGER.
RAPI_P2_GROUP }. The default value is RAPI_P10_GROUP.
Specify one from { RAPI_FAD, RAPI_FAD2, RAPI_FAD3, RAPI_FAD4,
RAPI_FAD6, RAPI_FAD12 }. The default value is RAPI_FAD4.
RAPI_8BIT.
Specify one from { RAPI_AD_ON, RAPI_AD_OFF }. The default value is
RAPI_AD_OFF.
Specify one from { RAPI_WITH_SAMPLE_HOLD,
RAPI_WITHOUT_SAMPLE_HOLD }.
The default value is RAPI_WITHOUT_SAMPLE_HOLD.
Specify one from { RAPI_SOFTWARE_TRIGGER,
RAPI_EXTERNAL_TRIGGER }.
The default value is RAPI_SOFTWARE_TRIGGER.
Rev.1.00 2007.11.1
REC10B0002-0100
90
Remark
Program example
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
#include " rapi_ad_m16c_62p.h"
void AdIntFunc( void ){}
void func( void )
{
/* Set up A/D converter as one short mode */
__CreateADC( RAPI_ONE_SHOT|RAPI_AN2|RAPI_FAD2| RAPI_WITH_SAMPLE_HOLD
Boolean __EnableADC (unsigned long data1, unsigned int data2)
data1 Setup data 1
data2 Number of analog input pins used by A/D converter
Controls operation of the A/D converter by starting or stopping it.
[data1]
RAPI_AN0 Uses AN0 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN1 Uses AN1 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN2 Uses AN2 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN3 Uses AN3 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN4 Uses AN4 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN5 Uses AN5 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN6 Uses AN6 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN7 Uses AN7 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN00 Uses AN00 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN01 Uses AN01 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN02 Uses AN02 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN03 Uses AN03 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN04 Uses AN04 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN05 Uses AN05 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN06 Uses AN06 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN07 Uses AN07 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN20 Uses AN20 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
Rev.1.00 2007.11.1
REC10B0002-0100
92
RAPI_AN21 Uses AN21 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN22 Uses AN22 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN23 Uses AN23 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN24 Uses AN24 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN25 Uses AN25 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN26 Uses AN26 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_AN27 Uses AN27 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_ANEX0 Uses ANEX0 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_ANEX1 Uses ANEX1 pin for the analog input pin.
Selectable only when one-shot mode or repeat mode is used.
RAPI_P0_GROUP
RAPI_P10_GROUP
RAPI_P2_GROUP
RAPI_AD_ON Sets the A/D converter to start operating.
RAPI_AD_OFF Sets the A/D converter to stop operating.
[data2]
The set value differs with the A/D conversion mode used.
One-shot mode Specify 1.
Repeat mode
Single sweep mode Specify 2, 4, 6, or 8.
Repeat sweep mode 0
Repeat sweep mode 1 Specify 1, 2, 3, or 4.
If A/D converter was successfully controlled, RAPI_TRUE is returned; if failed,
Return value
Functionality
Reference
Remark
RAPI_FALSE is returned.
A/D converter
__CreateADC, __DestroyADC, __GetADC, __GetADCAll
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Uses port P0 group for the analog input pin. Selectable only when
sweep mode, repeat sweep mode 0, or repeat sweep mode 1 is used.
Uses port P10 group for the analog input pin. Selectable only when
sweep mode, repeat sweep mode 0, or repeat sweep mode 1 is used.
Uses port P2 group for the analog input pin. Selectable only when
sweep mode, repeat sweep mode 0, or repeat sweep mode 1 is used.