Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

ARASU ENGINEERING COLLEGE

DEPARTMENT OF ECE

EC6711 EMBEDDED LABORATORY

LAB MANUAL

YEAR / SEMESTER: IV / V DEPARTMENT: ECE


ARM® ARCHITECTURE AND PROGRAMMING GUIDE

ARASU ENGINEERING COLLEGE

DEPARTMENT OF ECE

ARM® ARCHITECTURE AND PROGRAMMING


GUIDE
ARM 7 TDMI® –PHILIPS LPC 214x Series

PART 1

KARTHIK S

KARTHIK S AEC
ANNA UNIVERSITY CHENNAI
Regulation 2013

EC6711 EMBEDDED LABORATORY

SYLLABUS

LIST OF EXPERIMENTS

1. Study of ARM evaluation system

2. Interfacing ADC and DAC.

3. Interfacing LED and PWM.

4. Interfacing real time clock and serial port.

5. Interfacing keyboard and LCD.

6. Interfacing EPROM and interrupt.

7. Mailbox.

8. Interrupt performance characteristics of ARM and FPGA.

9. Flashing of LEDS.

10. Interfacing stepper motor and temperature sensor.

11. Implementing zigbee protocol with ARM.

TOTAL: 45 Periods
INDEX

Page
S.no Date Name of the Experiment Marks Signature
no

1 Study of ARM evaluation system

2 Interfacing ADC and DAC.

3 Interfacing LED and PWM

Interfacing real time clock and serial


4
port

5 Interfacing keyboard and LCD

6 Interfacing EPROM and interrupt

7 Mailbox

8 Interrupt performance characteristics of


ARM and FPGA

9 Flashing of LEDS

10 Interfacing stepper motor and


temperature sensor

11 Implementing ZIGBEE protocol with


ARM
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

What is ARM?
 ARM is an intellectual property (IP) Core.
 The important IP’s of ARM include its low power, low cost, high efficient RISC
microprocessors, system on chips and other peripherals.
 ARM (ARM Architecture 2016) is a family of Reduced Instruction Set Computing
(RISC) microprocessors developed specifically for mobile and embedded computing
environments.
 Due to their small sizes and low power requirements, ARM processors have become the
most widely used processors in mobile devices, e.g. smart phones, and embedded
systems. Currently, most embedded systems are based on ARM processors.

Features of ARM:

 ARM Processors are based on reduced instruction set computing (RISC) architecture.
 ARM Processors follow Load and Store type architecture where the data processing is
performed only on the contents of the registers rather than directly on the memory.

 32-bit ARM Processors have two instruction sets: general 32-bit ARM Instruction Set
and 16-bit Thumb Instruction Set.

 They have a wide range of clock frequency ranging from 1MHz to few GHz.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

ARM7TDMI:

 The ARM7TDMI-S processor is a member of the ARM family of general-purpose 32-bit


microprocessors.
 Only load, store, and swap instructions can access data from memory.
 The ARM7TDMI-S processor uses a three stage pipeline to increase the speed of the flow
of instructions to the processor.

ARM7TDMIS stands for

T: THUMB;

D for on-chip Debug support, enabling the processor to halt in response to a debug
request,

M: enhanced Multiplier, yield a full 64-bit result, high performance

I: Embedded ICE hardware (In Circuit emulator)

S: Synthesizable

There are three basic instruction sets for ARM.

A 32- bit ARM instruction set

A 16 –bit Thumb instruction set and

The 8-bit Java Byte code used in Jazelle state

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

LPC 2148:

LPC2148 is the widely used IC from ARM-7 family.


It is manufactured by Philips and it is pre-loaded with many inbuilt peripherals making it
more efficient and a reliable option for the beginners

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Features of LPC214x:
 64 I/O pins
 32kB on chip SRAM
 512kB on chip FLASH memory
 2kB end point USB RAM

INPUT/OUTPUT PORTS (GPIO of LPC2148):


 LPC2148 has two IO ports each of 32-bit wide
 Port 0 and Port 1
 Pins of each port labeled as Px.y where “x” stands for port number, 0 or 1. Where “y”
stands for pin number usually between 0 to 31.
 Each pin can perform multiple functions.
 For example: Pin no.1 which is P0.21 serves as GPIO as well as PWM5, AD1.6 (A/D
converter1, input 6), CAP1.3 (Capture input for Timer1, Channel 3).

