0% found this document useful (0 votes)
268 views76 pages

Embedded Lab Manual

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

Embedded Lab Manual

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

Embedded System Lab Manual Dept.

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

INTRODUCTION OF THE ARM LPC 2148

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

32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

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.

In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software.

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.

In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA.

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.

Single 10-bit D/A converter provides variable analog output.

• 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.

• Vectored interrupt controller with configurable priorities and vector addresses.

• Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.

• Up to nine edge or level sensitive external interrupt pins available

3
Embedded System Lab Manual Dept. of EEE

BLOCK DIAGRAM OF LPC 2148 ARM MICRO CONTROLLER

4
Embedded System Lab Manual Dept. of EEE

1.2- GENERAL BLOCK DIAGRAM

9V Input On-Board JTAG 4 Nos I2C

+5V/3.3V ISP Programmer Port 7-Segment Disp.

8 Nos. 2x16 LCD

Digital Inputs

USB 2.0 DAC Output

Temperature Relay/Motor
Sensor
Driver

I2C RTC 4X4 Matrix

Battery Backup Keypad


LPC 2148
40Pin Expansion 128x64 GLCD
Connector

On-Board Analog 4-way Traffic


Inputs
Light Module

Buzzer / PS/2 Two 8 Nos.


2x RS232
PWM O/P Ext Interrupts Point LEDs

5
Embedded System Lab Manual Dept. of EEE

1.3. LPC 2148 ARM Micro Controller Development Board

6
Embedded System Lab Manual Dept. of EEE

Steps involved to Create a New Project in Keil uVision 5 for ARM7 LPC2148

Step 1: Open Keil uVision 5

Step 2: Now open Project –> New uVision Project

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

Step 6: A dialogue box appears to copy Startup.s to project folder,


just click yes

Step 7: Now it appears like the below image.

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.

Then click on OK.

13
Embedded System Lab Manual Dept. of EEE

12. Now Type the source code for LED Blinking

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

The Flash magic tool appears as above.

Below are the steps for flashing the ARM LPC2148:

 Select the LPC2148


 Give the COM port number according to Device Manager (COM1)
 Give baud rate as 9600
 Oscillator as 12.000 Mhz
 Tick mark the “Erase blocks used by firmware”
 Now select the hex file path
 Tick verify after programming checkbox.
 And click START
After successfully burned the code , Finished (In green Colour) appears at the bottom as shown in
image below

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

Configure P0 (PINSEL0) GPIO

IODIR0 (P0.7) output

LED Blinking with delay

On/Off with 1 sec delay

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:

LED (P1.20): Enable LED, Put Jumper JP4 to ‘E’ Mode.

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>

unsigned int delay;

int main(void)

IO1DIR = (1<<20); // Configure P1.20 as Output

while(1)

IO1CLR = (1<<20); // CLEAR (0) P1.20 to turn LED ON

for(delay=0; delay<500000; delay++); // delay

IO1SET = (1<<20); // SET (1) P1.10 to turn LEDs OFF

for(delay=0; delay<500000; delay++); // delay

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]

P1.16 – P1.23 (Output)

Read Switches

(SW20-SW27)

Switch Status (LEDs)

(LD1 – LD8)

END

22
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

PROGRAM TO READ SWITCH STATUS AND DISPLAYED IN POINT LEDS.

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

Configure P0 (PINSEL0) GPIO

IODIR0 (P0.7) output

Buzzer

On/Off with 1 sec delay

26
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

INTERFACE THE BUZZER

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:

Buzzer (P0.7) : Enable Buzzer, Put Jumper JP1 to ‘E’ Mode.

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

[A]Square waveform generation using internal DAC of LPC2148


#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 = 1023;
DACR = ( (1<<16) | (value<<6) );
delay_ms(100);
value = 0;
DACR = ( (1<<16) | (value<<6) );
delay_ms(100);
}
}

31
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

WAVEFORM GENERATION USING 10 BIT DAC

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:

 First, configure P0.25/AOUT pin as DAC output using PINSEL Register.


 Then set settling time using BIAS bit in DACR Register.

 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

[B]Triangular wave generation using internal DAC of LPC2148

#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

[A] SQUARE WAVE FORM

[B]TRIANGULAR WAVEFORM

TABULATION:

WAVEFORM AMPLITUDE TIME (MS) FREQUENCY (HZ)

