AMRITA SCHOOL OF ENGINEERING, BENGALURU
DEPARTMENT OF ELECTRONICS & COMMUNICATION
ENGINEERING
B. TECH. IV SEMESTER AY 2024-2025
23ECE211 MICROCONTROLLER AND INTERFACING
ASSIGNMENT
JANUARY TO APRIL 2025
Submitted by
REGISTRATION NAME SIGNATURE WITH
NUMBER DATE
BL.EN.U4ECE23020 K VENKATA
KARTHIK
FACULTY EXAMINER SIGNATURE WITH EVALUATION DATE:
COMMENTS (IF ANY):
Page 1 of 32
Question Number: 1
Question: Write an assembly language program to generate first ten numbers
of Fibonacci series. Assume the numbers are stored in memory and store the
result into the memory.
Tool Used: Keil uVision4
Program:
AREA FIBO, CODE, READONLY
ENTRY
MOV R0, #0
MOV R1, #1
MOV R2, #0x40000000
MOV R4, #10
STR R0, [R2], #4
STR R1, [R2], #4
SUB R4, R4, #2
LOOP
ADD R3, R0, R1
STR R3, [R2], #4
MOV R0, R1
MOV R1, R3
SUBS R4, R4, #1
BNE LOOP
STOP B STOP
END
Screenshot of the program from the tool:
Page 2 of 32
Screenshot of the output from the tool:
Conclusion:
In this assembly language program, we successfully generated the first ten numbers of the
Fibonacci series using ARM7 (LPC2148) instructions. The program stores each
Fibonacci number sequentially in memory starting from address 0x40000000.
References:
1. LPC2148 User Manual – NXP Semiconductors
2. ARM7TDMI-S Technical Reference Manual – ARM Limited
Question number: 2
Question: Write an assembly language program to arrange an array of eight 32-bit
numbers stored in memory location in ascending order. Assume the numbers are stored in
memory and store the result into the memory.
Tool Used: Keil uVision4
Program:
AREA CODE, CODE, READONLY
ENTRY
LDR R0,=0x40000000
MOV R1,#8
MOV R2,#0
Outloop
CMP R2,R1
Page 3 of 32
BEQ STOP
MOV R3,#0
LDR R4,=0x40000000
Inloop
CMP R3,R1
SUB R5,R1,R2
SUBS R5,R5,#1
CMP R3,R5
BGE outincrement
LDR R6,[R4]
LDR R7,[R4,#4]
CMP R6,R7
BLE Noswap
STR R7,[R4]
STR R6,[R4,#4]
Noswap
ADD R4,R4,#4
ADD R3,R3,#1
B Inloop
outincrement
ADD R2,R2,#1
B Outloop
STOP
B STOP
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Page 4 of 32
Conclusion:
This Assembly Language program implements the bubble sort algorithm to arrange eight
32-bit integers in ascending order. It directly manipulates memory using load and store
instructions.
References:
1. ARM7TDMI Technical Reference Manual – ARM Ltd
2. LPC2148 User Manual – NXP
Question Number: 3
Question: Write an assembly language program to find the largest of six 32-bit numbers
stored in memory. Assume the numbers are stored in memory and store the result into the
memory.
Tool Used: Keil uVision4
Program:
AREA CODE, CODE, READONLY
ENTRY
LDR R0,=0x40000000
LDR R1,[R0]
MOV R2,#1
Loop
CMP R2,#6
BEQ Result
Page 5 of 32
ADD R3,R0,R2,LSL#2
LDR R4,[R3]
CMP R4,R1
MOVGT R1,R4
ADD R2,R2,#1
B Loop
Result
LDR R5,=0x40000018
STR R1,[R5]
End
B End
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Conclusion:
Page 6 of 32
This Assembly Language program effectively finds the maximum of six 32-bit integers
stored in memory by comparing each value with a running maximum. It uses basic load,
compare, conditional move, and store operations to perform the task in a memory-
efficient manner.
References:
1. ARM7TDMI-S Technical Reference Manual – ARM Ltd
2. LPC2148 User Manual – NXP
Question Number: 4
Question: Write an assembly language program to find factorial of a number stored in
memory. Assume the numbers are stored in memory and store the result into the memory.
Tool Used: Keil uVision4
Program:
AREA CODE, CODE, READONLY
ENTRY
LDR R0, =0x40000000
LDR R1, [R0]
MOV R2, #1
MOV R3, R1
CMP R3, #0
BEQ Result
Loop
MOV R5, R2
MUL R2, R5, R3
SUB R3, R3, #1
CMP R3, #1
BGT Loop
Result
LDR R4, =0x40000004
STR R2, [R4]
End
B End
END
Screenshot of the program from the tool:
Page 7 of 32
Screenshot of the output from the tool:
Conclusion:
This program uses a loop and the MUL instruction to compute the factorial of a number.
References:
1. LPC2148 User Manual – NXP
2. ARM7TDMI-S Reference Manual – ARM Ltd
Question Number: 5
Page 8 of 32
Question: Write an assembly language program to exchange the two set of arrays of
data blocks with five 32-bit numbers in each data block stored in memory. Assume the
numbers are stored in memory and store the result into the memory.
Tool Used: Keil uVision4
Program:
AREA EXCHANGE_ARRAYS, CODE, READONLY
ENTRY
LDR R0, =0x40000000
LDR R1, =0x40000014
MOV R2, #0
LOOP
CMP R2, #5
BGE DONE
MOV R3, R2
LSL R3, R3, #2
ADD R4, R0, R3
ADD R5, R1, R3
LDR R6, [R4]
LDR R7, [R5]
STR R7, [R4]
STR R6, [R5]
ADD R2, R2, #1
B LOOP
DONE
B DONE
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Page 9 of 32
Conclusion:
This program demonstrates how to swap two blocks of data in memory using load (LDR)
and store (STR) instructions, and a simple loop.
References:
1. ARM7TDMI-S Technical Reference Manual
2. LPC2148 User Manual – NXP
Question Number: 6
Question: Write an assembly language program to perform division by successive
subtraction. Assume the numbers are stored in memory and store the result into the
memory. Assume the numbers are stored in memory and store the result into the memory.
Tool Used: Keil uVision4
Program:
AREA DIVISION, CODE, READONLY
ENTRY
LDR R0, =0x40000000
LDR R1, [R0]
LDR R2, =0x40000004
LDR R3, [R2]
MOV R4, #0
MOV R5, R1
CMP R3, #0
Page 10 of 32
BEQ DIV_ZERO
DIV_LOOP
CMP R5, R3
BLT STORE_RESULT
SUB R5, R5, R3
ADD R4, R4, #1
B DIV_LOOP
STORE_RESULT
LDR R6, =0x40000008
STR R4, [R6]
LDR R7, =0x4000000C
STR R5, [R7]
DONE
B DONE
DIV_ZERO
MOV R4, #0
MOV R5, #0
B STORE_RESULT
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Page 11 of 32
Conclusion:
This program implements manual division using successive subtraction using Assembly
Language Programming
References:
1. ARM7TDMI-S Technical Manual – ARM
2. NXP LPC2148 User Manual – For memory and I/O details
Question Number: 7
Question: Write an ALP to find the number of leading zeros in given 32-bit number
Tool Used: Keil uVision4
Program:
AREA LEADING_ZEROS, CODE, READONLY
ENTRY
LDR R0, =0x40000000
LDR R1, [R0]
MOV R2, #0
MOV R3, #0x80000000
CHECK_BIT
TST R1, R3
BNE STORE_RESULT
ADD R2, R2, #1
CMP R2, #32
BEQ STORE_RESULT
Page 12 of 32
LSR R3, R3, #1
B CHECK_BIT
STORE_RESULT
LDR R4, =0x40000004
STR R2, [R4]
DONE
B DONE
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Conclusion:
Page 13 of 32
This program manually counts the number of leading zeros in a 32-bit number using a
TST and shift-left approach.
References:
1. ARM7TDMI Technical Reference Manual
2. NXP LPC2148 User Manual
Question Number: 8
Question: Write an ALP to perform Multiplication of two 32-bit numbers using MULL
and UMULL instructions.
Tool Used: Keil uVision4
Program: A) For UMULL
AREA CODE, CODE, READONLY
ENTRY
START
LDR R0, =0x40000000
LDR R1, [R0]
LDR R2, [R0, #4]
UMULL R4, R5, R1, R2
STR R4, [R0, #8]
STR R5, [R0, #0x0C]
STOP B STOP
END
B) For SMULL
AREA CODE, CODE, READONLY
ENTRY
START
LDR R0, =0x40000000
LDR R1, [R0]
LDR R2, [R0, #4]
SMULL R4, R5, R1, R2
STR R4, [R0, #8]
STR R5, [R0, #0x0C]
STOP B STOP
END
Screenshot of the program from the tool:
Page 14 of 32
A) UMULL
B) SMULL
Screenshot of the output from the tool:
A) UMULL
B) SMULL
Page 15 of 32
Conclusion:
This program demonstrates 64-bit multiplication of 32-bit numbers using the SMULL
and UMULL instruction.
References:
1. ARM Architecture Reference Manual
2. UMULL / MULL instructions – ARM7TDMI
Question Number: 9
Question: Write an ALP to multiply the register content by a constant number 7 using
shift and add method.
Tool Used: Keil uVision4
Program:
AREA CODE,CODE,READONLY
ENTRY
LDR R0,=0x40000000
LDR R1,[R0]
MOV R2,R1,LSL#2
MOV R3,R1,LSL #1
ADD R4,R2,R3
ADD R4,R4,R1
LDR R0,=0x40000004
STR R4,[R0]
End
B End
Page 16 of 32
END
Screenshot of the program from the tool:
Screenshot of the output from the tool:
Conclusion:
This program multiplies a number by 7 using logical shifts and addition.
References:
1. ARM Architecture Reference Manual
2. Keil MDK-ARM IDE Help Documentation
Question Number: 10
Page 17 of 32
Question: Write a program to detect a button press and toggle an LED every time the
button is pressed.
Tool Used: Keil uVision4, Proteus
Program:
#include <LPC214x.h>
void delay_ms(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++)
for (j = 0; j < 6000; j++);
}
int main(void) {
int prev_state = 1;
int led_state = 0;
int current_state;
IO0DIR |= (1 << 0);
IO0DIR &= ~(1 << 1);
while (1) {
current_state = (IO0PIN & (1 << 1)) >> 1;
if (prev_state == 1 && current_state == 0) {
led_state = !led_state;
if (led_state)
IO0SET = (1 << 0);
else
IO0CLR = (1 << 0);
delay_ms(20);
}
prev_state = current_state;
}
}
Components Required:
LPC2138 Microcontroller
LED
Push Button
Resistors
Power Supply (3.3V)
Ground (GND)
Screenshot of the program from the tool:
Page 18 of 32
Screenshot of the circuit from the tool:
Screenshot of the output from the tool:
Page 19 of 32
Conclusion:
This project demonstrates how to use an LPC2138 ARM7 microcontroller to implement a
simple LED toggle system triggered by a push-button press.
References:
1. NXP Semiconductors – LPC2148 Data Sheet & User Manual
2. Keil MDK-ARM – Getting Started Guide
3. Proteus Design Suite – Official Documentation
Question Number: 11
Question: Write a program to interface a 16x2 character LCD display using GPIO pins
to show a message.
Tool Used: Keil uVision4, Proteus
Components Required:
LPC2138 Microcontroller (U1)
16x2 LCD Display (LCD1) - LM016L
Power Supply Rails
Connections between LCD and LPC2138
Program:
Page 20 of 32
#include <LPC214x.h>
#define RS (1 << 4)
#define EN (1 << 5)
#define D4 (1 << 6)
#define D5 (1 << 7)
#define D6 (1 << 8)
#define D7 (1 << 9)
void delay_ms(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++)
for (j = 0; j < 6000; j++);
}
void lcd_enable() {
IO0SET = EN;
delay_ms(2);
IO0CLR = EN;
}
void lcd_send_nibble(unsigned char data) {
IO0CLR = D4 | D5 | D6 | D7;
if (data & 0x01) IO0SET |= D4;
if (data & 0x02) IO0SET |= D5;
if (data & 0x04) IO0SET |= D6;
if (data & 0x08) IO0SET |= D7;
lcd_enable();
}
void lcd_send_cmd(unsigned char cmd) {
IO0CLR = RS;
lcd_send_nibble(cmd >> 4);
lcd_send_nibble(cmd & 0x0F);
delay_ms(2);
}
void lcd_send_data(unsigned char data) {
IO0SET = RS;
lcd_send_nibble(data >> 4);
lcd_send_nibble(data & 0x0F);
delay_ms(2);
}
void lcd_init() {
IO0DIR |= RS | EN | D4 | D5 | D6 | D7;
delay_ms(20);
lcd_send_cmd(0x02);
lcd_send_cmd(0x28);
lcd_send_cmd(0x0C);
lcd_send_cmd(0x06);
lcd_send_cmd(0x01);
Page 21 of 32
}
void lcd_send_string(const char *str) {
while (*str)
lcd_send_data(*str++);
}
int main(void) {
lcd_init();
lcd_send_string("Hello, YUVARAJ!");
while (1);
}
Screenshot of the program from the tool:
Screenshot of the circuit from the tool:
Screenshot of the output from the tool:
Page 22 of 32
Conclusion:
In this project, I successfully interfaced a 16x2 character LCD (LM016L) with the
LPC2138 ARM7 microcontroller using GPIO pins.
References:
1. LPC2148 Datasheet – NXP Semiconductors
2. Keil uVision IDE – ARM C compiler and debugger
3. LM016L LCD Datasheet – Hitachi 16x2 LCD module
Question Number: 12
Question: Generate a PWM signal with adjustable duty cycle to control the speed of a
DC motor. Use a potentiometer to adjust the duty cycle.
Tool Used: Keil uVision4, Proteus
Components Required:
LPC2138 Microcontroller (U1)
Power Supply Rails
L293D Module
DC Motor
Program:
#include <lpc214x.h>
Page 23 of 32
#define bit(x) (1 << (x))
#define delay for(i = 0; i <= 60000; i++)
unsigned int i;
int main() {
IO0DIR = 0xF; // Declaring P0.0 - P0.3 as output
IO0PIN = 0; // Clear all IO pins in P0
VPBDIV = 0x01; // PCLK = 60MHz
while (1) {
/* Forward */
IO0SET = bit(0); // IN1 = 1
IO0CLR = bit(1); // IN2 = 0
delay; delay;
/* Off */
IO0CLR = bit(0) | bit(1); // IN1 = IN2 = 0
delay; delay;
/* Reverse */
IO0SET = bit(1); // IN2 = 1
IO0CLR = bit(0); // IN1 = 0
delay; delay;
/* Off */
IO0CLR = bit(0) | bit(1); // IN1 = IN2 = 0
delay; delay;
}
}
Screenshot of the program from the tool:
Screenshot of the circuit from the tool:
Page 24 of 32
Screenshot of the output from the tool:
Page 25 of 32
Conclusion: In this project, I successfully generated a PWM signal using the LPC2138
ARM7 microcontroller to control the speed of a DC motor.
References:
1. LPC2148 Datasheet – NXP Semiconductors
2. Keil uVision IDE – ARM C compiler and debugger
Question Number: 13
Question: Implement a real-time clock (RTC) using the LPC2148. The program should
output the current time in hours, minutes, and seconds format on a serial terminal or
display it on an LCD screen.
Tool Used: Keil uVision4, Proteus
Components Required:
LPC2138 Microcontroller (U1)
Power Supply Rails
LCD Display
Program:
#include <LPC214X.H>
#include "LCD.h"
void RTC_Init(void);
void Display_Time(void);
unsigned int hour, min, sec;
int main(void) {
LCD_Init(); // Initialize LCD
RTC_Init(); // Initialize RTC
LCD_Cmd(0x80); // Set cursor to first line
LCD_Write_Text("Time:");
while (1) {
Display_Time();
}
}
// RTC Initialization
void RTC_Init(void) {
CCR = 0x02; // Reset RTC
SEC = 0;
MIN = 0;
Page 26 of 32
HOUR = 12; // Set initial time to 12:00:00
CCR = 0x01; // Enable RTC
}
// Display current time on LCD
void Display_Time(void) {
hour = HOUR;
min = MIN;
sec = SEC;
LCD_Cmd(0xC0); // Move to second line
LCD_Write(hour / 10 + '0');
LCD_Write(hour % 10 + '0');
LCD_Write(':');
LCD_Write(min / 10 + '0');
LCD_Write(min % 10 + '0');
LCD_Write(':');
LCD_Write(sec / 10 + '0');
LCD_Write(sec % 10 + '0');
Delay_ms(500);
}
Screenshot of the program from the tool:
Page 27 of 32
Screenshot of the circuit from the tool:
Screenshot of the output from the tool:
Page 28 of 32
Conclusion:
In this project, I successfully implemented a real-time clock (RTC) using the LPC2148
ARM7 microcontroller to display the current time in hours, minutes, and seconds format
on a 16x2 LCD screen.
References:
1. LPC2148 Datasheet – NXP Semiconductors
2. Keil uVision IDE – ARM C compiler and debugger
3. LM016L LCD Datasheet – Hitachi 16x2 LCD module
Question Number: 14
Question: Write a program to read the analog value from a temperature sensor (e.g.,
LM35) connected to the ADC pin of LPC2148.
Tool Used: Keil uVision4, Proteus
Components Required:
LPC2138 Microcontroller (U1)
16x2 LCD Display (LCD1) - LM016L
Power Supply Rails
Connections between LCD and LPC2138
Program:
#include <LPC213x.H>
#include "LCD.h"
void ADC1_Init(void) {
PINSEL1 |= (1 << 18); // P0.28 as AD1.1
AD1CR = (1 << 1) | // Select AD1.1
(4 << 8) | // CLKDIV
(1 << 16); // Power ON
}
unsigned int Read_ADC(void) {
AD1CR |= (1 << 24); // Start conversion
while (!(AD1GDR & (1U << 31))); // Wait for DONE bit
return (AD1GDR >> 6) & 0x3FF; // Return 10-bit result
}
void Display_Temperature(unsigned int temp) {
char buffer[16];
sprintf(buffer, "%3d C", temp);
LCD_Write_Text(buffer);
}
Page 29 of 32
void ADC1_Init(void);
unsigned int Read_ADC(void);
void Display_Temperature(unsigned int temp);
int main(void) {
unsigned int adc_value, temperature;
LCD_Init(); // Initialize LCD
ADC1_Init(); // Initialize ADC1
LCD_Cmd(0x80);
LCD_Write_Text("Temp:");
while (1) {
adc_value = Read_ADC(); // Read ADC value
temperature = (adc_value * 3.3 / 1023) * 100; // Convert to °C (LM35 = 10mV/°C)
LCD_Cmd(0x86); // Move to next position
Display_Temperature(temperature);
Delay_ms(500);
}
}
Screenshot of the program from the tool:
Page 30 of 32
Screenshot of the circuit from the tool:
Screenshot of the output from the tool:
Page 31 of 32
Conclusion:
In this project, the analog output from the LM35 temperature sensor was successfully
read using the LPC2148's ADC module. The temperature data was accurately processed
and displayed on the LCD screen in real-time.
References:
1. LPC2148 Datasheet – NXP Semiconductors
2. Keil uVision IDE – ARM C compiler and debugger
3. LM016L LCD Datasheet – Hitachi 16x2 LCD module
Question Number: 15
Question: Write a program to communicate with an I2C EEPROM to read and write
data.
Tool Used: Keil uVision4, Proteus
Components Required:
Page 32 of 32