PORT 0:

 32-bit I/O port with individual direction controls for each bit.
 Total of 28 pins of the Port 0 can be used as a general purpose bi-directional digital I/Os
 P0.31 provides digital output functions only.
 Pins P0.24, P0.26 and P0.27 are not available
PORT 1:

 32-bit bi-directional I/O port with individual direction controls for each bit
 Pins 0 through 15 of port 1 are not available.
 Pins 16 through 31 are used in programming
S. No Port Number Pins Available Function(Default)
1 Port 0 P0.0 to P0.31 YES GPIO
(P0.24,P0.26,P0.27
– Not available)
2 Port 1 P1.16 to P1.31 YES GPIO

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

LPC2148 GPIO Configuration:


The first step in LPC2148 programming is to configure GPIO Pins. PORT0 and PORT1
are controlled via set of registers explained below.

The important five registers are,

IODIR
IOSET
IOCLR
IOPIN
PINSEL

IODIR:

 Controls the direction of each Port Pin (Input or Output)


 32 Bit Register (Each bit for one pin)

IOPIN:

 GPIO Port Pin value register


 Current State of the GPIO configured port pins can always be read from this register

IOSET:

 GPIO Port Output Set registers


 Register controls the state of output pins
 Writing ones produces highs at the corresponding port pins

IOCLR:

 GPIO Port Output Clear registers


 Controls the state of output pins
 Writing ones produces lows at the corresponding port pins and clears the corresponding
bits in the IOSET register

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PINSEL:

 32 bit register which is used to select the function of the pins in which the user needs it to
operate.
 There are totally three PINSEL register (2 bits for Each pin)

 PINSEL0 – Controls functions of Port0.0 – Port0.15


 PINSEL1 – Controls functions of Port0.16-Port0.31
 PINSEL2 – Controls functions of Port1.16-Port1.31

The following table shows the PINSEL0 and corresponding functions on the PORT0.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Program statement methods to set pin direction

Example 1: Set the pin number 3 of port 0 as output pin (P0.3 -> Output)

Method 1: IO0DIR = (1 << 3);

Pin number

Value

Port number

Method 2: IO0DIR |= 0x00000008;

Method 3: IO0DIR |= (1<<3) ------------ Best Method

Example 2: Set the pin number 4 of port 0 as input pin (P0.4 -> Input)

IO0DIR |= (0<<4);

Example 3: Make the Pin 11 of Port 0 as output and set it to logic ‘1’ and logic ‘0’.

IO0DIR |= (1<<11);

IO0SET |= (1<<11);

IO0CLR |= (1<<11);

Example 4: Make Pin 12 of Port 0 and pin 18 of port 1 as Output pins

IO0DIR |= (1<<12);

IO1DIR |= (1<<18);

Example 5: Make pin 6 of port 0 as input and pin 16 of port 1 as Input pins

IO0DIR |= (0<<6);

IO1DIR |= (0<<16);

Example 6: Make pin 17 and pin 18 of port 1 as output pin

IO1DIR |= (1<<17) |= (1<<18);

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 1: LED BLINKING USING ARM LPC 2148

P0.13

ARM 7 TDMI

LPC 2148

Program:

# include<LPC214x.H> Library

Unsigned int delay; Variable for delay (data type Integer)

int main(void) Main loop

PINSEL0 |= 0x00000000;

IO0DIR |= (1<<13); Setting P0.13 as Output

while (1) Infinite loop (The statements will execute forever)

IO0SET |= (1<<13); Set the pin P0.13 to Logic HIGH

for (dealy=0;delay<500000;delay++) Simple delay statement (500mS)

IO0CLR |+ (1<<13); Setting pin P0.13 to logic LOW

for(dealy=0;delay<500000;delay++) Simple delay statement (500mS)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 2: SWITCH AND LED USING ARM LPC 2148

P0.13

ARM 7 TDMI

LPC 2148

P1.17

Program:

# include<LPC214x.H>

int main (void)

IO0DIR |= (1<<13);

IO1DIR &= ~ (1<<17);

while (1)

