Microcontroller Lab Manual
Microcontroller Lab Manual
Introduction to ARM7
LPC2148 Microcontroller
ARM-Advanced RISC Machine is a 32-bit RISC (Reduced Instruction Set Computer) processor
architecture developed by ARM Holdings.
ARM7 is most successful and widely used processor family in embedded system applications.
LPC2148 is manufactured by NXP Semiconductor (Phillips) and it is preloaded with many
in-built features and peripherals. This makes it more efficient and reliable choice for an high-end
application developer.
It’s more important to have basic knowledge of pin configuration, memory, IO ports and basic
registers.
MEMORY:
LPC2148 has 32kB on chip SRAM and 512kB on chip FLASH memory. This chip has built in
support up to 2kB end point USB RAM. This memory is more than enough for almost all
applications.
LPC2148 has two IO ports each of 32-bit wide, provided by 64 IO pins. Ports are named as P0 and
P1. 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.
REGISTERS FOR C PROGRAMMING
IOSEL0
Port 0 has 32 pins (P0.0 to P0.31). Each pin can have multiple functions. On RESET, all pins are
configured as GPIO pins. However we can re-configure using the registers IOSEL0 and IOSEL1.
IOSEL0 is used to select function of P0.0 to P0.15. Each pin has up to 4 functions so 2 bits/pin
in IOSEL0 is provided for selecting function.
01 Function 1
10 Function 2
11 Function 3
IOSEL1
IOSEL1 is used to select function of Pins P0.16 to P0.31
IOSEL2
IOSEL2 is used to select function of Pins P1.16 to P1.31
IO0DIR
IO0DIR is used to configure pins of Port 0-P0 as input or output pins.
1= Output Pin
0= Input Pin
Example: IO0DIR=0x0000FFFF means P0.0 to P0.15 are configured as output pins and P0.16 to
P0.31 are configured as input pins.
To program microcontroller we will be using MDK-ARM Keil µVision4 IDE and Flash Magic
Tool. Keil MDK is the complete software development environment for a range of Arm Cortex-
M based microcontroller devices. MDK includes Keil Studio, the µVision IDE,
and debugger, Arm C/C++ compiler, and essential middleware components. It supports all silicon
vendors with more than 10,000 devices and is easy to learn and use.
Keil has Lite or Evaluation edition which limits the code size of 32kB. This could be more than
enough for our projects. Flash Magic is utility, we’ll use this to load hex file into flash memory of
LPC2148 microcontroller. We also need hardware’s i.e. microcontroller evaluation board to run
and test Hardware interface code.
STEP 2
STEP 3
Next step is to run setup file MDK474.EXE and then we’ll get pop-up box, hit on Next and
Proceed Installation.
STEP 4
Read license agreement, check I agree to all the terms…., and click Next.
STEP 5
Select Destination folder where you want to install Keil or default destination is already there.
And hit on Next.
STEP 6
Fill up required fields with all relevant information and click on Next.
STEP 7
STEP 8
Tick on show release notes, deselect remaining (as per your choice) and click on Finish.
Here is simple guide to start working with Keil µVision which can be used for:
c) Debugging programs
Here is step by step guide to create fresh new project for ARM7 LPC2148 Microcontroller
using MDK-ARM µVision4.
1. Once we’ve installed Keil, click on Keil µVision4 icon. This will appear on desktop after
installation Keil.
5. Expand NXP icon and select specific chip i.e. LPC2148 After this, a dialog box will pop-up
on screen. This will ask you whether to copy startup code for LPC2148. Click on Yes.
6. Then we’ll get basic workplace to get start with writing code in. When we expand Target1 in
left project pane. We see Startup.s is already added which is necessary for running code in
Keil.
d. Copies the exception vectors from ROM and RAM for systems with memory remapping
16. To run the program in keil software,click on debug button to enter into Debug mode.
The debugger provides a number of features that help us to follow the execution of a program.It
allow us to examine what effect each instruction has on the processor’s registers.
b) Inspect the values in the processor’s registers and memory to see how they have changed after
each instruction.
17. For Hardware implementation we need to Setup Flash Magic and load HEX file into
LPC2148 Microcontroller.
1.
LAB PROGRAMS
1) Using Keil software, observe the various Registers, Dump, CPSR, with a simple
Assembly Language Programs (ALP).
OUTPUT
2. Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
(a) ALP for Data Transfer operations
AREA register, CODE, READONLY
ENTRY
MOV R0,#0X0034 ;Move immediate number to R0
MOV R1,R0 ;Move R1<--R0
MOV R2,R1,LSL#2 ;R2 = 4*R1
MOVS R3, R1, LSR #1 ;R2 = 2*R1
LDR R4,=DATA ; load address of number into R4
LDR R5,[R4] ;load First word from DATA address to R5
LDRH R6, [R4,#2] ;load second word from DATA address to R6
LDRH R7, [R4,#4] ;load third word from DATA address to R7
MRS R8,cpsr ;Move status register content to R8
STOP B STOP
DATA DCW 0X1234,0x6789,0xF7A4 ; Declaration of no’s in the memory
END
Output:
Output:
OUTPUT:
Output:
AREA LARGE,CODE,READONLY
ENTRY
MOV R5,#5 ;R5 = length of array - 1
LDR R1,=ARRAY ;load starting addressing of array
LDR R2,[R1],#4 ;load 1st element of array
LOOP LDR R4,[R1],#4 ;load next element of array
CMP R2,R4 ;compare 1st and 2nd element
BHI NEXT
MOV R2,R4 ;R2=largest value
NEXT SUBS R5,R5,#1 ;decrement the counter after every comparison
BNE LOOP ; repeat until R5=0
STOP B STOP
ARRAY DCD 0X23,0X45,0XFF,0X76,0X12,0X99
END
OUTPUT:
6 .Develop an ALP to count the number of ones and zeros in two consecutive memory
locations.
OUTPUT:
7 Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.
#include <lpc214x.h>
int main(void)
{
volatile int i, j, temp;
int arr[ ] = {4,1,3,5,2}; //the array to be sort
//bubble sort
for (i = 1; i < 5; i++)
{
for (j = 0; j < 5 - i; j++)
{
if (arr[j] > arr[j + 1]) //Compares first and second element of the array
{
temp = arr[j]; // If first element is greater, swap the elements of the array
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
while(1);
}
Output:
#include <lpc214x.h>
int main()
{
volatile int n, I,fact =1;
n=5; //initialize the number
while(1);
}
OUTPUT:
#include <lpc214x.h>
int main(void)
{
volatile int i;
OUTPUT:
Input sting: Translated String:
#include <lpc214x.h>
void initClocks(void);
void initTimer0(void);
__irq void timer0ISR(void);
int main(void)
{
initClocks(); // Initialize PLL to setup clocks
initTimer0(); // Initialize Timer0
IO0DIR = (1<<10); // Configure pin P0.10 as Output
IO0PIN = (1<<10);
Output:
VIVA QUESTIONS
a) True
b) False ANS:-B
28. Which error occurs when the receiver can’t process the character?
a) Overrun error
b) Underrun error
c) Framing error
d) Break condition ANS:- A
29. What is the speed of the 8250 UART?
a) 4800bits/sec
b) 1200bits/sec
c) 12000bit/sec
d) 9600bits/sec ANS:- D
30. Which error occurs when UART transmitter has completed sending a
character and the transmit buffer is empty?
a) Overrun error
b) Underrun error
c) Framing error
d) Break condition ANS:- B
31. Which error occurs when the designated start and stop bits are not found?
a) Overrun error
b) Underrun error
c) Framing error
d) Break condition ANS:-C
32. Secure digital card application uses which protocol?
a) UART
b) SPI
c) I2C
d) USART ANS:- B
33. SPI device communicates in
a) Simplex
b) Half duplex
c) Full duplex
d) Both half and full duplex ANS:- C
34. Do SPI have/has a single master?
a) True
b) False ANS:- A
35. SPI is described as Asynchronous serial interface.
a) True
b) False ANS:- B
36. How many logic signals are there in SPI?
a) 5 signals
b) 6 signals
c) 4 signals
d) 7 signals ANS:-A
37. SPI uses how many lines?
a) 4 lines
b) 1 line
c) 3 lines
d) 2 lines ANS:- D
38. The main importance of ARM micro-processors is providing operation with
(a) Low cost and low power consumption
(b) Higher degree of multi-tasking
(c) Lower error or glitches
(d) Efficient memory management ANS:-A
39. ARM processors where basically designed for
(a) Main frame systems
(b) Distributed systems
(c) Mobile systems
(d) Super computers ANS:-C
40. The ARM processors doesn’t support Byte address ability ?
(a) True
(b) False ANS:-B
41. The address space in ARM is
(a) 2^24
(b) 2^64
(c) 2^16
(d) 2^32 ANS:-D
(a) Copied-registers
(b) Banked registers
(c) EXtra registers
(d) Extential registers ANS:-B
47. The banked registers are used for
(a) Switching between supervisor and interrupt mode
(b) Extended storing
(c) Same as other general purpose registers
(d) None of the mentioned ANS:- A
48. Each instruction in ARM machines is encoded into Word.
(a) 2 byte
(b) 3 byte
(c) 4 byte
(d) 8 byte ANS:-C
49. All instructions in ARM are conditionally executed.
(a) True
(b) False ANS:-A
50. Thumb-2 technology is implemented in which of the following?
(a) All ARM processors
(b) All ARMv7 processors
(c) ARMv7-A processors only
(d) ARMv7-A and ARMv7-R but not ARMv7-M ANS:-B
51. The ARM processor registers R13, R14, and R15 are architecturally used for
special purposes.
Which is the correct respective sequence of special purpose registers?
(a) PC, LR, SP
(b) LR, PC, SP
(c) SP, LR, PC
64. Which types of an embedded systems involve the coding at a simple level in an
embedded 'C', without any necessity of RTOS?
a. Small Scale Embedded Systems
b. Medium Scale Embedded Systems
c. Sophisticated Embedded Systems
d. All of the above ANS:-A
65. What is/are the configuration status of control unit in RISC Processors?
a. Hardwired
b. Microprogrammed
c. Both a and b
d. None of the above ANS:-A
66. How is the nature of instruction size in CISC processors?
a. Fixed
b. Variable
c. Both a and b
d. None of the above ANS:-B