Square wave form

Triangular Wave form

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)

Configure duty cycle for


PWM3 using MR0 MR2
and MR3

Wait for Change in Analog Value

Update Duty Cycle Value

Stay Un-terminated

END

36
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

PULSE WIDTH MODULATION (PWM) WAVEFORM GENERATION

AIM:
To write the embedded C program to generate a PWM waveform using LPC2148 ARM
Micro controller.

APPARATUS REQUIRED :

1. LPC 2148 ARM Microcontroller Development board.


2 Keil µVision version 5
3. Flash Magic .

INPUT:

OUTPUT:

AD0.3 (P0.1,P0.7)
PWM3 is used for Demo (P0.1)

ALGORITHM:

 Reset and disable PWM counter using PWMTCR


 Load prescale value according to need of application in the PWMPR
 Load PWMMR0 with a value corresponding to the time period of your PWM wave
 Load any one of the remaining six match registers (two of the remaining six match registers for
double edge controlled PWM) with the ON duration of the PWM cycle. (PWM will be generated
on PWM pin corresponding to the match register you load the value with).
 Load PWMMCR with a value based on the action to be taken in the event of a match between
match register and PWM timer counter.
 Enable PWM match latch for the match registers used with the help of PWMLER
 Select the type of PWM wave (single edge or double edge controlled) and which PWMs to be
enabled using PWMPCR
 Enable PWM and PWM counter using PWMTCR+++

37
Embedded System Lab Manual Dept. of EEE

PROGRAM:

#include <LPC214x.H> /* LPC21xx definitions */


#include <stdio.h>
void PWM0_isr(void) __irq
{
PWMIR |= 0x00000001; /* Clear match0 interrupt */
VICVectAddr = 0x00000000;
}

void init_PWM (void) {

VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWM ISR vector address */


VICVectCntl8 = 0x00000028; /* Set channel */
VICIntEnable = 0x00000100; /* Enable the interrupt */
PINSEL0 |= 0x00008008; /* Enable P0.7 and P0.1 as PWM output */
PWMPR = 0x00000000; /* Load prescaler */

PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control, output


enabled */
PWMMCR = 0x00000003; /* On match with timer reset the counter */
PWMMR0 = 0x400; /* set cycle rate to sixteen ticks */
PWMMR1 = 0; /* set rising edge of PWM2 to 100 ticks */
PWMMR2 = 0x200; /* set falling edge of PWM2 to 200 ticks */
PWMMR3 = 0x100; /* set rising edge of PWM3 to 100 ticks */
PWMLER = 0xF; /* enable shadow latch for match 1 - 3 */
PWMTCR = 0x00000002; /* Reset counter and prescaler */
PWMTCR = 0x00000009; /* enable counter and PWM, release counter from reset
*/
}

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

AD0CR = 0x00230608; /* Setup A/D: 10-bit AIN0 @ 3MHz */


AD0CR |= 0x01000000; /* Start A/D Conversion */
while (1)
{ /* Loop forever */
do
{
val = AD0GDR;
/* Read A/D Data Register */
} while ((val & 0x80000000) == 0); /* Wait for end of A/D Conversion */
val = ((val >> 6) & 0x3FF); /* Extract AIN0 Value */
Delay (); Delay();

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:

PWM DUTYCYCLE = (TON/ TOTAL TIME)* 100

TOTAL TIME =TON+ TOFF

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)

Initialize UART0 at 9600 Baudrate

Transmit Characters to UART0


through U0THR

Wait for Receive Interrupt

Send to Serial port as Echo

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 :

1. LPC 2148 ARM Microcontroller Development board.