if (IO1PIN & (1<<17)

IO0SET |= (1<<13);

else

IO0CLR |= (1<<13);

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 3: BLINKING OF LEDs USING ARM LPC 2148

LEDs connected to P0.16 through P0.23

Program: #
include
<LPC214x.H>

Unsigned int delay;

int main (void)

{
PINSEL1 |= 0X00000000;

IO0DIR |= 0X00FF0000;

while (1)

IO0SET |= 0X00FF0000;

for(delay=0;delay<500000;delay++);

IO0CLR |= 0X00FF0000;

for(delay=0;delay<500000;delay++);}}

PRPOGRAM 4 LCD INTERFACE

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Commands:

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Our Example:

4 P0.30

5 P0.29

6 P0.28

LCD 11 P1.16

12 P1.17

18 P1.23

Register COMMAND DATA

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

RS 0 1

R/W 0 0

EN HIGH to LOW HIGH to LOW

Important Commands used:

 0X38 -> Initialize LCD on 2X16 LCD Display


 0X0E -> Display ON cursor Blink
 0X06 -> Shift cursor Right
 0X01 -> Clear Cursor
 0X80 -> Force cursor @ beginning of First line

Program:

Definitions:
#include <LPC214x.h>

# define LCD_RS 0X40000000  P0.30

#define LCD_RW 0X20000000  P0.29

#define LCD_EN 0X10000000  P0.28

Main Functions:

void lcd_cmd(unsigned char val);

void lcd_data(unsigned char val);

void delay(unsigned int);

void gpio_init();

unsigned char cmd[5]=(0X38,0X0E,0X06,0X01,0X80);

unsigned char msg1[] = “karthik”;

unsigned char msg2[]=”ridu”;

int main()

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Unsigned int I;

gpio_init();

For(i=0;i<5;i++)

lcd_cmd(cmd[i]);

for(i=0;msg1[i]!=’\0’;i++)

lcd_data (msg[i]);

lcd_cmd(0XC0);

for(i=0;msg2[i]!=’\0’;i++)

lcd_data(msg2[i]);

while(1)

Void gpio_init()

PINSEL1 = 0X00000000;

PINSEL2 = 0X00000000;

IO0DIR |= 0X70000000;

IO1DIR |= 0X00FF0000;

IO0CLR |= 0X70000000;

IO1CLR |= 0X00FF0000;

void lcd_cmd(unsigned char val)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

IO1PIN = (val<<16)

IOOCLR = LCD_RS;

IO0CLR = LCD_RW;

IO0SET = LCD_EN;

delay(50);

IO0CLR = LCD_EN;

delay(5000000);

void lcd_data(unsigned char val)

