A3 PDF
A3 PDF
CERTIFICATE
Date: ……...................................
EVALUATION PLAN I
2 ARITHMETIC PROGRAMS 17
3 ARITHMETIC PROGRAMS 24
9 ADC INTERFACING 80
10 DAC INTERFACING 87
11 PWM INTERFACING 93
APPENDIX A 105
APPENDIX B 109
APPENDIX C 113
Course Objectives
To gain knowledge about assembly language and Embedded C programming
To implement the programs using various instructions in from the instruction set
of microcontroller.
To understand various interfacing circuits necessary for various applications and
programming using ARM.
Course Outcomes
At the end of this course, students will be able to
To gain knowledge about simulator for an embedded system.
To comprehend the software development for ARM cortex-M microcontroller
using assembly language.
To comprehend the software development for ARM cortex-M microcontroller
using embedded C language
To design real world systems using Arm cortex-M embedded system.
Evaluation plan
Split up of 60 marks for Regular Lab Evaluation
Four regular evaluations will be carried out once in every three weeks.
Each evaluation is for 10 marks with following split up:
Record : 4 Marks
Evaluation: 4 Marks
Execution: 2 Marks
Total = 10 Marks
Total Regular Evaluation Marks: 4 * 10 =40 Marks
Students are required to carry out a project in Embedded System ARM
LPC1768 Controller and ALS evaluation board
Output and Work done: 10 Marks
Report: 5 Marks
Viva a: 5 Marks
Total Mini project Evaluation Marks: 20 Marks
i
INSTRUCTIONS TO THE STUDENTS
Pre- Lab Session Instructions
1. Students should carry the Lab Manual Book and the required stationery to every
lab session
2. Be in time and follow the institution dress code
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
ESD LAB MANUAL Start up Keil U Vision4
LAB1:
Before you start up, you are recommended that you create a folder to hold all your
project files. For example: you can create a folder "FirstARM-Project" ready before
hand.
Step1:
You can start up uVision4 by clicking on the icon from the desktop or from
the "Start" menu or "All Programs" on a lab PC. The following screen is what you will
see
1|Page
ESD LAB MANUAL Start up Keil U Vision4
To create a project, click on the "Project" menu from the uVision4 screen and select
"New uVision Project...".
2|Page
ESD LAB MANUAL Start up Keil U Vision4
From the "Select Device for Target" window, select "NXP" as the vendor. In that select
LPC1768 ARM controller , then click on OK button
Make sure you click on "NO" for the following pop up window.
3|Page
ESD LAB MANUAL Start up Keil U Vision4
From the "File" menu, select "New", you will see the "Text1*" text edit window. That is
the place you will write your ARM Assembly language program. You can write the
program into this window. (Note: give a tab space at the beginning)
Save the program by clicking on the "Save" or "Save As" from the "File" menu and give
it a name.
4|Page
ESD LAB MANUAL Start up Keil U Vision4
Right click on the "Source Group 1", select "Add Files to Group 'Source Group 1'".
Select "Files of type" as "asm Source file (*.s*;*.src*;*.a*), then select the file
"FirstARM.s" for example. Click on "Add", and then click on "Close".
5|Page
ESD LAB MANUAL Start up Keil U Vision4
Click on the "+" beside the "Source Group 1", you will see the program "FirstARM.s".
Click on the "Build" button or from the "Project" menu, you will see the following
screen.
6|Page
ESD LAB MANUAL Start up Keil U Vision4
Click on "OK" for the pop up window showing "EVALUATION MODE, Running with
Code Size Limit: 32K".
Open uVision4 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 better view.
Run the program step by step; observe the change of the values in the registers.
7|Page
ESD LAB MANUAL Start up Keil U Vision4
To trace the program use 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 PC executing the function and want
the function to be executed completely one can use Step Out. In the 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|Page
ESD LAB MANUAL Start up Keil U Vision4
Click on the "Start/Stop Debug Session" again to stop execution of the program.
These are:
9|Page
ESD LAB MANUAL Start up Keil U Vision4
Application 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.
Application execution
The application code begins executing at the label start, where it loads the decimal
values 10 and 3 into registers R0 and R1. These registers are added together and the
result placed in R0.
Program end
The END directive instructs the assembler to stop processing the source file. Every
assembly language source module must finish with an END directive on a last line. Any
lines following the END directive are ignored by the assembler.
10 | P a g e
ESD LAB MANUAL Start up Keil U Vision4
11 | P a g e
ESD LAB MANUAL LAB 1: Data transfer Programs
LAB NO: 1
Question: Write a ARM assembly language program to copy 16 bit variable from code
memory to data memory.
__Vectors
DCD 0x10001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
Reset_Handler
LDR R0, =SRC; Load address of SRC into R0
LDR R1, =DST; Load the address of DST onto R1
12 | P a g e
ESD LAB MANUAL LAB 1: Data transfer Programs
END
Observations to be made
1. Data storage into the memory: Click on Memory window you get label
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 you get label Memory2 option type address pointed by R1 in address
space and observe data movement to another location before execution and after
execution.
Exercise questions
1. Write an ARM assembly language program to transfer block of ten 32 bit
numbers from one memory to another
a. When the source and destination blocks are non-overlapping
b. When the source and destination blocks are overlapping
Hint: Use Register indirect addressing mode or indexed addressing mode
13 | P a g e
ESD LAB MANUAL LAB 1: Data transfer Programs
14 | P a g e
ESD LAB MANUAL LAB 1: Data transfer Programs
15 | P a g e
ESD LAB MANUAL LAB 1: Data transfer Programs
16 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
LAB 2:
__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,=VALU2 ;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
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
17 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
Exercise questions
1. Write a program to add ten 32 bit numbers stored in code segment and store
the result in data segment
2. Write a program to add two 128 bit numbers stored in code segment and store
the result in data segment.
Hint: Use indexed addressing mode.
3. Write a program to subtract two 32 bit numbers
4. Write a program to subtract two 128 bit numbers
18 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
19 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
20 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
21 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
22 | P a g e
ESD LAB MANUAL LAB 2: Arithmetic Programs
23 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
LAB 3
Title: Arithmetic Programs.
Aim: Familiarization of Arithmetic operations - multiplication and division.
__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
Reset_Handler
LDR R0, =VALUE1 ;pointer to the first value1
LDRH R1,[R0] ;load the first value into r1
LDR R0,=VALU2 ;pointer to the second value
LDRH R3, [R0] ;load second number into r3
MUL R6, R1,R3 ;Multiply the values from R1 and R3 and store
;least significant 32 bit number into R6.
LDR R2, =RESULT
STR R6,[R2] ; store result in r6
STOP
B STOP
VALUE1 DCD 0X1234 ; First 32 bit number
VALUE2 DCD 0X5678 ; Second 32 bit number
AREA data, DATA, READWRITE
RESULT DCD 0
24 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
__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 R2,#00
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
up SUB R1, R3 ;Subtract two numbers
ADD R2,#01 ;increment a counter
CMP R1,R3 ;compare two numbers
BCS up ;check R1is greater than R3 or not, if yes loop
LDR R6, =RESULT ;Quotient
STR R2,[R6,#4]
STR R1,[R6] ;Store remainder.
STOP
B STOP
VALUE1 DCD 0x200000000 ;First 32 bit number
25 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
Exercise questions
1. Write a program to multiply two 32 bit numbers using repetitive addition
Hint: If two numbers are in R0 and R1 Registers then use following
algorithm
Sum=0;
do { sum=sum+R0; R1--; ;Use ADS instruction for addition and use ADD
;instruction to increment a register by 1
if carry then
R2++; ;Increment carry value by one.
} while(R1!=0); ;Use Compare instruction to check greater
;than or not. And Brach instructions for loop
Result= R2 and R0
2. Repeat the above program for BCD multiplication
3. Find the sum of ‘n’ natural numbers using MLA instruction.
4. Write an assembly language program to find GCD of two numbers
Hint:
While(a!=b)
{
If(a>b)
a=a-b;
else
b=b-a;
} Return (a);
26 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
Exit;
Else
i++;
} while(remainder!=0);
Return (i*a);
27 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
28 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
29 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
30 | P a g e
ESD LAB MANUAL LAB 3: Arithmetic Programs
31 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
LAB 4:
Title: Code conversion Programs.
Aim: Familiarization of logical instructions and code conversion programs.
Question: Write an assembly program to convert a 2 digit hexadecimal number into
unpacked ASCII.
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
LDR R0,=NUM
LDR R3,=RESULT
LDRB R1,[R0] ; load hex number into register R1
AND R2,R1,#0x0F ; mask upper 4 bits
CMP R2,#09 ; compare the digit with 09
BLO DOWN ; if it is lower than 9 then jump to down
; lable
ADD R2,#07 ;else add 07 to that number
DOWN
ADD R2,#0x30 ; Add 30H to the number, Ascii value of first
STRB R2,[R3] ; digit
AND R3,R1,#0xF0 ; Mask the second digit
MOV R3,R3,LSR#04 ; Shift right by 4 bits
CMP R3,#09 ; check for >9 or not
BLO DOWN1
ADD R3,#07
DOWN1
32 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
33 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
34 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
35 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
36 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
AREA ascend, code, readonly
ENTRY
Reset_Handler
mov r4,#0
mov r1,#10
ldr r0, =list
ldr r2, =result
up ldr r3, [r0,r4]
str r3, [r2,r4]
add r4, #04
sub r1,#01
cmp r1,#00
bhi up
ldr r0, =result
; inner loop counter
mov r3, #10
sub r3, r3, #1
mov r9, r3 ; R9 contain no of passes
; outer loop counter
outer_loop
mov r5, r0
37 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
Exercise questions:
38 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
39 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
40 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
41 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
42 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
43 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
Lab 6
Title: Interfacing LED to ARM microcontroller.
Aim: Interface LEDs to the ARM cortex LPC1768 microcontroller using ALS
interfacing board.
Steps to be followed
Project Creation in Keil uvision4 IDE:
• Create a project folder before creating 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 you 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 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).
• 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.
44 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
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();
LPC_GPIO0->FIODIR |= 0x00000FF0;
;Configure P0.4-P0.11 as output
;port
while(1)
{
LED = 0x00000010; Initial value on LED
for(i=1;i<9;i++) //On the LED's serially
{
LPC_GPIO0->FIOSET = LED;
45 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
;unit.
LED = 0x00000010;
}
}
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 CPU. Select Oscillator clock out of three.
This selection is done by CLKSRCSEL register.
46 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
• If we disable the PLL0 System clock will be bypassed directly into 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.
47 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
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
48 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
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
connected to CNA1.
Exercise Questions:
1. Write a C program to display 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 corresponding port pin as GPIO using corresponding PINSEL register
and input pin using corresponding FIODIR register.
3. Write a program to simulate an 8- bit ring counter with key press (SW2).
49 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
50 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
51 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
52 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
LAB 7.
Title: Programs on multiplexed seven segment display
Aim: To interface and understand the working of multiplexed seven segments
display
Introduction:
There are four multiplexed 7-segment display units (U8, U9, U10 and U11) on the
board. Each display has 8-inputs SEG_A (Pin-7), SEG_B (Pin-6), SEG_C
(Pin-4), SEG_D (Pin-2), SEG_E (Pin-1), SEG_F (Pin-9), SEG_G (Pin-10) and
SEG_H (Pin-5) and the remaining pins pin-3 & pin-8 are Common Cathode
CC. These segments are common cathode type hence active high devices.
At power on all the segments are pulled up. A four bits input through CNB2 is used
for multiplexing operation. A 1-of-10 Decoder/Driver U7 is used to accept BCD
inputs and provide appropriate outputs for enabling the required display.
8 bits data is provided in this block using CNA2. All the data lines are taken
buffered at U12 before giving to the displays.
53 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
At controller end any 2 connector are required for interfacing this block.
54 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
#include <LPC17xx.h>
#include <stdio.h>
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
55 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
while(1)
{
Delay();
dig_count +=1;
if(dig_count == 0x05)
{ dig_count = 0x00;
one_sec_flg =0xFF;
}
if(one_sec_flg == 0xFF)
{
one_sec_flg = 0x00;
dig1 +=1;
if(dig1 == 0x0A)
{
dig1 = 0;
dig2 +=1;
if(dig2 == 0x0A)
{
dig2 = 0;
dig3+=1;
if(dig3 == 0x0A)
{
dig3 = 0;
dig4 += 1;
if(dig4 == 0x0A)
{
dig4 = 0;
} //end of dig4
} //end of dig3
56 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
} //end of dig2
} //end of dig1
} //end of one_sec if
Display();
} //end of while(1)
}//end of main
}
temp1 &= 0x0F;
temp2 = array_dec[temp1]; // Decoding to 7-segment
temp2 = temp2 << 4;
57 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
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.
58 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
Exercise Questions:
1. Write a C program to simulate a 4 digit BCD down counter. Use timer for a delay
2. Write a C program for 4 digit BCD up/down counter on seven segment using a
switch and timer with a delay of 1-second between each count.
3. Write a program for 4 digit Hexadecimal up/down counter on seven segment
using a switch and timer with a delay of 1-second between each count.
59 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
60 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
61 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
62 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
63 | P a g e
ESD LAB MANUAL LAB7: Seven segment display program
64 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
LAB 8:
Title: Liquid Crystal Display (LCD) and Keyboard interfacing
Aim: To interface and understand the working of LCD and matrix key board
Introduction:
LCD: A 16×2 alphanumeric LCD can be used to display the message from controller.
16 pin small LCD has to be mounted to the connector CN11. 10 pin connector CNAD is
used to interface this LCD from controller. Only higher 4 data lines are used among the
8 LCD data lines. Use POT3 for contrast adjustment and Short the jumper JP16 to use
this LCD. LCD connector CN11 is described in this table. CN11 is single row 16 pin
female berg.
65 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
66 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
#include <lpc17xx.h>
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay_lcd(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
void clear_ports(void);
void lcd_puts(unsigned char *);
int main(void)
{
unsigned long adc_temp;
unsigned int i;
float in_vtg;
unsigned char vtg[7],dval[7];
unsigned char Msg3[11] = {"MIT"};
unsigned char Msg4[12] = {"Department of ICT:"};
SystemInit();
SystemCoreClockUpdate();
lcd_init();
temp1 = 0x80;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg3[0]);
temp1 = 0xC0;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg4[0]);
67 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
}
//lcd initialization
void lcd_init()
{
/* Ports initialized as GPIO */
LPC_PINCON->PINSEL3 &= 0xFC003FFF; //P0.23 to P0.28
clear_ports();
delay_lcd(3200);
temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);
temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);
temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);
temp2 = (0x20<<19);
wr_cn();
delay_lcd(30000);
temp1 = 0x28;
lcd_com();
delay_lcd(30000);
temp1 = 0x0c;
lcd_com();
delay_lcd(800);
temp1 = 0x06;
lcd_com();
delay_lcd(800);
temp1 = 0x01;
68 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
lcd_com();
delay_lcd(10000);
temp1 = 0x80;
lcd_com();
delay_lcd(800);
return;
}
void lcd_com(void)
{
temp2 = temp1 & 0xf0;//move data (26-8+1) times : 26 - HN
//place, 4 - Bits
temp2 = temp2 << 19; //data lines from 23 to 26
wr_cn();
temp2 = temp1 & 0x0f; //26-4+1
temp2 = temp2 << 23;
wr_cn();
delay_lcd(1000);
return;
}
void clr_disp(void)
{
temp1 = 0x01;
lcd_com();
delay_lcd(10000);
return;
}
void clear_ports(void)
{
/* Clearing the lines at power on */
LPC_GPIO0->FIOCLR = DT_CTRL; //Clearing data lines
LPC_GPIO0->FIOCLR = RS_CTRL; //Clearing RS line
LPC_GPIO0->FIOCLR = EN_CTRL; //Clearing Enable line
return;
}
70 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
while(buf1[i]!='\0')
{
temp1 = buf1[i];
lcd_data();
i++;
if(i==16)
{
temp1 = 0xc0;
lcd_com();
}
}
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 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.
71 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
72 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
73 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
74 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
75 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
Sample program: To read a key from the matrix keyboard and display its key code on
the LCD.
#include <LPC17xx.h>
void scan(void);
temp = var1;
LPC_GPIO2->FIOCLR = 0x00003C00;
LPC_GPIO2->FIOSET = var1;
flag = 0;
scan();
76 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
if(flag == 1)
break;
} //end for(row=1;row<5;row++)
if(flag == 1)
break;
} //2nd while(1)
void scan(void)
{
unsigned long temp3;
temp3 = LPC_GPIO0->FIOPIN;
temp3 &= 0x0780000;
if(temp3 != 0x00000000)
{
flag = 1;
if (temp3 ==0x0080000)
col=0;
else if (temp3==0x0100000)
col=1;
else if (temp3==0x00200000)
col=2;
else if (temp3==0x0400000)
col=3;
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.
Exercise questions:
1. Write a program to input an expression of the type A operator B =, from the key
board, where A and B are the single digit BCD numbers and operator may be +
or - .Display the result on the LCD.
78 | P a g e
ESD LAB MANUAL LAB8: LCD and Keyboard interfacing
79 | P a g e
ESD LAB MANUAL LAB9: ADC program
Lab 9.
Title: Analog to Digital Convertor program
Aim: To understand the working of a 12 bit internal Analog-to-Digital Converter
(ADC)
Introduction: The LPC1768 contains a single 12-bit successive approximation
ADC with eight channels and DMA support. 12-bit 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. On board there
are two interfaces for internal ADC’s. AD0.5 (pin P1.31) of controller is used to
convert the analog input voltage varied using POT1 to digital value. AD0.4(Pin
1.30) used convert the analog voltage varied using POT4. A input voltage range of 0
to 3.3V is accepted. 000 to FFF is the converted digital voltage range here. Short
JP18 (2, 3) to use AD0.4.
Sample program: 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();
80 | P a g e
ESD LAB MANUAL LAB9: ADC program
SystemCoreClockUpdate();
temp1 = 0x80;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg3[0]);
temp1 = 0xC0;
lcd_com();
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
//for(i=0;i<2000;i++); //delay for conversion
while((adc_temp = LPC_ADC->ADGDR) == 0x80000000);
//wait till 'done' bit is 1, indicates conversion complete
adc_temp = LPC_ADC->ADGDR;
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++);
temp1 = 0x8A;
lcd_com();
delay_lcd(800);
lcd_puts(&vtg[0]);
temp1 = 0xCB;
lcd_com();
delay_lcd(800);
lcd_puts(&dval[0]);
for(i=0;i<200000;i++);
for(i=0;i<7;i++)
vtg[i] = dval[i] = 0x00;
adc_temp = 0;
81 | P a g e
ESD LAB MANUAL LAB9: ADC program
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 question
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.
82 | P a g e
ESD LAB MANUAL LAB9: ADC program
83 | P a g e
ESD LAB MANUAL LAB9: ADC program
84 | P a g e
ESD LAB MANUAL LAB9: ADC program
85 | P a g e
ESD LAB MANUAL LAB9: ADC program
86 | P a g e
ESD LAB MANUAL LAB10: DAC program
Lab 10:
Title: Program on Digital to Analog Convertor (DAC)
Aim: To understand the working of a 10 bit DAC and check the waveform on
Cathode Ray Oscilloscope (CRO).
Introduction: LPC1768 has 10 bit internal DAC with dedicated conversion timer
and DMA support. The DAC allows to generate a variable analog output. The
maximum output value of the DAC is VREFP. The equation to calculate output
voltage value is given as below.
AOUT = DACR value x ((VREFP - VREFN)/1024) + VREFN
An analog output from the controller can be observed in this block at TP8. Open JP5
to use this feature and use CRO to watch analog output value.
Sample program: To generate a sawtooth waveform using DAC and display it on
CRO.
#include <lpc17xx.h>
void DAC_Init(void);
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */
/* Initialize DAC */
DAC_Init();
while ( 1 )
{
LPC_DAC->DACR = (i << 6) ;
87 | P a g e
ESD LAB MANUAL LAB10: DAC program
LPC_DAC->DACCNTVAL = 0x00FF;
LPC_DAC->DACCTRL = (0x1<<1)|(0x1<<2);
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
88 | P a g e
ESD LAB MANUAL LAB10: DAC program
Hardware setup:
Open the jumper JP5
Connect TP8 pin to CRO positive wire and TP3 to CRO negative wire. Scale the
CRO to the proper display
Working procedure: Reset the controller and observe the analog output waveform
on CRO.
Exercise questions
1. Using DAC generate a triangular waveform with maximum possible peak-peak
amplitude.
2. Using DAC, generate a variable frequency sine waveform. Use ROW-0 of
keyboard for frequency variation
89 | P a g e
ESD LAB MANUAL LAB10: DAC program
90 | P a g e
ESD LAB MANUAL LAB10: DAC program
91 | P a g e
ESD LAB MANUAL LAB10: DAC program
92 | P a g e
ESD LAB MANUAL LAB 11: PWM program
LAB 11:
Title: Program on Pulse Width Modulation (PWM)
Aim: To interface and understand the working of PWM
Introduction: The PWM is based on the standard Timer block and inherits all
of its features, although only the PWM function is pinned out on theLPC1768. The
Timer is designed to count cycles of the system derived clock and optionally switch
pins, generate interrupts or perform other actions when the specified timer values occur,
based on seven match registers. The PWM function is in addition to these features, and
is based on match register events. A PWM output from the controller can be observed as
an intensity variation of the LED LD10.
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
pwm_init();
while(1)
{
for(i=0;i<=1000;i++); // delay
}//end of while
}//end of main
93 | P a g e
ESD LAB MANUAL LAB 11: PWM program
void pwm_init(void)
{
LPC_SC->PCONP |= (1<<6); //PWM1 is powered
LPC_PINCON->PINSEL3 &= ~(0x0000C000); //cleared if any other
//functions are enabled
LPC_PINCON->PINSEL3 |= 0x00008000; //pwm1.4 is selected for the pin
//P1.23
NVIC_EnableIRQ(PWM1_IRQn);
return;
}
void PWM1_IRQHandler(void)
{
LPC_PWM1->IR = 0xff; //clear the interrupts
if(flag == 0x00)
{
LPC_PWM1->MR4 += 100;
LPC_PWM1->LER = 0x000000FF;
flag = 0xff;
LPC_PWM1->LER = 0x000000fF;
}
}
else if(flag1 == 0xff)
{
LPC_PWM1->MR4 -= 100;
LPC_PWM1->LER = 0x000000fF;
Exercise question:
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
95 | P a g e
ESD LAB MANUAL LAB 11: PWM program
96 | P a g e
ESD LAB MANUAL LAB 11: PWM program
97 | P a g e
ESD LAB MANUAL LAB 11: PWM program
98 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
LAB 12
Title: Program on stepper motor
Aim : To interface and understand the working of stepper motor
Introduction: The Stepper motor can be interfaced to the board by connecting it to
the Power Mate PM1. The direction of the rotation can be changed through software.
The DC Motor can also be interfaced to the board by connecting it to the Reliamate
RM5. The direction of the rotation can be changed through software.
The Relay K2 is switched between ON and OFF state. The LED L12 will toggle for
every relay switch over. The contact of NO & NC of the relay can be checked at the
MKDSN connector CN12 pins 1 & 2 using a CRO– these contacts can be connected
to external devices. Using connector CNA5 micro controller can interface with this
block.
Description of the connector pins are given in below table.
PM1– it's a 5 pin straight male power mate. PIN descriptions are as given below.
99 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
while(1)
{
for(j=0;j<50;j++) // 20 times in Clock wise Rotation
clock_wise();
} // End of while(1)
} // End of main
100 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
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
var2 = ~var1;
var2 = var2 & 0x000000F0;
LPC_GPIO0->FIOPIN = ~var1;
//LPC_GPIO0->FIOSET = var1;
//LPC_GPIO0->FIOCLR = var2;
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
var2 = ~var1;
var2 = var2 & 0x000000F0;
LPC_GPIO0->FIOPIN = ~var1;
//LPC_GPIO0->FIOSET = var1;
//LPC_GPIO0->FIOSET = var2;
for(k=0;k<3000;k++); //for step speed variation
}
}
101 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication: 1 No
• Stepper motor 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 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.
Exercise question
Write a C program to rotate the stepper motor in the clockwise direction when SW2
is high and anticlockwise direction when SW2 is low.
102 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
103 | P a g e
ESD LAB MANUAL LAB 12: Stepper motor program
104 | P a g e
ESD LAB MANUAL Appendix A
Appendix A: Instructions
105 | P a g e
ESD LAB MANUAL Appendix A
106 | P a g e
ESD LAB MANUAL Appendix A
EQ Z set equal
NE Z clear not equal
CS/HS C set unsigned higher or same
CC/LO C clear unsigned lower
MI N set negative
PL N clear positive or zero
VS V set overflow
VC V clear no overflow
HI C set and Z clear unsigned higher
LS C clear or Z set unsigned lower or same
GE N equals V signed greater or equal
LT N not equal to V signed less than
GT Z clear AND (N equals V) signed greater than
LE Z set OR (N not equal to V) signed less than or equal
AL (ignored) always (usually omitted)
The instructions LDM and STM provide four different addressing modes. The
addressing mode specifies the behavior of the base register and is explained in the
following table.
107 | P a g e
ESD LAB MANUAL Appendix A
Examples:
STMDB R2!,{R4,R5,LR}
LDMIA R0!,{R1-R5}
STMDB R6!,{R0,R1,R5}
108 | P a g e
ESD LAB MANUAL Appendix B
Literal Addressing
In this addressing mode data is a part of instruction. ‘#’ symbol is used to indiacate 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
109 | P a g e
ESD LAB MANUAL Appendix B
in a single 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
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.
111 | P a g e
ESD LAB MANUAL Appendix B
This is used to facilitate the reading of sequential data in structures such as arrays,
tables, and vectors. A pointer register is used to hold the base address. An offset can be
added to achieve the effective address. For example,
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,
112 | P a g e
ESD LAB MANUAL 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
113 | P a g e
ESD LAB MANUAL 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.
114 | P a g e
ESD LAB MANUAL Appendix C
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.
115 | P a g e