2 Keil µVision version 5
3. Flash Magic .

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)
{

char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";

VPBDIV = 0x02; //Divide Pclk by two

init_serial();

while(1)

while (*Ptr)

putchar(*Ptr++);

putchar(getchar()); //Echo terminal

//<<<<<<<<<<<<<<<<<<<<<<<<< Serial Initialization >>>>>>>>>>>>>>>>>>>>>>>>>>>>

void init_serial (void) /* Initialize Serial Interface */

PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 */

U0LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit */

44
Embedded System Lab Manual Dept. of EEE

U0DLL = 0x000000C3; /* 9600 Baud Rate @ 30MHz VPB Clock */

U0LCR = 0x00000003; /* DLAB = 0 */

//<<<<<<<<<<<<<<<<<<<<<<<<<<< Putchar Function >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int putchar (int ch) /* Write character to Serial Port */

if (ch == '\n')

while (!(U0LSR & 0x20));

U0THR = CR; /* output CR */

while (!(U0LSR & 0x20));

return (U0THR = ch);

//<<<<<<<<<<<<<<<<<<<<<<<<<<<< Getchar Function >>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int getchar (void) /* Read character from Serial Port */

while (!(U0LSR & 0x01));

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

UART at 9600 Baudrate

Read ADC0.1

(ADC Data Registers)

Conversion value move to UART1 Registers

Send to Serial port

END

46
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

TEMPERATURE SENSOR (LM 35) INTERFACE

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:

AD0.1 (P0.28) - LM35 Temp Sensor

OUTPUT:

UART0 Pins : P0.8 - Txd | P0.9 – Rxd

Connect Serial Cable at P2 (Board DB9 connector) to PC’s DB9 Connector.

47
Embedded System Lab Manual Dept. of EEE

PROGRAM

#include <LPC214x.h>

#include <stdio.h>

#define DONE 0x80000000

#define START 0x01000000

#define PRESET 0x00230600

void Delay ()

unsigned int i,j;

for (i=0;i<50;i++)

for (j=0;j<500;j++);

void Welcome ()

printf ("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.\n\r");

printf (" Developed By : R&D Wing \n\r");

printf (" © 2009 Pantech Solutions Pvt Ltd \n\r");

printf ("--------------------------------------------------------\n\r");

printf ("*** Temperature Sensor Interfacing with Tyro Kit ***\n\r");

printf ("--------------------------------------------------------\n\r");

printf (">> Put Jumper J in 'E' Mode to Enable Temp Sensor Block \n\r");

printf (">> Connect UART1 to COM Port @ 9600 Baud Rate\n\n\r");

printf ("********************************************************\n\r");

printf ("************************* Result ***********************\n\r");

printf ("********************************************************\n\n\r");

48
Embedded System Lab Manual Dept. of EEE

void Serial_Init ()

PINSEL0 |= 0x00050000; //Configure TxD1 and RxD1 @ P0.8 & P0.9

U1LCR = 0x83;

U1DLL = 195;

U1LCR = 0x03;

void main ()

unsigned long Val;

VPBDIV = 0x02; //pclk @ 30MHz

Serial_Init ();

PINSEL1 = 0x01 << 24; //P0.28 configure as ADC0.1

Welcome ();

AD0CR = PRESET | 0x02; //ADC Config: 10bit/9Clock | BURST = 1 | CLKDIV =


0x06

AD0CR |= START; //Start Conversion NOW

while (1)

do

Val = AD0GDR;

}while ((Val & DONE) == 0); //Check if Conversion is DONE

Val = ((AD0GDR >> 6) & 0x3FF); //Extract Result from Bits AD0GDR.15 -
AD0GDR.6

49
Embedded System Lab Manual Dept. of EEE

printf (">> Current Temperature : %4d ", Val);

printf ("\xF8\F \r");

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

Configure PINSEL0 for INT1


and INT2

Configure PINSEL0 for


UART0 @ 9600bps

Enable VIC for External


Interrupt Slot and write an
ISR

Send the Incremented


value to UART0

END

52
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

STUDY OF EXTERNAL INTERRUPTS

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

INT 2 (P0.15) – Press to Increment the data

OUTPUT:
UART0 Pins : P0.8 - Txd | P0.9 – Rxd

Connect Serial Cable at P1 (Board DB9 connector) to PC’s DB9 Connector.

53
Embedded System Lab Manual Dept. of EEE

PROGRAM

#include <lpc214x.h>

#include <stdio.h>

int volatile EINT1 = 0;

int volatile EINT2 = 0;

void ExtInt_Serve1(void)__irq;

void ExtInt_Serve2(void)__irq;

/*----------------------------------< INT2 Initialization >------------------------------*/

void ExtInt_Init2(void)

EXTMODE |= 4;
//Edge sensitive mode on EINT2

EXTPOLAR = 0;
//Falling Edge Sensitive

PINSEL0 |= 0x80000000;
//Enable EINT2 on P0.15

VICVectCntl1 = 0x20 | 16; //Use VIC1


