Cse2243 Es Lab Manual-2024
Cse2243 Es Lab Manual-2024
CERTIFICATE
satisfactorily completed the lab exercises prescribed for Embedded systems lab [CSE
2243] of Second Year B. Tech. in Computer Science and Engineering Degree at MIT,
Date: ……...................................
Signature
Faculty in Charge
CONTENTS
EVALUATION PLAN i
5 PROGRAMS ON SORTING 20
9 KEYBOARD INTERFACING 39
APPENDIX A 54
APPENDIX B 58
APPENDIX C 62
Course Objectives
Course Outcomes
On the completion of this laboratory course, the students will be able to:
Evaluation plan
● Internal Assessment Marks : 60%
i
INSTRUCTIONS TO THE STUDENTS
Pre- Lab Session Instructions
1. Students should carry the Class notes, Lab Manual and the required stationery to
every lab session.
2. Be in time and follow the Instructions from Lab Instructors.
3. Must Sign in the log register provided.
4. Make sure to occupy the allotted seat and answer the attendance.
5. Adhere to the rules and maintain the decorum.
ii
● Questions for lab tests and examination are not necessarily limited to the questions
in the manual, but may involve some variations and / or combinations of the
questions.
● A sample note preparation is given later in the manual as a model for observation.
ii
LAB NO 1
Sample lab observation note preparation
Add two immediate values in the registers and store the result in the third register.
Program:
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors
DCD 0X10001000
DCD Reset_Handler
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R0, #10
MOV R1, #3
ADD R2, R0, R1
END
Sample output:
IV
LAB NO 1
LAB NO: 1
Objectives:
Step 1:
● Create a directory with section followed by roll number (to be unique); e.g. A21
1
LAB NO 1
To create a project, click on the "Project" menu from the µVision-4 screen and select
"New µVision Project”. Then, select the folder you have created already, give project
name and save.
From the "Select Device for Target Target 1..." window, select "NXP" as the vendor. In
that, select LPC1768 ARM controller, and then click on OK button. Some general
information of the chip is shown in the description box.
2
LAB NO 1
Make sure you click on "NO" for the following pop up window.
From the "File" menu, select "New", to get the editor window. Type the program here.
(Note: give a tab space at the beginning). Save the program with .s extension in the
directory.
3
LAB NO 1
Click on the + symbol near the Target 1 in the top left corner of the window. Right click
on the "Source Group 1", select "Add Existing Files to Group 'Source Group 1'".
4
LAB NO 1
Select "Files of type" as "asm Source file (*.s*;*.src*;*.a*), then select the file. Click
on "Add", and then click on "Close".
Click on the "+" beside the "Source Group 1", you will see the program “ Addition.s”
Click on the "Build" button or from the "Project" menu, you will see the following screen.
5
LAB NO 1
6
LAB NO 1
Click on "OK" for the pop up window showing "EVALUATION MODE, Running with
Code Size Limit: 32K". You will see the following window.
7
LAB NO 1
Open µVision4 to full screen to have a better and complete view. The left hand side
window shows the registers and the right side window shows the program code. There
are some other windows open. Adjust the size of them to have a better view.
Run the program step by step; observe the change of the values in the registers.
Run the program using the Step Over button or click on Step Over from the Debug
menu. It executes the instructions of the program one after another. To trace the program
one can use the Step button, as well. The difference between the Step Over and Step is
in executing functions. While Step goes into the function and executes its instructions
one by one, Step Over executes the function completely and goes to the instruction next
to the function. To see the difference between them, trace the program once with Step
Over and then with Step. When the PC is executing the function and wants the function
to be executed completely one can use Step Out. In this case, the instructions of the
function will be executed, it returns from the function, and goes to the instruction which
is next to the function call.
8
LAB NO 1
9
LAB NO 1
Click on the "Start/Stop Debug Session" again to stop execution of the program.
An ARM assembly language module has several constituent parts. These are:
⮚ Assembler directives are the commands to the assembler that direct the assembly
process.
⮚ They do not generate any machine code i.e. they do not contribute to the final size
of machine code, and they are assembler specific
AREA:
The AREA directive tells the assembler to define a new section of memory. The memory
can be code (instructions) or data and can have attributes such as READONLY,
READWRITE and so on. This is used to define one or more blocks of indivisible memory
for code or data to be used by the linker. The following is the format:
10
LAB NO 1
AREA sectionname attribute, attribute, …
The following line defines a new area named mycode which has CODE and READONLY
attributes:
AREA mycode, CODE, READONLY
Commonly used attributes are CODE, DATA, READONLY, READWRITE, ALIGN and
END.
READONLY:
It is an attribute given to an area of memory which can only be read from. It is by default
for CODE. This area is used to write the instructions.
READWRITE:
It is an attribute given to an area of memory which can be read from and written to. It is
by default for DATA.
CODE:
It is an attribute given to an area of memory used for executable machine instructions. It
is by default READONLY memory.
DATA:
It is an attribute given to an area of memory used for data and no instructions can be
placed in this area. It is by default READWRITE memory.
ALIGN:
It is an attribute given to an area of memory to indicate how memory should be allocated
according to the addresses. When the ALIGN is used for CODE and READONLY, it is
aligned in 4-bytes address boundary by default since the ARM instructions are 32-bit
word. If it is written as ALIGN = 3, it indicates that the information should be placed in
memory with addresses of 23, that is for example 0x50000, 0x50008, 0x50010, 0x50018
and so on.
11
LAB NO 1
EXPORT:
The EXPORT directive declares a symbol that can be used by the linker to resolve symbol
references in separate object and library files.
DCD (Define constant word):
Allocates a word size memory and initializes the values. Allocates one or more words of
memory, aligned on 4-byte boundaries and defines initial run time contents of the
memory.
ENTRY:
The ENTRY directive declares an entry point to the program. It marks the first instruction
to be executed. In applications using the C library, an entry point is also contained within
the C library initialization code. Initialization code and exception handlers also contain
entry points.
END:
It indicates to the assembler the end of the source code. The END directive is the last line
of the ARM assembly program and anything after the END directive in the source file is
ignored by the assembler.
Example:
12
LAB NO 1
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;
MOV R0, #10
MOV R1, #3
ADD R0, R1
STOP B STOP
END ;End of the program
Solved Exercise:
Write an ARM assembly language program to copy 32-bit data from code memory to data
memory.
Program:
AREA RESET, DATA, READONLY
EXPORT __Vectors
13
LAB NO 1
__Vectors
DCD 0x10001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0, =SRC ; Load address of SRC into R0
LDR R1, =DST ; Load the address of DST onto R1
LDR R3, [R0] ; Load data pointed by R0 into R3
STR R3,[R1] ; Store data from R3 into the address pointed by R1
STOP
B STOP ; Be there
SRC DCD 8 ; SRC location in code memory
AREA mydata, DATA, READWRITE
DST DCD 0 ;DST location in data memory
END
Observations to be made:
1. Data storage into the memory: Click on Memory window and go to Memory1
option. Type address pointed by R0 in address space and observe how the data
are stored into the memory.
2. Data movement from one memory to another memory: Click on Memory
window and go to Memory2 option. Type address pointed by R1 in address
space and observe data movement to another location before execution and after
execution.
14
LAB NO 2
Lab Exercises:
1. Write an ARM assembly language program to store data into general purpose
registers.
2. Write an ARM assembly language program to transfer a 32-bit number from
one location in the data memory to another location in the data memory.
3. Write an ARM assembly language program to transfer block of ten 32-bit
numbers from code memory to data memory when the source and destination
blocks are non-overlapping.
Additional Exercise:
1. Reverse an array of ten 32-bit numbers in the memory.
15
LAB NO 3
LAB NO: 3 Date:
Objectives:
Solved Exercise:
Write a program to add two 32-bit numbers available in the code memory. Store the
result in the data memory.
__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0, =VALUE1 ;pointer to the first value1
LDR R1, [R0] ;load the first value into R1
LDR R0, =VALUE2 ;pointer to the second value
LDR R3, [R0] ;load second number into r3
ADDS R6, R1, R3 ;add two numbers and store the result in r6
16
LAB NO 3
LDR R2, =RESULT
STR R6, [R2]
STOP
B STOP
VALUE1 DCD 0X12345678 ; First 32 bit number
VALUE2 DCD 0XABCDEF12 ; Second 32 bit number
AREA data, DATA, READWRITE
RESULT DCD 0
END
Lab Exercises:
1. Write a program to perform subtraction operation on two 32-bit numbers
available in the code memory. Store the result in the data memory.
2. Write an assembly program to multiply two 32-bit numbers.
3. Write an assembly language program to implement division by repetitive
subtraction.
4. Find the sum of ‘n’ natural numbers using MLA instruction.
Additional Exercises:
1. Write a program to add ten 32-bit numbers available in code memory and store
the result in data memory.
2. Write an assembly language program to generate Fibonacci series.
3. Write an assembly language program to find GCD and LCM of two 8-bit
numbers
17
LAB NO 5:
Solved Exercise:
Write an assembly language program to unpack a 32-bit BCD number into eight 32-bit
ASCII numbers.
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R5, #4
LDR R0,=NUM
LDR R3,=RESULT
UP LDRB R1,[R0], #1 ; load BCD number into register R1
AND R2,R1,#0x0F ; mask upper 4 bits
ADD R2,#0x30 ; Add 30H to the number, Ascii value of first digit
STR R2,[R3], #4
AND R4,R1,#0xF0 ; Mask the second digit
MOV R4,R4,LSR#04 ; Shift right by 4 bits
ADD R4,#0x30 ; Ascii value of second digit
STR R4,[R3], #4
18
LAB NO 5:
SUBS R5, #1
BNE UP ;Repeat 4 times
STOP B STOP
NUM DCD 0x12345678
AREA data, DATA, READWRITE
RESULT DCD 0
END
Lab Exercises:
Additional Exercises:
1. Write an assembly language program to unpack a 32-bit BCD number into eight
32-bit numbers.
2. Multiply two 16-bit packed BCD and store the result in packed BCD form.
19
LAB NO 5:
LAB NO: 5 Date:
PROGRAMS ON SORTING
Objectives:
Lab Exercises:
21
LAB NO 5:
Additional Exercises:
1. Repeat question 4 for a fully descending stack using STMDB and LDM
instruction wherever necessary.
2. Write an ARM ALP that contains a list of numbers and makes a count of
a) Even and Odd numbers. b) Numbers greater than 10
3. Implement Full ascending and empty descending stack using LDR, STR, ADD
and SUB instructions.
22
LAB NO 6:
LAB NO: 6 Date:
Steps to be followed
Project Creation in Keil uvision4 IDE:
• Create a project folder before creating a NEW project.
• Use separate folder for each project
• Open Keil uVision4 IDE software by double clicking on “Keil Uvision4” icon.
• Select “Project” then to “New Project” and save it with a name in the respective
Project folder, which is already created.
• Select the device as “NXP (founded by Philips)” Select “LPC1768” then Press
“OK” and then press “YES” button to add “system_LPC17xx.s” file.
• Go to “File” select “New” to open an editor window. Create a source file and use
the header file “LPC17xx.h” in the source file and save the file. Color syntax
highlighting will be enabled once the file is saved with a Recognized extension
such as “.C “.
• Right click on “Source Group 1” and select the option “Add Files to Group 'Source
Group 1' “add the. C source file(s) to the group.
• Again right click on Source Group 1 and select the option “Add Files to Group
'Source Group 1' “add the file -
C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c
• Any changes made to this file at the current project will directly change the source
system_LPC17xx.C file. As a result, other project settings may get altered. So,
it is recommended to copy the file.
C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c to the project folder
and add to the source group.
• Important: This file should be added during each project creation.
• Select “Project” then select “Translate” to compile the File (s).
23
LAB NO 6:
• Select “Project” , select “Build Target” for building all source files such as
“.C”,”.ASM”, “.h”, files, etc…This will create the hex file if there are no warnings
& no errors.
Solved Exercise:
Note: Before writing the program please check GPIO port pins available in the kit
(Refer Appendix C.)
#include <LPC17xx.h>
int main(void)
{
SystemInit(); //Add these two function for its internal operation
SystemCoreClockUpdate();
LED = 0x00000010;
24
LAB NO 6:
for(i=1;i<9;i++) //Off the LED's serially
{
LPC_GPIO0->FIOCLR = LED;
//Turn OFF LED at LSB (LED connected to p0.4)
for(j=0;j<10000;j++);
LED <<= 1;
}
}
}
● In Project Window Right click “TARGET1” and select “options for target
‘TARGET1’ select to option “Target” in that select
1. XTAL 12.0MHz
2. Select IROM1 (starting 0×0 size 0×8000).
3. Select IRAM1 (starting 0×10000000 size 0×8000).
● Then go to option “Output”
Select “Create Hex file”.
● Then go to option “Linker”
Select use memory layout from target dialog
• There are three clock sources for the CPU. Select Oscillator clock out of three.
This selection is done by CLKSRCSEL register.
• If we disable the PLL0 System clock will be bypassed directly into the CPU
clock divider register.
• Use CCLKCFG register for choosing the division factor of 4 to get 3MHz out
of 12 MHz Oscillator frequency
• For any other peripherals use the PCLK same as CCLK.
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
26
LAB NO 6:
• Cross cable for programming and serial communication: 1 No
• One working USB port in the host computer system and PC for
downloading the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No
Some Settings for downloading the program in FLASH MAGIC:
Step1. Connect 9 pin DSUB cross cable from PC to CN9 at the board.
Step2. On the 2 way dip switch SW21. Short jumper JP3
Step3. Open flash magic 6.01
Step4. Make following setting in Flash magic(Only once)
a. Communications:
Device: LPC1768
Com Port: COM1
Baud Rate: 9600
Interface: None(ISP)
Oscillator: 12MHz
b. ERASE:
Select “Erase Blocks Used By Hex File”.
c. Hex file:
Browse and select the Hex file which you want to download.
d. Options:
Select “Verify After Programming”.
Go to Options -> Advanced Options->communications
Do not select High Speed Communications, keep baud rate 115200.
Options -> Advanced Options->Hardware config
Select Use DTR & RTS to control RST & ISP Pin.
Select Keep RTS asserted while COM Port open.
T1 = 50ms. T2 = 100ms.
Step5. Start:
Click “Start” to download the hex file to the controller.
Step6. Connect one end of 10 pin FRC cable to CNA1, Short other end to CNA
Step7. Press reset controller switch SW1 and Check output on the LEDs
27
LAB NO 6:
connected to CNA1.
Lab Exercises:
1. Write a C program to display an 8-bit binary up counter on the LEDs.
2. Write a C program to read a key and display an 8-bit up/down counter on the
LEDs.
Hint: Use key SW2 (if SW2=1, up counter else down counter), which is available
at CNB1 pin 7. Connect CNB1 to any controller connector like CNB, CNC, etc.
Configure the corresponding port pin as GPIO using corresponding PINSEL
register and as input pin using corresponding FIODIR register.
3. Write a program to simulate an 8- bit ring counter with key press (SW2).
28
LAB NO 7
LAB NO: 7. Date:
29
LAB NO 7
At the controller end, any 2 connectors are required for interfacing this block.
30
LAB NO 7
Lookup Table for displaying 0,1,2,3 to 9
Solved Exercise:
WAP to simulate 4-digit BCD down counter on the multiplexed seven segment display.
#include<LPC17xx.h>
unsigned char tohex[10]={0X3F, 0X06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0X07,
0X7F, 0X6F};
int main()
{
LPC_GPIO0->FIODIR|=0XFF0;
LPC_GPIO1->FIODIR|=0XF<<23;
for(arr[3]=0; ; arr[3]--)
{
for(arr[2]=9; arr[2]>=0; arr[2]--)
for(arr[1]=9; arr[1]>=0; arr[1]--)
for(arr[0]=9; arr[0]>=0; arr[0]--)
{
for(i=0; i<4; i++)
31
LAB NO 7
{
LPC_GPIO1->FIOPIN=i<<23;
LPC_GPIO0->FIOPIN=tohex[arr[i]]<<4;
for(j=0; j<1000; j++);
}
for(j=0; j<1000; j++);
LPC_GPIO0->FIOCLR|=0X00000FF0;
}
if(arr[3]==0)
arr[3]=10;
}
}
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication : 1 No
• One working USB in the host computer system and PC for downloading the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No
Hardware setup: Connect a 10 core FRC cable from CNA to CNA2 and CNB to CNB2.
Working procedure: After software download and hardware setup, press the reset,
Observe the count from 0000 to 9999 on the display.
Lab Exercises:
1. Write a C program to display the number “1234” serially in the seven segment
display.
2. Write a C program to simulate a 4 digit BCD down counter. Use a timer for delay.
3. Write a C program for 4 digit BCD up/down counters on seven segment using a
switch and timer with a delay of 1-second between each count.
4. Write a program for 4 digit Hexadecimal up/down counters on seven segment using
a switch and timer with a delay of 1-second between each count.
32
LAB NO 8
33
LAB NO 8
34
LAB NO 8
Solved Exercise:
WAP to display message on LCD
#include <lpc17xx.h>
void lcd_init(void);
void write(int, int);
void delay_lcd(unsigned int);
void lcd_comdata(int, int);
void clear_ports(void);
void lcd_puts(unsigned char *);
int main(void)
{
unsigned char Msg1[4] = {"MIT"};
unsigned char Msg2[19] = {"Department of CSE:"};
SystemInit();
SystemCoreClockUpdate();
lcd_init();
lcd_comdata(0x80, 0);
delay_lcd(800);
lcd_puts(&Msg1[0]);
lcd_comdata(0xC0, 0);
delay_lcd(800);
lcd_puts(&Msg2[0]);
}
//lcd initialization
void lcd_init()
{
/*Ports initialized as GPIO */
LPC_PINCON->PINSEL1 &= 0xFC003FFF; //P0.23 to P0.28
clear_ports();
delay_lcd(3200);
35
LAB NO 8
lcd_comdata(0x33, 0);
delay_lcd(30000);
lcd_comdata(0x32, 0);
delay_lcd(30000);
return;
}
void clear_ports(void)
{
/* Clearing the lines at power on */
LPC_GPIO0->FIOCLR = 0x0F<<23; //Clearing data lines
LPC_GPIO0->FIOCLR = 1<<27; //Clearing RS line
LPC_GPIO0->FIOCLR = 1<<28; //Clearing Enable line
return;
}
37
LAB NO 8
}
return;
}
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication: 1 No
• One working USB port in the host computer system and PC for downloading
the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No
Hardware setup:
Connect 10 pin FRC cable from CND to CNAD. Short the jumper JP16 & JP5.
Use POT3 for contrast adjustment.
Working procedure: After software download and hardware setup, press the
reset. A fixed message will display on the LCD.
Exercise Questions:
1. Simulate DIE tossing on LCD.
Hint: Program reads the external interrupt using the key SW2. A random number
between 0-6 should be displayed on the LCD upon keypress.
38
LAB NO 9
LAB NO: 9 Date:
KEYBOARD INTERFACING
Objectives:
In this lab students will be able to
● Interface and understand the working of matrix keyboard.
Introduction:
Keyboard connection: The switches SW3 to SW18 are organized as 4 rows X 4
columns matrix. One end of all the switches are configured as columns. The other end
of the matrix is configured as rows. A row line will always be an output from the
controller. Column lines are pulled to ground. A high level sent from the row will
appear at column end if the switch is pressed.
Connector CNB3 is used for interfacing this block with the controller. At the controller
end any connector can be used to interact with this connector CNB3.
39
LAB NO 9
Solved Exercise:
WAP to read a key from the matrix keyboard and display its key code on the LCD.
#include <LPC17xx.h>
#include "lcd-disp.c" // use all the functions of lcd program
void scan(void);
unsigned char Msg1[13] = "KEY PRESSED=";
unsigned char row, var, flag, key;
unsigned long int i, var1, temp, temp1, temp2, temp3;
unsigned char SCAN_CODE[16] = {0x11,0x21,0x41,0x81,
0x12,0x22,0x42,0x82,
0x14,0x24,0x44,0x84,
0x18,0x28,0x48,0x88};
40
LAB NO 9
unsigned char ASCII_CODE[16] = {'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};
int main(void)
{
LPC_GPIO2->FIODIR |= 0x00003C00; //made output P2.10 to P2.13 (rows)
LPC_GPIO1->FIODIR &= 0xF87FFFFF; //made input P1.23 to P1.26(cols)
;not required since it is by default
LPC_GPIO0->FIODIR |= 0x0F<<23 | 1<<27 | 1<<28;
clear_ports();
delay_lcd(3200);
lcd_init();
while(1)
{
while(1)
{
for(row=1;row<5;row++)
{
if(row == 1)
var1 = 0x00000400;
else if(row == 2)
var1 = 0x00000800;
else if(row == 3)
var1 = 0x00001000;
41
LAB NO 9
else if(row == 4)
var1 = 0x00002000;
temp = var1;
void scan(void)
{
42
LAB NO 9
temp3 = LPC_GPIO1->FIOPIN;
temp3 &= 0x07800000; //check if any key pressed in the enabled row
if(temp3 != 0x00000000)
{
flag = 1;
temp3 >>= 19; //Shifted to come at HN of byte
temp >>= 10; //shifted to come at LN of byte
key = temp3|temp; //get SCAN_CODE
}//if(temp3 != 0x00000000)
}//end scan
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication : 1 No
• One working USB port in the host computer system and PC for downloading
the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No
Hardware setup: Connect 10 core FRC cable from CNB to CNB3, short JP4(1, 2)
Connect another 10 core FRC cable from CND to CNAD, Short the jumper JP16 &
JP5. Use POT3 for contrast.
Working procedure: After software download and hardware setup, use the reset.
Identity of key pressed (0 to F) will be displayed on LCD.
Lab Exercise:
Write a program to input an expression of the type A operator B =, from the keyboard,
where A and B are the single digit BCD numbers and operator may be + or -. Display
the result on the LCD.
43
LAB NO 10
LAB NO: 10 Date:
Solved Exercise:
WAP to configure and read analog data from ADC channel no 5, and display the digital
data on the LCD.
#include<LPC17xx.h>
#include<stdio.h>
#include"AN_LCD.h"
#define Ref_Vtg 3.300
#define Full_Scale 0xFFF //12 bit ADC
int main(void)
{
unsigned long adc_temp;
unsigned int i;
float in_vtg;
unsigned char vtg[7], dval[7];
unsigned char Msg3[11] = {"ANALOG IP:"};
unsigned char Msg4[12] = {"ADC OUTPUT:"};
SystemInit();
SystemCoreClockUpdate();
44
LAB NO 10
SystemCoreClockUpdate();
lcd_comdata(0x80, 0);
delay_lcd(800);
lcd_puts(&Msg3[0]);
lcd_comdata(0xC0, 0);
delay_lcd(800);
lcd_puts(&Msg4[0]);
while(1)
{
LPC_ADC->ADCR = (1<<5)|(1<<21)|(1<<24); //0x01200001;
//ADC0.5, start conversion and operational
while(!(LPC_ADC->ADDR5 & 0x80000000));
//wait till 'done' bit is 1, indicates conversion complete
adc_temp = LPC_ADC->ADDR5;
adc_temp >>= 4;
adc_temp &= 0x00000FFF; //12 bit ADC
in_vtg = (((float)adc_temp * (float)Ref_Vtg))/((float)Full_Scale);
//calculating input analog voltage
sprintf(vtg, "%3.2fV", in_vtg);
//convert the readings into string to display on LCD
sprintf(dval, "%x", adc_temp);
for(i=0; i<2000; i++);
lcd_comdata(0x89, 0);
delay_lcd(800);
lcd_puts(&vtg[0]);
lcd_comdata(0xC8, 0);
delay_lcd(800);
lcd_puts(&dval[0]);
45
LAB NO 10
for(i=0;i<200000;i++);
for(i=0;i<7;i++)
vtg[i] = dval[i] = 0x00;
adc_temp = 0;
in_vtg = 0;
}
}
Components required
● ALS-SDA-ARMCTXM3-01 : 1 No.
● Power supply (+5V) : 1 No.
● Cross cable for programming and serial communication : 1 No
● One working COM port (Ex: COM1) in the host computer system and PC
for downloading the software.
● 10 core FRC cables of 8 inch length 2 No
● USB to B type cable 1 No
Exercise
1. Write a C program to display the digital value representing the difference in
analog voltages at ADC channel 4 and channel 5 on LCD using BURST and
Software mode.
46
LAB NO 11
LAB NO: 11 Date:
Solved Exercise:
WAP to vary the intensity of an LED using PWM.
#include <LPC17xx.h>
void initPWM(void);
void updatePulseWidth(unsigned int pulseWidth);
void delayMS(unsigned int milliseconds);
int main(void)
{
int pulseWidths[] = {0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000,
27000}; //Pulse Widths for varying LED Brightness
const int numPulseWidths = 10;
int count=1;
int dir=0; //direction, 0 = Increasing, 1 = Decreasing
initPWM(); //Initialize PWM
while(1)
{
updatePulseWidth(pulseWidths[count]); //Update LED Pulse Width
delayMS(10000);
47
LAB NO 11
if(count == (numPulseWidths-1) || count == 0)
{
dir = !dir; //Toggle direction if we have reached count limit
}
if(dir) count--;
else count++;
}
}
void initPWM(void)
{
LPC_PINCON->PINSEL3 |= 0x8000; //Select PWM1.4 output for Pin1.23,
function 2
LPC_PWM1->PCR = 0x1000; //enable PWM1.4, by default it is single Edged
LPC_PWM1->PR = 0;
LPC_PWM1->MR0 = 30000; //period=10ms if pclk=cclk/4
LPC_PWM1->MCR = (1<<1); //Reset PWM TC on PWM1MR0 match
LPC_PWM1->LER = 0xff; //update values in MR0 and MR1
LPC_PWM1->TCR = 0x00000002; //RESET COUNTER TC and PC
LPC_PWM1->TCR = 0x00000009; //enable TC and PC
}
Lab Exercises:
Write a program to set the following intensity levels to the LED connected to PWM
output. Use ROW-0 of keyboard for intensity variation
Intensity level Key pressed
10% 0
25% 1
50% 2
75% 3
49
LAB NO. 12
PM1– it's a 5 pin straight male power mate. PIN descriptions are as given below.
50
LAB NO. 12
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
while(1)
{
for(j=0;j<50;j++)
clock_wise();
51
LAB NO. 12
for(j=0;j<50;j++)
anti_clock_wise();
} // End of while(1)
} // End of main
void clock_wise(void)
{
var1 = 0x00000008; //For Clockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1<<1; //For Clockwise
LPC_GPIO0->FIOPIN = var1;
void anti_clock_wise(void)
{
var1 = 0x00000100; //For Anticlockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1>>1; //For Anticlockwise
LPC_GPIO0->FIOPIN = var1;
Hardware setup: Connect 10 pin FRC cable from CNA to CNA5. Connect the
stepper motor to PM1.
Working procedure: Stepper motor will rotate clockwise and in anti-clock wise
direction automatically after reset.
Lab Exercise:
Write a C program to rotate the stepper motor in the clockwise direction when SW2 is
high and anticlockwise direction when SW2 is low.
53
Appendix A
Appendix A: Instructions
55
Appendix A
LDMIA R0!,{R1-R5}
STMDB R6!,{R0,R1,R5}
57
Appendix B
Appendix B: Addressing modes
Literal Addressing
In this addressing mode data is a part of instruction. ‘#’ symbol is used to indicate the
data. ARM and Thumb instructions can only be 32 bits wide. You can use a MOV or
MVN instruction to load a register with an immediate value from a range that depends on
the instruction set. Certain 32-bit values cannot be represented as an immediate operand
to a single 32-bit instruction, although you can load these values from memory in a single
58
Appendix B
instruction. you can load any 32-bit immediate value into a register with two instructions,
a MOV followed by a MOVT. Or, you can use a pseudo-instruction, MOV32, to construct
the instruction sequence for you. You can also use the LDR pseudo-instruction to load
immediate values into a register
Examples Meaning
----------------------------------------------------------------------
CMP R0, #22 ;Compare Register content R0 with 22
----------------------------------------------------------------------
ADD R1, R2, #18 ;Add the content of R2 and 18 then store
;the result in R1
----------------------------------------------------------------------
MOV R1, #30 ;copy the data 30 into register R1
----------------------------------------------------------------------
MOV R1, #0Xff ;copy the data ff in hexadecimal into R1
----------------------------------------------------------------------
MOV R2, #0xFF0000FF
----------------------------------------------------------------------
AND R0, R1, #0xFF000000
----------------------------------------------------------------------
CMN R0, #6400 ; update the N, Z, C and V flags
----------------------------------------------------------------------
CMPGT SP, R7, LSL #2 ; update the N, Z, C and V flags
----------------------------------------------------------------------
▪ MOV can load any 8-bit immediate value, giving a range of 0x0-0xFF (0-255). It can
also rotate these values by any even number. These values are also available as
immediate operands in many data processing operations, without being loaded in a
separate instruction.
▪ MVN can load the bitwise complements of these values. The numerical values are -
(n+1), where n is the value available in MOV.
▪ A MOVT instruction that can load any value in the range 0x0000 to 0xFFFF into the
most significant half of a register, without altering the contents of the least significant
half.
▪ The LDR Rd,=const pseudo-instruction generates the most efficient single instruction
to load any 32-bit number
59
Appendix B
Introduction to Register Indirect Addressing : Register indirect addressing means that
the location of an operand is held in a register. It is also called indexed addressing or base
addressing.
Register indirect addressing mode requires three read operations to access an operand. It
is very important because the content of the register containing the pointer to the operand
can be modified at runtime. Therefore, the address is a vaiable that allows the access to
the data structure like arrays.
This is similar to the above, but it first accesses the operand at the location pointed by the
base register, then increments the base register. For example,
Register R15 is the program counter. If you use R15 as a pointer register to access
operand, the resulting addressing mode is called PC relative addressing. The operand is
specified with respect to the current code location. Please look at this example,
Instruction Effective Address
----------------------------------------------------------------------
LDR R0, [R15, #24] R15 + 24 ;loads R0 with the word
;pointed at by R1+24
----------------------------------------------------------------------
61
Appendix C
APPENDIX C
GPIO extension connectors:
There are four 10 pin FRC type male connectors, they extends the controllers
general purpose port lines for the use of user requirements. Details on each connector is
given below:
CNA –10 pin male box type FRC connector. Port lines P0.4 to P0.11 from controller are
terminated in this connector. They can be extended to interface few on board or external
peripherals. The pins mentioned in the above table are configured to work as a GPIO's at
power on. Other alternate functions on those pins needs to be selected using
respective PINSEL registers.
CNB – 10 pin male box type FRC connector. Port lines fromP1.23 to P1.26 and P2.10
to P2.13 are terminated in this connector.
62
Appendix C
CNC – 10 pin male box type FRC connector. Port lines fromP0.15 to P0.22 and P2.13
are terminated in this connector.
CND – 10 pin male box type FRC connector. Port lines fromP0.23 to P0.28 and P2.0 to
P2.1 are terminated in this connector.
63
Appendix C
64