Embedded Lab Manual
Embedded Lab Manual
of EEE
CONTENTS
PAGE
SL.NO DATE NAME OF THE EXPERIMENTS SIGNATURE
NO
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
1
Embedded System Lab Manual Dept. of EEE
2
Embedded System Lab Manual Dept. of EEE
The LPC2148 microcontrollers are based on a 32 bit ARM7TDMI-S CPU with real-time emulation and
embedded trace support, that combines the microcontroller with embedded high speed flash memory of 512 kB
FEATURES
8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program memory.128 bit wide
interface/accelerator enables high speed 60 MHz operation.
Single flash sector or full chip erase in 400 ms and programming of 256 bytes in 1 ms.
Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the on-chip Real Monitor
software and high speed tracing of instruction execution.
USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14analog inputs, with
conversion times as low as 2.44 ms per channel.
• Two 32-bit timers/external event counters (with four capture and four compare channels each), PWM unit (six
outputs) and watchdog.
• Low power real-time clock with independent power and dedicated 32 kHz clock input.
• Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus
(400 kbit / s), SPI and SSP with buffering and variable data length capabilities.
3
Embedded System Lab Manual Dept. of EEE
4
Embedded System Lab Manual Dept. of EEE
Digital Inputs
Temperature Relay/Motor
Sensor
Driver
5
Embedded System Lab Manual Dept. of EEE
6
Embedded System Lab Manual Dept. of EEE
Steps involved to Create a New Project in Keil uVision 5 for ARM7 LPC2148
7
Embedded System Lab Manual Dept. of EEE
Step 3: Give Name to Project e.g. “LED blinking” and save it.
Step 4: then appears the popup box Select Device for Target
“Target1”. Click the drop down menu where you need to select Legacy
Device Database [no RTE].
NOTE: If you need to install ARM7 packages this Legacy device database
packages.
8
Embedded System Lab Manual Dept. of EEE
Step 5: Select our Device name LPC2148 under the NXP category
and click OK
9
Embedded System Lab Manual Dept. of EEE
The project name and its folders can be seen on the left side in
the project window.
8. Now go to File tab and add New file from the menu.
10
Embedded System Lab Manual Dept. of EEE
9. Save the file from the previous step with a specific name. Add .c extension to the file name. Eg.(led
blinking.c)
10. Add this .c extension file to Source Group folder in the project
window by right clicking on Source Group1 folder and
selecting Add Existing Files to Group ‘Source Group1’...
11
Embedded System Lab Manual Dept. of EEE
Select the previously saved file from the window that pops up and add it to the Source Group1. In our
case, LED Blinking.c
11. Now click on the Options for Target ‘Target1’... symbol shown in red box in the image below or
press Alt+F7 or right click on Target1 and click on Options for Target ‘Target1’....
Options for target window will open. Go to the Output tab in that window. Tick ‘√’ Create HEX File option.
Which will be burn into the microcontroller.
12
Embedded System Lab Manual Dept. of EEE
In the options for target window, go to the Linker tab. Select the Use Memory Layout from Target
Dialogue option.
13
Embedded System Lab Manual Dept. of EEE
13. Once the code is typed, Build the code by clicking on the button shown in red in the image below.
You can also build the project from the Build Target option in the Project tab or by pressing F7 on the
keyboard.
You can see creating hex file ... in the Build Output window as shown in the image.
14. Once the project is built, a hex file is created in the Objects folder inside the folder of your project.
Use Flash Magic software to burn this hex file in your microcontroller.
So open Flash Magic
14
Embedded System Lab Manual Dept. of EEE
15
Embedded System Lab Manual Dept. of EEE
Now you can see the that LED starts blinking on the development board
16
Embedded System Lab Manual Dept. of EEE
17
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
18
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
LED BLINKING
AIM:
To write the Embedded C Program to Blinking the LED with time delay intervals using LPC2148
ARM Micro Controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic .
OUTPUT:
ALGORITHM:
1. Declare the data type of the variables.
2. Configure the IODIR 0 GPIO registers as P1.20 as output .
3. Blink the LED based on delay.
19
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <lpc214x.h>
int main(void)
while(1)
20
Embedded System Lab Manual Dept. of EEE
RESULT :
Thus the embedded C program to blinking the LED with time delay intervals using
LPC2148 ARM Micro controller was executed and output was verified.
21
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
Configure IODIR1[GPIO]
Read Switches
(SW20-SW27)
(LD1 – LD8)
END
22
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to read switch status and display in LEDs using LPC2148
ARM Micro controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic .
INPUT:
Switch SW - SW (P1.16-P1.24)
OUTPUT:
Point LEDS (P1.25-P1.31)
ALGORITHM:
1. Declare the data type of the variables.
2. Configure the IODIR 1 GPIO registers as P1.16-P1.24 as output .
3. Read the status of switches and turn on LED based on the status of the LED’s.
23
Embedded System Lab Manual Dept. of EEE
PROGRAM:
#include <LPC214x.h>
#include <stdio.h>
#define LED 16
#define Switch 24
void Delay(int);
int main(void)
{
unsigned char Status=1;
PINSEL2 &= 0xFFFFFFF3; //Configure P1.16 - P1.31 as GPIO
IO1DIR = 0x00 << Switch; //Configure P1.24 - P1.31 as Input
IO1DIR |= 0xFF << LED; //Configure P1.16 - P1.23 as Output
IO1PIN = 0;
while(1)
{
Status = 1;
IOSET1 = 0xFF << LED;
Delay (10);Delay (10);
IOCLR1= 0xFF << LED;
Delay (10);Delay (10);Delay (10);
while (~Status)
{
Status = ((IO1PIN & (0xFF << Switch)) >> Switch);
IO1PIN = ((~Status) << LED);
}
}
}
void Delay(int n)
{
int p,q;
for(p=0;p<n;p++)
{
for(q=0;q<0x9990;q++);
}}
24
Embedded System Lab Manual Dept. of EEE
RESULT :
Thus the embedded C program to read switch status and display in LEDs using LPC2148 ARM
Micro controller was executed and output was verified.
25
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
Buzzer
26
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to ON/Off buzzer with time delay intervals using
LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic .
OUTPUT:
ALGORITHM:
1. Declare the data type of the variables.
2. Configure the IODIR 0 GPIO registers as P0.7 as output .
3. turn ON/OFF the buzzer based on delay.
27
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <LPC214x.h>
#include <stdio.h>
#define BUZZ 7
void Delay(void);
void Wait(void);
void Delay()
{
unsigned int i,j;
for(i=0;i<1000;i++)
for(j=0;j<700;j++);
}
void main()
{
PINSEL0 = 0x00; //Configure Port0.7 as GPIO
IODIR0 = 3 << BUZZ; //Configure Port0.7 as OutPut pin
while(1)
{
IOSET0 = 1 << BUZZ;
Delay();
IOCLR0 = 1 << BUZZ;
Delay();
}
}
28
Embedded System Lab Manual Dept. of EEE
RESULT :
Thus the embedded C program to ON/Off buzzer with time delay intervals using LPC2148
ARM Micro controller was executed and output was verified.
29
Embedded System Lab Manual Dept. of EEE
FLOW CHART:
30
Embedded System Lab Manual Dept. of EEE
PROGRAM
31
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to generate a triangular and square wave form using
internal 10 bit DAC using LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic.
Input:
Output:
DAC pin (P0.25)
ALGORITHM:
Now write 10-bit value (which we want to convert into analog form) in VALUE field of DACR
Register.
32
Embedded System Lab Manual Dept. of EEE
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 60MHz */
}
}
int main (void)
{
uint16_t value;
uint8_t i;
i = 0;
PINSEL1 = 0x00080000; /* P0.25 as DAC output */
while(1)
{
value = 0;
while ( value != 1023 )
{
DACR = ( (1<<16) | (value<<6) );
value++;
}
while ( value != 0 )
{
DACR = ( (1<<16) | (value<<6) );
value--;
}
}
}
33
Embedded System Lab Manual Dept. of EEE
OUTPUT WAVEFORMS
[B]TRIANGULAR WAVEFORM
TABULATION:
34
Embedded System Lab Manual Dept. of EEE
RESULT :
Thus the embedded C program to generate the triangular and Square wave form with internal
10 bit DAC using LPC2148 ARM Micro controller was executed and output was verified with
oscilloscope.
35
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize
Variables
Configure Pins
PINSEL0 (PWM3)
PINSEL1 (ADC)
Stay Un-terminated
END
36
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to generate a PWM waveform using LPC2148 ARM
Micro controller.
APPARATUS REQUIRED :
INPUT:
OUTPUT:
AD0.3 (P0.1,P0.7)
PWM3 is used for Demo (P0.1)
ALGORITHM:
37
Embedded System Lab Manual Dept. of EEE
PROGRAM:
void Delay ()
{
unsigned int i,j;
for (i=0;i<250;i++)
for (j=0;j<700;j++);
}
int main (void)
{
unsigned long val;
unsigned long oldval = 0;
VPBDIV = 0x02;
PINSEL0 |= 0x00050000;
PINSEL1 = 0x15400000;
init_PWM();
U1LCR = 0x83;
U1DLL = 0xC3;
U1LCR = 0x03;
38
Embedded System Lab Manual Dept. of EEE
if (val != oldval)
{
PWMMR2 = val;
PWMLER = 0xF;
oldval = val;
printf ("Val : %4d \n\r", val);
}
}
}
MODEL GRAPH
39
Embedded System Lab Manual Dept. of EEE
FORMULA:
40
Embedded System Lab Manual Dept. of EEE
RESULT :
Thus the embedded C program to generate the PWM wave form using LPC2148 ARM Micro
controller was executed and output was verified with oscilloscope.
41
Embedded System Lab Manual Dept. of EEE
Flow Chart
START
Initialize Variables
Configure Pins
PINSEL0 (UART0)
END
42
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
TRANSMISSION FROM KIT AND RECEPTION FROM PC USING SERIAL PORT (UART)
AIM:
To write the embedded C program to transmission from kit and reception of data from PC
using UART serial port using LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
INPUT:
OUTPUT:
: : Connect Serial Cable at P1(Board DB9 connector) to PC’s DB9 Connector.
ALGORITHM:
1. Start
2. Initialise UART0 serial interface using following instruction
PINSEL0=0X0000 0005;//Enable P0.0-TxD0,P0.1-RxD0
U0LCR=0X83; //8-BIT Character lenth,NO parity,1 stop bit, DLAB=1
U0DLL=0XC3; //Baud rate=9600@PCLK=30Mhz
U0LCR=0X03;//DLAB=0
LPC2148 will receive characters transmitted by PC
3. LPC2148 will transmit the characters received back to PC
4. Transmit different AT commands through UART module using instruction
while(!(U0LSR&0X20));//Monitor TI flag
5. If transmission buffer is Empty,Transmit single character at a time
U0THR=ch;
6. END
43
Embedded System Lab Manual Dept. of EEE
PROGRAM:
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;
int main(void)
{
init_serial();
while(1)
while (*Ptr)
putchar(*Ptr++);
44
Embedded System Lab Manual Dept. of EEE
if (ch == '\n')
return (U0RBR);
RESULT
Thus the embedded C program to transmit from kit and receive of data from PC using UART
serial port using LPC2148 ARM Micro controller was executed and output was verified.
45
Embedded System Lab Manual Dept. of EEE
Flow Chart
START
Initialize Variables
Configure Pins
PINSEL0 (UART1)
Initialize ADC
Read ADC0.1
END
46
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to read on-chip ADC value of Temperature sensor LM35
and display in hyper terminal using UART1 using LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic .
INPUT:
OUTPUT:
47
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <LPC214x.h>
#include <stdio.h>
void Delay ()
for (i=0;i<50;i++)
for (j=0;j<500;j++);
void Welcome ()
printf ("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.\n\r");
printf ("--------------------------------------------------------\n\r");
printf ("--------------------------------------------------------\n\r");
printf (">> Put Jumper J in 'E' Mode to Enable Temp Sensor Block \n\r");
printf ("********************************************************\n\r");
printf ("********************************************************\n\n\r");
48
Embedded System Lab Manual Dept. of EEE
void Serial_Init ()
U1LCR = 0x83;
U1DLL = 195;
U1LCR = 0x03;
void main ()
Serial_Init ();
Welcome ();
while (1)
do
Val = AD0GDR;
Val = ((AD0GDR >> 6) & 0x3FF); //Extract Result from Bits AD0GDR.15 -
AD0GDR.6
49
Embedded System Lab Manual Dept. of EEE
50
Embedded System Lab Manual Dept. of EEE
RESULT
Thus the embedded C program to read on-chip ADC value of Temperature sensor LM35 and
display in hyper terminal using UART1 using LPC2148 ARM Micro controller was executed and output
was verified.
.
51
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize a
Global Variable
END
52
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to read the external interrupts INT1 and INT2 and display in
hyper terminal using UART1 using LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
1. LPC 2148 ARM Microcontroller Development board.
2 Keil µVision version 5
3. Flash Magic .
INPUT:
INT 1 (P0.14) –Press to Increment the data
OUTPUT:
UART0 Pins : P0.8 - Txd | P0.9 – Rxd
53
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <lpc214x.h>
#include <stdio.h>
void ExtInt_Serve1(void)__irq;
void ExtInt_Serve2(void)__irq;
void ExtInt_Init2(void)
EXTMODE |= 4;
//Edge sensitive mode on EINT2
EXTPOLAR = 0;
//Falling Edge Sensitive
PINSEL0 |= 0x80000000;
//Enable EINT2 on P0.15
void ExtInt_Init1(void)
EXTMODE |= 2;
//Edge sensitive mode on EINT1
EXTPOLAR = 0;
//Falling Edge Sensitive
54
Embedded System Lab Manual Dept. of EEE
PINSEL0 |= 0x20000000;
//Enable EINT2 on P0.14
void Serial_Init(void)
for(i=0;i<count;i++)
for(j=0;j<1000;j++);
55
Embedded System Lab Manual Dept. of EEE
void main(void)
Serial_Init();
putchar(0x0C);
DelayMs(100);
printf (">>> Press Interrupt Keys SW2(INT1) and SW3(INT2) for Output... \n\n\n\r");
DelayMs(100);
while(1)
DelayMs(500);
DelayMs(500);
void ExtInt_Serve1(void)__irq
++EINT1;
EXTINT |= 2;
VICVectAddr = 1;
56
Embedded System Lab Manual Dept. of EEE
void ExtInt_Serve2(void)__irq
++EINT2;
EXTINT |= 4;
VICVectAddr = 0;
RESULT
Thus the embedded C program to read the external interrupts INT1 and INT2 and display in
hyper terminal using UART1 using LPC2148 ARM Micro controller was executed and output was verified.
57
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
Configure Pins
Initialize I2C1
END
58
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
Relay 1 – 2
59
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
RELAY INTERFACE
AIM:
To write the embedded C program to toggle Relays with delay intervals using LPC2148 ARM
Micro controller.
APPARATUS REQUIRED :
INPUT:
OUTPUT:
60
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <lpc21xx.h>
#include <stdio.h>
void Delay()
for(i=0;i<2000;i++)
for(j=0;j<900;j++);
void main(void)
PINSEL2 = 0x00;
61
Embedded System Lab Manual Dept. of EEE
Delay();
Delay();
Delay();
Delay();
62
Embedded System Lab Manual Dept. of EEE
RESULT
Thus the embedded C program to toggle Relays with delay intervals using LPC2148 ARM
Micro controller was executed and output was verified.
63
Embedded System Lab Manual Dept. of EEE
FLOW CHART
START
Initialize Variables
“>PS-Primer 2148<”
Configure IODIR0
Initialize LCD
LCD Command
END
64
Embedded System Lab Manual Dept. of EEE
EX.NO : DATE :
AIM:
To write the embedded C program to display the message in 2 lines in 2X 16 LCD using
LPC2148 ARM Micro controller.
APPARATUS REQUIRED :
INPUT:
OUTPUT:
.
ALGORITHM:
65
Embedded System Lab Manual Dept. of EEE
PROGRAM
#include <LPC214x.H>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
for(i=0;i<n;i++)
for(j=0;j<12000;j++)
{;}
//----------------------------------
//----------------------------------
66
Embedded System Lab Manual Dept. of EEE
LCD4_Convert(data);
void lcd_initialize(void)
int i;
for(i=0;i<4;i++)
lcd_cmd(cmd[i]);
delay(15);
//----------------------------------
//----------------------------------
LCD4_Convert(data);
67
Embedded System Lab Manual Dept. of EEE
//----------------------------------
//----------------------------------
char i;
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
delay(5);
lcd_data(msg[i]);
i++;
delay(15);
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
delay(5);
lcd_data(msg1[i]);
68
Embedded System Lab Manual Dept. of EEE
i++;
delay(15);
if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
//0x4000; //EN
delay(8);
IOCLR0= EN;
//0x4000; //EN
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
//0x4000; //EN
delay(8);
IOCLR0= EN;
//0x4000; //EN
69
Embedded System Lab Manual Dept. of EEE
void main()
PINSEL1 = 0;
//Configure P0.16 - P0.31 as GPIO
while(1);
70
Embedded System Lab Manual Dept. of EEE
RESULT
Thus the embedded C program to display the message in 2 lines in 2X 16 LCD using
LPC2148 ARM Micro controller was executed and output was verified.
71
Embedded System Lab Manual Dept. of EEE
Viva Questions
4.What is embedded c?
The C standard doesn't care about embedded, but vendors of embedded systems usually provide standalone
implementations with whatever amount of libraries they're willing to provide. C is a widely used general purpose high level
programming language mainly intended for system programming.
72
Embedded System Lab Manual Dept. of EEE
73
Embedded System Lab Manual Dept. of EEE
10.What is RTC
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on, and optionally when
it is off.
The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link between integrated
circuits (ICs).
Standard I2C compliant bus interfaces that may be configured as Master, Slave, or Master/Slave.
Arbitration between simultaneously transmitting masters without corruption of serial data on the bus.
Programmable clock to allow adjustment of I2C transfer rates.
Bidirectional data transfer between masters and slaves.
74
Embedded System Lab Manual Dept. of EEE
16.List out the types data transfer instruction set in LPC2148 ARM microcontrollers
18. What is a Thread? What are the differences between process and thread?
A thread is a single sequence stream within in a process. Because threads have some of the properties of
processes, they are sometimes called lightweight processes. Threads are popular way to improve application through
parallelism. For example, in a browser, multiple tabs can be different threads. MS word uses multiple threads, one thread to
format the text, other thread to process inputs, etc.
A thread has its own program counter (PC), a register set, and a stack space. Threads are not independent of one other like
processes as a result threads shares with other threads their code section, data section and OS resources like open files
and signals
19. What are the different scheduling algorithms
First-Come, First-Served (FCFS) Scheduling.
Shortest-Job-Next (SJN) Scheduling.
Priority Scheduling.
Shortest Remaining Time.
Round Robin(RR) Scheduling.
Multiple-Level Queues Scheduling.
µC/OS – II,POSIX, VxWorks, OSOpen, OS-9, pSOSystem, RTEMS,Linux/RT-Linux, Virtuoso, Windows CE,
PalmOS, QNX Neutrino,
75
Embedded System Lab Manual Dept. of EEE
OSTimeDly()
OSTimeDlyHMSM()
OSTimeDlyResume()
76