for EINT2 ; 16 is index of EINT2

VICVectAddr1 = (unsigned long) ExtInt_Serve2; //Set Interrupt Vec Addr in VIC1

VICIntEnable |= 1<<16; //Enable


EINT2

/*----------------------------------< INT1 Initialization >------------------------------*/

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

VICVectCntl0 = 0x20 | 15; //Use VIC0


for EINT2 ; 15 is index of EINT1

VICVectAddr0 = (unsigned long) ExtInt_Serve1; //Set Interrupt Vec Addr in VIC0

VICIntEnable |= 1<<15; //Enable


EINT1

/*----------------------------------< Serial Initialization >------------------------------*/

void Serial_Init(void)

PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0

U0LCR = 0x00000083; //8-bit data, no parity, 1-stop


bit

U0DLL = 0x00000061; //XTAL = 12MHz (pclk = 60


MHz, VPB = 15MHz(pclk=cclk/4)

U0LCR = 0x00000003; //DLAB = 0;

/*------------------------------------< Delay Function >----------------------------------*/

void DelayMs(unsigned int count) {

unsigned int i,j;

for(i=0;i<count;i++)

for(j=0;j<1000;j++);

55
Embedded System Lab Manual Dept. of EEE

/*------------------------------------< Main Function >----------------------------------*/

void main(void)

Serial_Init();

ExtInt_Init1(); //Initialize Interrupt 1

ExtInt_Init2(); //Initialize Interrupt 2

putchar(0x0C);

printf ("***************** External Interrupt Demo ***************************\n\n\r");

DelayMs(100);

printf (">>> Press Interrupt Keys SW2(INT1) and SW3(INT2) for Output... \n\n\n\r");

DelayMs(100);

while(1)

DelayMs(500);

printf("INT1 Generated : %d | INT2 Generated : %d \r", EINT1, EINT2);

DelayMs(500);

/*----------------------------------< Interrupt Sub-Routine >------------------------------*/

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

PINSEL0 (UART | I2C1)

Initialize I2C1

Read Switch Status

READ, WRITE or ERASE EEPROM


based on Switch Status

Send Process to Serial port

END

58
Embedded System Lab Manual Dept. of EEE

FLOW CHART

START

Initialize Variables

Configure P1 (PINSEL2) GPIO

IODIR1 (P1.20 – P1.21) output

Relay 1 – 2

On/Off with 1 sec delay

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 :

1. LPC 2148 ARM Microcontroller Development board.


2 Keil µVision version 5
3. Flash Magic .

INPUT:

OUTPUT:

Relay1 (P1.20) | Relay2 (P1.21)

60
Embedded System Lab Manual Dept. of EEE

PROGRAM

#include <lpc21xx.h>

#include <stdio.h>

#define RLY1 20 //RLY1 (P1.20)

#define RLY2 21 //RLY2 (P1.21)

void Delay()

unsigned int i,j;

for(i=0;i<2000;i++)

for(j=0;j<900;j++);

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Main Code Begins


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

void main(void)

PINSEL2 = 0x00;

IODIR1 = 1 << RLY1; //Configure P1.20 Output

IODIR1 |= 1 << RLY2; //Configure P1.21 Output

while(1) //loop forever

61
Embedded System Lab Manual Dept. of EEE

IOSET1 = 1 << RLY1;

Delay();

IOCLR1= 1 << RLY1;

Delay();

IOSET1 = 1 << RLY2;

Delay();

IOCLR1= 1 << RLY2;

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

DISP MSG Array

“>PS-Primer 2148<”

Configure IODIR0

(P0.16 – P0.23) – Output

Initialize LCD

(2x16 | 4-Bit mode)

LCD Command

LCD Data Display


Display LCD Message
LCD 1st & 2nd Line

END

64
Embedded System Lab Manual Dept. of EEE

EX.NO : DATE :

2X16 CHAR LCD INTERFACE

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 :

1. LPC 2148 ARM Microcontroller Development board.


2 Keil µVision version 5
3. Flash Magic .

INPUT:

LCD Control - P0.16(RS) | P0.17(RW) | P0.18 (E)

LCD Data - P0.19 – P0.22 (D4…D7)

OUTPUT:
.

ALGORITHM:

65
Embedded System Lab Manual Dept. of EEE

PROGRAM

#include <LPC214x.H>

#define RS 0x10000

#define RW 0x20000

#define EN 0x40000

void lcd_cmd (unsigned char);

void lcd_data (unsigned char);

void lcd_initialize (void);

void lcd_display (void);

void LCD4_Convert(unsigned char);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01}; //lcd commands

