Renesas M16C, М62P User Manual

REC10B0002-0100
M16C/62P Group Renesas Embedded Application Programming Interface
Reference Manual
Reference Manual
Rev.1.00 Revision Date: Nov.1, 2007
www.renesas.com
Renesas Embedded
Application Programming Interface
Reference Manual
<M16C/62P Group>
Rev.1.00 2007.11.1 REC10B0002-0100
2
Table of Contents
Table of Contents ............................................................... 3
1. Introduction................................................................... 5
2. Driver ....................................................................... 6
2.1 Overview.................................................................. 6
2.2 Driver Features ............................................................. 6
2.3 Serial Interface Driver........................................................ 7
2.4 Timer Driver ............................................................... 8
2.4.1 Timer Mode ............................................................ 8
2.4.2 Event Counter Mode ..................................................... 8
2.4.3 Pulse Width Modulation Mode (PWM Mode).................................. 8
2.4.4 Pulse Period Measurement Mode ........................................... 8
2.4.5 Pulse Width Measurement Mode............................................ 8
2.5 I/O Port Driver ............................................................. 9
2.6 External Interrupt Driver..................................................... 10
2.7 A/D Converter Driver ....................................................... 11
3. Standard Types ............................................................... 12
4. Library Reference............................................................. 13
4.1 API List by Peripheral Facility ................................................ 13
4.2 Description of Each API ..................................................... 15
4.2.1 Serial I/O ........................................................... 16
__BasicOpenSerialDriver................................................... 16
__BasicCloseSerialDriver................................................... 17
__BasicSetSerialFormat .................................................... 18
__BasicStartSerialReceiving................................................. 21
__BasicStartSerialSending .................................................. 22
__BasicReceivingStatusRead ................................................ 23
__BasicSendingStatusRead.................................................. 24
__BasicStopSerialReceiving................................................. 25
__BasicStopSerialSending .................................................. 26
__OpenSerialDriver ....................................................... 27
__CloseSerialDriver ....................................................... 28
__ConfigSerialDriverNotify................................................. 29
__SetSerialFormat......................................................... 31
__SetSerialInterrupt ....................................................... 32
__StartSerialReceiving ..................................................... 34
__StartSerialSending....................................................... 35
__StopSerialReceiving ..................................................... 36
__StopSerialSending....................................................... 37
__PollingSerialReceiving ................................................... 38
__PollingSerialSending..................................................... 39
4.2.2 Timer ................................................................ 40
__CreateTimer ........................................................... 40
__EnableTimer ........................................................... 42
Rev.1.00 2007.11.1 REC10B0002-0100
3
__DestroyTimer .......................................................... 43
__CreateEventCounter ..................................................... 44
__EnableEventCounter..................................................... 47
__DestroyEventCounter .................................................... 48
__GetEventCounter........................................................ 49
__CreatePulseWidthModulationMode ......................................... 50
__EnablePulseWidthModulationMode......................................... 53
__DestroyPulseWidthModulationMode ........................................ 54
__CreatePulsePeriodMeasurementMode ....................................... 55
__EnablePulsePeriodMeasurementMode ....................................... 57
__DestroyPulsePeriodMeasurementMode ...................................... 58
__GetPulsePeriodMeasurementMode.......................................... 59
__CreatePulseWidthMeasurementMode........................................ 60
__EnablePulseWidthMeasurementMode ....................................... 62
__DestroyPulseWidthMeasurementMode ...................................... 63
__GetPulseWidthMeasurementMode .......................................... 64
__SetTimerRegister ....................................................... 65
__EnableTimerRegister..................................................... 67
__ClearTimerRegister...................................................... 68
__GetTimerRegister ....................................................... 69
4.2.3 I/O Port ............................................................ 71
__SetIOPort ............................................................. 71
__ReadIOPort ............................................................ 74
__WriteIOPort............................................................ 76
__SetIOPortRegister....................................................... 78
__ReadIOPortRegister ..................................................... 80
__WriteIOPortRegister..................................................... 81
4.2.4 External interrupt..................................................... 82
__SetInterrupt ............................................................ 82
__EnableInterrupt ......................................................... 84
__GetInterruptFlag ........................................................ 85
__ClearInterruptFlag....................................................... 86
4.2.5 A/D converter........................................................ 87
__CreateADC ............................................................ 87
__EnableADC............................................................ 92
__DestroyADC ........................................................... 95
__GetADC .............................................................. 96
__GetADCAll............................................................ 97
Rev.1.00 2007.11.1 REC10B0002-0100
4
1. Introduction
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.
NO Facility
classification
Single-data
1 __BasicOpenSerialDriver
serial I/O
2 __BasicCloseSerialDriver 3 __BasicSetSerialFormat 4 __BasicStartSerialReceiving 5 __BasicStartSerialSending 6 __BasicReceivingStatusRead 7 __BasicSendingStatusRead 8 __BasicStopSerialReceiving 9
Multi-data
10 __OpenSerialDriver
serial I/O
11 __CloseSerialDriver 12 __ConfigSerialDriverNotify 13 __SetSerialFormat 14 __SetSerialInterrupt 15 __StartSerialReceiving 16 __StartSerialSending 17 __StopSerialReceiving 18 __StopSerialSending 19 __PollingSerialReceiving 20
Timer
21 __CreateTimer 22 __EnableTimer 23 __DestroyTimer 24 __CreateEventCounter 25 __EnableEventCounter
26 __DestroyEventCounter 27 __GetEventCounter 28 __CreatePulseWidthModulationMode
29 __EnablePulseWidthModulationMode 30 __DestroyPulseWidthModulationMode 31 __CreatePulsePeriodMeasurementMode 32 __EnablePulsePeriodMeasurementMode 33 __DestroyPulsePeriodMeasurementMode 34
__BasicStopSerialSending
__PollingSerialSending
__GetPulsePeriodMeasurementMode
API API operation
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
Rev.1.00 2007.11.1 REC10B0002-0100
13
35 __CreatePulseWidthMeasurementMode 36
Timer
37 __DestroyPulseWidthMeasurementMode 38 __GetPulseWidthMeasurementMode 39 __SetTimerRegister
40 __EnableTimerRegister 41 __ClearTimerRegister 42
I/O port
43 __SetIOPort 44 __ReadIOPort 45 __WriteIOPort 46 __SetIOPortRegister 47 __ReadIOPortRegister 48
External
49 __SetInterrupt
interrupt
50 __EnableInterrupt 51 __GetInterruptFlag 52
A/D converter
53 __CreateADC 54 __EnableADC 55 __DestroyADC 56 __GetADC
67
__EnablePulseWidthMeasurementMode
__GetTimerRegister
__WriteIOPortRegister
__ClearInterruptFlag
__GetADCAll
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)
data Setup data
Opens and initializes a specified serial port.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__BasicCloseSerialDriver
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
#include ”rapi_sif_m16c_62p”
void func( void ) { /* Open serial driver */ return __BasicOpenSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
16
__BasicCloseSerialDriver
Synopsis
Description
<Close a serial port>
Boolean __BasicCloseSerialDriver(unsigned long data)
data Setup data
Closes a specified serial port. 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
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__BasicOpenSerialDriver
If an undefined value is specified in the argument, operation of the API cannot be
Remark
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void ) { /* Close serial driver */ return __BasicCloseSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
17
__BasicSetSerialFormat
Synopsis
Description
<Set serial communication>
Boolean __BasicSetSerialFormat(unsigned long data1, unsigned char data2)
data1 Setup data 1 data2 Setup data 2
Sets serial communication according to specified parameters.
[data1]
For data1, the following values can be set. To set multiple definition values at the same time, use the symbol “|” to separate each specified value.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
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 bits RAPI_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_INT Internal clock is used as the clock source of serial communication. RAPI_SIO_CKDIR_EXT External 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_NON No parity bit RAPI_PARITY_EVEN Even parity bit RAPI_PARITY_ODD Odd 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 inverted RAPI_DPOL_INV Polarity inverted
(SI/O3, SI/O4)
RAPI_SIO_DPOL_NON Polarity not inverted RAPI_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)
RAPI_BCSS_F1 f1SIO RAPI_BCSS_F2 f2SIO RAPI_BCSS_F8 f8SIO RAPI_BCSS_F32 f32SIO
(SI/O3, SI/O4)
RAPI_SIO_BCSS_F1 f1SIO RAPI_SIO_BCSS_F2 f2SIO RAPI_SIO_BCSS_F8 f8SIO RAPI_SIO_BCSS_F32 f32SIO
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
| RAPI_BCSS_F1 | RAPI_DPOL_NON | RAPI_LSB_SEL, 20);
}
Rev.1.00 2007.11.1 REC10B0002-0100
20
__BasicStartSerialReceiving
Synopsis
Description
Return value
Functionality
Reference
Remark
<Receive 1 data>
Boolean __BasicStartSerialReceiving(unsigned long data)
data Setup data
Starts receiving 1 data of serial communication.
[data]
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
If data reception in serial communication was successfully started, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicReceivingStatusRead, __BasicStopSerialReceiving
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void ) {
..........
__BasicStartSerialReceiving( RAPI_COM1 );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
21
__BasicStartSerialSending
Synopsis
Description
For data1, the following values can be set.
Return value
Functionality
Reference
Remark
<Transmit 1 data>
Boolean _BasicStartSerialSending(unsigned long data1, unsigned int data2)
data Setup data data Transmit data
Starts sending 1 data of serial communication.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If data transmission in serial communication was successfully started, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicSendingStatusRead, __BasicStopSerialSending
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
Void func( void ) {
..........
__BasicStartSerialSending( RAPI_COM1, 0x00AA );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
22
__BasicReceivingStatusRead
Synopsis
Description
For data, the following values can be set.
Return value
(UART0, UART1, UART2)
(SI/O3, SI/O4)
Functionality
Reference
Remark
<Read receive status>
unsigned int __BasicReceivingStatusRead(unsigned long data)
data Setup data
Returns the receive status of serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
The receive status of serial communication is returned. The returned value is one of the following.
RAPI_RX_INCOMPLETE Reception not complete yet. Other than above Reception complete. The value read from the UARTi receive
buffer register (i = 0 to 2).
RAPI_RX_INCOMPLETE Reception not complete yet. Other than above Reception complete. Low-order 8 bits: The value read from the
SI/Oi transmit/receive register (i = 3, 4).
Serial I/O
__BasicStartSerialReceiving, __BasicS topSerialReceiving
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 ) { unsigned int rcv_data;
..........
rcv_data = __BasicReceivingStatusRead( RAPI_COM1 );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
23
__BasicSendingStatusRead
Synopsis
Description
Return value
Functionality
Reference
Remark
<Read transmit status>
Boolean __BasicSendingStatusRead(unsigned long data)
data Setup data
Returns the transmit status of serial communication. 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
If no data exists in the transmit buffer, RAPI_TRUE is returned; if data exists, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialSending, __BasicStopSerialSending
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 ) {
..........
if (__BasicSendingStatusRead( RAPI_COM1 ) == RAPI_TRUE) { /* Transmission completion */ }
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
24
__BasicStopSerialReceiving
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop reception>
Boolean Rapi_BasicStopSerialReceiving(unsigned long data)
data Setup data
Stops receiving data in serial communication
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2
If data reception in serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialReceiving
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 */ __BasicStopSerialReceiving ( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
25
__BasicStopSerialSending
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop transmission>
Boolean __BasicStopSerialSending(unsigned long data)
data Setup data
Stops transmitting data in serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2
If data transmission in serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialSending
For the M16C SI/03 and SI/04, this API cannot be used.
When operating in clock synchronous serial communication 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 cannot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void ) { /* Stop sending data in serial communication */ __BasicStopSerialSending ( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
26
__OpenSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Open a serial port>
Boolean __OpenSerialDriver(unsigned long data)
data Setup data
Opens and initializes a specified serial port.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__CloseSerialDriver
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 ) { /* Open serial driver */ return __OpenSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
27
__CloseSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Close a serial port>
Boolean __CloseSerialDriver(unsigned long data)
data Setup data
Closes a specified serial port.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
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
of serial communication.
[data]
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
[func]
user.
b7 b6 b5 b4 b3 b2 b1 b0
0 0XX 0XXX
(SI/O3,SI/O4)
b7b6b5b4b3b2b1 b
00XX 0000
Rev.1.00 2007.11.1 REC10B0002-0100
Overrun error
Framing error
Parity error
Transmission completed
Reception completed
Transmission co mp leted
Reception completed
29
0 No error 1 Error occurred
0 No error 1 Error occurred
0 No error 1 Error occurred
0 Not completed 1 Completed
0 Not completed 1 Completed
0Not completed 1 Completed
0Not completed 1 Completed
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
Return value
RAPI_TRUE is returned.
Functionality
Serial I/O
__StartSerialReceiving, __StartSerialSending
Reference
If an undefined value is specified in the first argument, operation of the API cannot
Remark
be guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void Notify(unsigned char result) { if ((result&RAPI_OVER_ERR) == RAPI_OVER_ERR) { /* Overrun error */ } if ((result&RAPI_FRAMING_ERR) == RAPI_FRAMING_ERR) { /* Framing error */ } if ((result&RAPI_PARITY_ERR) == RAPI_PARITY_ERR) { /* Parity error */ } if ((result&RAPI_TX_END) == RAPI_TX_END) { /* Transmission completion */ } if ((result&RAPI_RX_END) == RAPI_RX_END) { /* Reception completion */ } }
Boolean func( void ) { /* Set callback functions of RAPI_COM1 to serial driver */ return __ConfigSerialDriverNotify( RAPI_COM1, Notify ); }
Rev.1.00 2007.11.1 REC10B0002-0100
30
__SetSerialFormat
Synopsis
Description
For details about parameters, refer to the description of __BasicSetSerialFormat.
Return value
Functionality
Reference
Remark
<Set serial communication>
Boolean __SetSerialFormat(unsigned long data1, unsigned char data2)
data1 Setup data 1 data2 Setup data 2
Sets serial communication according to specified parameters.
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 __SetSerialFormat(RAPI_COM1 | RAPI_SM_SYNC | RAPI_CKDIR_INT |
RAPI_BCSS_F1 | RAPI_DPOL_NON | RAPI_LSB_SEL, 20);
}
Rev.1.00 2007.11.1 REC10B0002-0100
31
__SetSerialInterrupt
Synopsis
Description
For interrupt settings, the following values can set. (UART0, UART1, UART2)
(SI/O3, SI/O4)
<Set serial interrupts>
Boolean __SetSerialInterrupt(unsigned long data)
data Setup data
Sets serial interrupts according to specified parameters.
[data]
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
RAPI_INT_TX_DIS Transmit interrupt disabled RAPI_INT_TX_LV_1 Transmit interrupt priority level 1 RAPI_INT_TX_LV_2 RAPI_INT_TX_LV_3 Transmit interrupt priority level 3 RAPI_INT_TX_LV_4 Transmit interrupt priority level 4 RAPI_INT_TX_LV_5 Transmit interrupt priority level 5 RAPI_INT_TX_LV_6 Transmit interrupt priority level 6 RAPI_INT_TX_LV_7 Transmit interrupt priority level 7 RAPI_INT_RX_DIS Receive interrupt disabled RAPI_INT_RX_LV_1 Receive interrupt priority level 1 RAPI_INT_RX_LV_2 Receive interrupt priority level 2 RAPI_INT_RX_LV_3 Receive interrupt priority level 3 RAPI_INT_RX_LV_4 Receive interrupt priority level 4 RAPI_INT_RX_LV_5 Receive interrupt priority level 5 RAPI_INT_RX_LV_6 Receive interrupt priority level 6 RAPI_INT_RX_LV_7
RAPI_INT_SIO_DIS SI/O interrupt disabled RAPI_INT_SIO_LV_1 SI/O interrupt priority level 1 RAPI_INT_SIO_LV_2 RAPI_INT_SIO_LV_3 SI/O interrupt priority level 3 RAPI_INT_SIO_LV_4 RAPI_INT_SIO_LV_5 SI/O interrupt priority level 5 RAPI_INT_SIO_LV_6 RAPI_INT_SIO_LV_7 SI/O interrupt priority level 7
Transmit interrupt priority level 2
Receive interrupt priority level 7
SI/O interrupt priority level 2
SI/O interrupt priority level 4
SI/O interrupt priority level 6
Return value
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).
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
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).
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__ConfigSerialDriverNotify, __SetSerialInterrupt, __StartSerialReceiving
If an undefined value is specified in the argument, operation of the API cann ot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
unsigned int buffer[10];
void func( void ) { /* Reception interrupt disable */ __SetSerialInterrupt( RAPI_COM1 | RAPI_INT_TX_DIS | RAPI_INT_RX_DIS ); /* Start reception */ __StartSerialReceiving( RAPI_COM1, 5, buffer ); while(1){ __PollingSerialReceiving( RAPI_COM1 ); } }
Rev.1.00 2007.11.1 REC10B0002-0100
38
__PollingSerialSending
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Polling transmission>
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).
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
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”
unsigned int buffer[10];
void func( void ) { /* Transmission interrupt disable */ __SetSerialInterrupt( RAPI_COM1 | RAPI_INT_TX_DIS | RAPI_INT_RX_DIS ); /* Start transmission */ __StartSerialSending( RAPI_COM1, 5, buffer ); while(1){ __PollingSerialSending( RAPI_COM1 ); } }
Rev.1.00 2007.11.1 REC10B0002-0100
39
4.2.2 Timer __CreateTimer
Synopsis
Description
<Set timer mode>
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_ON Sets 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
guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void ) { /* Disable timer A1 as timer mode */ __EnableTimer( RAPI_TIMER_A1 | RAPI_TIMER_OFF ); }
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.
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
Return value
Functionality
Reference
Remark
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_RELOAD Selects 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_REGISTER Selects 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.
Timer (event counter mode)
__EnableEventCounter, __DestroyEventCounter, __GetEventCounter
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 B0 as event counter mode */ __CreateEventCounter( RAPI_TIMER_B0|RAPI_TIMER_ON|RAPI_FALLING, 5, 0x80, 0, TimerIntFunc ); }
Rev.1.00 2007.11.1 REC10B0002-0100
46
__EnableEventCounter
Synopsis
Description
For data, the following defi nition values can be set. To set multiple definition values at
Return value
Functionality
Reference
Remark
<Control operation of event counter mode>
Boolean __EnableEventCounter(unsigned long data)
data Setup data
Controls operation of the timer that is set to specified timer mode by starting or stopping it.
[data]
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_ON
RAPI_TIMER_OFF
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.
Timer (event counter mode)
__CreateEventCounter, __DestroyEventCounter, __GetEventCounter
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 ) { /* Disable timer B1 as event counter mode */ __EnableEventCounter( RAPI_TIMER_B1|RAPI_TIMER_OFF ); }
Rev.1.00 2007.11.1 REC10B0002-0100
47
__DestroyEventCounter
Synopsis
Description
<Discard settings of event counter mode>
Boolean __DestroyEventCounter(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.
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
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
Timer (event counter mode)
__CreateEventCounter, __EnableEventCounter, __GetEventCounter
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.
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
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (event counter mode)
__CreateEventCounter, __EnableEventCounter, __DestroyEventCounter
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_ON Sets 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_ON Selects 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.
Functionality
Timer (pulse width modulation mode (PWM mode))
__EnablePulseWidthModulationMode, __DestroyPulseWidthModulationMode
Reference
If an undefined value is specified in the first argument, operation of the API cannot
Remark
be guaranteed.
Program example
#include "rapi_timer_m16c_62p.h"
void TimerIntFunc( void ){}
pin input can only
iIN
Rev.1.00 2007.11.1 REC10B0002-0100
51
void func( void )
{ unsigned int p_tim[] = {0xAA, 0xBB, 0xCC};
/* Set up timer A3 as pulse width modulation mode */
__CreatePulseWidthModulationMode( RAPI_TIMER_A3|RAPI_TIMER_ON|RAPI_F8, 5, p_tim, TimerIntFunc); }
Rev.1.00 2007.11.1 REC10B0002-0100
52
__EnablePulseWidthModulationMode
Synopsis
Description
For data, the following defi nition values can be set. To set multiple definition values at
Return value
Functionality
Reference
Remark
<Control operation of pulse width modulation mode>
Boolean __EnablePulseWidthModulationMode(unsigned long data)
data Setup data
Controls operation of the timer that is set to specified pulse width modulation mode by starting or stopping it.
[data]
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_ON
RAPI_TIMER_OFF
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (pulse width modulation mode (PWM mode))
__CreatePulseWidthModulationMode, __DestroyPulseWidthModulationMode
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.
Program example
#include "rapi_timer_m16c_62p.h"
void func( void ) { /* Enable timer A2 as pulse width modulation mode */ __EnablePulseWidthModulationMode( RAPI_TIMER_A2|RAPI_TIMER_ON ); }
Rev.1.00 2007.11.1 REC10B0002-0100
53
__DestroyPulseWidthModulationMode
Synopsis
Description
For data, the following definition values can be set.
Return value
Functionality
Reference
Remark
<Discard settings of pulse width modulation mode>
Boolean __DestroyPulseWidthModulationMode(unsigned long data)
data Setup data
Discards settings of the timer that is set to specified pulse width modulation mode.
[data]
RAPI_TIMER_A0 RAPI_TIMER_A1 RAPI_TIMER_A2 RAPI_TIMER_A3 RAPI_TIMER_A4
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (pulse width modulation mode (PWM mode))
__CreatePulseWidthModulationMode, __EnablePulseWidthModulationMode
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_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 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,
Return value
Functionality
Reference
__GetPulsePeriodMeasurementMode
Remark
Program example
RAPI_TRUE is returned.
Timer (pulse period measurement mode)
__EnablePulsePeriodMeasurementMode, __DestroyPulsePeriodMeasurementMode,
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_ON Sets 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.
Timer (pulse period measurement mode)
__CreatePulsePeriodMeasurementMode, __DestroyPulsePeriodMeasurementMode,
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 )
{ /* Enable timer B1 as pulse period measurement mode */ __EnablePulsePeriodMeasurementMode( RAPI_TIMER_B1|RAPI_TIMER_ON ); }
Rev.1.00 2007.11.1 REC10B0002-0100
57
__DestroyPulsePeriodMeasurementMode
Synopsis
Description
For data, the following definition values can be set.
Return value
Functionality
Reference
__GetPulsePeriodMeasurementMode
Remark
<Discard settings of pulse period measurement mode>
Boolean __DestroyPulsePeriodMeasurementMode(un signed long data)
data Setup data
Discards settings of the timer that is set to specified pulse period measurement mode.
[data]
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.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (pulse period measurement mode)
__CreatePulsePeriodMeasurementMode, __EnablePulsePeriodMeasurementMode,
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 ) { /* Destroy the setting of timer B2 as pulse period measurement mode */ __DestroyPulsePeriodMeasurementMode( RAPI_TIMER_B2 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
58
__GetPulsePeriodMeasurementMode
Synopsis
Description
For data, the following definition values can be set.
Return value
Functionality
Reference
__DestroyPulsePeriodMeasurementMode
Remark
<Get measured value in pulse period measurement mode>
Boolean __GetPulsePeriodMeasurementMode(unsigned long data1, unsigned int *data2)
data1 Setup data 1 data2 Pointer to the buffer in which counter value is stored
Gets the counter value of the timer that is set to specified pulse period measurem ent mode.
[data1]
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.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (pulse period measurement mode)
__CreatePulsePeriodMeasurementMode, __EnablePulsePeriodMeasurementMode,
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_ON Sets 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.
Timer (pulse width measurement mode)
__EnablePulseWidthMeasurementMode, __DestroyPulseWidthMeasurementMode,
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_ON Sets 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.
Timer (pulse width measurement mode)
__CreatePulseWidthMeasurementMode, __DestroyPulseWidthMeasurementMode,
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 ) { /* Disable timer B5 as pulse width measurement mode */ __EnablePulseWidthMeasurementMode( RAPI_TIMER_B5|RAPI_TIMER_OFF ); }
Rev.1.00 2007.11.1 REC10B0002-0100
62
__DestroyPulseWidthMeasurementMode
Synopsis
Description
For data, the following definition values can be set.
<Discard settings of pulse width measurement mode>
Boolean __DestroyPulseWidthMeasurementMode(unsigned long data)
data Setup data
Discards settings of the timer that is set to specified pulse width measurement mode.
[data]
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.
Return value
Functionality
Reference
__GetPulseWidthMeasurementMode
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (pulse width measurement mode)
__CreatePulseWidthMeasurementMode, __EnablePulseWidthMeasurementMode,
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 ) { /* Destro y the setting of timer B0 as pulse width measurement mode */ __DestroyPulseWidthMeasurementMode( RAPI_TIMER_B0 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
63
__GetPulseWidthMeasurementMode
Synopsis
Description
For data, the following definition values can be set.
Return value
Functionality
Reference
__DestroyPulseWidthMeasurementMode
Remark
<Get measured value in pulse width measurement mode>
Boolean __GetPulseWidthMeasurementMode(unsigned long data1, unsigned int *data2)
data1 Setup data 1 data2 Pointer to the buffer in which counter value is stored
Gets the counter value of the timer that is set to specified pulse width measurement mode.
[data1]
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.
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE
is returned.
Timer (pulse width measurement mode)
__CreatePulseWidthMeasurementMode, __EnablePulseWidthMeasurementMode,
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.
Timer (register manipulation)
__EnableTimerRegister, __ClearTimerRegister, __GetTimerRegister
Rev.1.00 2007.11.1 REC10B0002-0100
65
If an undefined value is specified in the first argument, operation of the API cannot be guaranteed. The specifiable timers differ with each CPU used.
Program example
#include " rapi_timer_m16c_62p.h"
void func( void ) { unsigned char data[] = {0,0,0,0,0,0,0};
/* 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_ON Sets 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.
Timer (register manipulation)
__SetTimerRegister, __ClearTimerRegister, __GetTimerRegister
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 ) { /* Activate timer A1 */ __EnableTimerRegister( RAPI_TIMER_A1|RAPI_TIMER_ON ); }
Rev.1.00 2007.11.1 REC10B0002-0100
67
__ClearTimerRegister
Synopsis
Description
<Clear timer register>
Boolean __ClearTimerRegister(unsigned long data)
data Setup data
Sets the timer register of a specified timer to its initial value after reset.
[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.
Return value
Functionality
Reference
Remark
If the timer specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Timer (register manipulation)
__SetTimerRegister, __EnableTimerRegister, __GetTimerRegister
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.
Timer (register manipulation)
Rev.1.00 2007.11.1 REC10B0002-0100
69
Reference
__SetTimerRegister, __EnableTimerRegister, __ClearTimerRegister
Remark
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.
Rev.1.00 2007.11.1 REC10B0002-0100
72
Functionality
Reference
__WriteIOPortRegister
Remark
I/O port
__ReadIOPort, __WriteIOPort, __SetIOPortRegister, __ReadIOPortRegister,
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.
I/O port
__SetIOPort, __WriteIOPort, __SetIOPortRegister, __ReadIOPortRegister,
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.
I/O port
__SetIOPort, __ReadIOPort, __SetIOPortRegister, __ReadIOPortRegister, __WriteIOPortRegister
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 P0 register 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.
I/O port
__SetIOPort, __ReadIOPort, __WriteIOPort, __ReadIOPortRegister, __WriteIOPortRegister
output. Specifiable only when port P1 is used.
Rev.1.00 2007.11.1 REC10B0002-0100
78
Program example
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 P0 register 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.
I/O port
__SetIOPort, __ReadIOPort, __WriteIOPort, __SetIOPortRegister, __WriteIOPortRegister
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 P0 register 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.
I/O port
__SetIOPort, __ReadIOPort, __WriteIOPort, __SetIOPortRegister, __ReadIOPortRegister
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_FALLING Specifies 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
RAPI_KI0_ENABLE Uses _KI0 pin input. RAPI_KI1_ENABLE Uses _KI1 pin input. RAPI_KI2_ENABLE Uses _KI2 pin input. RAPI_KI3_ENABLE Uses _KI3 pin input.
• Specifiable definition values when _INT0–5 interrupts are used (RAPI_INT0 to RAPI_INT5 specified)
(Polarity) Specify one from { RAPI_INT_RISING, RAPI_INT_FALLING,
• Specifiable definition values when key input interrupt is used (RAPI_KEY specified)
(Input pin) To use _KI0, _KI1, _KI2, or _KI3 pin input, specify RAPI_KI0_ENABLE,
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
interrupt.
interrupt.
interrupt.
RAPI_INT_BOTH }. The default value is RAPI_INT_FALLING.
RAPI_KI1_ENABLE, RAPI_KI2_ENABLE, or RAPI_KI3_ENABLE,
respectively. The default value is RAPI_INT_FALLING.
Rev.1.00 2007.11.1 REC10B0002-0100
82
Return value
Functionality
Reference
Remark
If the external interrupt specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
External interrupt
__EnableInterrupt, __GetInterruptFlag, __ClearInterruptFlag
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 IntFunc( void ){}
void func( void ) { /* Set up _INT0 interrupt */ __SetInterrupt( RAPI_INT0|RAPI_INT_FALLING, 0, IntFunc ); }
Rev.1.00 2007.11.1 REC10B0002-0100
83
__EnableInterrupt
Synopsis
Description
<Control external interrupt>
Boolean __EnableInterrupt(unsigned long data1, unsigned int data2)
data1 Setup data 1 data2 Setup data 2
Changes the operating condition of a specified external interrupt.
[data1]
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.
Return value
Functionality
Reference
Remark
[data2]
Specify the interrupt priority level (0–7) to be set in the interrupt control register.
If the external interrupt specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
External interrupt
__SetInterrupt, __GetInterruptFlag, __ClearInterruptFlag
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 ) { /* Activate _INT1 interrupt ( interrupt priority level 5 ) */ __EnableInterrupt( RAPI_INT1, 5 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
84
__GetInterruptFlag
Synopsis
Description
<Get the status of external interrupt flag>
Boolean __GetInterruptFlag(unsigned long data1, unsigned int *data2))
data1 Setup data 1 data2 Pointer to the buffer in which the acquired flag data is stored
Gets the value of interrupt request flag of a specified external interrupt.
[data1]
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.
[data2]
Value of interrupt request flag (0: Interrupt not requested; 1: Interrupt requ ested)
Return value
Functionality
Reference
Remark
If the external interrupt specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
External interrupt
__SetInterrupt, __EnableInterrupt, __ClearInterruptFlag
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 ) { unsigned char data;
/* Get flag of _INT2 interrupt */ __GetInterruptFlag( RAPI_INT2, &data ); }
00000 0 0
Rev.1.00 2007.11.1 REC10B0002-0100
85
__ClearInterruptFlag
Synopsis
Description
Return value
Functionality
Reference
Remark
<Clear external interrupt flag>
Boolean __ClearInterruptFlag(unsigned long data)
data Setup data
Clears the interrupt request flag of a specified external interrupt.
[data]
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.
If the external interrupt specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
External interrupt
__SetInterrupt, __EnableInterrupt, __GetInterruptFlag
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
| RAPI_EXTERNAL_TRIGGER |RAPI_AD_ON|RAPI_10BIT| RAPI_ANEX_UNUSED,
}
1, 5, AdIntFunc );
Rev.1.00 2007.11.1 REC10B0002-0100
91
__EnableADC
Synopsis
Description
<Control operation of A/D converter>
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.
Rev.1.00 2007.11.1 REC10B0002-0100
93
Program example
#include "rapi_ad_m16c_62p.h"
void func( void ) { /* Disable A/D converter */ __EnableADC( RAPI_AN0|RAPI_AD_OFF, 1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
94
__DestroyADC
Synopsis
Description
Return value
Functionality
Reference
<Discard settings of A/D converter>
Boolean __DestroyADC(void)
Discards settings of a specified A/D converter.
If converter setting was successfully discarded, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
A/D converter
__CreateADC, __EnableADC, __GetADC, __GetADCAll
Program example
#include "rapi_ad_m16c_62p.h"
void func( void ) { /* Destroy A/D converter */ __DestroyADC(); }
Rev.1.00 2007.11.1 REC10B0002-0100
95
__GetADC
Synopsis
Description
<Get A/D converted value (register specified)>
Boolean __GetADC(unsigned long data1, unsigned int *data2)
data1 Setup data 1 data2 Pointer to the buffer in which A/D converted value is stored.
Gets the A/D converted value from a specified A/D register.
For data1, the following values can be set.
RAPI_AD0 Selects A/D register 0. RAPI_AD1 Selects A/D register 1. RAPI_AD2 Selects A/D register 2. RAPI_AD3 Selects A/D register 3. RAPI_AD4 Selects A/D register 4. RAPI_AD5 Selects A/D register 5. RAPI_AD6 Selects A/D register 6. RAPI_AD7 Selects A/D register 7.
Return value
Functionality
Reference
Remark
If A/D converted value was successfully acquired, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
A/D converter
__CreateADC, __EnableADC, __DestroyADC, __GetADCAll
If an undefined value is specified in the first argument, operation of the API cannot
be guaranteed.
Program example
#include "rapi_ad_m16c_62p.h"
void func( void ) { unsigned int data;
/* Get an A/D convertered data of A/D register 0 */ __GetADC( RAPI_AD0, &data ); }
Rev.1.00 2007.11.1 REC10B0002-0100
96
__GetADCAll
Synopsis
Description
<Get A/D converted value (all registers)>
Boolean __GetADCAll(unsigned int *data)
data Pointer to the buffer in which A/D converted value is stored.
Gets the A/D converted value from all A/D registers. The A/D registers from which A/D converted values are acquired are listed below.
[M16C] : [0] A/D register 0 (16 bytes) [1] A/D register 1 [2] A/D register 2 [3] A/D register 3 [4] A/D register 4 [5] A/D register 5 [6] A/D register 6 [7] A/D register 7
Return value
Functionality
Reference
If A/D converted values were successfully acquired, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
A/D converter
__CreateADC, __EnableADC, __DestroyADC, __GetADC
Program example
#include "rapi_ad_m16c_62p.h"
void func( void ) { unsigned int data[8];
/* Get A/D convertered datas of A/D register */ __GetADCAll( data ); }
Rev.1.00 2007.11.1 REC10B0002-0100
97
M16C/62P Group
Renesas Embedded
Application Programming Interface
Reference Manual
Rev.1.00 2007.11.1 REC10B0002-0100
Rev. 1.00
Issued: November 2007
98
Loading...