Professional Documents
Culture Documents
Arm
Arm
DEPARTMENT OF ECE
LAB MANUAL
DEPARTMENT OF ECE
PART 1
KARTHIK S
KARTHIK S AEC
ANNA UNIVERSITY CHENNAI
Regulation 2013
SYLLABUS
LIST OF EXPERIMENTS
7. Mailbox.
9. Flashing of LEDS.
TOTAL: 45 Periods
INDEX
Page
S.no Date Name of the Experiment Marks Signature
no
7 Mailbox
9 Flashing of LEDS
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:
T: THUMB;
D for on-chip Debug support, enabling the processor to halt in response to a debug
request,
S: Synthesizable
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
LPC 2148:
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
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
IODIR
IOSET
IOCLR
IOPIN
PINSEL
IODIR:
IOPIN:
IOSET:
IOCLR:
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)
The following table shows the PINSEL0 and corresponding functions on the PORT0.
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
Example 1: Set the pin number 3 of port 0 as output pin (P0.3 -> Output)
Pin number
Value
Port number
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);
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);
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
P0.13
ARM 7 TDMI
LPC 2148
Program:
# include<LPC214x.H> Library
PINSEL0 |= 0x00000000;
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
P0.13
ARM 7 TDMI
LPC 2148
P1.17
Program:
# include<LPC214x.H>
IO0DIR |= (1<<13);
while (1)
IO0SET |= (1<<13);
else
IO0CLR |= (1<<13);
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
Program: #
include
<LPC214x.H>
{
PINSEL1 |= 0X00000000;
IO0DIR |= 0X00FF0000;
while (1)
IO0SET |= 0X00FF0000;
for(delay=0;delay<500000;delay++);
IO0CLR |= 0X00FF0000;
for(delay=0;delay<500000;delay++);}}
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
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
RS 0 1
R/W 0 0
Program:
Definitions:
#include <LPC214x.h>
Main Functions:
void gpio_init();
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;
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);
{
IO1PIN = (val<<16)
IOOSET = LCD_RS;
IO0CLR = LCD_RW;
IO0SET = LCD_EN;
delay (50);
IO0CLR = LCD_EN;
delay(5000000);
{
unsigned int j;
for (j=0;j<value;j++);
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
Program:
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
#include <lpc214x.h>
void gpio_init();
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;
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
unsigned int k;
for(k=0;k<value;k++);
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
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.
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,
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.
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
6-Single edged or
3-Double edged.
PWM REGISTERS
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
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
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
A system that generates a clock signal with reference to an input signal generally
from a crystal oscillator.
PLL in LPC2148:
PLL0 PLL 1
Input clock to both the PLLs must be between 10 MHz to 25 MHz strictly.
Basics:
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
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:
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
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:
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
* 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.
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
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.
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
PROGRAM:
#include<lpc214x.h>
Void main ()
{
PINSEL1 |= 0x01000000;
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)
Do
I = AD0CDR;
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
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.
e.g. if we set VALUE = 512, then, we can get analog voltage on AOUT pin as
((512/1024) * VREF) = VREF/2.
This is Analog Output pin of LPC2148 DAC peripheral where we can get Analog output
voltage from digital value.
These are the power and ground pins for DAC. These should be same as VDD& VSS.
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
Now write 10-bit value (which we want to convert into analog form) in VALUE field of
DACR Register.
EXAMPLE:
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 */
uint16_t value;
uint8_t i;
i = 0;
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)
while(i !=42)
value = sin_wave[i];
delay_ms(1);
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
i++;
i = 0;
value = 0;
value++;
while ( value != 0 )
value--;
value = 0;
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
value++;
value = 1023;
delay_ms(100);
value = 0;
delay_ms(100);
value = 1023;
KARTHIK S AEC
ARM® ARCHITECTURE AND PROGRAMMING GUIDE
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
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>
while (1)
{
}
}
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