Professional Documents
Culture Documents
R T E Societys
Rural Engineering College Hulkoti
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------------
-
Lab Manual
Prepared by
Lab Instructor
Ameer Betageri
Syllabus
PART-A: Conduct the following Study experiments to learn ALP using ARM Cortex M3 Registers using
an Evaluation board and the required software tool.
1. ALP to multiply two 16 bit binary numbers.
2. ALP to find the sum of first 10 integer numbers.
3. ALP to find the number of O's and 1's in a 32 bit data
4. ALP to find determine whether the given 16 bit is even or odd
5. ALP to write data to RAM
PART-B: Conduct the following experiments on an ARM CORTEX M3 evaluation board using
evaluation version of Embedded 'C' & Keil Uvision-4 tool/compiler.
10. Interface a 4x4 keyboard and display the key code on an LCD.
12. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between.
13. Measure Ambient temperature using a sensor and SPI ADC IC.
This chapter describes the Build Mode of µVision and explains the user interface; outlines the options for
generating and maintaining projects, including output file options, and highlights configuration options for
optimum code quality.
The required steps for creating application programs are listed below:
1. Package Installer File explains how to install LPC1768 device to µVision5 project file.
2. Create Project File explains how to create a µVision5 project file.
DEPT OF E&C, REC, HULKOTI 2
Embedded System Lab Manual 18ECL66 Sem: VI
3. Select Device describes how tool settings, peripherals, and dialogs are customized.
4. Set Options for Target explains how to specify relevant parameters for your target.
5. Create Source File describes how to add new files to the project.
6. Configure a Target
Configure Cortex-M Target describes how to change the startup-code and how to use the library
retarget file for Cortex-M devices. In addition, this is a brief explanation of CMSIS.
7. Create File Group explains how to structure the code files for a better overview.
8. Specify Memory Layout describes how to change file and group attributes.
9. Build Project describes the build-options.
Package Installer:
3 In Pack Installer select NXP - LPC1700 Series. Click on Install in Action menu so as to
µVision5 maintains the files that belong to a project in one project file. It takes only a few steps to create a
new project file with µVision4:
3. Switch to the new folder and type the project name Test1. µVision4 automatically adds the extension
.uvproj.
4. Click Save & Select Device for Target Target 1 is opened, select NXP
When you create a new project, µVision4 asks you to select a microcontroller. This step customizes
DEPT OF E&C, REC, HULKOTI 4
Embedded System Lab Manual 18ECL66 Sem: VI
the µVision4 environment with pre-configured options and sets the tool options, peripherals, and
dialogs for that particular device. The Select Device for Target dialog shows the µVision Device
Database.
Select the microcontroller you use. For this example, choose the NXP(founded by philips)
5 Now Manage Run Time Environment window will open as shown in the fig below.
Expand CMSIS option and select the CORE by selecting the check box.
Expand Divice option and select the Startup by selecting the check box.
6 Now the Target is created. Right Click on Target1 and Select Option for Target Target1
..
OR Press Alt+F7
8 Click on new document for writing the program & save the code with .c extension in desired folder.
10 Right click on the source Group1 & select Add Files to Group Source Group 1.
Select the file from the folder where project is saved & click on add.
Build Project
Build the project once the coding is done and check for errors. For building the project click F7 or click on
below shown option.
1. Translate and link the source files of the application with a click on one of the build-buttons
located in the Build Toolbar.
2. Errors or warnings are displayed in the Build Output Window. Double-click on a message to jump to
the line where the incident occurred.
3. Once you have generated your application successfully, you can start debugging.
Click on Install
Click on Select Device Button, expand ARM Cortex option & select the device LPC-1768
5 Select the COM Port Name, follow these Steps for knowing the PORT Name
a. Insert one end of the USB cable to the USB Port and Other end to kit.
b. Right Click on My Computer option from the desktop and select Manage Option as shown in
the below figure.
c. Click on Manage button and select the Device Manager Option as shown below
d. Expand Ports option on the right hand side to see the Serial port name of the USB Connected.
For Example : USB Serial Port(COM8)
6 Once the PORT name is known Select from COM Port dropdown, Set the Baud Rate and Oscillator
(MHz) to 115200 and 12.0 respectively & check the Erase Flash+Code Rd prot Used by Hex file.
7 Select the program from the desktop machine on click of Browse button
8 Once the program is selected click on the Start Button for downloading the code. Program is
downloaded through USB Port & check for the desired Output.
9 Now Press the Reset Button on VTCM3_B_1 kit and check for the desired output.
Register Configuration
LPC1768 has its GPIOs divided into five ports PORT0 - PORT4, although many of them are not
physically 32bit wide. Refer the data sheet for more info. The Below registers will be used for
Configuring and using the GPIOs registers for sending and receiving the Digital signals. A structure
LPC_GPIOn(n= 0,1,2,3) contains all the registers for required for GPIO operation. Refer lpc17xx.h
file for more info on the registers.
LPC1768 GPIO
PINSEL FIODIR FIOSET, FIOCLR, FIOPIN
Selects Pin Function Configure Pin Access the Port Pin
Direction
PINSEL: GPIO Pins Select Register Almost all the LPC1768 pins are multiplexed to
support more than 1 function. Every GPIO pin has a minimum of one function and max of four
functions. The required function can be selected by configuring the PINSEL register. As there
can be up to 4 functions associated with a GPIO pin, two bits for each pin are available to select
the function. This implies that we need two PINSEL registers to configure a PORT pins. By this
the first 16(P0.0-P0.16) pin functions of PORT0 can be selected by 32 bits of PINSELO register.
The remaining 16 bits(P0.16-P0.32) are configured using 32bits of PINSEL1 register. As mentioned
earlier every pin has max of four functions. Below table shows how to select the function for a
particular pin using two bits of the PINSEL register.
Values Direction
0 Input
1 Output
Values FIOSET
0 No Effect
1 Sets High on Pin
FIOCLR:Fast Port Output Clear Register.
This register controls the state of output pins. Writing 1s produces lows at the corresponding port
pins. Writing 0s has no effect.
Values FIOCLR
0 No Effect
1 Sets Low on Pin
This register is used for both reading and writing data from/to the
PORT. Output: Writing to this register places corresponding values in all bits of the
particular PORT pins. Input: The current state of digital port pins can be read from this register,
regardless of pin direction or alternate function selection (as long as pins are not
DEPT OF E&C, REC, HULKOTI 18
Embedded System Lab Manual 18ECL66 Sem: VI
Registers on LPC1768 are present on Peripheral AHB bus(Advanced High performance Bus) for fast
read/write timing. So, these are basically Fast I/O or Enhanced I/O and hence the naming
convention in datasheet uses a prefix of FIO instead of something like GIO for all the registers
related to GPIO. Lets go through these as given below.
1) FIODIR : This is the GPIO direction control register. Setting a bit to 0 in this register will configure
the corresponding pin to be used as an Input while setting it to 1 will configure it as Output.
2) FIOMASK : This gives masking mechanism for any pin i.e. it is used for Pin access control. Setting
a bit to 0 means that the corresponding pin will be affected by changes to other registers like
FIOPIN, FIOSET, FIOCLR. Writing a 1 means that the corresponding pin won‟t be affected by other
registers.
3) FIOPIN : This register can be used to Read or Write values directly to the pins. Regardless of the
direction set for the particular pins it gives the current start of the GPIO pin when read.
4) FIOSET : It is used to drive an „output‟ configured pin to Logic 1 i.e HIGH. Writing Zero does
NOT have any effect and hence it cannot be used to drive a pin to Logic 0 i.e LOW. For driving pins
LOW FIOCLR is used which is explained below.
5) FIOCLR : It is used to drive an „output‟ configured pin to Logic 0 i.e LOW. Writing Zero does NOT
have any effect and hence it cannot be used to drive a pin to Logic 1.
Most of the PINS of LPC176x MCU are Multiplexed i.e. these pins can be configured to provide up
to 4 different functions. By default, after Power-On or Reset : all pins of all ports are set as GPIO
so we can directly use them when learning GPIO usage. The different functions that any particular
pin provides can be selected by setting appropriate value in the PINSEL register for the
corresponding pin. Each pin on any port has 2 corresponding bits in PINSEL register. The first 16
pins (0-15) on a given port will have a corresponding 32 bit PINSEL register and the rest 16 bits will
have another register. For example bits 0 & 1 in PINSEL0 are used to select function for Pin 1 of
Port 0, bits 2 & 3 in PINSEL0 are used to select function for PIN 2 of port 0 and so on. The same is
applicable for PINMODE register which will go through in last section of this article. Have a look at
the diagram given below.
PINSEL0 Register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
P0.15 P0.14 P0.13 P0.12 P0.11 P0.10 P0.9 P0.8 P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
PINSEL1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
P0.31 P0.30 P0.29 P0.28 P0.27 P0.26 P0.25 P0.24 P0.23 P0.22 P0.21 P0.20 P0.19 P0.18 P0.17 P0.16
Example : Port 0.0 pin‟s function is decided by contents of PINSEL0 register bit 0 and bit 1
Since by default all pins are configured as GPIOs we don‟t need to explicitly assign a „0‟
value to PINSEL register in Programming examples.
PART-A EXPERIMENTS
EXPERMENT No 1
__main
mov r0,#0x0004
mov r1,#0xffff
mul r2,r0,r1
HERE B HERE
END
Result:
EXPERMENT No 2
;addition of 10 numbers 1 to 10
;The result of addition is stored in r2
__main
mov r0,#0
mov r1,#1
loop1 add r0,r1
add r1,#1
cmp r1,#0x0b
bne loop1
HERE B HERE
END
Result:
EXPERMENT No 3
HERE B HERE
END
Result:
EXPERMENT No 4
; Finding number given 16-bit number odd or even
; r3 holds 16-bit number
; r1 holds number 0xAA if number is even
; r1 holds number 0xff if number is odd
HERE B HERE
END
Result:
EXPERMENT No 5
; Writing data to RAM using different store instructions
ldr r4,=data
strb r2,[r4]
strh r2,[r4,#4]
str r2,[r4,#8]
strd r2,r3,[r4,#12]
HERE B HERE
END
Result :
PART-B EXPERIMENTS
LED D1 D2 D3 D4 D5 D6 D7 D8
LPC-1768
81 80 79 78 77 76 48 49
Pin No
LPC-1768
P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11
Port No
D11, D12, D13 and D14 are Common Cathode segments connected to LPC-1768 device so that
each segment is individually controlled by a general purpose I/O pin. When the LPC-1768 device
drives logic 0 the corresponding segment turns on. See fig and table for more details.
Seven
Segment g f a b p c d e
Data Lines
LPC-1768 Pin
75 74 73 70 69 68 67 66
No
LPC-1768
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
Port No
Display Encoding:
16 X 2 LCD Display
An LCD display is specifically manufactured to be used with microcontrollers, which means that it
cannot be activated by standard IC circuits. It is used for displaying different messages on a
miniature liquid crystal display. It displays all the letters of alphabet, Greek letters, punctuation
marks, mathematical symbols etc. In addition, it is possible to display symbols made up by the
user. Other useful features include automatic message shift (left and right), cursor appearance,
LED backlight etc.
There are pins along one side of a small printed board. These are used for connecting to the
microcontroller.
Digits to Hex There are in total
Display Segments
display code of 14 pins marked
g f a b p c d e with numbers (16 if
0 1 0 0 0 1 0 0 0 88 it has backlight).
1 1 1 1 0 1 0 1 1 EB Their function is
described in the
2 0 1 0 0 1 1 0 0 4C
table below:
3 0 1 0 0 1 0 0 1 49
4 0 0 1 0 1 0 1 1 2B LCD Pin Configuration
5 0 0 0
LCD 1 LCD1 Pin 0 LPC- 0 1 LPC-19
6 0 0 0 No 1 Functions
1 1 17681 0 176818
Pin
Pin No Port No
7 1 1 0 0 1 0 1 1 CB
1 GND - -
8 0 0 0 0 1 0 0 0 08
2 VCC - -
9 0 0 0 0 1 0 0 1 09
3 - -
A 0 0 0 0 1 0 1 0 0A
4 RS 24 P2.28
B 0 0 1 1 1 0 0 0 38
5 R/W GND GND
C 1 0 0 1 1 0 0 0 98
6 EN 25 P2.25
D 0 1 1 0 1 0 0 0 68
7 DAT1 75 P2.0
E 0 0 0 1 1 1 0 0 1C
8 DAT2 74 P2.1
9 DAT3 73 P2.2
F 0 0 0 1 1 1 1 0 1E
10 DAT4 70 P2.3
11 DAT5 69 P2.4
12 DAT6 68 P2.5
13 DAT7 67 P2.6
14 DAT8 66 P2.7
15 VCC - -
16 GND - -
DC (direct current) motor rotates continuously. It has two terminals positive and negative.
Connecting DC power supply to these terminals rotates motor in one direction and reversing the
polarity of the power supply reverses the direction of rotation.
The speed of Dc motor can maintained at a constant speed for a given load by using Pulse Width
Modulation (PWM) technique. By changing the width of the pulse of applied to dc motor, the
power applied is varied thereby DC motor speed can be increased or decreased. Wider the pulse
Faster is the Speed, Narrower is the Pulse, and Slower is the Speed
U9 is L293 driver IC used to drive the dc motor. It has enable lines which is used to switch on the
DC motor. It is connected to P4.28. Logic 1 enables the driver and logic 0 disables the
driver.P4.28 and P4.29 are used for Motor 1 direction and speed control.
A stepper motor is a special type of electric motor that moves in increments, or steps, rather than
turning smoothly as a conventional motor does. Typical increments are 0.9 or 1.8 degrees, with 400
or 200 increments thus representing a full circle. The speed of the motor is determined by the time
delay between each incremental movement.
U8 is a Driver Buffer (ULN2003) device connected to LPC-1768 Device and can be used for
driving Stepper Motor. On the LPC-1768, P1.22 to P1.25 is used to generate the pulse sequence
required to run the stepper Motor. Also, the Stepper Motor is powered by its own power supply pin
(COM), which is connected to a 12V supply. Table shows connections for stepper Motor.
Stepper Motor Pin connection table.
Stepper LPC-1768 LPC-1768
Motor Coil Pin No Port No
A 39 P1.22
B 37 P1.23
C 38 P1.24
D 39 P1.25
Relay Configurations:
DEPT OF E&C, REC, HULKOTI 29
Embedded System Lab Manual 18ECL66 Sem: VI
USER
DEFINE S1 S6 S11 S12 S17 S22 S23 S24
D KEYS
LPC-
1768 1 2 3 4 5 6 7 8
Pin No
LPC-
1768 P1.14 P1.15 P1.16 P1.17 P1.18 P1.19 P1.20 P1.21
Port No
ADC:
12-bit successive approximation analog to digital converter.
Input multiplexing among 8 pins.
Power-down mode.
Measurement range VREFN to VREFP (typically 3 V; not to exceed VDDA voltage level).
12-bit conversion rate of 200 kHz.
Burst conversion mode for single or multiple inputs.
Optional conversion on transition on input pin or Timer Match signal. Basic clocking for the A/D
converters is provided by the APB clock. A programmable divider is included in each
converter to scale this clock to the clock (maximum 13 MHz) needed by the successive
approximation process. A non-burst mode conversion requires 65 clocks and a burst mode
conversion requires 64 clocks.
As VTCM3_3 board comes with two ADC inputs. One is connected to a potentiometer for external
analog voltage and another is for temperature measurement.
A 5K variable POT is connected to AD0(P0.23) input of LPC1768. By varying this we are applying 0
to 3.3V to ADC0 input. This analog voltage input can be converted into digital output.
An LM35 temperature sensor is connected through ADC SSP IC to SSEL input of LPC1768 for
ambient temperature measurement.
DAC:
Features
Buffered output
As VTCM3_3 board comes with one DAC output for generation different wave forms. AOUT
(P0.26) is connected to TEST point TP1. The generated waveforms can be viewed through TP1
(DAC) and TP2 (GND) by connecting CRO.
PWM:
Features
Counter or Timer operation (may use the peripheral clock or one of the capture inputs as the
clock source).
Seven match registers allow up to 6 single edge controlled or 3 double edge controlled PWM
outputs, or a mix of both types. The match registers also allow:
Supports single edge controlled and/or double edge controlled PWM outputs. Single edge
controlled PWM outputs all go high at the beginning of each cycle unless the output is a
constant low. Double edge controlled PWM outputs can have either edge occur at any position
within a cycle. This allows for both positive going and negative going pulses.
Pulse period and width can be any number of timer counts. This allows complete flexibility in
the trade-off between resolution and repetition rate. All PWM outputs will occur at the same
repetition rate.
Double edge controlled PWM outputs can be programmed to be either positive going or
negative going pulses.
Match register updates are synchronized with pulse outputs to prevent generation of
DEPT OF E&C, REC, HULKOTI 32
Embedded System Lab Manual 18ECL66 Sem: VI
Erroneous pulses. Software must "release" new match values before they can become effective.
May be used as a standard timer if the PWM mode is not enabled.
A 32-bit Timer/Counter with a programmable 32-bit prescaler.
Two 32-bit capture channels take a snapshot of the timer value when an input signals
transitions. A capture event may also optionally generate an interrupt. As VTCM3_3 board
comes with one DAC output for generation different wave forms. AOUT (P0.26) is connected to
TEST point TP1. The generated waveforms can be viewed through TP1 (DAC) and TP2 (GND) by
connecting CRO.
As VTCM3_3 board comes with one PWM output for generation PWM wave forms. AOUT (P0.26)
is connected to TEST point TP1. The generated waveforms can be viewed through TP1 (DAC) and
TP2 (GND) by connecting CRO.
EXPERMENT No 6
#include "LPC17xx.h"
{
while (!(LPC_UART0->LSR & 0x01));
return (LPC_UART0->RBR);
}
EXPERMENT No 7
#include <LPC17xx.H>
#include "lcd.h"
LPC_GPIO4->FIOCLR |= MOTOR_MASK;
LPC_GPIO4->FIOSET |= temp;
}
LPC_GPIO4->FIODIR |= MOTOR_MASK;
LPC_GPIO2->FIODIR |= MTE;
LPC_GPIO2->FIOCLR |= MTE;
lcd_putstring16(0,"1,2 START/STOP");
lcd_putstring16(1,"3,4 SPED DCMOTOR");
while(1)
{
if (!(LPC_GPIO1->FIOPIN & KEY_START))
{
motor_write(0x01);
LPC_GPIO2->FIOSET |= MTE;
}
LPC_GPIO2->FIOCLR |= MTE;
}
if (del == 0)
LPC_GPIO2->FIOSET |= MTE;
else
{
LPC_GPIO2->FIOCLR |= MTE;
for (i=0; i < del; i++);
LPC_GPIO2->FIOSET |= MTE;
for (i=0; i < del; i++);
}
}
}
EXPERMENT No 8
LPC_GPIO1->FIODIR |= MOTOR_MASK;
LPC_GPIO1->FIOCLR |= MOTOR_MASK;
LPC_GPIO1->FIODIR &= ~( KEY_CW | KEY_CCW);
LPC_GPIO1->FIOSET |= (KEY_CW | KEY_CCW);
motor_write(stpval);
while(1)
{
if (!(LPC_GPIO1->FIOPIN & KEY_CW))
dir = 0;
if (!(LPC_GPIO1->FIOPIN & KEY_CCW))
dir = 1;
DEPT OF E&C, REC, HULKOTI 36
Embedded System Lab Manual 18ECL66 Sem: VI
if (dir == 0)
{
if (stpval == 8)
stpval = 1;
else
stpval <<= 1;
}
else
{
if (stpval == 1)
stpval = 8;
else
stpval >>= 1;
}
motor_write(stpval);
delay(del);
}
}
}
EXPERMENT No 9A
#include <LPC17xx.H>
#include "lcd.h"
#define voltage 1024
#define freq 120000
while(1)
{
LPC_DAC->DACR = (voltage/2 << 6);
for(m = freq; m > 1; m--);
LPC_DAC->DACR = (voltage << 6);
for(m = freq; m > 1; m--);
}
}
EXPERMENT No 9B
EXPERMENT No 10
#include <LPC17xx.H>
#include "lcd.h"
LPC_GPIO1->FIOCLR |= COLMASK;
LPC_GPIO1->FIOSET |= temp;
}
init_lcd();
LPC_GPIO1->FIODIR |= COLMASK;
LPC_GPIO1->FIODIR &= ~(ROWMASK);
col_write(rval[i]);
key++;
if (!(LPC_GPIO1->FIOPIN & ROW2))
break;
key++;
if (!(LPC_GPIO1->FIOPIN & ROW3))
break;
key++;
if (!(LPC_GPIO1->FIOPIN & ROW4))
break;
key++;
}
if (key == 0x10)
lcd_putstring16(1,"Key Pressed = ");
else
{
lcd_gotoxy(1,14);
lcd_putchar(keyPadMatrix[key]);
}
}
EXPERMENT No 11
#include <lpc17xx.h>
#include "lcd.h"
#define PINSEL_EINT0 20
#define PINSEL_EINT1 22
#define SBIT_EINT0 0
#define SBIT_EINT1 1
#define SBIT_EXTMODE0 0
#define SBIT_EXTMODE1 1
#define SBIT_EXTPOLAR0 0
#define SBIT_EXTPOLAR1 1
void EINT0_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT0);
LPC_GPIO0->FIOPIN ^= LED1;
}
void EINT1_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT1);
LPC_GPIO0->FIOPIN ^= LED2;
}
DEPT OF E&C, REC, HULKOTI 40
Embedded System Lab Manual 18ECL66 Sem: VI
int main()
{
init_lcd();
lcd_putstring16(0,"XTERNL INTERUPTS");
lcd_putstring16(1,"I0-LED1 I1-LED2");
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
while(1)
{
// Do nothing
}
}
EXPERMENT No 12
// Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between
LPC_GPIO2->FIODIR = 0x000000FF;
LPC_GPIO2->FIOPIN = 0x000000FF;
LPC_GPIO1->FIODIR |= 0x3C000000;
LPC_GPIO1->FIOPIN &= ~(0x3C000000);
init_lcd();
EXPERMENT No 13
#include <LPC17xx.H>
#include <stdio.h>
#include "lcd.h"
#include "spi.h"
int main (void)
{
uint8_t msb, lsb;
uint16_t ADCValue;
float temp;
char lstr[10];
SPI_Init();
init_lcd();
while(1)
{
SPI_EnableChipSelect();
delay(1);
SPI_Write(0x01);
msb = SPI_Write(0xA0);
lsb = SPI_Write(0x00);
SPI_DisableChipSelect();
msb &= 0x0F;
ADCValue = (msb << 8) | lsb;
delay(500);
}
}