Professional Documents
Culture Documents
Introduction
As you may recall ARM defines two types of interrupt requests: FIQ (Fast Interrupt request) and
IRQ (Normal Interrupt request). There are 22 interrupt sources from the different peripherals in
LPC2148. A hardware called Vectored Interrupt Controller (VIC) serves as a bridge between these
interrupt sources and the ARM core.
External Interrupt
IRQ
Timers
VIC ARM Core
UARTs
.
. FIQ
.
You can configure each interrupt in LPC2148 as FIQ, vectored IRQ or non-vectored IRQ interrupts.
When an interrupt is vectored, a separate interrupt Service Routine (ISR) exists for that interrupt.
For FIQ and non-vectored IRQ interrupts, however, there is only one Interrupt Service Routine
(ISR) respectively (one for FIQ and one for non-vectored IRQ interrupts).
Configure registers inside the VIC (Refer to VIC chapter of user manual of LPC2148)
o Configure interrupt as FIQ or IRQ
o Configure address of ISR that is executed when the interrupt occurs
o Enable the interrupt
Configure registers inside the peripheral that generates the interrupt (Refer to
corresponding peripheral on the user manual of LPC2148)
External Interrupt
There are four external interrupt sources on LPC2148: EINT0 - EINT3. These interrupts can be
configured to be edge-triggered or level-triggered. In this lab we will see how to use one of the
external interrupts, EINT1.
EINT1 is connected to pin P0.14 on the microcontroller. This pin is connected to a button on the
LPC2148 Education board. You will write a program that counts the number of button presses
and displays the count value on an LCD. You will use EINT1 to detect button presses.
1
1. Configure registers inside the VIC
This configuration is made easier by functions inside interrupts.c file. To use these functions
#include interrupts.h into your main source file. Use the following functions for configuration.
channel: Specifies interrupt source. You can find the channel number for each interrupt source on
page 73 of the user manual. For EINT1 the channel number is 15 or VIC_EINT1.
*ISR: Specifies the name of the function that is used as an ISR when the specified interrupt source
generates an interrupt. When the specified interrupt occurs, the code inside this function is
executed.
IntNumber: Specifies interrupt number (priority). There can be up to 16 vectored IRQ interrupts (0
to 15). The number shows the priority of the interrupt, with 0 indicating highest priority.
install_FIQ (unsigned int channel, void (*ISR) (void)): Configures an interrupt as FIQ. Note
that there can only be one ISR for FIQ.
Registers specific to external interrupts also need to be configured. The following configuration is
used for our example.
You will find all configurations in the function EINT1_Init inside the source file main.c.
Note: There are interrupt flags for each type of interrupt. These flags are set when an
interrupt occurs. They need to be cleared by software inside the ISR.
Task1: Using the provided template write a program that counts the number of button
presses and displays the count value on an LCD. Use EINT1 to detect button presses.
2
Lab3 Home Work
Reaction Timer
A Reaction timer shows how fast a person can respond to an event. A flow chart for a possible
implementation of a reaction timer is given below. Use the flow chart to write a reaction timer
program. A schematic is provided.
Configure Peripherals
LED ON
Button
Pressed?
NO HINT
To generate random delay
b/n 0 and 20sec
YES
#include <stdlib.h>
LED OFF #include delay.h
Wait a random time
.
Event LED ON
Start Timer from 0 //generate random number b/n 0
//and 20000
int i = rand()%20000;
Reaction delay_ms(i);
NO
Time
Button Use timer library for
Pressed? measuring reaction time
(the library uses Timer 0)
Use EINT1 to detect
Response YES button press
Read timer
Display response(reaction) time
in milliseconds on LCD