Lab Manual (3) (2)
Lab Manual (3) (2)
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.
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.
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.
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
Experiment 4:
Develop an Embedded c program Display String on LCD using LPC2148
controller
1. Open Keil μVision4 software.
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.
Experiment 5:
Develop an Embedded c program for Serial transmission of data using
LPC2148 controller
1. Open Keil μVision4 software.
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.
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.
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>
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.
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.
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.
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.
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.
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.
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.
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.
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;
}
Code
#include<LPC214x.h>
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.
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