{
IO1PIN = (val<<16)

IOOSET = LCD_RS;

IO0CLR = LCD_RW;

IO0SET = LCD_EN;

delay (50);

IO0CLR = LCD_EN;

delay(5000000);

void delay(unsigned int value)

{
unsigned int j;

for (j=0;j<value;j++);

PROGRAM 5 ARM STEPPER MOTOR

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Program:

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

#include <lpc214x.h>

void delay(unsigned int value);

void gpio_init();

unsigned char cmd[4] = (0X11,0X22,0X44,0X88);

unsigned int j;

int main()

unsigned int i;

gpio_init();

while(1)

for(i=0;i<4;i++)

IO0PIN = cmd[i]<<15;

delay(0X500000);

Void gpio_init ()

PINSEL0=0X00000000;

IO0DIR = 0X0000F000;

IO0CLR = 0x0000F000;

void delay(unsigned int value)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

unsigned int k;

for(k=0;k<value;k++);

PROGRAM 6 ARM PWM GENERATION

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Why we need PWM?

Microcontroller can’t produce any other value different than 0V and 3.3V. Here PWM feature
allows us to generate any voltage level between 0V and 3.3V. The main application of
PWM is to control the power delivered to the loads.

PWM in LPC2148 ARM7

LPC2148 has PWM peripheral through which we can generate multiple PWM signals on
PWM pins. Also, LPC2148 supports two types of controlled PWM outputs as,

Single Edge Controlled PWM Output

All the rising (positive going) edges of the output waveform are positioned/fixed at the beginning
of the PWM period. Only falling (negative going) edge position can be controlled to vary the
pulse width of PWM.

Double Edge Controlled PWM Output

All the rising (positive going) and falling (negative going) edge positions can be controlled to
vary the pulse width of PWM. Both the rising as well as the falling edges can be positioned
anywhere in the PWM period.

LPC2

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

148 has 6 PWM output pins which can be used as

 6-Single edged or
 3-Double edged.

There as seven-match registers to support these 6-PWM output signals

PWM REGISTERS

1. PWMTCR (PWM Timer Control Register)


 8-BIT REGISTER
 Used to control the operation of the PWM Timer Counter.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

2. PWMMR0-PWMMR6 (PWM Match Registers)

 These are 32-bit registers.


 The values stored in these registers are continuously compared with the PWM
Timer Counter value.
 When the two values are equal, the timer can be reset or stop or an interrupt may
be generated.

3. PWMMCR (PWM Match Control Register)


 It is a 32-bit register.
 It controls what action is to be taken on a match between the PWM Match
Registers and PWM Timer Counter.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

4. PWMPCR (PWM Control Register)

5. PWMLER (PWM Latch Enable Register)

6. PWMPR

Prescaler Register: This is used to specify the Prescaler value for incrementing
the PWMTC (Resolution)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

7. PWMPCR (PWM Control Register)

Steps to setup PWM in LPC2148 ARM7

 Setup the Pin Select Register to select PWM for the port we want
 Select the mode of the PWM i.e. single edge or double edge using PWMPCR register

 The resolution of the PWM, which is defined by the Pre-scale value, is set to the Pre-scale
Register.
 The cycle rate of the PWM signal i.e. the period of the PWM signal is set using the
PWMMR0 register.
 The pulse widths of the PWM outputs are set using the match registers i.e. PWMMR1
through PWMMR6.
 The next important step is to set the Latch Enable bits to the corresponding Match
Registers using PWMLER register.
 we need to enable the PWM outputs. In order to do this, we need to use the PWMPCR
register.
 we need to reset the PWM Timers. To reset the Timers, we need to make use of PWMTCR
register.
 We need to do is to enable the PWM Timer Counters and the PWM Mode. For this, we
have to use the PWMTCR register again.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM:

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 7 ARM LPC2148 CLOCK USING PLL

PLL -> Phase Locked Loop

 A system that generates a clock signal with reference to an input signal generally
from a crystal oscillator.

PLL in LPC2148:

Two PLL blocks

PLL0 PLL 1

Used to generate Strictly for USB

System clock goes

to CPU and peripherals

Input clock to both the PLLs must be between 10 MHz to 25 MHz strictly.

Input clock is multiplied with a suitable multiplier and scaled accordingly

Basics:

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

The PLL inputs and settings must meet the following

 FOSC is in the range of 10 MHz to 25 MHz


 CCLK is in the range of 10 MHz to Fmax (PLL O/P)

Setting up and using PLL:

 We have Multiplier and a Divider which decide the output frequency/clock form PLL
block.
 To access PLL we need to have a key in order to use or configure it. The key
here is the ‘Feed Sequence’.
 Feed Sequence is nothing but assignment of 2 particular ‘fixed’ values to a
register PLL0FEED
 Fixed values are 0xAA and 0x55 are ‘in order’!

PLL Registers:

1. PLLxCON :(x= PLL block 0 or 1) – Used to enable and connect PLL

Bit’0’ – Enable

Bit’1’– Connect
Connect -> Switching from internal RC Oscillator to PLL O/P clock

PLL is connected only when both the bits are ‘1’ and Feed Sequence is applied

2. PLLxCGF: The multiplier and divider values are stored in this register

First five bits (‘0’ to ‘4’) are called MSEL -> Stores multiplier value

Next two bits (‘5’ and ‘6’) are called PSEL used to store divider value

3. PLLxSTAT: Read only register, holds current status of PLL enable, connect, MSEL
and PSEL values

Tenth bit (‘9’) contains LOCK status. When PLL locks bit ‘9’ becomes ‘1’

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

STEPS:

* Setup PLL
* Apply Feed Sequence
* Wait for PLL to lock and then Connect PLL
* Apply Feed Sequence

Values of MSEL and PSEL:

Setting-up Peripheral Clock:

The peripheral clock is derived from CPU clock (CCLK)

The APB (Advanced Peripheral Bus) divider decides the peripheral clock

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

By Default PCLK runs at 1/4th the speed of CCLK. To control APB Divider we have a register
called VPBDIV. The value in VPBDIV controls the division of CCLK to generate PCLK as
shown below:

Program: (With PWM Generation)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 8 ARM ADC

The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive approximation analog to


digital converter.

* LPC2148 has two inbuilt ADC Modules, named as ADC0 & ADC1
* ADC0 has 6-Channels (AD0.1-AD0.6)
* ADC1 has 8-Channels (AD1.0-AD1.7).
* ADC operating frequency is 4.5 MHz (max.), operating frequency decides the
conversion time.
* Supports power down mode.
* Burst conversion mode for single or multiple inputs.

ADC related channels and pins:

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Registers of ADC:

AD0CR – A/D Control Register: This is the main control register for AD0.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

AD0GDR – A/D Global Data Register:

This is the global data register for the corresponding ADC module. It contains the ADC’s DONE
bit and the result of the most recent A/D conversion.

These two registers are mainly used in basic programs

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM:

AD0.1 is used (p0.28) we need PINSEL1 register

#include<lpc214x.h>

Void main ()

{
PINSEL1 |= 0x01000000;

unsigned int i, adc_data;

AD0CR = 0x00200F02 // (first eight bits for channel selection(AD0.1), next eight bits for
frequency selection (60MHz/0F = 4MHz), next bits(17,18,19 for 11clocks/10cycles), (21 to
switch on ADC), (24,25,26 start- 000-no start, 001- start), (27 start conversion), others reserved)

AD0CR |= 0x01000000; // Start ADC

Do

I = AD0CDR;

while (i & 0x08000000) == 0)) // check for MSB of ADCDR

