Arm Lab Manual
Arm Lab Manual
CHAPTER 1
INTRODUCTION TO ARM Cortex M3 PROCESSOR
The ARM Cortex-M3 is a general purpose 32-bit microprocessor, which offers high
performance and very low power consumption. The Cortex-M3 offers many new features,
including a Thumb-2 instruction set, low interrupt latency, hardware divide,
interruptible/continuable multiple load and store instructions, automatic state save and restore
for interrupts, tightly integrated interrupt controller with Wake-up Interrupt Controller and
multiple core buses capable of simultaneous [Link] techniques are employed so that
all parts of the processing and memory systems can operate continuously. Typically, while one
instruction is being executed, its successor is being decoded, and a third instruction is being
fetched from memory.
The processor has a Harvard architecture, which means that it has a separate instruction bus
and data bus. This allows instructions and data accesses to take place at the same time, and
as a result of this, the performance of the processor increases because data accesses do not
affect the instruction pipeline. This feature results in multiple bus interfaces on Cortex-M3,
each with optimized usage and the ability to be used simultaneously. However, the
instruction and data buses share the same memory space (a unified memory system). In
other words, you cannot get 8 GB of memory space just because you have separate bus
interfaces.
It is worthwhile highlighting that the Cortex-M3 processor is not the first ARM
processor to be used to create generic micro controllers. The venerable ARM7 processor has
been very successful in this market, The Cortex-M3 processor builds on the success of the
ARM7 processor to deliver devices that are significantly easier to program and debug and yet
deliver a higher processing capability.
ARM was formed in 1990 as Advanced RISC Machines Ltd., a joint venture of Apple
Computer, Acorn Computer Group, and VLSI Technology. In 1991, ARM introduced the
ARM6 processor family, and VLSI became the initial licensee. Subsequently, additional
companies, including Texas Instruments, NEC, Sharp, and ST Microelectronics, licensed the
ARM processor designs, extending the applications of ARM processors into mobile phones,
computer hard disks, personal digital assistants (PDAs), home entertainment systems, and
many other consumer products.
Nowadays, ARM partners ship in excess of 2 billion ARM processors each year. Unlike
many semiconductor companies, ARM does not manufacture processors or sell the chips
directly. Instead, ARM licenses the processor designs to business partners, including a majority
of the world’s leading semiconductor companies. Based on the ARM low-cost and power-
efficient processor designs, these partners create their processors, micro controllers, and
system-on-chip solutions. This business model is commonly called intellectual property (IP)
licensing.
Architecture versions
Over the years, ARM has continued to develop new processors and system blocks.
These include the popular ARM7TDMI processor and, more recently, the ARM1176TZ (F)-S
processor, which is used in high-end applications such as smart phones. The evolution of
features and enhancements to the processors over time has led to successive versions of the
ARM architecture. Note that architecture version numbers are independent from processor
names. For example, the ARM7TDMI processor is based on the ARMv4T architecture (the T
is for Thumb instruction mode support).
The ARMv5E architecture was introduced with the ARM9E processor families,
including the ARM926E -S and ARM946E -S processors. This architecture added “Enhanced”
Digital Signal Processing (DSP) instructions for multimedia applications. With the arrival of
the ARM11 processor family, the architecture was extended to the ARMv6. New features in
this architecture included memory system features and Single Instruction–Multiple Data
(SIMD) instructions. Processors based on the ARMv6 architecture include the ARM1136J (F)-
S, the ARM1156T2 (F)-S, and the ARM1176JZ (F)-S.
Over the past several years, ARM extended its product portfolio by diversifying its CPU
development, which resulted in the architecture version 7 or v7. In this version, the
architecture design is divided into three profiles:
Enhancement and extension of instruction sets used by the ARM processors has been
one of the key driving forces of the architecture’s evolution. Historically (since ARM7TDMI),
two different instruction sets are supported on the ARM processor: the ARM instructions that
are 32 bits and Thumb instructions that are 16 bits. During program execution, the processor
can be dynamically switched between the ARM state and the Thumb state to use either one of
the instruction sets. The Thumb instruction set provides only a subset of the ARM instructions,
but it can provide higher code density. It is useful for products with tight memory
requirements.
The Thumb-2 Technology and Instruction Set Architecture
The Thumb- 2 technology extended the Thumb Instruction Set Architecture (ISA) into
a highly efficient and powerful instruction set that delivers significant benefits in terms of ease
of use, code size, and performance. The extended instruction set in Thumb-2 is a super set of
the previous 16-bit Thumb instruction set, with additional 16-bit instructions alongside 32-bit
instructions. It allows more complex operations to be carried out in the Thumb state, thus
allowing higher efficiency by reducing the number of states switching between ARM state and
Thumb state.
Focused on small memory system devices such as micro controllers and reducing the
size of the processor, the Cortex-M3 supports only the Thumb-2 (and traditional Thumb)
instruction set. Instead of using ARM instructions for some operations, as in traditional
ARM processors, it uses the Thumb-2 instruction set for all operations. As a result, the
Cortex-M3 processor is not backward compatible with traditional ARM processors.
Nevertheless, the Cortex-M3 processor can execute almost all the 16-bit Thumb
instructions, including all 16-bit Thumb instructions supported on ARM7 family processors,
making application porting easy. With support for both 16-bit and 32-bit instructions in the
Thumb-2 instruction set, there is no need to switch the processor between Thumb state (16-bit
instructions) and ARM state (32-bit instructions). For example, in ARM7 or ARM9 family
processors, you might need to switch to ARM state if you want to carry out complex
calculations or a large number of conditional operations and good performance is needed,
whereas in the Cortex-M3 processor, you can mix 32-bit instructions with 16-bit instructions
without switching state, getting high code density and high performance with no extra
complexity.
The Thumb-2 instruction set is a very important feature of the ARMv7 architecture.
Compared with the instructions supported on ARM7 family processors (ARMv4T
architecture), the Cortex-M3 processor instruction set has a large number of new features. For
the first time, hardware divide instruction is available on an ARM processor, and a number of
multiply instructions are also available on the Cortex-M3 processor to improve data-crunching
performance. The Cortex-M3 processor also supports unaligned data accesses, a feature
previously available only in high-end processors.
Low-cost micro controllers: The Cortex-M3 processor is ideally suited for low-cost micro
controllers, which are commonly used in consumer products, from toys to electrical
appliances. It is a highly competitive market due to the many well-known 8-bit and 16-bit
micro controller products on the market. Its lower power, high performance, and ease-of- use
advantages enable embedded developers to migrate to 32-bit systems and develop products
with the ARM architecture.
Automotive: Another ideal application for the Cortex-M3 processor is in the automotive
industry. The Cortex-M3 processor has very high-performance efficiency and low interrupt
latency, allowing it to be used in real-time systems. The Cortex-M3 processor supports up to
240 external vectored interrupts, with a built-in interrupt controller with nested interrupt
supports and an optional MPU, making it ideal for highly integrated and cost-sensitive
automotive applications.
Data communications: The processor’s low power and high efficiency, coupled with
instructions in Thumb-2 for bit-field manipulation, make the Cortex-M3 ideal for many
communications applications, such as Bluetooth and ZigBee.
Industrial control: In industrial control applications, simplicity, fast response, and reliability
are key factors. Again, the Cortex-M3 processors interrupt feature, low interrupt latency, and
enhanced fault-handling features make it a strong candidate in this area.
The Cortex-M3 processor is the central processing unit (CPU) of a micro controller
chip. In addition, numbers of other components are required for the whole Cortex-M3
processor-based micro controller. After chip manufacturers license the Cortex-M3 processor,
they can put the Cortex-M3 processor in their silicon designs, adding memory, peripherals,
input/output (I/O), and other features. Cortex-M3 processor-based chips from different
manufacturers will have different memory sizes, types, peripherals, and features.
CHAPTER 2
LPC-1768
The LPC-1768 is an ARM Cortex-M3 based microcontroller for embedded applications
featuring a high level of integration and low power consumption. The ARM Cortex-M3 is a
next generation core that offers system enhancements such as enhanced debug features and a
higher level of support block integration.
The LPC-1768 operate at CPU frequencies of up to 100 MHz. The LPC1768 operates
at CPU frequencies of up to 120 MHz. The ARM Cortex-M3 CPU incorporates a 3-stage
pipeline and uses a Harvard architecture with separate local instruction and data buses as well
as a third bus for peripherals. The ARM Cortex-M3CPU also includes an internal prefetch unit
that supports speculative branching.
Features:
Multilayer AHB matrixes interconnect provides a separate bus for each AHB
[Link] masters include the CPU, General Purpose DMA controller, Ethernet
MAC, and the USB interface. This interconnect provides communication with no
arbitration delays.
Split APB bus allows high throughput with few stalls between the CPU and
DMA. Serial interfaces:
Ethernet MAC with RMII interface and dedicated DMA controller.
USB 2.0 full-speed device/Host/OTG controller with dedicated DMA controller
and on-chip PHY for device, Host, and OTG functions.
Four UARTs with fractional baud rate generation, internal FIFO, and DMA
support.
One UART has modem control I/O and RS-485/EIA-485 support, and one UART
has IrDA support.
CAN 2.0B controller with two channels.
SPI controller with synchronous, serial, full duplex communication and
programmable data length.
Two SSP controllers with FIFO and multi-protocol capabilities. The SSP
interfaces can be used with the GPDMA controller.
Three enhanced I2C bus interfaces, one with an open-drain output supporting full
I2C specification and Fast mode plus with data rates of 1 Mbit/s, two with
standard port pins. Enhancements include multiple address recognition and
monitor mode.
I2S (Inter-IC Sound) interface for digital audio input or output, with fractional rate
control. The I2S-bus interface can be used with the GPDMA. The I2S-bus interface
Supports 3-wire and 4-wire data transmit and receive as well as master
clock input/output.
Other peripherals:
70 (100 pin package) General Purpose I/O (GPIO) pins with configurable pull-
up/down resistors. All GPIOs support a new, configurable open-drain operating
mode. The GPIO block is accessed through the AHB multilayer bus for fast
access and located in memory such that it supports Cortex-M3 bit banding and
use by the General Purpose DMA Controller.
12-bit Analog-to-Digital Converter (ADC) with input multiplexing among eight
pins, conversion rates up to 200 kHz, and multiple result registers. The 12-bit
ADC can be used with the GPDMA controller
10-bit Digital-to-Analog Converter (DAC) with dedicated conversion timer and
DMA support.
Four general purpose timers/counters, with a total of eight capture inputs and ten
compare outputs. Each timer block has an external count input. Specific timer
events can be selected to generate DMA requests
One motor control PWM with support for three-phase motor control
Quadrature encoder interface that can monitor one external quadrature encoder.
One standard PWM/timer block with external count input.
RTC with a separate power domain and dedicated RTC oscillator. The RTC block
Department of Electronics and Communication Engineering, BIT Page 8
Embedded Systems - 18ECL66
Chapter 3
Hardware Configurations
LED Pin Configuration
LED D8 D7 D6 D5 D4 D3 D2 D1
LPC-1769 Port No P0-7 P0-6 P0-5 P0-4 P0-3 P0-2 P0-1 P0-0
D11, D12, D13 and D14 are Common Cathode segments connected to LPC-1768
device so that each segment is individually controlled by a general purpose I/O pin. When
the LPC-1768 device drives logic ‘0’ the corresponding segment turns on. See fig and table
for more details.
Seven Segment
DP F A B G C D E
Data Lines
LPC-1768
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
Port
that 32 output pins are needed in this case). The solution to this problem is called
MULTIPLEXING. This is how an optical illusion based on the same operating principle as a
film camera is made. Only one digit is active at a time, but they change their state so quickly
making impression that all digits of a number are simultaneously active Each digit can made
active using switching transistors Q1, Q2, Q3 and Q4 and these on switched on and off by
selection lines which are in turn connected to LPC-1768 ports. Table shows the details of seven
segment selection lines.
Seven Segment Selection table.
16 X 2 LCD Display
There are pins along one side of a small printed board. These are used for connecting
to the microcontroller. There are in total of 14 pins marked with numbers (16 if it has
backlight). Their function is described in the table below:
DC (direct current) motor rotates continuously. It has two terminals positive and
negative. Connecting DC power supply to these terminals rotates motor in one direction
and reversing the polarity of the power supply reverses the direction of rotation.
The speed of Dc motor can maintained at a constant speed for a given load by using
“Pulse Width Modulation (PWM)” technique. By changing the width of the pulse of
applied to dc motor, the power applied is varied thereby DC motor speed can be increased
or decreased. Wider the pulse Faster is the Speed, Narrower is the Pulse, and Slower is the
Speed
U9 is L293 driver IC used to drive the dc motor. It has enable lines which is used to
switch on the DC motor. It is connected to P4.28. Logic ‘1’ enables the driver and logic
‘0’ disables the driver.P4.28 and P4.29 are used for Motor 1 direction and speed control.
DC Motor Pin connection table.
A stepper motor is a special type of electric motor that moves in increments, or steps,
rather than turning smoothly as a conventional motor does. Typical increments are 0.9 or
1.8 degrees, with 400 or 200 increments thus representing a full circle. The speed of the
motor is determined by the time delay between each incremental movement.
Relay Configurations:
The hex keypad is a peripheral that is organized in rows and Columns. Hex key Pad 16 Keys
arranged in a 4 by 4 grid, labeled with the hexadecimal digits 0 to F. An example of this can
been seen in Figure 1, below. Internally, the structure of the hex keypad is very simple. Wires
run in vertical columns (we call them C0 to C3) and in horizontal rows (called R0 to R3).
These 8 wires are available externally, and will be connected to the lower 8 bits of the port.
Each key on the keypad is essentially a switch that connects a row wire to a column wire.
When a key is pressed, it makes an electrical connection between the row and column. Table
shows connections for HEX KEY Pad matrix.
HEX KEY Pad matrix table.
VT1768 3_3board provides eight individual KEYS connected to LPC-1768 device through
PORT1. S1 to S6,S11and S16 are connected to general purpose I/O pins on 2148 device as
shown in table. 2148 device port pin drives to Logic ‘0’ when the corresponding key is
pressed. Table shows connections for USER KEY Pad connection.
A speaker is a device which converts electrical signal to audible signal.J7 is a two pin
RMC where we are connecting external speaker. We drove it through Q5 which in turn
connected to P3.25 via Jumper [Link] need to send Logic ‘1’ to generate Tone.
Speaker /Buzzer pin connection Table.
1 P0.20
DAC:
Features
• 10-bit digital to analog converter
• Resistor string architecture
• Buffered output
• Selectable speed vs. power
• Maximum update rate of 1 MHZ.
As VTCM3_3 board comes with one DAC output for generation different wave
forms. AOUT (P0.26) is connected to TEST point TP1. The generated waveforms can be
viewed through TP1 (DAC) and TP2 (GND) by connecting CRO.
PWM:
Features
Counter or Timer operation (may use the peripheral clock or one of the capture inputs as
the clock source).
Seven match registers allow up to 6 single edge controlled or 3 double edge controlled
PWM outputs, or a mix of both types. The match registers also allow:
– Continuous operation with optional interrupt generation on match.
– Stop timer on match with optional interrupt generation.
– Reset timer on match with optional interrupt generation.
Supports single edge controlled and/or double edge controlled PWM outputs. Single edge
controlled PWM outputs all go high at the beginning of each cycle unless the output is a
constant low. Double edge controlled PWM outputs can have either edge occur at any
position within a cycle. This allows for both positive going and negative going pulses.
Pulse period and width can be any number of timer counts. This allows complete
flexibility in the trade-off between resolution and repetition rate. All PWM outputs will
occur at the same repetition rate.
Double edge controlled PWM outputs can be programmed to be either positive going or
negative going pulses.
Match register updates are synchronized with pulse outputs to prevent generation of
Erroneous pulses. Software must "release" new match values before they can
become effective.
May be used as a standard timer if the PWM mode is not enabled.
A 32-bit Timer/Counter with a programmable 32-bit pre scaler.
Two 32-bit capture channels take a snapshot of the timer value when an input signals
transitions. A capture event may also optionally generate an interrupt. As VTCM3_3
board comes with one DAC output for generation different wave forms. AOUT (P0.26) is
connected to TEST point TP1. The generated waveforms can be viewed through TP1
(DAC) and TP2 (GND) by connecting CRO.
As VTCM3_3 board comes with one PWM output for generation PWM wave forms.
AOUT (P0.26) is connected to TEST point TP1. The generated waveforms can be viewed
through TP1 (DAC) and TP2 (GND) by connecting CRO.
Chapter 4
Why Use KeilMDK ?MDK provides these features particularly suited for Cortex-M users:
Make sure that SystemInit() and System Core Clock Update() are included in the main program
Build go to Target1-option for Target 1
Select output -> select Create Hex File
*Project--- Build
CHAPTER 5
STEPS TO EXECUTE in KEIL µVISION 4 for Assembly programs
1 DOUBLE CLICK ON ICON µVISION 4 (on Desktop)
2 GO TO PROJECT AND CLOSE PROJECT
3 GO TO PROJECT NEW µVISION PROJECT
4 TYPE NAME OF PROJECT AND SAVE
SELECT DEVICE FOR TARGET √ NXP(FOUNDED BY PHILIPS) DOUBLE
5
CLICK√√ SELECT LPC1768 √ OK √
Dialog Box appears like COPY NXP LPC17xx Startup code to project folder and
6
Add file to project ?
7 If it is an ALP Program click NO
To create Target
a. RIGHT CLICK TARGET √ OPTIONS FOR TARGET √
8 b. TARGET √ Select CLK = 12MHZ
c. OUTPUT √ SELECT CREATE HEX FILE
d. LINKER√ SELECT USE MEMORY LAYOUT FROM TARGET DIALOG
e. DEBUG √ SIMULATOR √ OK
GO TO FILE √ NEW FILE √ SAVE AS √ PROJECT NAME .s (ex: prog1.s)
9
FOR ALP / PROJECT NAME .c (ex: prog1.c) FOR C PROGRAM
10 TYPE THE PROGRAM IN NEW FILE WINDOW SAVE THE PROGRAM
RIGHT CLICK ON SOURCE GROUP ADD SYSTEM_LPC17XX.c ( Local
11 Disk C: Keil ARM Startup NXP LPC17XX) & ABOVE SAVED PROGRAM TO
SOURCE GROUP
12 TO ASSEMBLE / COMPILE √ PROJECT √ BUILD TARGET (F7)
13 DEBUG CLICK START / STOP DEBUG SESSION EVALUATION MODEOK
14 RUN THE PROGRAM OR USE F1 KEY
15 FOR SINGLE STEP USE F11 KEY
16 CHECK THE RESULTS
PERIPHERALS √ GPIO FAST INTERFACE (SELECT REQUIRED
a. PORT) / GPIO FAST INTERRUPTS / CORE PERIPHERALSFOR
EXTERNAL INTERRUPT etc
b. VIEW LOGIC ANALYZER WINDOW FOR WAVEFORMS
c, VIEW SERIAL WINDOW √ UART #1 FOR MESSAGE DISPLAY.
VIEW DISASSEMBLY WINDOW FOR THE EQUIVALENT
d.
INSTRUCTION FOR C SYNTAX
VIEW PROJECT WINDOW FOR GENERAL PURPOSE REGISTER &
e.
STATUS REGISTER CONTENTS
CYCLE-I
Experiment -1
ALP to multiply two 16 bit binary numbers.
AREA RESET, DATA, READONLY ; Reset region
DCD 0X20001000 ; stack pointer value when stack is empty
DCD START
RESULTS:
Memory Location before execution and after execution
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -2
ALP to find the sum of first 10 integer numbers.
AREA RESET, DATA, READONLY
DCD 0x20001000
DCD START
AREA MY_CODE, CODE, READONLY
ENTRY
START
MOV R2, #10
MOV R1, #0
LOOP ADD R1, R2
SUBS R2, #1
BNE LOOP
STOP B STOP
END
RESULTS:
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -3
ALP to find the number of O's and l's in a 32 bit data.
AREA RESET, DATA, READONLY
DCD 0X20001000
DCD START
AREA MY_CODE, CODE, READONLY
ENTRY
START
LDR R2, DATA1
LDR R0, [R2]
MOV R1, #32
MOV R2, #00 ; No of One's
MOV R3, #00 ; No of Zero's
LOOP RORS R0, R0, #1
ADC R2, R2, #0
SUBS R1, #1
BNE LOOP
MOV R1, #32
SUB R3, R1, R2
STOP B STOP
DATA1 DCD 0X40000010
END
RESULTS:
REG Before execution and after execution
INPUT:
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -4
ALP to find determine whether the given 16 bit is even or odd.
AREA RESET, DATA, READONLY
DCD 0X20001000
DCD START
RESULTS:
REG Before execution and after execution
INPUT:
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -5
Write an ALP to store data in RAM.
RESULTS:
REG Before execution and after execution
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -6
Interface a Stepper motor and rotate it in clockwise and anti-clock wise
direction.
{
unsigned int j=0,i=0;
for(j=0;j<count;j++)
{
for(i=0;i<12000;i++);
}}
void motor_write( uint32_t data )
{
uint32_t temp;
temp = data & MOTOR_MASK;
MOTOR_CTRL_CLR = MOTOR_MASK;
MOTOR_CTRL_SET = temp;
}
int main (void)
{
unsigned int del=10;
uint32_t stpval=0x01;
unsigned char dir=0;
MOTOR_CTRL_DIR |= MOTOR_MASK;
KEY_DIR &= ~( KEY_CW | KEY_CCW); // Set these lines as Inputs
KEY_SET |= ( KEY_CW | KEY_CCW); // Pull-up
motor_write(stpval);
while(1)
{
if (!(KEY_PIN & KEY_CCW)) //CCW key pressed
dir = 0;
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the waveforms of Full step/ Half step/Wave sequence (Simulator)
3. Observe the clock and anti clock wise rotation of the digital stepper motor
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -7
Interface and Control the speed of a DC Motor.
/* DC MOTOR CONFIGURATION*/
{
uint32_t temp;
temp=(data << 28) & MOTOR_MASK;
MOTOR_CTRL_CLR |= MOTOR_MASK;
MOTOR_CTRL_SET |= temp;
}
MOTOR_CTRL_DIR |= MOTOR_MASK;
MOTOR_EN_DIR |= MTE;
MOTOR_EN_CLR = MTE; // switch OFF both Motors
KEY_DIR &= ~( KEY_CW | KEY_CCW); // Set these lines as Inputs
KEY_SET |= (KEY_CW | KEY_CCW); // Pull-up
motor_write(dir);
while(1)
{
if (!(KEY_PIN & KEY_CCW)) //CCW key pressed
{
dir = 0x01;
motor_write(dir);
}
if (!(KEY_PIN & KEY_CW)) //CW key pressed
{
dir = 0x02;
motor_write(dir);
}
count++;
if (count >= match)
MOTOR_EN_CLR = MTE; // switch OFF Motor
else
MOTOR_EN_SET = MTE; // switch ON Motor
if (count > 10) count=0;
}
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the clock and anti clock wise rotation of Dc motor
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -8
Demonstrate the use of External Interrupt to Toggle an LED ON/OFF.
/* EXTERNAL INTERRUPTCONFIGURATION*/
#include<LPC17xx.h>
#define PINSEL_EINT0 20
#define PINSEL_EINT1 22
#define LED1 (1<<4)
#define LED2 (1<<5)
#define SBIT_EINT0 0
#define SBIT_EINT1 1
#define SBIT_EXTMODE0 0
#define SBIT_EXTMODE1 1
#define SBIT_EXTPOLAR0 0
#define SBIT_EXTPOLAR1 1
void EINT0_IRQHandler(void)
{
LPC_SC->EXTINT=(1<<SBIT_EINT0);
LPC_GPIO0->FIOPIN^=LED1;
}
void EINT1_IRQHandler(void)
{
LPC_SC->EXTINT=(1<<SBIT_EINT1);
LPC_GPIO0->FIOPIN^=LED2;
}
int main()
{
LPC_SC->EXTINT=(1<<SBIT_EINT0)| (1<<SBIT_EINT1);
LPC_SC->EXTINT=(1<<SBIT_EXTMODE0)| (1<<SBIT_EXTMODE1);
LPC_PINCON->PINSEL4=(1<<PINSEL_EINT0)|(1<<PINSEL_EINT1);
LPC_GPIO0->FIODIR=(LED1|LED2);
LPC_GPIO0->FIOPIN=0x00;
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
while(1)
{
}
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the waveforms (Simulator) Record (PULSE)
3. Observe the LEDS on the Kit (Toggling)
4. Record the wave forms and observe the amplitude for the different interrupts
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -9
Display “HELLO WORLD” message using INTERNAL UART.
#include "LPC17xx.h"
#define OSC 12000000 /* oscillator frequency */
#define MASTER (OSC * 8) /* master clock frequency <= 100Mhz */
/* FOSC an integer multiple of */
#define PLL (MASTER * 3) /* PLL frequency (275Mhz to 550Mhz) */
/* Same as FCCLK, or which even multiples */
#define PCLK (MASTER / 4) /* peripheral clock frequency, FCCLK 1/2, 1/4*/
/* Or FCCLK, the same */
#define UART0_BAUDRATE 115200 /* Serial communication baud rate 9600 */
void UART0_Init (void)
/* UART0 configuration*/
{
unsigned int BAUDRATE;
LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */
LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0)*/
LPC_UART0->LCR = 0x83; /* Allows you to latch with settings */
BAUDRATE = (PCLK / 16) / UART0_BAUDRATE; /* set the baud rate */
LPC_UART0->DLM = BAUDRATE / 256;
LPC_UART0->DLL = BAUDRATE % 256;
LPC_UART0->LCR = 0x03; /* Allows you to delatch with settings */
LPC_UART0->FCR = 0x06;
}
/* check Line Control Register and Transmit Hold Register */
{
while (*s != 0)
UART0_SendByte(*s++);
}
/* UART Main program to display Message*/
int main(void)
{
SystemInit();
UART0_Init();
UART0_SendString("HELLO WORLD !!!");
}
RESULT
1. Check the Terminal Window
2. Check the UART 1 Serial Window
3. Check the THR and LCR registers contents(Simulation)
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -10
A) Interface A DAC and Generate Triangular Waveform.
/* DAC CONFIGURATION*/
#include<lpc17xx.h>
#define voltage 1023 //(10bit = 1024 max = 3.3v)
#define TIME 10
int main (void)
{
uint32_t i = 0;
uint32_t m;
LPC_PINCON->PINSEL1 |= (1<<21); //Select AOUT function for P0.26
while (1)
{
for (i = 0; i < voltage; i++)
{
LPC_DAC->DACR = (i << 6);
for (m = TIME; m > 1; m--);
}
{
LPC_DAC->DACR = (i << 6);
for (m = TIME; m > 1; m--);
}
}
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the waveforms (Simulator) Record (Amplitude, Delay)
3. Observe the waveform on Digital oscilloscope
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
/* DAC CONFIGURATION*/
#include<lpc17xx.h>
#define voltage 1024 //(10bit = 1024 max =
3.3v)
#define TIME 120
int main(void)
{ uint32_t i, m;
LPC_PINCON->PINSEL1|=(1<<21);
while(1)
{
for(i = 0; i < voltage; i++)
{
LPC_DAC->DACR = (voltage/2 << 6);// load the data of 10 bit starting
for(m = TIME; m > 1; m--); // from 6th bit of DACR Register
}
{
LPC_DAC->DACR = (voltage<< 6);
for(m = TIME; m > 1; m--);
}
}
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the waveforms (Simulator) Record (Amplitude, Delay)
3. Observe the waveform on Digital oscilloscope
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -11
Interface a 4X4 Keyboard and display the key code on an LCD.
//GLCD-DATA(J5)->P2_0-7(J25)
//HEX KEYS(J14)->P1_16-23(J21)
#include<LPC17xx.h>
#include "lcdint.h"
#define COL1 (1<<16)
#define COL2 (1<<17)
#define COL3 (1<<18)
#define COL4 (1<<19)
#define ROW1 (1<<20)
#define ROW2 (1<<21)
#define ROW3 (1<<22)
#define ROW4 (1<<23)
#define COLMASK (COL1|COL2|COL3|COL4)
#define ROWMASK (ROW1|ROW2|ROW3|ROW4)
#define KEY_DIR LPC_GPIO1->FIODIR
#define KEY_SET LPC_GPIO1->FIOSET
#define KEY_CLR LPC_GPIO1->FIOCLR
#define KEY_PIN LPC_GPIO1->FIOPIN
void col_write(unsigned char data)
{
unsigned int temp=0;
temp=(data<<16)& COLMASK;
KEY_CLR|=COLMASK;
KEY_SET|=temp;
}
int main(void)
{
unsigned char key,i;
unsigned char rval[ ]={0x7,0xB,0xD,0XE,0X0};
unsigned char KeyPadMatrix[ ]=
{
'C','8','4','0',
'D','9','5','1',
'E','A','6','2',
'F','B','7','3'
};
init_lcd();
KEY_DIR |=COLMASK;
KEY_DIR &=~(ROWMASK);
lcd_putstring16(0,"press hex keys");
lcd_putstring16(1,"key pressed=");
while(1)
{
key=0;
for(i=0;i<4;i++)
{
col_write(rval[i]);
if(!(KEY_PIN & ROW1))
break;
key++;
if(!(KEY_PIN & ROW2))
break;
key++;
if(!(KEY_PIN & ROW3))
break;
key++;
if(!(KEY_PIN & ROW4))
break;
key++;
}
if(key==0x10)
lcd_putstring16(1,"key pressed=");
else
{
lcd_gotoxy(1,14);
lcd_putchar(KeyPadMatrix[key]);
}
}
}
RESULT
1. Observe the Keycode ON LCD SCREEN for the KEY pressed
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -12
Display the HEX Digits 0 to F on a 7-segment LED interface, with an
appropriate delay in between.
#include<LPC17xx.H>
// DATA CODED IN THE FORMAT [DP,F,A,B,G,C,D,E]
//* LOOK UP TABLE FOR THE DIGITS FROM 0 TO F*//
unsigned char data7[] =
{0x88,0xEB,0xC4,0xC1,0xA3,0x91,0x90,0xCB,0x80,0x81,0x82,0xB0,0x9C,0xE0,0x94,0x96
};
//* MAIN PROGRAM*/
int main(void)
{
unsigned int i,j;
unsigned char count=0;
LPC_GPIO2->FIODIR=0x000000FF;
while(1)
{
for (i=0; i<5000;i++)
{
}
++count;
}
}
RESULT
1. Observe the LED ON 7 SEGMENT DISPLAY
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
Experiment -13
Measure ambient Temperature using a sensor and SPI ADC IC.
//GLCD-DATA(J5)->P2_0-7(J25)
//ADC_TEMP(J29)->P0_8-18(J20)
SPI_Init();
init_lcd();
while(1)
{
SPI_EnableChipSelect();
delay(1);
SPI_Write(0x01);
msb = SPI_Write(0xA0); // SGL=1, ODD=0, MSBF=1
lsb = SPI_Write(0x00);
SPI_DisableChipSelect();
msb &= 0x0F;
ADCValue = (msb << 8) | lsb;
delay(500);
}
}
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
ADDITIONAL EXPERIMENTS
1. Blinking the LED connected to PORT PIN P0.4.
#include<LPC17xx.H>
void delay (unsigned long int x);
int main()
{
SystemInit();
LPC_PINCON->PINSEL0=0X00000000;
LPC_GPIO0->FIODIR=0XFFFFFFFF;
while(1)
{
LPC_GPIO0->FIOSET=0X00000010;
delay(0X500000);
LPC_GPIO0->FIOCLR=0X00000010;
delay(0X500000);
}
}
void delay(unsigned long int x)
{
unsigned long int i=0;
for(i=0;i<x;i++);
}
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
ADDITIONAL EXPERIMENTS
2. Interface a simple Switch and display its status through Relay, Buzzer
and LED
// ADC-DAC(J27)->P0_19-26(J22)
// KEYS(J15)->P1_16-23(J21)
// LED(J1->J17)
#include<LPC17xx.h>
#define key1 (1<<16) //p1.16
#define key2 (1<<17) //p1.17
#define key3 (1<<18) //p1.18
#define LED (1<<4) //p0.4
#define RELAY (1<<19) //p0.19
#define BUZZ (1<<20) //p0.20
int main(void)
{
LPC_GPIO0 -> FIODIR |= LED; //LED ON PORT0 O/P
LPC_GPIO0 -> FIOCLR = LED; //LED OFF
while(1)
{
if(!(KEY_PIN & key1))
LPC_GPIO0 -> FIOSET = LED;
else
LPC_GPIO0 -> FIOCLR = LED;
if(!(KEY_PIN & key2))
LPC_GPIO0 -> FIOSET = RELAY;
else
LPC_GPIO0 -> FIOCLR = RELAY;
if(!(KEY_PIN & key3))
LPC_GPIO0 -> FIOSET = BUZZ;
else
LPC_GPIO0 -> FIOCLR = BUZZ;
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the GPIO output window
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
ADDITIONAL EXPERIMENTS
2. Using the Internal PWM module of ARM controller generate PWM and
vary its duty Cycle
#include <lpc17xx.h>
#define SBIT_CNTEN 0
#define SBIT_PWMEN 2
#define SBIT_PWMMR0R 1
#define SBIT_LEN3 3
#define SBIT_PWMENA3 11
#define PWM_3 20
void delay_ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<50000;j++);
}
int main(void)
{
int dutyCycle;
LPC_PINCON->PINSEL7 = (3<<PWM_3);
LPC_PWM1->TCR = (1<<SBIT_CNTEN) | (1<<SBIT_PWMEN);
LPC_PWM1->PR = 0x0;
LPC_PWM1->MCR = (1<<SBIT_PWMMR0R);
LPC_PWM1->MR0 = 100;
LPC_PWM1->MR3 = 50;
LPC_PWM1->PCR = 1<<SBIT_PWMENA3;
while(1)
{
for(dutyCycle=0; dutyCycle<100; dutyCycle+=1)
{
LPC_PWM1->MR3 = dutyCycle;
LPC_PWM1->LER = 1<<SBIT_LEN3;
delay_ms(5);
}
RESULT
1. Observe the ports on logic analyzer (Simulator)
2. Observe the waveforms (Simulator) Record (PULSE WIDTH)
3. Observe the waveform on Digital oscilloscope
Evaluation of Experiment:
Design
Viva Voce – 05M Conduction – 10M Record – 10M
(Observation Book) – 05M
Faculty Signature:
APPENDIX A
APPENDIX B
LAYOUT OF ARM CORTEX M3 LPC 1768
APPENDIX C
APPENDIX D
JUMPER DETAILS
References:
[1]. UM10360 LPC17XX USER MANUAL REV 4-23 APRIL 2012
[2]. [Link]
[3]. [Link]
[4]. [Link]
[5]. Assembly language Programming ARM Cortex-M3 – Vincent Mahout