0% found this document useful (0 votes)
7 views

Lab Manual (3) (2)

The document is a lab manual detailing experiments using the Keil IDE with the ARM LPC2148 microcontroller. It includes step-by-step instructions for creating projects, writing embedded C programs for various tasks such as blinking LEDs, displaying strings on an LCD, and serial data transmission. Each experiment outlines the necessary code, setup, and debugging procedures to successfully execute the tasks.

Uploaded by

dhakshayani568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lab Manual (3) (2)

The document is a lab manual detailing experiments using the Keil IDE with the ARM LPC2148 microcontroller. It includes step-by-step instructions for creating projects, writing embedded C programs for various tasks such as blinking LEDs, displaying strings on an LCD, and serial data transmission. Each experiment outlines the necessary code, setup, and debugging procedures to successfully execute the tasks.

Uploaded by

dhakshayani568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 118

Lab Manual

Experiment 1:
Overview and introduction to Keil IDE
Keil with ARM LPC2148
Steps to create project in Keil for LPC2148
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project


3. Create a folder and name it as Lab1 and save the project as Lab1 in the folder
Lab1.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.

5. Click on yes to add startup file to the project.


6. Now click on new from file menu to create a file in the project.
7. It displays empty file. Type the program and save it as lab1 .c extension for C
program.
Code
#include<lpc214x.h>
//#define sw(IOSET0=(1<<0))
#define buzzer 0x00000002
unsigned int sw;
int main()
{
IODIR0=0x0000000E;
//IOPIN0=0x00000000;
while(1)
{
sw=IOSET0 & 0x00000001;
if(sw=0x00000001)
{
IOSET0=buzzer;
}
else
{
IOCLR0=buzzer;
}
}
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to peripherals menu, click on GPIO Slow Interface and select Port 0. It
displays port window to check output.
14.Now click on program window and press F11 continuously to check output on
the port window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
Experiment 2:
Develop an Embedded C program to blink an LED without timers.
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab2 and save the project as Lab2 in the folder
Lab2.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays empty file. Type the program and save as lab2.c.

Code
#include<lpc214x.h>
void delay();
void main()
{
IO0DIR=0xFFFFFFFF;
while(1)
{
IOSET0=0xFFFFFFFF;
delay();
IOCLR0=0xFFFFFFFF;
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<100;i++);
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to peripherals menu, click on GPIO Slow Interface and select Port 0. It
displays port window to check output.
14.Now click on program window and press F11 continuously to check output on
the port window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
Experiment 3:
Develop an Embedded C program to blink an LED when switch is pressed

1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab3 and save the project as Lab3 in the folder
Lab3.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.

5. Click on yes to add startup file to the project.


6. Now click on new from file menu to create a file in the project.
7. It displays empty file. Type the program and save as lab3.c.
Code
#include<lpc21xx.h>
void delay(unsigned int t)
{
unsigned int i, j;
for(i=0;i<t;t++)
for(j=0;j<1000;j++);
}
int main()
{
PINSEL0=0x0000;
IODIR0=0xFF;
while(1)
{
IOSET0=0xFF;
delay(100);
IOCLR0=0xFF;
delay(100);
}
return 0;
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to peripherals menu, click on GPIO Slow Interface and select Port 0. It
displays port window to check output.
14.Now click on program window and press F11 continuously to check output on
the port window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
16.To show the simulation with virtual hardware, use Proteus software.
17.Open Proteus 8 Professional software.
18.From file menu, select new project
19.From the project window, change the folder and give name as Lab3 to the
project.
20.Click on next until it shows finish. Then click on finish.
21.It shows an empty template as shown in figure
22.Now select the required devices for the connections.
23.For this experiment the devices needed are
a. LPC2138 – 1
b. Resistor - 1
c. Capacitor - 2
d. Switch - 1
e. LED – 2
f. Cell – 1
g. Crystal - 1
h. Ground - 3 connections
24.To select the devices click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
b. Resistor – Type resistor in the keywords option and select generic in
subcategory and then select RES Device from the displayed options.
c. Capacitor – Type capacitor in the keywords option and select ceramic disc
in subcategory and then select Ceramic 22P capacitor
d. Switch – Type switch and click on OK (no need to select a specific option)
e. Cell – Type cell in the keywords option and select CELL Battery (single-
cell).
f. Crystal – Type crystal in the keywords option and select CRYSTAL Device
Quartz crystal
g. LED – Type “led anim” in the keywords option and select a colored LED.
Do it for two times to get 2 LEDs
h. Ground – Select Terminals from left pane icons. And select ground from
them. Do this for three times to get 3 ground terminals.
25.Complete the connections as shown in figure.
26.While connecting the devices, some device properties need to be changed.
a. Crystal – Right click on the device and click on edit properties, now change
frequency to 12MHz
b. Cell – Right click on the device and click on edit properties, now change
voltage to 3.3V
c. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
27.Now open Keil uvision 4 to create “Hex” File.
28.Open the project Lab3 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
29.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

30.Now build the project to create hex file.


31.Now open Proteus software and open Lab3 project.
32.In the schematic picture, right click on LPC2138 and select edit properties
option.
33.Select the hex file from the option Program File by clicking on the folder icon.

34.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
35.Click on the play button at the bottom of the screen. It will show the output.
36.For this experiment, by clicking on the switch LED will lit on and off.
Output screen
When Switch is on

When switch is off

Experiment 4:
Develop an Embedded c program Display String on LCD using LPC2148
controller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab3 and save the project as Lab4 in the folder
Lab4.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays empty file. Type the program and save as lab4.c.

Code
#include <lpc214x.h>
void initLCD(void);
//void enable(void);
void LCD_Write(unsigned int c);
void LCD_cmd(unsigned int LCD_cmd);
void delay(void);
int main(void)
{
unsigned char ch[] = "*Welcome*";
unsigned char ch1[] = "*ESD Lab*";
unsigned int i,j,k,t;
initLCD();
for(i=0;ch[i]!='\0';i++)
{
LCD_Write(ch[i]);
}
LCD_cmd(0xc3);
for(j=0;ch1[j]!='\0';j++)
{
LCD_Write(ch1[j]);
}
while(1)
{
//for(k=0;k<16;k++)
//{
//LCD_cmd(0x1c);
//fot(t=0;t<300;t++);
//}
}
}
void initLCD(void)
{
IO0DIR=0x0FFFF00;
delay();
LCD_cmd(0x38);
LCD_cmd(0x01);
LCD_cmd(0x0c);
LCD_cmd(0x83);
LCD_cmd(0x06);
}
void LCD_Write(unsigned int c)
{
IO0PIN=(c<<16) | (1<<10);
delay();
}
void LCD_cmd(unsigned int LCD_cmd)
{
IO0PIN=(LCD_cmd<<16) | (0<<10);
delay();
}
void delay(void)
{
int i=0,x=0;
IO0PIN |=(1<<13);
for(i=0;i<199;i++)
{
x++;
}
IO0PIN&=~(1<<13);
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.

10.If there are no errors click on OK in the displayed window.


11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to peripherals menu, click on GPIO Slow Interface and select Port 0. It
displays port window to check output.
14.Now click on program window and press F11 continuously to check output on
the port window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
16.To show the simulation with virtual hardware, use Proteus software.
17.Open Proteus 8 Professional software.
18.From file menu, select new project
19.From the project window, change the folder and give name as Lab4 to the
project.
20.Click on next until it shows finish. Then click on finish.
21.It shows an empty template as shown in figure
22.Now select the required devices for the connections.
23.For this experiment the devices needed are
a. LPC2138 – 1
b. Cell – 1
c. LCD - 1
d. Ground - 1 connections
24.To select the devices click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
b. Cell – Type cell in the keywords option and select CELL Battery (single-
cell).
c. LCD – Type lcd in the keywords option and select LM016L Display 16x2
Alphanumeric LCD
d. Ground – Select Terminals from left pane icons. And select ground from
them. Do this for three times to get 3 ground terminals.
25.Complete the connections as shown in figure.
26.While connecting the devices, some device properties need to be changed.
a. Cell – Right click on the device and click on edit properties, now change
voltage to 3.3V
b. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
27.Now open Keil uvision 4 to create “Hex” File.
28.Open the project Lab4 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
29.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

30.Now build the project to create hex file.


31.Now open Proteus software and open Lab4 project.
32.In the schematic picture, right click on LPC2138 and select edit properties
option.
33.Select the hex file from the option Program File by clicking on the folder icon.
34.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
35.Click on the play button at the bottom of the screen. It will show the output.
36.For this experiment, the LCD will display the string “Welcome ESD Lab”
Output screen

Experiment 5:
Develop an Embedded c program for Serial transmission of data using
LPC2148 controller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab5 and save the project as Lab5 in the folder
Lab5.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab5.c.

Code

#include<lpc214x.h>
int main(void)
{
PINSEL0=5;
U0LCR=0x83;
U0DLM=0x00;
U0DLL=97;
U0LCR=0x03;
while(1)
{
while(!(U0LSR & 0x20));
U0THR='a';
}
}

8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.

10.If there are no errors click on OK in the displayed window.


11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to serial windows option in the tool bar and select UART 1. It displays
UART window at the bottom of the screen.
14.Now click on program window and press F11 continuously to check output on
the UART window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
16.To show the simulation with virtual hardware, use Proteus software.
17.Open Proteus 8 Professional software.
18.From file menu, select new project
19.From the project window, change the folder and give name as Lab5 to the
project.
20.Click on next until it shows finish. Then click on finish.
21.It shows an empty template as shown in figure
22.Now select the required devices for the connections.
23.For this experiment the devices needed are
a. LPC2138 – 1
b. DC - 2
c. Virtual Terminal - 1 connections
24.To select the devices click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
b. DC – Select Generator mode from the left pane icons. Select DC and
double click on the dashboard.
c. Virtual Terminal – Select Virtual Instruments mode from the left pane
icons. Select Virtual Terminal and double click on the dashboard.
25.Complete the connections as shown in figure.
26.While connecting the devices, some device properties need to be changed.
a. DC – Right click on the device and click on edit properties, now change
voltage to 3.3V
b. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
27.Now open Keil uvision 4 to create “Hex” File.
28.Open the project Lab5 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
29.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

30.Now build the project to create hex file.


31.Now, open Proteus software and open Lab5 project.
32.In the schematic picture, select active popup mode from the left pane icons
and drag it on the virtual terminal, to get popup window of virtual terminal.
33.In the schematic picture, right-click on LPC2138 and select edit properties
option.
34.Select the hex file from the option Program File by clicking on the folder icon.

35.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
36.Click on the play button at the bottom of the screen. It will show the output.
37.For this experiment, the virtual terminal will display the character ‘a’.
Output screen

Experiment 6:
Develop an Embedded c program for Serial communication receiving of
data using LPC2148 controller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab6 and save the project as Lab6 in the folder
Lab6.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab6.c.

Code

#include <lpc21xx.h>
#include <stdio.h>

unsigned char receive()


{
while(!(U0LSR & 0x01));
return (U0RBR);
}

void transmit(unsigned char ch)


{
while(!(U0LSR & 0x20));
U0THR=ch;
}

void main()
{
unsigned char key;
PINSEL0=5;
U0LCR=0X83;
U0DLM=0X00;
U0DLL=97;
U0LCR=0X03;
while(1)
{
key=receive();
transmit(key);
}
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to serial windows option in the tool bar and select UART 1. It displays
UART window at the bottom of the screen.

14.Now click on program window and press F11 continuously to check output on
the UART window.

15.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
16.To show the simulation with virtual hardware, use Proteus software.
17.Open Proteus 8 Professional software.
18.From file menu, select new project
19.From the project window, change the folder and give name as Lab5 to the
project.

20.Click on next until it shows finish. Then click on finish.


21.It shows an empty template as shown in figure
22.Now select the required devices for the connections.
23.For this experiment the devices needed are
d. LPC2138 – 1
e. DC - 2
f. Virtual Terminal - 2 connections
24.To select the devices, click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
d. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
e. DC – Select Generator mode from the left pane icons. Select DC and
double click on the dashboard.
f. Virtual Terminal – Select Virtual Instruments mode from the left pane
icons. Select Virtual Terminal and double click on the dashboard.
25.Complete the connections as shown in figure.
26.While connecting the devices, some device properties need to be changed.
c. DC – Right click on the device and click on edit properties, now change
voltage to 3.3V
d. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
27.Now open Keil uvision 4 to create “Hex” File.
28.Open the project Lab6 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
29.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

30.Now build the project to create hex file.


31.Now, open Proteus software and open Lab6 project.
32.In the schematic picture, select active popup mode from the left pane icons
and drag it on the virtual terminals, to get popup window of virtual terminals.
33.In the schematic picture, right-click on LPC2138 and select edit properties
option.
34.Change clock frequency to 12 MHz and then select the hex file from the
option Program File by clicking on the folder icon.

35.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
36.Click on the play button at the bottom of the screen. It will show the output.
37.For this experiment, make the virtual terminal TX as active and then type any
characters. This data will be displayed in the RX virtual terminal. TX virtual
terminal.
Output screen

Experiment 7:
Develop an Embedded c program for interfacing street light based on the
command with string comparison using LPC2148 controller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab7 and save the project as Lab7 in the folder
Lab7.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab7.c.

Code
#include<lpc21xx.h>
#include<string.h>
unsigned char a[11],i;
void str(unsigned char*l);
void tx(unsigned char x);
int main()
{
PINSEL0=0X00000005;
IODIR0=0X00000003E;
U0LCR=0X83;
U0DLL=0X61;
U0LCR=0X03;
while(1)
{
for(i=0;i<16;i++)
{
while((U0LSR&0X01)==0);
a[i]=U0RBR;
U0THR=a[i];
while((U0LSR&0X40==0));
}
if(strcmp(a,"street lights on")==0)
{
IOSET0=0X00000004;
}
else if(strcmp(a,"street lights of")==0)
{
IOCLR0=0X00000004;
}
else
{
str("WRONG COMM");
}
tx(0x0a);
i=0;
}
}
void tx(unsigned char x)
{
U0THR=x;
while((U0LSR&0X40)==0);
}
void str(unsigned char*l)
{
while(*l!='\0')
tx(*l++);
}

8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.

10.If there are no errors click on OK in the displayed window.


11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to serial windows option in the tool bar and select UART 1. It displays
UART window at the bottom of the screen.
14.Go to peripherals option and select GPIO Slow Interface Port 0. It displays port
window.
15.Now click on program window and press F11 continuously to check output on
the UART window.

16.After completing the execution stop the debugging by selecting start/stop


debug session from debug menu.
17.To show the simulation with virtual hardware, use Proteus software.
18.Open Proteus 8 Professional software.
19.From file menu, select new project
20.From the project window, change the folder and give name as Lab7 to the
project.

21.Click on next until it shows finish. Then click on finish.


22.It shows an empty template as shown in figure
23.Now select the required devices for the connections.
24.For this experiment the devices needed are
a. LPC2138 – 1
b. DC - 1
c. Virtual Terminal - 2 connections
d. LED – 2
e. Ground – 2
25.To select the devices, click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
b. LED – Type led anim in the keywords option and select two leds of two
different colors.
c. DC – Select Generator mode from the left pane icons. Select DC and
double click on the dashboard.
d. Virtual Terminal – Select Virtual Instruments mode from the left pane
icons. Select Virtual Terminal and double click on the dashboard.
e. Ground – Select Terminals mode from the left pane icons. Select Ground
and double click on the dashboard.
26.Complete the connections as shown in figure.
27.While connecting the devices, some device properties need to be changed.
a. DC – Right click on the device and click on edit properties, now change
voltage to 3.3V
b. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
28.Now open Keil uvision 4 to create “Hex” File.
29.Open the project Lab7 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
30.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

31.Now build the project to create hex file.


32.Now, open Proteus software and open Lab7 project.
33.In the schematic picture, select active popup mode from the left pane icons
and drag it on the virtual terminals, to get popup window of virtual terminals.
34.In the schematic picture, right-click on LPC2138 and select edit properties
option.
35.Change clock frequency to 12 MHz and then select the hex file from the
option Program File by clicking on the folder icon.

36.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
37.Click on the play button at the bottom of the screen. It will show the output.
38.For this experiment, make the virtual terminal TX as active and then type
“street lights on”, then the message will be displayed on RX virtual terminal
and the LEDs will blink.
39.Type again “street lights of” then the message will be displayed on RX virtual
terminal and the LEDs will stop blinking.
Output screen
Experiment 8:
a. Develop an Embedded c program for interfacing seven segment display
using LPC2148 controller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab8 and save the project as Lab8 in the folder
Lab8.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab8.c.

Code
#include<lpc214x.h>
unsigned char dig[] = {0x88, 0xeb, 0x4c, 0x49, 0x2b, 0x19, 0x18, 0xcb,
0x08, 0x09, 0x0a, 0x38, 0x98, 0x68, 0x1c, 0x1e};
void delay(unsigned int count)
{
int j=0, i=0;
for(j=0; j<count;j++)
{
for(i=0;i<1200;i++);
}
}
int main(void)
{
unsigned char count=0;
IO0DIR |= (1 << 11);
IO0SET |= (1 << 11);
IO0DIR |= 0x007f8000;
while(1)
{
for(count=0;count<=15;count++)
{
IO0CLR = 0x007f8000;
IO0SET = (dig[count] << 15);
delay(1000);
}
}
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.Go to peripherals option and select GPIO Slow Interface Port 0. It displays port
window.

14.Now click on program window and press F11 continuously to check output on
GPIO port 0.
15.After completing the execution stop the debugging by selecting start/stop
debug session from debug menu.
16.To show the simulation with virtual hardware, use Proteus software.
17.Open Proteus 8 Professional software.
18.From file menu, select new project
19.From the project window, change the folder and give name as Lab8 to the
project.

20.Click on next until it shows finish. Then click on finish.


21.It shows an empty template as shown in figure
22.Now select the required devices for the connections.
23.For this experiment the devices needed are
a. LPC2138 – 1
b. Cell – 1
c. 7 segment - 1
d. Button switch - 1
e. Crystal – 1
f. Resistor – 1
g. Capacitor - 2
24.To select the devices, click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138.
b. 7 Segment – Type 7seg in the keywords option and select 7SEG-MPX4-CA.
c. Button switch – Type button in the keywords option and select button.
d. Cell – Type cell in the keywords option and select cell device battery
single-cell.
e. Capacitor – Type ceramic22 in the keywords option and select ceramic22P
option.
f. Crystal – Type crystal in the keywords option and select crystal device
option.
g. Resistor – Type Res in the keywords option and select res device option.
25.Complete the connections as shown in figure.
26.While connecting the devices, some device properties need to be changed.
a. Cell – Right click on the device and click on edit properties, now change
voltage to 3.3V
b. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
c. Crystal – Right click on the device and click on edit properties, now change
frequency to 12MHz.
27.Now open Keil uvision 4 to create “Hex” File.
28.Open the project Lab8 and right click on the target 1 from the left pane. Then
select “options for target target 1”.
29.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.

30.Now build the project to create hex file.


31.Now, open Proteus software and open Lab8 project.
32.In the schematic picture, select active popup mode from the left pane icons
and drag it on the virtual terminals, to get popup window of virtual terminals.
33.In the schematic picture, right-click on LPC2138 and select edit properties
option.
34.Change clock frequency to 12 MHz and then select the hex file from the
option Program File by clicking on the folder icon.

35.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
36.Click on the play button at the bottom of the screen. It will show the output.
37.For this experiment, the seven segment display will display the hexa-decimal
numbers from 0 to 9 and A to F.
Output screen
b. Develop an Embedded c program to implement PWM using LPC2148
microcontroller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab8 and save the project as Lab8 in the folder
Lab8.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab8_1.c.

Code
#include<lpc214x.h>
void pwm_init(void)
{
PINSEL0 = 0x8002;
PWMPCR = 0x600;
PWMMR0 = 150000;
PWMTCR = 0x09;
PWMMCR = 0x02;
}
int main(void)
{
pwm_init();
while(1)
{
PWMMR1 = 75000;
PWMMR2 = 90000;
PWMLER = 0x6;
}
}
8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.From the toolbar, select analysis windows option. In that option select Logic
Analyzer option. It displays a window as shown below.

14.Now click on setup option and assign the port bits that should be analyzed.
Click on square box and type PORT0.0 and press enter.
15.Again click on square box and type PORT0.7 and press enter.
16.Now change the display type as bit and color of your choice for two ports.
17.Then click on close option.

18.Now click on Run option from the tool bar or press “F5” to start execution.
19.It shows the sine wave for the two ports as shown below as the output.
Experiment 9:
Develop an Embedded c program for interfacing DAC to generate
triangular waves using LPC 2148 Microcontroller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab9 and save the project as Lab9 in the folder
Lab9.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab9.c.

Code
#include<lpc214x.h>
void delay()
{
int i;
for(i=0;i<2000;i++);
}
void main()
{
int i,j;
PINSEL1=1<<19;
DACR=0;
while(1)
{
for(i=0;i<1024;i++)
{
DACR=i<<6;
delay();
}
for(i=1023;i>=0;i--)
{
DACR=i<<6;
delay();
}
}
}

8. Add the C program to the project by right clicking on source group Add files
to Group “Source Group 1”. Select the required “C” file from the displayed
window and click on the Add button once and then close the window.
9. To compile the program press F7 or click on build option.
10.If there are no errors click on OK in the displayed window.
11.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
12.Click on OK button on the displayed window. Now the debug started.
13.From the toolbar, select analysis windows option. In that option select Logic
Analyzer option. It displays a window as shown below.

14.Now click on setup option and assign the port bits that should be analyzed.
Click on square box and type AOUT and press enter.
15.Now change the display type as analog and color of your choice for AOUT.
16.Then click on close option.

17.Now click on Run option from the tool bar or press “F5” to start execution.
18.Now click on All option in Zoom tab in Logical Analyzer.
19.It shows the triangular wave for the port AOUT as shown below as the output.

20.To show the simulation with virtual hardware, use Proteus software.
21.Open Proteus 8 Professional software.
22.From file menu, select new project
23.From the project window, change the folder and give name as Lab9 to the
project.
24.Click on next until it shows finish. Then click on finish.
25.It shows an empty template as shown in figure
26.Now select the required devices for the connections.
27.For this experiment the devices needed are
a. LPC2138 – 1
b. DC – 1
c. Oscilloscope - 1
28.To select the devices, click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.
f. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
g. DC – Select Generator mode from the left pane icons. Select DC and
double click on the dashboard.
h. Oscilloscope – Select Virtual Instruments mode from the left pane icons.
Select Oscilloscope and double click on the dashboard.
29.Complete the connections as shown in figure.
30.While connecting the devices, some device properties need to be changed.
c. DC – Right click on the device and click on edit properties, now change
voltage to 3.3V
d. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
31.Now open Keil uvision 4 to create “Hex” File.
32.Open the project Lab9 and right click on the target 1 from the left pane. Then
select “options for target target 1”.

33.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.
34.Now build the project to create hex file.
35.Now, open Proteus software and open Lab9 project.
36.In the schematic picture, right-click on LPC2138 and select edit properties
option.
37.Change clock frequency to 12 MHz and then select the hex file from the
option Program File by clicking on the folder icon.

38.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
39.Click on the play button at the bottom of the screen. It will show the output.
40.For this experiment, it shows the oscilloscope for output. In oscilloscope make
some changes as given below.
a. Trigger – change level to 71
b. Channel A – change position to 41, select DC, and voltage to 0.5mV.
c. Channel C – change position to 40, select OFF, and voltage to 0.2mV.
d. Horizontal – select seconds to 0.15mS
e. Channel B – change position to 0, select AC, and voltage to 1.13mV.
f. Channel D - change position to 120, select OFF, and voltage to 0.1mV.
g. Now stop execution by clicking on stop button.
h. Again start execution by clicking on play button.
Output Screen
Experiment 10:
Develop an Embedded c program for interfacing GSM module to send SMS
from LPC 2148 Microcontroller
1. Open Keil μVision4 software.

2. Create project by clicking on project  new μVision project

3. Create a folder and name it Lab10 and save the project as Lab10 in the folder
Lab10.
4. From the displayed window, select NXP (founded by Philips) and select
LPC2148 and click on OK button.
5. Click on yes to add startup file to the project.
6. Now click on new from file menu to create a file in the project.
7. It displays an empty file. Type the program and save as lab10.c.

Code
#include <LPC214x.h>

void Uart0Init()
{
PINSEL0 = 0x05;
U0LCR = 0x83;
U0DLM = 0x00;
U0DLL = 97;
U0LCR = 0x03;
}

unsigned char UART0_PutChar(unsigned char ch)


{
while(!(U0LSR & 0x20));
U0THR = ch;
return ch;
}

void UART0_PutS(unsigned char *ch)


{
while(*ch)
{
UART0_PutChar(*ch++);
}
}

8. Now, create an empty document by clicking on New option from menu.


9. Save it as GSM.c and write the code as given below

Code

#include<LPC214x.h>

void delay(unsigned int time)


{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<5000;j++);
}

void main()
{
Uart0Init();
UART0_PutS("ATE0\r\n");
delay(1000);
UART0_PutS("ATD7981290767;\r\n");
delay(10000);
UART0_PutS("ATH0\r");
delay(1000);
UART0_PutS("AT+CMGF=1\r\n");
delay(1000);
UART0_PutS("AT+CMGS=\"7981290767\"\r\n");
delay(1000);
UART0_PutS("Welcome to ESD Lab....\r");
delay(1000);
UART0_PutChar(0x1A);
while(1);
}

10.Add the two C programs to the project by right clicking on source group Add
files to Group “Source Group 1”. Select the required “C” file from the
displayed window and click on the Add button once and then close the
window.
11.To compile the program press F7 or click on build option.

12.If there are no errors click on OK in the displayed window.


13.To run the program press Ctrl+F5 or select start/stop debug session from
debug menu.
14.Click on OK button on the displayed window. Now the debug started.
15.From the toolbar, select serial windows and select UART1. Now, click on step
over option in the toolbar for execution.
16.After completing the execution stop the debugging by selecting start/stop
debug session from debug menu.
17.To show the simulation with virtual hardware, use Proteus software.
18.Open Proteus 8 Professional software.
19.From file menu, select new project
20.From the project window, change the folder and give name as Lab10 to the
project.

21.Click on next until it shows finish. Then click on finish.


22.It shows an empty template as shown in figure
23.Now select the required devices for the connections.
24.For this experiment the devices needed are
a. LPC2138 – 1
b. DC – 1
c. GSM module – 1
d. Virtual Terminal - 2
25.For getting GSM module in Proteus follow the steps below.
a. Download the GSM library from internet or copy the link for Library.
https://drive.google.com/file/d/11Vm3PwCvL2ci78_LwiQvn7k4kZEt6KW
S/view
b. GSM library folder contains three files named GSMLibraryTEP.hex,
GSMLibraryTEP.IDX and GSMLibraryTEP.LIB
c. Now copy the last two files i.e., GSMLibraryTEP.IDX and
GSMLibraryTEP.LIB and paste them in the folder C:\Program Files (x86)\
Labcenter Electronics\Proteus 8 Professional\DATA\LIBRARY\ (this is
from my laptop, check the folder where it is saved in your
laptop)
26.To select the devices, click on P option in the left pane, it displays the pick
devices window. Now type the device name in keywords option and select
appropriate device.

a. LPC2138 – Type lpc21 in the keywords option and select the last one
which is LPC2138
b. DC – Select Generator mode from the left pane icons. Select DC and
double click on the dashboard.
c. GSM module – Type GSM in the keywords option and select one of the
three modules.
d. Virtual Terminal – Select virtual instruments mode from the left pane
icons. Select virtual terminal and double click on the dashboard.
27.Complete the connections as shown in figure.
28.While connecting the devices, some device properties need to be changed.
a. DC – Right click on the device and click on edit properties, now change
voltage to 3.3V
b. LPC2138 – Right click on the device and click on edit properties, now
change frequency to 12MHz.
c. Virtual Terminal1 – Right click on virtual terminal which is connected to
LPC2148 TX pin and change the part reference as LPC2148.
d. Virtual Terminal2 – Right click on virtual terminal which is connected to
GSM module TX pin and change the part reference as GSM.
e. GSM module – Right click on the device and click on edit properties, now
select hex file from the option program file. The hex file is downloaded
previously with GSM Library. It is with the name GSMLibraryTEP.hex.
29.Now open Keil uvision 4 to create “Hex” File.
30.Open the project Lab10 and right click on the target 1 from the left pane.
Then select “options for target target 1”.
31.It displays a window. Select Output tab from the window and select “Create
HEX File”, and then select Linker tab and select “use Memory Layout from
Target Dialog”. Now click on OK button.
32.Now build the project to create hex file.
33.Now, open Proteus software and open Lab10 project.
34.In the schematic picture, right-click on LPC2138 and select edit properties
option.
35.Change clock frequency to 12 MHz and then select the hex file from the
option Program File by clicking on the folder icon.

36.Select the hex file from the files and click on open button. Now click on OK
button after selecting the required hex file.
37.In the schematic picture, select active popup mode from the left pane icons
and drag it on the virtual terminal, to get popup window of virtual terminal.
38.Click on the play button at the bottom of the screen. It will show the output.
39.For this experiment, it shows two virtual terminals are displayed. The virtual
terminal named LPC2148 tries to call the GSM module (SIM) with the phone
number. As the GSM module is not accepting the call LPC2148 hangs the call
and sends SMS to GSM through the phone number.

Output Screen

You might also like