adc_data = (1>>6) & 0x3FF; // shift the output bits to (0-9) LSB and mask all other bits

return (adc_data);

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 8 ARM DAC

ARM7 LPC2148 MCU incorporates a 10 bit DAC and provides buffered analog output

 LPC2148 has 10-bit DAC with resistor string architecture. It also works in Power down
mode.

 LPC2148 has Analog output pin (AOUT P0.25/AD0.4/AOUT) on chip, where we can get
digital value in the form of Analog output voltage.

 The Analog voltage on AOUT pin is calculated as ((VALUE/1024) * VREF). Hence, we


can change voltage by changing VALUE (10-bit digital value) field in DACR (DAC
Register).

 e.g. if we set VALUE = 512, then, we can get analog voltage on AOUT pin as
((512/1024) * VREF) = VREF/2.

AOUT (Analog Output)

This is Analog Output pin of LPC2148 DAC peripheral where we can get Analog output
voltage from digital value.

VREF (Voltage Reference)

Provides Voltage Reference for DAC

VDDA& VSSA (Analog Power and Ground)

These are the power and ground pins for DAC. These should be same as VDD& VSS.

Let’s see the Register used for DAC

DACR (DAC Register)

 DACR is a 32-bit register.


 It is a read-write register.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

Bit[15:6] – VALUE This field contains the 10-bit digital value that is to be converted in to
Analog voltage.

Bit[16] – BIAS: Setting this bit to 0 selects settling time of 1us max with max current
consumption of 700uA. Setting it to 1 will select settling time of 2.5us but with reduce max
current consumption of 300uA.

Programming Steps

 First, configure P0.25/AOUT pin as DAC output using PINSEL Register.

 Then set settling time using BIAS bit in DACR Register.

 Now write 10-bit value (which we want to convert into analog form) in VALUE field of
DACR Register.

EXAMPLE:

 Let’s write a simple program for LPC2148 DAC.

 Here, we will load the DACR value with various values to generate a sine wave,
triangular wave, sawtooth wave, square wave and DC wave.

 4 switches are used as inputs on P0.8 (for sine wave), P0.9 (for triangular wave), P0.10
(for sawtooth wave), and P0.11 (for square wave) pins.

 These pins are connected to 3.3 V through pull-up resistors. The switches are connected
as shown below. Only switch for P0.8 is shown in the figure. Switches are connected in a
similar manner to the other 3 pins as well.

 If we connect the DAC output pin P0.25 to an oscilloscope, we can observe the different
waves.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM:

#include <lpc214x.h>

#include <stdint.h>

void delay_ms(uint16_t j)

uint16_t x,i;

for(i=0;i<j;i++)

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 60MHz */

int main (void)

uint16_t value;

uint8_t i;

i = 0;