unsigned char msg[] = {">PS-Primer 2148<"}; //msg

unsigned char msg1[]= {":: LCD Demo! ::"}; //msg1

void delay(unsigned int n)

unsigned int i,j;

for(i=0;i<n;i++)

for(j=0;j<12000;j++)

{;}

//----------------------------------

// LCD Command Send

//----------------------------------

66
Embedded System Lab Manual Dept. of EEE

void lcd_cmd(unsigned char data)

IOCLR0|= RS; //0x1000; //RS

IOCLR0|= RW; //0x2000; //RW

LCD4_Convert(data);

void lcd_initialize(void)

int i;

for(i=0;i<4;i++)

IOCLR0 = 0xF << 19; //IOCLR 0/1

lcd_cmd(cmd[i]);

delay(15);

//----------------------------------

// LCD Data Send

//----------------------------------

void lcd_data (unsigned char data)

IOSET0 |= RS; //0x1000; //RS

IOCLR0|= RW; //0x2000; //RW

LCD4_Convert(data);

67
Embedded System Lab Manual Dept. of EEE

//----------------------------------

// LCD Display Msg

//----------------------------------

void lcd_display (void)

char i;

/* first line message */

lcd_cmd(0x80);

delay(15);

i=0;

while(msg[i]!='\0')

delay(5);

lcd_data(msg[i]);

i++;

delay(15);

/* second line message */

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);

void LCD4_Convert(unsigned char c)

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

IODIR0 = 0xFF << 16; //Configure Pins


P0.16 - P0.22 as Output Pins

lcd_initialize(); //Initialize LCD!

lcd_display(); //Display Message in


LCD

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

1) Explain what is embedded system in a computer system?


An embedded system is a special purpose computer system which is completely encapsulated by device it controls.
It is a programmed hardware device in which the hardware chip is programmed with specific function. It is a combination of
hardware and software.

2) Mention what are the essential components of embedded system?


Essential components of embedded system includes
 Hardware
 Processor
 Memory
 Timers
 I/O circuits
 System application specific circuits
 Software
 It ensures the availability of System Memory
 It checks the Processor Speed availability
 The need to limit power lost when running the system continuously
 Real Time Operating System
 It runs a process as per scheduling and do the switching from one process to another

3.What are the examples of embedded system?


An example of embedded system includes ATMs, cell phones, printers, thermostats, calculators, and videogame
consoles. Handheld computers or PDAs are also considered embedded devices because of the nature of their hardware
design, even though they are more expandable in software terms.

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.

5. What is main difference between C and embedded C?


As, embedded C is generally an extension of the C language, they are more or less similar. However, some
differences do exist, such as: C is generally used for desktop computers, while embedded C is for microcontroller based
applications. C can use the resources of a desktop PC like memory, OS, etc.

6.what is a Watchdog Timer?


A watchdog timer is an electronic device or electronic cards that execute specific operation after certain time period
if something goes wrong with an electronic system.

72
Embedded System Lab Manual Dept. of EEE

7. what is the need for an infinite loop in embedded systems?


Embedded systems require infinite loops for repeatedly processing or monitoring the state of the program. For
instance, the case of a program state continuously being verified for any exceptional errors that might just happen during run-
time such as memory outage or divide by zero, etc.

(I) what is semaphore?


A semaphore is an abstract data type or variable that is used for controlling access, by multiple processes to a
common resource in a concurrent system such as multi programming operating system.
Semaphores are commonly used for two purposes
To share a common memory space
To share access to files

(II) What is the ARM7TDMI?


The ARM7TDMI is a member of the Advanced RISC Machines (ARM) family of general purpose 32-bit microprocessors,
which offer high performance for very low power consumption and price.

Mention the features of ARM:


32-bit RISC-processor core (32-bit instructions),
• 37 pieces of 32-bit integer registers (16 available),
• Thumb instruction set,
• Pipelined (ARM7: 3 stages),
• Cached (depending on the implementation),
•Von Neuman-type bus structure (ARM7), Harvard (ARM9),
• Debug Interface,
• Embedded ICE macrocell
,• Jazelle DBX(Direct Bytecode eXecution)
What is meant by Pipelining
Pipelining is a technique that implements a form of parallelism called instruction-level parallelism within a single processor.

