
4BUsage Examples
5.1 21BInterrupt control
5.1. Interrupt control
Figure 5-1 shows an example of external interrupt use.
Pin IRQ0-A is used to detect a falling edge and generates an interrupt.
Pin IRQ1-B is used to detect a falling edge and is polled.
Pin
IRQ2-A
is used to detect a low-level signal and generates an interrupt. Further interrupts are prevented until the signal has
returned to the high level.
#include "r_pdl_io_port_library_SH7267.h"
#include "r_pdl_intc_library_SH7267.h"
#include "r_pdl_cmt_library_SH7267.h"
#include "r_pdl_cpg_library_SH7267.h"
/* PDL device-specific definitions */
#include "r_pdl_definitions.h"
volatile uint8_t switch_sw1_pressed;
volatile uint8_t irq2_low;
/* Callback function prototypes */
void IRQ0Handler(void);
void IRQ2Handler(void);
static void ReEnableIRQ2(void);
void main(void)
{
uint8_t irq_status;
/* Set the CPU's Interrupt Priority Level to 0 */
R_INTC_Write(
PDL_INTC_REG_IPR,
0,
0x0000
);
/* Configure the IRQ0 interrupt on pin IRQ0-A */
R_INTC_CreateExtInterrupt(
PDL_INTC_IRQ0,
PDL_INTC_IRQ_FALLING | PDL_INTC_A,7,
IRQ0Handler
);
/* Configure the IRQ1 interrupt on pin IRQ1-B */
R_INTC_CreateExtInterrupt(
PDL_INTC_IRQ1,
PDL_INTC_IRQ_FALLING | PDL_INTC_B,
0,
PDL_NA
);
/* Configure the IRQ2 interrupt on pin IRQ2-A */
R_INTC_CreateExtInterrupt(
PDL_INTC_IRQ2,
PDL_INTC_IRQ_LOW | PDL_INTC_A,
7,
IRQ2Handler
);
irq2_low = 0;
while(1)
{
/* Poll the IRQ1 flag */
R_INTC_GetExtInterruptStatus(
PDL_INTC_IRQ1,
&irq_status
Komentáře k této Příručce