PINSEL1 = 0x00080000; /* P0.25 as DAC output */

IO0DIR = ( IO0DIR & 0xFFFFF0FF ); /* Input pins for switch. P0.8 sine, P0.9
triangular, P0.10 sawtooth, P0.11 square */

uint16_t sin_wave[42] = {
512,591,665,742,808,873,926,968,998,1017,1023,1017,998,968,926,873,808,742,665,591,512,

436,359,282,216,211,151,97,55,25,6,0,6,25,55,97,151,211,216,282,359,436 };

while(1)

if ( !(IO0PIN & (1<<8)) ) /* If switch for sine wave is pressed */

while(i !=42)

value = sin_wave[i];

DACR = ( (1<<16) | (value<<6) );

delay_ms(1);

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

i++;

i = 0;

else if ( !(IO0PIN & (1<<9)) ) /* If switch for triangular wave is pressed */

value = 0;

while ( value != 1023 )

DACR = ( (1<<16) | (value<<6) );

value++;

while ( value != 0 )

DACR = ( (1<<16) | (value<<6) );

value--;

else if ( !(IO0PIN & (1<<10)) ) /* If switch for sawtooth wave is pressed */

value = 0;

while ( value != 1023 )

DACR = ( (1<<16) | (value<<6) );

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

value++;

else if ( !(IO0PIN & (1<<11)) ) /* If switch for square wave is pressed */

value = 1023;

DACR = ( (1<<16) | (value<<6) );

delay_ms(100);

value = 0;

DACR = ( (1<<16) | (value<<6) );

delay_ms(100);

else /* If no switch is pressed, 3.3V DC */

value = 1023;

DACR = ( (1<<16) | (value<<6) );

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

PROGRAM 9 ARM EXTERNAL INTERRUPT

External Interrupt:

Interrupt caused by an external source such as external switch, sensor or monitoring device.
Seven Pins of PORT0 on LPC2148 Microcontroller can be configured as external interrupt
input.

EINT0 External Interrupt Input 0 Pins P0.1 and P0.16 can be selected to perform EINT0 function

EINT1 External Interrupt Input 1 Pins P0.3 and P0.14 can be selected to perform EINT1 function

EINT2 External Interrupt Input 2 Pins P0.7 and P0.15 can be selected to perform EINT2 function

EINT3 External Interrupt Input 3 Pins P0.9, P0.20 and P0.30 can be selected to for EINT3

Registers of External Interrupt

The external interrupt function has four registers associated with it.

 EXTINT register
 EXTWAKEUP register
 EXTMODE and EXTPOLAR registers specify the level and edge sensitivity
parameters.

We will be using Pin P0.15 as an external interrupt pin. On our development board we also have buzzer
connected to Pin P1.15 of LPC2148.

KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE

#include <LPC214x.H>

void delay(int count);


void init_ext_interrupt(void);
__irq void Ext_ISR(void);

int main (void)


{
init_ext_interrupt(); // initialize the external interrupt

while (1)
{
}
}

void init_ext_interrupt() //Initialize Interrupt


{
EXTMODE = 0x4; //Edge sensitive mode on EINT2
EXTPOLAR &= ~(0x4); //Falling Edge Sensitive
PINSEL0 = 0x80000000; //Select Pin function P0.15 as EINT2
/* initialize the interrupt vector */
VICIntSelect &= ~ (1<<16); // EINT2 selected as IRQ 16
VICVectAddr5 = (unsigned int)Ext_ISR; // address of the ISR
VICVectCntl5 = (1<<5) | 16; //
VICIntEnable = (1<<16); // EINT2 interrupt enabled

EXTINT &= ~(0x4);


}
__irq void Ext_ISR(void) // Interrupt Service Routine-ISR
{
IO1DIR |= (1<<25);
IO1CLR |= (1<<25); // Turn ON Buzzer
delay(100000);
IO1SET |= (1<<25); // Turn OFF Buzzer

EXTINT |= 0x4; //clear interrupt


VICVectAddr = 0; // End of interrupt execution
}

void delay(int count)


{
int j=0,i=0;

for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}

In void int_ext_interrupt(); we’ll initialize interrupt vector and call ISR when interrupt occurs.

In _irq void Ext_ISR(void) function, we’ve set action to be performed while ISR been called

KARTHIK S AEC

You might also like