8. List out the features in LPC2148 ARM microcontrollers (K1,CO2)


32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.8 to 40 kB of on-chip static RAM and 32 to 512 kB
of on-chip flash program memory. In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software. 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.
In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA.
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.

9 .Write the application of GPIO in LPC2148 ARM microcontrollers


It is used to to interface the digital input device like limit switch , digital sensors, keypad etc.,
It is used to interface the digital out put devices like LCD ,buzzer and etc.,

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.

11. What is the Purpose of RTC


Measures the passage of time to maintain a calendar and clock. Provides Seconds, Minutes, Hours, Day of Month, Month,
Year, Day of Week, and Day of Year.

12.What is the UART COMMUNICATION?


A universal asynchronous receiver/transmitter (UART) is a microchip that performs serial-to-parallel conversion of data
received from peripheral devices and parallel-to-serial conversion of data coming from the CPU for transmission to peripheral
devices
Mention the feature of UART in LPC2148 ARM microcontrollers
 16 byte Receive and Transmit FIFOs
 Register locations conform to ‘550 industry standard.
 Receiver FIFO trigger points at 1, 4, 8, and 14 bytes.
 Built-in fractional baud rate generator with autobauding capabilities.
 Mechanism that enables software and hardware flow control implementation.

13. Mention the feature of ADC in LPC2148 ARM microcontrollers (K1,CO3)


 10 bit successive approximation analog to digital converter
 Measurement range 0 V to VREF (typically 3 V; not to exceed VDDA voltage level).
 10 bit conversion time 2.44 µs.
 Burst conversion mode for single or multiple inputs.

14.Mention the feature of SPI interface


 Synchronous, Serial, Full Duplex communication.
 Combined SPI master and slave.
 Maximum data bit rate of one eighth of the input clock rate.
 8 to 16 bits per transfer

15.Write the advantages of I2c bus in LPC2148 ARM microcontrollers (K1,CO3)

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

17.What is the RTOS?


A real time operating system (RTOS) is an operating system that guarantees a certain capability within a specified
time constraint.

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.

20. What is deadlock?


Deadlock is a situation when two or more processes wait for each other to finish and none of them ever
finish. Consider an example when two trains are coming toward each other on same track and there is only one track, none of
the trains can move once they are in front of each other. Similar situation occurs in operating systems when there are two or
more processes hold some resources and wait for resources held by other(s).

21.List out some popular Real Time Operating Systems(RTOS)

µC/OS – II,POSIX, VxWorks, OSOpen, OS-9, pSOSystem, RTEMS,Linux/RT-Linux, Virtuoso, Windows CE,
PalmOS, QNX Neutrino,

22.What is meant by kernel


A kernel, executive or nucleus is the smallest portion of the operating system that provides for task scheduling,
dispatching, and inter task communication.
23.What is meant by task
A task is an independent thread of execution that can compete with other concurrent tasks for processor execution
time.

75
Embedded System Lab Manual Dept. of EEE

24. What is multitasking and its types?


Multitasking to share CPU time between two or more tasks.
• Pre-emptive Multitasking
• Non-preemptive Multitasking

25. What is meant by Context switching?
• Context switching is the process of saving and restoring sufficient information for a real-time task so that it can be
resumed after being interrupted.

26.List out the task states of RTOS


Running , Ready, Block .

27.What is Rate monotonic Algorithm?


Given a set of periodic tasks and preemptive priority scheduling, then assigning priorities such that the tasks with
shorter periods have higher priorities (rate-monotonic), yields an optimal scheduling algorithm.

28. Mention the features of µc/os-II


The Real-Time Kernel is a portable, ROMable, scalable, preemptive real-time, multitasking kernel for microprocessors
and microcontrollers.

29. List out the task management function in µc/os-II


The functions to create task, suspend and resume, and time setting and time retrieving functions
 OSTaskCreate()
 OSTaskSuspend()
 OSTaskResume()
 OSTimeSet()
 OSTimeGet()

30.List out the time management function in µc/os-II

 OSTimeDly()
 OSTimeDlyHMSM()
 OSTimeDlyResume()

76

You might also like