Sei sulla pagina 1di 104

SUB.

CODE/NAME:EC6711/EMBEDDED LABORATORY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

SUBJECT: EMBEDDED LABORATORY

SEMESTER : VII

LAB MANUAL (EC6711)


(Version : 3)

PREPARED BY
Mr.T.PASUPATHI, AP/ECE
Mrs.P.THIRUMAGAL, AP/ECE

ACADEMIC YEAR 2018-2019 (ODD SEMESTER)

KINGS COLLEGE OF ENGINEERING PAGE 1 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

List of Experiments

CYCLE-I
1. Study of ARM evaluation system
2. Interfacing LED.
3. (i) Flashing of LEDS.
(ii)Interfacing PWM.
4. (i)Interfacing ADC.
(ii)Interfacing DAC.
5. (i)Interfacing LCD.
(ii)Interfacing keyboard.
6. (i)Interfacing serial port.
(ii)Interfacing real time clock

CYCLE-II
7. (i)Interfacing stepper motor.
(ii)Interfacing Temperature sensor
8. Implementing zigbee protocol with ARM.
9. Interfacing EPROM and interrupt.
10.Interrupt performance characteristics of ARM and FPGA
11.Mailbox.

STAFF SIGNATURE HOD/ECE

KINGS COLLEGE OF ENGINEERING PAGE 2 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

CONTENTS

DATE OF MARK
S.NO. TITLE OF THE EXPERIMENT PAGE SIGNATURE
EXPT (10)
CYCLE 1

1. Study of ARM evaluation system

2 Interfacing LED.

3.1 Flashing of LEDS.


3.2 Interfacing PWM.

4.1 Interfacing ADC.

4.2 Interfacing DAC.


5.1 Interfacing LCD.
5.2 Interfacing keyboard.

6.1 Interfacing serial port.


6.2 Interfacing real time clock
CYCLE 2

7.1 Interfacing stepper motor.


7.2 Interfacing Temperature sensor
8 Implementing zigbee protocol with
ARM.
9 Interfacing EPROM and interrupt.

10 Interrupt performance
characteristics of ARM and FPGA
11
Mailbox.

KINGS COLLEGE OF ENGINEERING PAGE 3 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

SIGN OF STAFF INCHARGE HOD/ECE

Expt. No:01
STUDY OF ARM EVALUATION SYSTEM
Date:

AIM:
To learn about the evolution, core features, general characteristics and applications of
ARM processors.
THEORY:
The LPC2148 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with
realtime emulation and embedded trace support, that combines the microcontroller with
embedded high speed flash memory ranging from 32 kB to 512 kB. A 128-bit wide memory
interface and unique accelerator architecture enable 32-bit code execution at the maximum
clock rate.
Due to their tiny size and low power consumption, LPC2148 are ideal for applications
where miniaturization is a key requirement, such as access control and point-of-sale. A blend
of serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple
UARTS, SPI, SSP to I2Cs and on-chip SRAM of 8kB up to 40kB, make these devices very well
suited for communication gateways and protocol converters, soft modems, voice recognition
and low end imaging, providing both large buffer size and high processing power. Various
32-bit timers, single or dual 10-bit ADC(s), 10-bit DAC, PWM channels and 45 fast GPIO lines
with up to nine edge or level sensitive external interrupt pins make these microcontrollers
particularly suitable for industrial control and medical systems.
FEATURES:
1. CPU operating voltage range of 3.0 V to 3.6 V.
2. One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total
of 6/14 analog inputs, with conversion times as low as 2.44 s per channel.
3. Single 10-bit D/A converter provide variable analog output.
4. 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

KINGS COLLEGE OF ENGINEERING PAGE 4 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

5. 8 to 40 kB of on-chip static RAM and 32 to 512kB of on-chip flash program


memory.
6. 128 bit wide interface/accelerator enables high speed 60 MHz operation.
7. On-chip integrated oscillator operates with an external crystal in range from 1MHz
to 30 MHz and with an external oscillator up to 50 MHz
8. In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader
software.
9. Two 32-bit timers/external event counters (with four capture and four compare
channels each), PWM unit (six outputs) and watchdog.
10.Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus
(400Kbit/s), SPI and SSP with buffering and variable data length capabilities.
ARCHITECTURE OVERVIEW:
 The LPC2148 consists of an ARM7TDMI-S CPU with emulation support, the ARM7 Local
Bus for interface to on-chip memory controllers, the AMBA Advanced High
performance Bus AHB for interface to the interrupt controller, and the VLSI
Peripheral Bus (A compatible superset of ARM’s AMBA Advanced Peripheral Bus)
for connection to on-chip peripheral functions.
 The LPC2148 configures the ARM7TDMI-S processor in little-endian byte order.
BLOCK DIAGRAM:
The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers high
performance and very low power consumption. The ARM architecture is based on Reduced
Instruction Set Computer (RISC) principles, and the instruction set and related decode
mechanism are much simpler than those of micro programmed Complex Instruction Set
Computers. Pipeline techniques are employed so that all parts of the processing and memory
systems can operate continuously.
Typically, while one instruction is being executed, its successor is being decoded, and a third
instruction is being fetched from memory. The ARM7TDMI-S processor also employs a
unique architectural strategy known as THUMB, which makes it ideally suited to high-
volume applications with memory restrictions, or applications where code density is an
issue. The key idea behind THUMB is that of a super-reduced instruction set.

KINGS COLLEGE OF ENGINEERING PAGE 5 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Essentially, the ARM7TDMI-S processor has two instruction sets:


 The standard 32-bit ARM instruction set.
 A 16-bit THUMB instruction set.

Fig 1.0 Architecture of ARM7


Fig 1.0 shows the architecture of ARM7 LPC2148 starter kit.The ARM7 LPC2148 Board
based on a 32/16 Bit ARM7TDMI-s CPU with real time Emulation and Embedded Trace
support, that combines with microcontroller with embedded high speed 512KB flash
memory. It can also work in 16-bit Thumb Mode.

KINGS COLLEGE OF ENGINEERING PAGE 6 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

IAR Embedded Workbench is the preferable IDE for this VSK-2148 board.

Fig 1.1: ARM7 LPC2148 starter kit


ON BOARD PERIPHERALS:
1. NXP LPC2148 Microcontroller (TQFP-64 Packaging).
2. 8 Digital Outputs – LED.
3. 8 Digital Inputs – Switch.
4. 4 x 4 Matrix Keypad.
5. Character Based LCD (16 x 2).
6. RS232 Port.
7. External interrupt Source.
8. Analog input Trimmer.
9. Two SPDT Relay.
10. I2C Peripherals
a) Real Time Clock.
b) Serial EEPROM.
c) Seven Segment.
11. Buzzer.

KINGS COLLEGE OF ENGINEERING PAGE 7 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

12. Temperature Sensor.


13. Stepper Motor Interface.
14. Power supply Section.
APPLICATION:
1. Industrial control
2. Medical systems
3. Access control
4. Point-of-sale
5. Communication gateway
6. Embedded soft modem
7. General purpose applications
LPC2148 PINOUT DETAILS

KINGS COLLEGE OF ENGINEERING PAGE 8 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.2: Pin description of LPC2148

KINGS COLLEGE OF ENGINEERING PAGE 9 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

IAR EMBEDDED WORKBENCH:


IAR Embedded Workbench IDE is a very powerful Integrated Development Environment
(IDE), that allows you to develop and manage complete embedded application projects. It is
a development platform, with all the features you would expect to find in your everyday
working place.
The IDE is the framework where all necessary tools are seamlessly integrated:
 The Highly optimizing IAR C/C++ compiler
 The IAR Assembler
 The versatile IAR Linker, including accompanying tools
 A powerful Editor
 A project Manager
 A command line Utility
 IAR C-SPY Debugger.
IAR Embedded workbench is available for many microprocessors and microcontrollers in
the 8,16,32-bit segments, allowing you to stay with a well-known development environment
also for your next project. It provides an easy-to-learn and highly efficient environment with
maximum code inheritance capabilities, comprehensive and specific target support.
IAR C/C++ COMPILER:
IAR C/C++ compiler offers the standard features of the C or C++ languages, plus many
extensions designed to take advantage of the ARM-specific facilities. The compiler is
integrated with other IAR systems software in the IDE.
Features:
 Generic and ARM-specific optimization techniques produce very efficient machine
code.
 Comprehensive output options, including reloadable object code, assembler source
code, and list files with optional assembler mnemonics.
 Support for ARM EABI ELF/DWARF format.
 The object code can be linked together with assembler routines.
 Generation of extensive debug information.

KINGS COLLEGE OF ENGINEERING PAGE 10 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

LANGUAGE FACILITIES:
 Support for the C and C++ programming language.
 Support for the IAR Extended EC++ with features such as full template support,
namespace,the cast operators static_cast,const_cast and reinterpt_cast,as well as
Standard Template Library (STL).
 Conformance to the ISO/ANSI C Standard for a free standing environment.
 IEEE Compatible floating point arithmetic.
IAR ASSEMBLER:
The IAR Assembler is integrated with other IAR systems software for the ARM Core. It
is a powerful relocating macro assembler with a versatile set of directives and expression
operators. The assembler features a built-in C-Language preprocessor and supports
conditional assembly.The assembler uses the same mnemonics and operand syntax as the
advanced RISC machines limited Assembler for ARM, which simplifies the migration of the
existing code.
IAR Assembler provides the following Features:
 C-Preprocessor
 List file with extensive cross-references output.
 Number of symbols and program size limited only by available memory.
 Support for complex expressions with external references.
 255 significant characters in symbol means.
CREATING AN APPLICATION PROJECT USING IAR WORKBENCH:
STEP1:Setting up a new project
Using the IDE, you can design advanced project models. You create a workspace to
which you add one or several projects.
CREATING THE NEW PROJECT
1. To create a new project, choose Project>Create New Project. The Create New
Project dialog box appears, which lets you base your new project on a project
template.

KINGS COLLEGE OF ENGINEERING PAGE 11 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.3: Create new project dialog box


2. From the Tool chain drop-down list, choose the tool chain you are using and click
OK.
3. For this tutorial, select the project template Empty project, which simply creates an
empty project that uses default project settings.
4. In the standard Save As dialog box that appears, specify where you want to place your
project file, that is, in your newly created projects directory. Type project1 in the File
name box, and click Save to create the new project.

KINGS COLLEGE OF ENGINEERING PAGE 12 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.4: Save as dialog box


The project will appear in the Workspace window.

Fig 1.5: Workspace window


By default, two build configurations are created: Debug and Release. In this tutorial
only Debug will be used. You choose the build configuration from the drop-down
menu at the top of the window. The asterisk in the project name indicates that there
are changes that have not been saved.

5. Before you add any files to your project, you should save the workspace. Choose
File>Save Workspace and specify where you want to place your workspace file. This
tutorial, you should place it in your newly created projects directory. Type tutorials in
the File name box, and click Save to create the new workspace.

KINGS COLLEGE OF ENGINEERING PAGE 13 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.6: New workspace dialog box

STEP2:ADDING FILES TO THE PROJECT


1. In the Workspace window, select the destination to which you want to add a source
file; a group or, as in this case, directly to the project.

Fig 1.7: New workspace dialog box – Adding existing project

KINGS COLLEGE OF ENGINEERING PAGE 14 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

2. Choose Project>Add Files to open a standard browse dialog box. Locate the files
Tutor.c and Utilities.c, select them in the file selection list, and click Open. add them to
the project1

Fig 1.8: Adding existing project


STEP3:SETTING PROJECT OPTIONS
1. Select the project folder icon project1 - Debug in the Workspace window and choose
Project>Options.
The Target options page in the General Options category is displayed.

KINGS COLLEGE OF ENGINEERING PAGE 15 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.9: Setting Project Options

Fig 1.10: General settings

2. Select C/C++ Compiler in the Category list to display the compiler option pages.

KINGS COLLEGE OF ENGINEERING PAGE 16 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.11: Compiler option page window

3. Verify these settings:

Fig 1.12: Compiler options

4. Click OK to set the options you have specified.


The project is now ready to be built.
STEP4:Compiling and linking the application
COMPILING THE SOURCE FILES
1. To compile the file Utilities.c, select it in the Workspace window.
2. Choose Project>Compile.

KINGS COLLEGE OF ENGINEERING PAGE 17 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Alternatively, click the Compile button in the toolbar or choose the Compile
command from the context menu that appears when you right-click on the selected
file in the Workspace window.
The progress is displayed in the Build messages window.

Fig 1.13: Compilation message


3. Compile the file Tutor.c in the same manner.
LINKING THE APPLICATION
Now you should set up the options for the IAR ILINK Linker.
1. Select the project folder icon project1 - Debug in the Workspace window and choose
Project>Options, or right click and choose Options from the context menu. Then
select Linker in the Category list to display the linker option pages.

KINGS COLLEGE OF ENGINEERING PAGE 18 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.14: Linker options

2. Click OK to save the linker options. Now you should link the object file, to generate
code that can be debugged.
3. Choose Project>Make. The progress will as usual be displayed in the Build messages
window. The result of the linking is a code file project1.out with debug information
located in the Debug\Exe directory and a map file project1.map located in the
Debug\List directory.
ISP UTILITY:
NXP semiconductors produce a range of microcontrollers that feature both on-chip flash
memory and the ability to be reprogrammed using In-System Programming technology.
Flash magic is windows software that allows easy access to all the ISP features provided by
the devices.These features include,
 Reading Flash memory
 Programminig the flash memory
 Erasing the Flash memory
 Performing a blank check on a section of flash memory.
 Reading the signature bytes.
Flash magic obtains access to the selected COM Port when ISP operations being Performed.
PROCEDURE:
STEP1: Select the COM port
STEP2: Select the baud rate.
STEP3: Select device.
STEP4: Interface –None ISP.
STEP 5: Select Osc-Frequency-12Mhz
STEP6: Enable “Erase blocks used by Hex Files.
STEP 7: Select the Hex File to be downloaded.

KINGS COLLEGE OF ENGINEERING PAGE 19 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 1.15: Flash magic window box

KINGS COLLEGE OF ENGINEERING PAGE 20 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. Compare Microprocessor and Microcontroller.

2. Compare Von Neuman and Harvard architecture.

3. What are the types of Memory?

4. Tell the features of ARM7 LPC2148.

5. What are the applications of ARM peocessor?

RESULT:
Thus the study of ARM Evaluation system and open source software IAR embedded
workbench was done.

KINGS COLLEGE OF ENGINEERING PAGE 21 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 2 INTERFACING OF LED’S


Date:
AIM:
To develop a ‘C’ program to make the LED blink (including delay routine). Upon
change in the delay program the speed should vary.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded -- --
workbench software.
3. Flash magic -- --
4. RS232 Cable -- 1 No

THEORY:
Light Emitting Diodes (LED) is the most commonly used components, usually for displaying
pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of
user input such as a mouse click or keystroke.
LEDs are based on the semiconductor diode. When the diode is forward biased (Switched
on), electrons are able to recombine with holes and energy is released in the form of light.
This effect is called Electroluminescence and color of the light is determined by the energy
gap of the semiconductor.

The ARM7 LPC2148 Primer board has eight numbers of point LEDs, connected with I/O Port
lines (P1.24 – P1.31) to make port pins high. Flash a LED using LPC2148 Primer Board. It
works by turning ON a LED & then turning it OFF & then looping back to START. However the
operating speed of microcontroller is very high so the flashing frequency will also be very
fast to be detected by human eye.

KINGS COLLEGE OF ENGINEERING PAGE 22 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

FIG 2.0: Interfacing LED with LPC2148


PROGRAM:
#include<nxp/iolpc2148.H>
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
// LED INTERFACE LINES
// LED0 - LED7 : P1.24 - P1.31

void main()
{
PINSEL2 = 0X00000000; // P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000; // p1.24 TO P1.31 Configured as Output port.
while(1)
{
IO1SET=0XFF000000; // P1.24 TO P1.31 goes to high state
delay();
IO1CLR=0XFF000000; // P1.24 TO P1.31 goes to low state
delay();
}
}
PROCEDURE:
STEP1: Create a New project
STEP2: Type the below code and save it with the name (Ex: anyname.c)

KINGS COLLEGE OF ENGINEERING PAGE 23 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

STEP3: Compile and build the program


STEP4: Burn the code to the device.
STEP5: Compile, Debug & Simulate the above code in IAR.
STEP6: For seeing the output in real-time, select the PROG mode, reset the board and
download the code in board using Flash Magic through UART0.
STEP7: Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP8: Run/Execute the program on the VSK – 2148 board and observe the LED blink
duration (on/off).

OUTPUT:
View the output in LED. It works by turning ON a LED & then turning it OFF & then looping
back to START.
VIVA QUESTIONS:
1. List the application of LED?

2. What are the features of LED?

3. Mention the GPIO pins of ARM7 LPC2148?

4. Mention the features of ARM7?

5. Which ports are used interfacing of LEDs?

RESULT:
Thus the interfacing of LED with ARM7 was done by using embedded C program.

KINGS COLLEGE OF ENGINEERING PAGE 24 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.:3.1
FLASHING OF LED’s
Date:

AIM:
To develop a ‘C’ program to flash the LED (including delay routine). Upon change in
the delay program the speed should vary.

APPARATUS REQUIRED:
S.No Description Specification Quantity
5. ARM Processor LPC2148 1 No
6. PC with IAR Embedded --
workbench software.
7. Flash magic --
8. RS232 Cable -- 1 No

THEORY:
Light Emitting Diodes (LED) is the most commonly used components, usually for displaying
pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of
user input such as a mouse click or keystroke.
LEDs are based on the semiconductor diode. When the diode is forward biased (Switched
on), electrons are able to recombine with holes and energy is released in the form of light.
This effect is called electroluminescence and color of the light is determined by the energy
gap of the semiconductor.
INTERFACING LED:
Fig.3.0 shows how to interface the LED to microcontroller. The Anode is connected through a
resistor to GND & the Cathode is connected to the Microcontroller pin. So when the Port Pin
is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.

KINGS COLLEGE OF ENGINEERING PAGE 25 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Flash a LED using LPC2148 Primer Board. It works by turning ON a LED & then turning it
OFF & then looping back to START. However the operating speed of microcontroller is very
high so the flashing frequency will also be very fast to be detected by human eye.
The ARM7 LPC2148 Primer board has eight numbers of point LEDs, connected with I/O Port
lines (P1.24 – P1.31) to make port pins high.
INTERFACING DIAGRAM:

FIG 3.0: Interfacing LED with LPC2148


PROGRAM:
#include<nxp/iolpc2148.H>
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
void main()
{
PINSEL2 = 0X00000000; // P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000; // p1.24 TO P1.31 Configured as Output port.
while(1)
{
IO1SET=0XAA000000; delay();
IO1CLR=0XAA000000; delay();
IO1SET=0X80000000; delay();
IO1CLR=0X80000000; delay();
IO1SET=0X40000000; delay();
IO1CLR=0X40000000; delay();
IO1SET=0X20000000; delay();
IO1CLR=0X20000000; delay();
IO1SET=0X10000000; delay();
IO1CLR=0X10000000; delay();

KINGS COLLEGE OF ENGINEERING PAGE 26 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

IO1SET=0X08000000; delay();
IO1CLR=0X08000000; delay();
IO1SET=0X04000000; delay();
IO1CLR=0X04000000; delay();
IO1SET=0X02000000; delay();
IO1CLR=0X02000000; delay();
IO1SET=0X01000000; delay();
IO1CLR=0X01000000; delay(); } }

PROCEDURE:
STEP1: Create a New project
STEP2: Type the below code and save it with the name (Ex: anyname.c)
STEP3: Compile and build the program
STEP4: Burn the code to the device.
STEP5: Compile, Debug & Simulate the above code in IAR.
STEP6: For seeing the output in real-time, select the PROG mode, reset the board and
download the code in board using Flash Magic through UART0.
STEP7: Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP8: Run/Execute the program on the VSK – 2148 board and observe the LED
blink duration (on/off).

KINGS COLLEGE OF ENGINEERING PAGE 27 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

RESULT:
Thus the interfacing and blinking of LED with ARM processor is done successfully

Expt. No.: 3.2


INTERFACING OF PWM
Date:

AIM:
To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
The PWM is based on the standard timer block and inherits all of its features, although only
the PWM function is pinned out on the LPC2148. The timer is designed to count cycles of the
peripheral clock (PCLK) and optionally generate interrupts or perform other actions when
specified timer values occur, based on seven match registers. The PWM function is also
based on match register events. VLEDD-02 board conned to VSK-2148 using port P4, P5.
Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a
processor's digital outputs. PWM is employed in a wide variety of applications, ranging from
measurement and communications to power control and conversion.
LPC2148 supports 2 types of PWM :
1) Single Edge PWM – Pulse starts with new Period i.e pulse is always at the beginning
2) Double Edge PWM – Pulse can be anywhere within the Period

KINGS COLLEGE OF ENGINEERING PAGE 28 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

A PWM block , like a Timer block , has a Timer Counter and an associated prescale Register
along with Match Registers. These work exactly the same way as in the case of Timers
In LPC214x we have 7 match registers inside the PWM block . Generally the first Match
register PWMMR0 is used to generate PWM period and hence we are left with 6 Match
Registers PWMMR1 to PWMMR6 to generate 6 Single Edge PWM signals or 3 Double Edge
PWM signals. Double edge PWM uses 2 match registers hence we can get only 3 double edge
outputs. The way this works in case of Single Edge PWM is as follows (and similarly for
Double Edge):
Following figure shows three different PWM signals. One is PWM output at a 25% duty cycle.
That is, the signal is on for 25% of the period and off the other 75%. Next shows PWM
output at 50%, 75% duty cycles, respectively.

FIG 3.1: PWM signal description

INTERFACING PWM WITH ARM7:

KINGS COLLEGE OF ENGINEERING PAGE 29 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

FIG 3.2: PWM output indicator of LPC2148

PROGRAM:
/* - - - - - Header Files - - - - - */
#include<nxp\iolpc2148.h>
/* - - - - - User Defined Variables - - - - - */
int x;
/* - - - - - delay Routine - - - - - */
void delay()
{
for( int i=0;i<=1500;i++);
}
/* - - - - - PWM function - - - - - */
void pwm(int x)
{
PINSEL0 = 0X00088005; /* To select Port pin P0.8 and also p0.9 as pwm4 and pwm6
*/
PWMPR = 0X00000000; /* To set Prescaler register value to one */
PWMPCR = 0X00004400; /* To select pwm2 as single edge controlled */
PWMMCR = 0X00000002; /* To Reset pwm timer counter when matches occur */
PWMMR0 = 1200 ; /* To set total time period of pwm output */
PWMMR2 = x;
PWMMR6 = 600;
PWMTCR = 0X00000002; /* To reset pwm timer */
PWMTCR = 0X00000009;
}
/* - - - - - main function starts here - - - - - */
void main()
{
PINSEL1_bit.P0_21=1;
IO0DIR_bit.P0_21=1;
PINSEL2 = 0X00000000;
IO1DIR = 0XFF000000;
int i;
while(1)
{
for(i=0;i<=1200;i++)
{

KINGS COLLEGE OF ENGINEERING PAGE 30 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

pwm(x);
delay();
x=x+1;
if(i>=1200)
{
x=0;
}
}
}
}

PROCEDURE:
STEP1. Create a New project
STEP2. Type the below code and save it with the name anyname.c
STEP3. Compile and build the program
STEP4. Burn the code to the device.
STEP5. Connect VLEDD-02 external board and connect J2 to P5(i/p) to view the
output.
STEP6. Compile, Debug & Simulate the above code in IAR.
STEP7. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.
STEP8. For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.
STEP9. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP10. Press the Switch and we can observe the variation in the intensity of the LEDs
depending on the duty cycle of the PWM

OUTPUT:
Press the SW20 switch (VLEDD-02) and view the output in VLEDD-02.

KINGS COLLEGE OF ENGINEERING PAGE 31 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. List the application of LED?

2. Mention the GPIO pins of ARM7 LPC2148?

3. Which pins of ARM7 are used to get the PWM output?

4. Define PWM

5. State the applications of PWM?

RESULT:

KINGS COLLEGE OF ENGINEERING PAGE 32 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Thus the interfacing of LED and PWM with ARM DEVELOPMENT KIT was done by using
embedded C program.

Expt. No.: 4.1 INTERFACING ADC


Date:
AIM:
To develop a C-Language program for reading an on-chip ADC, convert into decimal
and to display it in PC. The ADC input is connected to any analog sensor/ on board
potentiometer.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
ANALOG TO DIGITAL CONVERTER:
The analog to digital converter that which has a purpose to convert the analog input signal to
binary value that can be easily further processed or handle by microcontroller or
microprocessor.
The conversion is divided in to two parts
1) Quantization 2) Sampling
Quantization is the process of converting a continuous range of values (analog signal) into a
finite range of discreet values (digital numbers or Binary form).
The conversion involves of the input, so it necessarily introduces a small amount of error.

Fig 4.1: 3-Bit Quantization

KINGS COLLEGE OF ENGINEERING PAGE 33 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Sampling of input signal means to take ADC does the conversion periodically or repeatedly
after definite time periods rather than continuously. The result will gives a discrete-time and
discrete-amplitude digital signal from a continuous-time and continuous-amplitude analog
signal.
NEED of ADCs.
In our daily life, we have seen sensors and that are input devices, there are several sensors
that gives only analog or continuous values. Most of the time these values must be processed
and can be further shown output devices LCDs and 7-Segment as per user requirement. ADC
is used to convert analog (continuous) values to discrete (digital) values. Below are common
analog sensors which are used for different purposes.
1) Temperature Sensor
2) Glucose meter
3) Blood meter.
4) Speed Sensor etc.
Common ADC conversion Terminologies adopted by semiconductors companies:
1) Successive Approximation Methods
2) Delta-Sigma ADCs
3) Dual Slop ADCs
LPC2148 has 10-bit successive approximation ADC. Basic clocking for the A/D converter is
provided by the VPB clock. A Programmable divider is included in each converter to scale
this clock to 4.5 Mhz clock needed by the successive approximation process. A fully accurate
conversion requires 11 of these clocks
The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic
clocking for the A/D converters is provided by the VPB clock. A programmable divider is
included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by the
successive approximation process. A fully accurate conversion requires 11 of these clocks.
The ADC cell can measure the voltage on any of the ADC input signals.
VSK-2148 has one potentiometer for working with A/D Converter. Potentiometer outputs
are in the range of 0V to 3.3V.
Short the J4 jumper for reading the Potentiometer value by ADC.

KINGS COLLEGE OF ENGINEERING PAGE 34 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

PROGRAM:
#include<nxp/iolpc2148.h>
#include<stdio.h>
#define DESIRED_BAUDRATE 9600
#define CRYSTAL_FREQUENCY_IN_HZ 120000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
int putchar(int a)
{
while(!(U0THR&0X20));
return(U0THR=a);
}
void ADC_init()
{
AD0CR_bit.SEL=2;
AD0CR_bit.CLKDIV=12000000/4500000;
AD0CR_bit.BURST=1;
AD0CR_bit.CLKS=0;
AD0CR_bit.PDN=1;
AD0CR_bit.START=0x0001;
}
void Arm_Uart0_Init()
{
U0LCR=0x83;
VPBDIV=0x01;
U0DLL=DIVISOR&0xff;
U0DLM=DIVISOR>>8;
U0LCR=0x03;
U0FCR=0x05;
}
void main()
{
float ADCresult;
PINSEL0=0X00000005;
PINSEL1=0x01000000;
Arm_Uart0_Init();
ADC_init();
while(1)
{
while(AD0DR_bit.DONE==0);
ADCresult=(AD0DR>>6)& 0x3ff;
}

KINGS COLLEGE OF ENGINEERING PAGE 35 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

KINGS COLLEGE OF ENGINEERING PAGE 36 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

PROCEDURE TO VIEW THE RESULT:


STEP1. Create a New project
STEP2. Type the below code and save it with the name anyname.c
STEP3. Compile and build the program
STEP4. Download the Code to Controller.
STEP5. Compile, Debug & Simulate the above code in IAR.
STEP6. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.
STEP7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.
STEP8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP9. Open Win X-Talk, and select the COM port and the baud rate as 9600.
STEP10. Now vary the on board potentiometer knob and observe the values displayed
in PC.
STEP11. As you tune the knob, the values displayed in the PC/Laptop should vary from 0
to 1023 and there will be a shift in the position of the load line depending on
the values in the ADC.
STEP12. You can interface any other analog sensor also (range 0-3.3V) to measure and
display the following
parameters:temp./pressure/force/flow/acceleration/humidity etc.

OUTPUT:
View the output in PC-Hyper Terminal
RESULT:
Thus the interfacing of ADC (In-built) with ARM processor has been verified and observed
the output successfully.

KINGS COLLEGE OF ENGINEERING PAGE 37 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 4.2 INTERFACING DAC.


Date:
AIM:
To develop a C-Language program for an on-chip DAC to generate a square wave.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No
5. CRO (0-30) Mhz 1 No

THEORY:
DIGITAL ANALOG CONVERTER:
The two 10-bit buffered DAC channels can be used to convert digital signals into analog
voltage signal outputs.
The features of the DAC in LPC2148 are
 10 bit digital to analog converter

 Resistor string architecture

 Buffered output

 Power-down mode

 Selectable speed vs. power

PROGRAM:
/* - - - - - Header Files - - - - - */
#include<nxp/iolpc2148.h>
/*The settling time of the DAC is 2.5 μs and the maximum current is 350 μA when BIAS=1*/
#define DAC_BIAS 0x00010000
/* - - - - - delay routine - - - - - */
void delay(unsigned int x)
{
for(int i=0;i<=x;i++);
}
/* - - - - - main function - - - - -*/
void main()

KINGS COLLEGE OF ENGINEERING PAGE 38 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

{
PINSEL1=0X00080000;
while(1)
{
/* The Datas has to be passed or moved on to the VALUE bits i.e 15 - 6 and the result
will be (VALUE/(1024*Vref)) */
DACR = (1023 << 6) | DAC_BIAS;
delay(100000);
delay(100000);
delay(100000);
delay(100000);
/* The Datas has to be passed or moved on to the VALUE bits i.e 15 - 6 and the
result will be (VALUE/(1024*Vref)) */
DACR = (0 << 6) | DAC_BIAS;
delay(100000);
delay(100000);
delay(100000);
delay(100000);
}
}

PROCEDURE TO VIEW THE RESULT:


STEP 1. Create a New project
STEP 2. Type the code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download the Code to Controller.
STEP 5. Compile, Debug & Simulate the above code in IAR.
STEP 6. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.
STEP 7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.
STEP 8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 9. Connect the +ve terminal of the CRO probe to Aout and _ve terminal to AGND
pins on the board to see the variation in the pulse.

OUTPUT:
Output pin is connected in P9.

KINGS COLLEGE OF ENGINEERING PAGE 39 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

View the output in CRO .

KINGS COLLEGE OF ENGINEERING PAGE 40 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1.What is ADC?

2. Mention the common parameters for ADC.

3.List the Some of the Popular External ADCs:

4.What are the features o f DAC.

5.Write the expression for Aout of DAC?

RESULT:
Thus the interfacing of DAC (In-built) with ARM processor has been verified and observed
the output successfully.

KINGS COLLEGE OF ENGINEERING PAGE 41 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.:5.1
LCD INTERFACING
Date:

AIM:
To interface LCD with ARM processor.
APPARATUS REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
The LCD is an output device and abbreviated as Liquid Crystal Display. LCD is now a very
common option for graphical and alphanumeric displays. In our daily life, we can
alphanumeric displays LCD on coffee machine, cash register, weighing machine and
calculator as consumer electronics embedded products.
LCD CLASSIFICATIONS:
LCDs are generally two type character and graphic LCDs.
Graphical LCDs are again subdivided in two categories: Monochrome (Black and White) and
Color graphical LCD. Here we will discuss about Character LCDs. Character LCDs are those
which have ability to display numbers, alphabetical characters, special characters,
customized character (created by user). LCDs are available in different sizes common format
are LCD Row x Column LCD 16 x 1, LCD 16 x 2, LCD 20 x 2, LCD 40x 4. The display is a
standard LM016L which displays 2 lines of 16 characters (16 x 2)
ADVANTAGES OF LCD:
 LCD is easy to program for character and graphics
 The circuit having is much smaller and lighter than from LED or seven segment
 Due to easy availability with low prices, LCD is preferable then from LEDs
 There is no issue of refreshing LCD because it has its own controller.
 They are low power and comparatively flexible in their use.

KINGS COLLEGE OF ENGINEERING PAGE 42 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

 The ability to display various format like display numbers, alphabetical characters,
special characters, customized character (created by user) with graphic on graphic
LCD.

LCD IN 8-BIT MODE:


This is 8-bit data pins. D7-D0 are used to send information to the LCD or read the contents of
the LCD’s internal registers. The display receives ASCII codes for each character at the data
inputs.
LCD IN 4-BIT MODE:
Due to the ease of circuit designing LCD 16 x 2 is interfaced with LPC2148 microcontroller in
4-bit mode. No doubt program will be more complex than from interfacing LCD in 8-bit
mode. But this saves on GPIO and allows the LCD to be driven using only 6 lines RS, EN and
D4-D7 to microcontroller so that rest of the lines can be use for some other applications.
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0Bis used for
controlling LCD contrast.
RS (Register Select) :
If RS = 0, the instruction command code register is selected, allowing the user to send a
command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on the
LCD.
RW (Read/Write):
RW allows the user to write information to the LCD or read information from it. RW=1 when
reading; RW=0 when writing.
EN (Enable):
The LCD to latch information presented to its data pins uses the enable pin. When data is
supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to
latch in the data present at the data pins.

KINGS COLLEGE OF ENGINEERING PAGE 43 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

D0 – D7:
The 8-bit data pins, are used to send information to the LCD or read the contents of the
LCD’s internal registers. To display letters and numbers, we send ASCII codes for the letters
A-Z, a-z, and numbers 0-9 to these pins while making RS = 1.
CIRCUIT DIAGRAM-LCD INTERFACING:

FIG 5.1: Circuit diagram LCD Interfacing with LPC2148


As per above diagram all the Vss pins are connected to GND and all the VDD pins are
connected to +3.3V. Because LCD here is operating in 8-bit Mode. 11 pins are used as below:
Control Lines
 RS :Connected to P0.8
 RW :Connected to P0.9
 EN :Connected to P0.11
Data Lines
 D0 :Connected to P1.16
 D1 :Connected to P1.17
 D2 :Connected to P1.18

KINGS COLLEGE OF ENGINEERING PAGE 44 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

 D3 :Connected to P1.19
 D4 :Connected to P1.20
 D5 :Connected to P1.21
 D6 :Connected to P1.22
 D7 :Connected to P1.23
PROGRAM:LCD INTERFACING:
#include <nxp/iolpc2148.h>
#define LCD_EN 0X00000800
#define RS 0X00000100
#define DIOW 0X00000200
unsigned char arr1[16]="KCE ECE ERTS LAB";
unsigned char arr2[16]=" THANJAVUR ";
void delay_ms()
{
unsigned int i,j;
for(j=0;j<0xf;j++)
for(i=0;i<0xff;i++);
}
void busy_check()
{
delay_ms();
}
void command_write(int comm)
{
busy_check();
IO0CLR = RS;
IO0CLR = DIOW;
IO1PIN = comm<<16;
IO0SET = LCD_EN;
IO0CLR = LCD_EN;
}
void lcd_init()
{
command_write(0x38); // 5 * 7 Matrix
command_write(0x01); // Clear Display
command_write(0x0f); // Display ON and Cursor Blinking
command_write(0x86); // 5 * 7 Matrix
command_write(0x06);

KINGS COLLEGE OF ENGINEERING PAGE 45 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

}
void lcd_out(unsigned char z)
{
busy_check();
IO0SET = RS; //RS = 1
IO0CLR = DIOW;
IO1PIN = (z<<16); //data with Rs=1
IO0SET = LCD_EN;
IO0CLR = LCD_EN;
}
void main()
{
PINSEL2=0x00000000;
IO0DIR =0xffffffff; // RS, DIOW & LCDEN - Output Pins
IO1DIR =0xFFFFFFFF; // LCD0 to LCD7 - Output Pins
IO0DIR =0x5FFF7FFF;
IO1DIR =0xFFFFFFFF;
IO0CLR = 0X00000800;
IO1PIN = 0X00000000;
IO0PIN = 0X00000000;
IO0CLR = RS;
IO0CLR = DIOW;
IO0CLR = LCD_EN;
lcd_init();
command_write(0x80);
for(int i=0;i<16;i++)
lcd_out(arr1[i]);
command_write(0xC0);
for(int i=0;i<16;i++)
lcd_out(arr2[i]);
while(1);
}
PROCEDURE:
STEP 1. Create a New project
STEP 2. Type the below code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download the Code to Controller.
STEP 5. Compile, Debug & Simulate the above code in IAR.

KINGS COLLEGE OF ENGINEERING PAGE 46 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

STEP 6. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP 7. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 8. Now observe the output in LCD of ARM7 kit.
VIVA QUESTIONS:

1. What is LCD and mention features?

2. What are the classification of LCD?

3. What are the ports used for Keypad interfacing with LPC2148.

4. What are the ports used for control lines of LCD?

5. What are the ports used for data lines of LCD?

RESULT:

KINGS COLLEGE OF ENGINEERING PAGE 47 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Thus the interfacing of LCD with ARM7 microcontroller using embedded C program
has been verified successfully.

Expt. No.:5.2
KEYPAD INTERFACING WITH ARM
Date:
AIM:
To interface Keypad with ARM processor.
APPARATUS REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
KEYPAD
A keypad is a set of buttons arranged in a block or "pad" which usually bear digits, symbols
and usually a complete set of alphabetical letters. If it mostly contains numbers then it can
also be called a numeric keypad. Here we are using 4 X 4 matrix keypad.
INTERFACING KEYPAD
Fig. 1 shows how to interface the 4 X 4 matrix keypad to two ports in microcontroller. The
rows are connected to an output port and the columns are connected to an input port. To
detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch,
and then it reads the columns. If the data read from the columns is D3-D0=1111, no key has
been pressed and the process continues until a key press is detected. However, if one of the
column bits has a zero, this means that a key press has occurred. For example, if D3-
D0=1101, this means that a key in the D1 column has been pressed. After a key press is
detected, the microcontroller will go through the process of identifying the key. Starting with

KINGS COLLEGE OF ENGINEERING PAGE 48 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

the top row, the microcontroller grounds it by providing a low to row D0 only; then it reads
the columns.
If the data read is all 1s, no key in that row is activated and the process is moved to the next
row. It grounds the next row, reads the columns, and checks for any zero. This process
continues until the row is identified. After identification of the row in which the key has been
pressed, the next task is to find out which column the pressed key belongs to.

Fig. 5.1: Interfacing keypad to Microcontroller


INTERFACING KEYPAD WITH LPC2148
We now want to scan a keypad in LPC2148 Primer Board. In case of 4X4 matrix Keypad both
the ends of switches are connected to the port pin i.e. four rows and four columns. So in all
sixteen switches have been interfaced using just eight lines. 1Keypads arranged by matrix
format, each row and column section pulled by high or low by selection J5, all row
lines(P1.24 – P1.27) and column lines(P1.28 to P1.31) connected directly by the port pins.
PIN ASSIGNMENT WITH LPC2148

KINGS COLLEGE OF ENGINEERING PAGE 49 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

FIG 5.2: Pin assignment with LPC2148


PROGRAM:
KEYBOARD INTERFACING:
/* 4 x 4 Matrix Key Pad Interface */

#include<nxp/iolpc2148.h>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
void delay_ms()
{
int i,j;
for(i=0;i<=0xff;i++)
for(j=0;j<=0xf0;j++);
}
int putchar(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20));
U0THR='\r';
}

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

KINGS COLLEGE OF ENGINEERING PAGE 50 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

void Arm_Uart0_Init()
{
U0LCR=0x83;
VPBDIV=0x01;
U0DLL=DIVISOR&0xFF;
U0DLM=DIVISOR>>8;
U0LCR=0x03 ;
U0FCR=0x05 ;
}
void main()
{

PINSEL0 = 0x00000005;
PINSEL2 = 0x00000000;
IO0DIR = 0X00F00005;
Arm_Uart0_Init();
printf("\n\r 4 x 4 Matrix Key Pad Interface ");
printf("\n\r Press any Key Pad Interface ");
while(1)
{
IO0PIN=0x00E00000; // First Scan Line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000)
{
switch(IO0PIN & 0x000F0000)
{
case 0x00070000 : printf("F");break;
case 0x000B0000 : printf("B");break;
case 0x000D0000 : printf("7");break;
case 0x000E0000 : printf("3");break;
}
}
IO0PIN=0x00D00000;

if(( IO0PIN & 0x000F0000 )!= 0x000F0000)


{
switch(IO0PIN & 0x000F0000)
{
case 0x00070000 : printf("E");break;
case 0x000B0000 : printf("A");break;

KINGS COLLEGE OF ENGINEERING PAGE 51 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

case 0x000D0000 : printf("6");break;


case 0x000E0000 : printf("2");break;
}
}
IO0PIN=0x00B00000;
if(( IO0PIN & 0x000F0000 )!= 0x0F000000)
{
switch(IO0PIN & 0x000F0000)
{
case 0x00070000 : printf("D");break;
case 0x000B0000 : printf("9");break;
case 0x000D0000 : printf("5");break;
case 0x000E0000 : printf("1");break;
}
}
IO0PIN=0x00700000;
if(( IO0PIN & 0x000F0000 )!= 0x000F0000)
{
switch(IO0PIN & 0x000F0000)
{
case 0x00070000 : printf("C");break;
case 0x000B0000 : printf("8");break;
case 0x000D0000 : printf("4");break;
case 0x000E0000 : printf("0");break;
}
}
delay_ms();
}
}

PROCEDURE TO VIEW THE OUTPUT:


STEP 1. Create a New project
STEP 2. Type the below code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download the Code to Controller.
STEP 5. Compile, Debug & Simulate the above code in IAR.

KINGS COLLEGE OF ENGINEERING PAGE 52 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

STEP 6. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.
STEP 7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP 8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 9. Press the keys in keypad and observe the output in LCD.

RESULT:
Thus the interfacing of keypad was verified successfully.

KINGS COLLEGE OF ENGINEERING PAGE 53 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 6.1 INTERFACING REAL TIME CLOCK.


Date:
AIM:
To develop a C-Language program to generate RTC.
APPARATUS REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
The Real Time Clock (RTC) is a set of counters for measuring time when system power
is on, and optionally when it is off. It uses little power in Power-down mode. On the
LPC2141/2/4/6/8, the RTC can be clocked by a separate 32.768 KHz oscillator, or by a
programmable prescale divider based on the VPB clock. Also, the RTC is powered by its own
power supply pin, VBAT, which can be connected to a battery or to the same 3.3 V supply
used by the rest of the device.

KINGS COLLEGE OF ENGINEERING PAGE 54 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 6.1: Real Time Clock Block diagram


REGISTER DESCRIPTION:
Clock Control Register (CCR - 0xE002 4008)
The clock register is a 5-bit register that controls the operation of the clock divide circuit.
Bit Symbol Bit Symbol Bit Symbol Description
Description Description
0 CLKEN Clock Enable. When this bit is a one the time counters are
enabled. When it is a zero, they are disabled so that they
may be initialized.
1 CTCRST CTC Reset. When one, the elements in the Clock Tick
Counter are reset. The elements remain reset until
CCR[1] is changed to zero.
3:2 CTTEST Test Enable. These bits should always be zero during
normal operation
4 CLKSRC If this bit is 0, the Clock Tick Counter takes its clock from
the Prescaler, as on earlier devices in the Philips
Embedded ARM family.
If this bit is 1, the CTC takes its clock from the 32 kHz
oscillator that’s connected to the RTCX1 and RTCX2 pins
7:5 -- Reserved, user software should not write ones to
reserved bits. The value read from a reserved bit is not
defined

KINGS COLLEGE OF ENGINEERING PAGE 55 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

PROGRAM:
#include<nxp/iolcp2148.h>
Void delay()
{
For(ini i=0;i<5000;i++)
}
Voidcmd_write(int X)
{
IO1PIN=X<<16;
IO0SET=(1<<8);
IO0CLR=(1<<9);
IO0CLR=(1<<11);
IO0SET=(1<<11);
delay();
IO0CLR=(1<<11);
}
voiddata_write(int X)
{
IO1PIN=X<<16;
IO0SET=(1<<8);
IO0CLR=(1<<9);
IO0CLR=(1<<11);
IO0SET=(1<<11);
delay();
IO0CLR=(1<<11);
}
void main()
PINSEL2=0X00000000;
IO1DIR=0X00FF0000;
PINSEL0=0X00000000;
IO0DIR=0X00000B00;
cmd_write(0X38);
cmd_write(0X01);
cmd_write(0X0F);
cmd_write(0X06);
cmd_write(0X82);
data_write(‘K’);
int h,m,s,h1,h2,m1,m2,s1,s2;
HOUR=02;

KINGS COLLEGE OF ENGINEERING PAGE 56 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

MIN=25;
SEC=00;
CCR=0X11;
for(;;)
{
h=HOUR;
m=MIN;
s=SEC;
h1=(h/10);
h2=(h%10);
m1=(m/10);
m2=(m%10);
s2=(s/10);
s2=(s%10);
cmd_write(0X80);
data_write(h1+0X30);
data_write(h2+0X30);
data_write(‘:’);
data_write(m1+0X30);
data_write(m1+0X30);
data_write(‘:’);
data_write(s1+0X30);
data_write(s1+0X30);
}
PROCEDURE:
STEP 1. Create a New project
STEP 2. Type the code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download a Code to the Controller
STEP 5. Compile, Debug & Simulate the above code in IAR.
STEP 6. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.
STEP 7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP 8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 9. Now observe the output in LCD, it should display the digital clock running

KINGS COLLEGE OF ENGINEERING PAGE 57 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. What are Real Time Clocks?

2. What are the applications of RTC.

3. Explain about CCR.

4. Explain the following commands.


IO1PIN
IO0SET
IO0CLR

5. What are the uses of following commands.


cmd_write
data_write

RESULT:

Thus the interfacing of RTC was verified successfully.

KINGS COLLEGE OF ENGINEERING PAGE 58 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.:6.2 INTERFACING UART WITH LPC2148 ARM.


Date:
AIM:
To interface UART with ARM LPC2148 and to transmit the data serially.
APPARATUS REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
UART- RS-232 COMMUNICATION
There are two basic types of serial communications,
(i) Synchronous and
(ii) Asynchronous.
With synchronous communications, the two devices initially synchronize themselves to each
other, and then continually send characters to stay in sync. Even when data is not really
being sent, a constant flow of bits allows each device to know where the other is at any given
time. That is, each character that is sent is either actual data or an idle character.
Synchronous communications allows faster data transfer rates than asynchronous methods,
because additional bits to mark the beginning and end of each data byte are not required.

KINGS COLLEGE OF ENGINEERING PAGE 59 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Data-bits

CLK

Start-bit Stop-bit

Fig:6.2: Frame format of RS232


Asynchronous means "no synchronization", and thus does not require sending and receiving
idle characters. However, the beginning and end of each byte of data must be identified by
start and stop bits. The start bit indicates when the data byte is about to begin and the stop
bit signals when it ends. The requirement to send these additional two bits causes
asynchronous communication to be slightly slower than synchronous however it has the
advantage that the processor does not have to deal with the additional idle characters.
An asynchronous line that is idle is identified with a value of 1 (also called a mark state). By
using this value to indicate that no data is currently being sent, the devices are able to
distinguish between an idle state and a disconnected line.
One of the LPC2148s many powerful features is its integrated UART, otherwise known as a
serial port. The fact that the LPC2148 has an integrated serial port means that you may very
easily read and write values to the serial port. If it were not for the integrated serial port,
writing a byte to a serial line would be a rather tedious process-requiring turning on and off
one of the I/O lines in rapid succession to properly "clock out" each individual bit, including
start bits, stop bits, and parity bits. However, we do not have to do this. Instead, we simply
need to configure the serial ports operation mode and baud rate. Once configured, all we
have to do is write to an SFR to write a value to the serial port or read the same SFR to read a
value from the serial port.

KINGS COLLEGE OF ENGINEERING PAGE 60 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

INTERFACING DIAGRAM:

FIG 6.3: Interfacing UART with LPC2148


PROGRAM:
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ // since VPBDIV=0x01
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
char arr[]=" \n\r Vimicro system Pvt ltd. Chennai - 96. " ;
char serial_tr(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20));
U0THR='\r';
}
while (!(U0LSR&0x20)) {}
U0THR=ch;
return ch;
}
void Arm_Uart0_Init(void)
{
PINSEL0 = 0x00000005;
U0LCR=0x83;

KINGS COLLEGE OF ENGINEERING PAGE 61 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VPBDIV=0x01;
U0DLL=DIVISOR&0xFF;
U0DLM=DIVISOR>>8;
U0LCR=0x03 ;
U0FCR=0x05 ;

}
void main ()
{
int i;
Arm_Uart0_Init();
while(1)
{
for(i=0;arr[i]!='\0';i++)
{
serial_tr(arr[i]);
}
}
}

PROCEDURE:
STEP 1. Create a New project
STEP 2. Type the code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download a Code to the Controller
STEP 5. Compile, Debug & Simulate the above code in IAR.
STEP 6. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.
STEP 7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP 8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 9. Open Win X- Talk, Select COM port and Baud rate as 9600
STEP 10. Now observe the output data in the PC, it should display the data.

KINGS COLLEGE OF ENGINEERING PAGE 62 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. Mention what are the essential components of embedded system?

2. Mention how I/O devices are classified for embedded system?

3.How do you interface with UART with LPC2148.

4.Compare synchronous and Asynchronous communication.

5.What are the registers used to configure UART.

RESULT:
Thus the interfacing of UART was verified successfully.

KINGS COLLEGE OF ENGINEERING PAGE 63 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 7.1


INTERFACING STEPPER MOTOR.
Date:
AIM:
To write C Programs for running stepper motor either in clock-wise or counter-
clockwise.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No
5. Stepper Motor 12 V DC 1 No

THEORY:
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a
central metal gear. To make the motor shaft turn, first one electromagnet is given power,
which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When the
gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the next
electromagnet. So when the next electromagnet is turned on and the first will turn off, the
gear rotates slightly to align with the next one and from there the process is repeated. Each
of those slight rotations is called a "step." In that way, the motor can be turned to a precised
angle. There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.

KINGS COLLEGE OF ENGINEERING PAGE 64 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Interfacing diagram:

Fig 7.1: Interfacing diagram of stepper motor with LPC2148

Jumper Position

Closed 1 and 2 - Internal voltage for stepper motor.


Closed 2 and 3 - External voltage for stepper motor.

Fig 7.2: Jumper position settings

KINGS COLLEGE OF ENGINEERING PAGE 65 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Procedure
STEP1. Create a New project
STEP2. Type the code and save it with the name anyname.c
STEP3. Compile and build the program
STEP4. Download a Code to the Controller
STEP5. Compile, Debug & Simulate the above code in IAR.
STEP6. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.
STEP7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP9. Now connect/interface the stepper motor at the motor port available in the
VSK -2148 Board with proper polarity.
STEP10. The stepper motor will rotate in the forward and reverse direction.
Program
/* - - - - Header files - - - - */
#include<nxp/iolpc2148.h>
/* - - - - - delay routine - - - - - */
void delay()
{
int i;
for(i=0;i<5000;i++);
}
/* - - - - - stepper motor functions - - - - - */
/* - - - - - forward rotation - - - - - */
void fwd()
{
IO0PIN = 0X90;
delay();
IO0PIN = 0X50;
delay();

KINGS COLLEGE OF ENGINEERING PAGE 66 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

IO0PIN = 0X60;
delay();
IO0PIN = 0XA0;
delay();
}
/* - - - - - reverse rotation - - - - - */
void rev()
{
IO0PIN = 0XA0;
delay();
IO0PIN = 0X60;
delay();
IO0PIN = 0X50;
delay();
IO0PIN = 0X90;
delay();
}
void main()
{
IO0DIR=0xF0; //Set port line as output port
for(int i=0;i<=50;i++)
{
fwd();
}
for(int i=0;i<=50;i++)
{
rev();
} }

OUTPUT:
Stepper motor terminal are connect to P10 connector.

KINGS COLLEGE OF ENGINEERING PAGE 67 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

RESULT:
Thus, the interfacing of stepper motor with ARM7 processor has been done.

Expt. No.: 7.2


INTERFACING TEMPERATURE SENSOR.
Date:

AIM:
To write C Programs to observe the variation in the temperature sensor.
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
Temperature Sensor
The temperature sensor that is used here is LM35. The LM35 series are precision
integrated-circuit temperature sensors, whose output voltage is linearly proportional to the
Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature
sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage
from its output to obtain convenient Centigrade scaling. The LM35 does not require any
external calibration.

KINGS COLLEGE OF ENGINEERING PAGE 68 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 7.1: Interfacing diagram of temperature sensor with LPC2148

PROCEDURE:
STEP 1. Create a New project
STEP 2. Type the code and save it with the name anyname.c
STEP 3. Compile and build the program
STEP 4. Download a Code to the Controller
STEP 5. Compile, Debug & Simulate the above code in IAR.
STEP 6. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK –
2148 Board, and Power on the Board.
STEP 7. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.
STEP 8. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 9. Now check the jumpers J4 and J6. Jumper J4 has to be left opened whereas
jumper J6 has to be closed.
STEP 10. Open Win X- Talk and select the COM port and the desired baud rate as 9600.
STEP 11. Heat the temperature sensor to view the variation in the temperature
PROGRAM:
#include<nxp/iolpc2148.h>
#include<stdio.h>
#define DESIRED_BAUDRATE 9600
#define CRYSTAL_FREQUENCY_IN_HZ 120000000

KINGS COLLEGE OF ENGINEERING PAGE 69 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

#define PCLK CRYSTAL_FREQUENCY_IN_HZ


#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
int putchar(int a)
{
while(!(U0THR&0X20));
return(U0THR=a);
}
void ADC_init()
{
AD0CR_bit.SEL=2;
AD0CR_bit.CLKDIV=12000000/4500000;
AD0CR_bit.BURST=1;
AD0CR_bit.CLKS=0;
AD0CR_bit.PDN=1;
AD0CR_bit.START=0x0001;
}
void Arm_Uart0_Init()
{
U0LCR=0x83;
VPBDIV=0x01;
U0DLL=DIVISOR&0xff;
U0DLM=DIVISOR>>8;
U0LCR=0x03;
U0FCR=0x05;
}
void main()
{
float ADCresult;
PINSEL0=0X00000005;
PINSEL1=0x01000000;

KINGS COLLEGE OF ENGINEERING PAGE 70 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Arm_Uart0_Init();
ADC_init();
while(1)
{
while(AD0DR_bit.DONE==0);
ADCresult=(AD0DR>>6)& 0x3ff;
printf("\n\r Temperature value ----->%f",ADCresult*0.097);
}
}

OUTPUT:
change the jumper setting close the J6 and open the J4 jumer.
View the output in PC-Hyper Terminal Link.

VIVA QUESTIONS:
1.Write a short note on stepper motor.

2.What are pins used to interface stepper motor with LPC2148.

3. What are the applications of stepper motor.

4. Write a short note on temperature sensor LM35.

KINGS COLLEGE OF ENGINEERING PAGE 71 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

5.What are Pins used to interface temperature sensor with LPC2148.

RESULT:
Thus, the interfacing of temperature sensor with ARM7 processor has been done and
executed the temperature value.

Expt. No.: 8
Date: IMPLEMENTING ZIGBEE PROTOCOL WITH ARM
AIM:
To implement the wireless protocol with ARM
APPARATUS AND SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No
5. Xbee modules -- 2 Nos

THEORY:
The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF
Modules were directed to operate within the ZigBee protocol. The modules provide reliable

KINGS COLLEGE OF ENGINEERING PAGE 72 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

delivery of data between remote devices. Zigbee is the communication protocol like wifi and
Bluetooth. Xbee is the module using Zigbee protocol
SOME OF ITS FEATURES ARE:
STEP 1. ZigBee is targeted at radio-frequency (RF) applications
STEP 2. Low data rate, long battery life, and secure networking
STEP 3. Transmission range is between 10 and 75 meters (33~246 feet)
STEP 4. The addressing space allows of extreme node density—up to
18,450,000,000,000,000,000 devices (64 bit IEEE address) using local
addressing, simple networks of more than 65,000 nodes can be configured,
with reduced address overhead
STEP 5. The radios use direct-sequence spread spectrum coding, which is managed by
the digital stream into the modulator.
STEP 6. To ensure reliable data transmission
STEP 7. Binary phase shift keying (BPSK) in the 868/915 MHz
STEP 8. Offset quadrature phase shift keying (O-QPSK) at 2.4 GHz

Fig 8.1:Xbee interfacing with PC

KINGS COLLEGE OF ENGINEERING PAGE 73 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 8.2: Xbee interfacing with microcontroller


Procedure

STEP 1. Create a New project


STEP 2. Type the code and save it with the name (anyname.c)
STEP 3. Compile and build the program
STEP 4. Burn the Code in controller.

PROGRAM (TX PROGRAM):


/* Keypad Interface
// K1 TO K8 : P0.16 TO P0.23
// Key Value is displayed on UART0
// SCAN LINES : P0.20 TO P0.23 (OUTPUT)
// READ LINES : PO.16 TO P0.19 (INPUT) */
/* - - - - - header files - - - - - */
#include<nxp/iolpc2148.h>
#include<stdio.h>
#include "uart.h"
/* - - - - - user defined variables - - - - - */
int i;
unsigned char dat[16]="Press Any Key";
/* - - - - - delay routine - - - - - */
void delay()

KINGS COLLEGE OF ENGINEERING PAGE 74 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

{
long int i;
for(i=0;i<50000;i++);
}
/* - - - - - main function - - - - - */
void main()
{
PINSEL2 = 0x00000000; /* P0.16 TO P0.23 Configured as GPIO. */
IO0DIR = 0X00F00F05; /* P0.20 TO P0.23 (O/P), P0.16 TO P0.19(I/P) */
IO1DIR=0x00ff0000;
uart_inital();
printf("\n\r 4 x 4 Matrix Key Pad Interface ");
printf("\n\r Press any Key Pad Interface ");
while(1)
{
IO0PIN=0x00E00000; /* Scan First Line */
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) /* Check if any key is pressed in
4th row */
{
switch(IO0PIN & 0x000F0000) /* Check which one of the key is pressed */
{#include<nxp/iolpc2148.h>
#include<stdio.h>

void timer0_conf()
{
VPBDIV = 0X01; //12MHZ
T0TCR = 0X00; //STOP TIMER
T0PR = 0X12000; //load prescasle or timer value
T0TCR = 0X02; //reset timer0
}

void delay(unsigned int ms)


{
T0TC = 0x00; //reset the timer0 counter
T0TCR = 0X02; //reset timer0
T0TCR = 0X01; //start timer0
while(T0TC<=ms); //wait for matching timer counter
T0TCR = 0x00; //stop timer0
}

KINGS COLLEGE OF ENGINEERING PAGE 75 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

void uart0_conf()
{
PINSEL0 = 0X05;
VPBDIV = 0X01;
U0LCR = 0X83; // 8bit data,divisior latch
U0DLL = 0X4E; //9600 baudrate
U0DLM = 0X00; //msb
U0LCR = 0X03; //8bit data

int putchar(int dat)


{
U0THR = dat; //tx holding reg
while(!(U0LSR & 0x20)); //wait for tx holding reg empty
return dat;
}

void main()
{
PINSEL1 = 0X00000000;
IO0DIR = 0X00F00005; //P0.20 t0 P0.23 as o/p or P0.16 t0 P0.20 as i/P
timer0_conf();
uart0_conf();
while(1)
{
IO0PIN=0x00E00000; // First Scan Line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check if any key is pressed in //4th row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed
{
case 0x00070000 :
printf("F");
break;
case 0x000B0000 :
printf("B");
break;
case 0x000D0000 :

KINGS COLLEGE OF ENGINEERING PAGE 76 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

printf("7");
break;
case 0x000E0000 :
printf("3");
break;
}
}
IO0PIN=0x00D00000; //Move second data to scan line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check if any key is pressed in 3rd row.
{
switch(IO0PIN & 0x000F0000) //check which one of the key is pressed
{
case 0x00070000 :
printf("E");
break;
case 0x000B0000 :
printf("A");
break;
case 0x000D0000 :
printf("6");
break;
case 0x000E0000 :
printf("2");
break;
}
}
IO0PIN=0x00B00000; //Move 3rd scan data to port line
if(( IO0PIN & 0x000F0000 )!= 0x0F000000)//Scan any key is pressed in 2nd row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed in 2nd row
{
case 0x00070000 :
printf("D");
break;
case 0x000B0000 :
printf("9");
break;
case 0x000D0000 :
printf("5");

KINGS COLLEGE OF ENGINEERING PAGE 77 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

break;
case 0x000E0000 :
printf("1");
break;
}
}
IO0PIN=0x00700000; //Move 4th scan data to port line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check any key is pressed in 1st row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed in 1st row
{
case 0x00070000 :
printf("C");
break;
case 0x000B0000 :
printf("8");
break;
case 0x000D0000 :
printf("4");
break;
case 0x000E0000 :
printf("0");
break;
}
}
}
}

RX PROGRAM:
#include<nxp/iolpc2148.h>
void uart0_conf()
{
VPBDIV = 0X01; //12Mhz clk
U0LCR = 0X83; //8bit data,
U0DLL = 0X4E; //9600 baudrate LSB

KINGS COLLEGE OF ENGINEERING PAGE 78 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

U0DLM = 0X00; //MSB


U0LCR = 0X03; //8bit data
}
void main()
{
PINSEL0 = 0X00000005; //uart0 enable
PINSEL2 = 0X00000000; //port 1 configura
IO1DIR = 0XFF000000; //pin conf the output p0.31 to p0.24
uart0_conf();
while(1)
{
char t =U0RBR; //USART0 Rx Buffer
if(t==0x30)
{
IO1CLR = 0xff000000;
//IO1SET = 0x11000000;
}
if(t==0x31)
{
IO1CLR = 0xff000000; IO1SET = 0x11000000;
}
if(t==0x32)
{
IO1CLR = 0xff000000; IO1SET = 0x22000000;
}
if(t==0x33)
{
IO1CLR = 0xff000000; IO1SET = 0x33000000;
}
if(t==0x34)
{
IO1CLR = 0xff000000; IO1SET = 0x44000000;
}
if(t==0x35)
{
IO1CLR = 0xff000000; IO1SET = 0x55000000;
}
if(t==0x36)
{

KINGS COLLEGE OF ENGINEERING PAGE 79 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

IO1CLR = 0xff000000; IO1SET = 0x66000000;


}
if(t==0x37)
{
IO1CLR = 0xff000000; IO1SET = 0x77000000;
}
if(t==0x38)
{
IO1CLR = 0xff000000; IO1SET = 0x88000000;
}
if(t==0x39)
{
IO1CLR = 0xff000000; IO1SET = 0x99000000;
}
if(t==0x41)
{
IO1CLR = 0xff000000; IO1SET = 0xaa000000;
}
if(t==0x42)
{
IO1CLR = 0xff000000; IO1SET = 0xbb000000;
}
if(t==0x43)
{
IO1CLR = 0xff000000; IO1SET = 0xcc000000;
}
if((t==0x44))
{
IO1CLR = 0xff000000; IO1SET = 0xdd000000;
}
if(t==0x45)
{
IO1CLR = 0xff000000; IO1SET = 0xee000000;
}
if(t==0x46)
{
IO1CLR = 0xff000000; IO1SET = 0xff000000;
}

KINGS COLLEGE OF ENGINEERING PAGE 80 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

}}

PROCEDURE TO SEE OUTPUT:


STEP 1. Compile, Debug & Simulate the above code in IAR.
STEP 2. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Boards, and Power on the Board.
STEP 3. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.
STEP 4. Connect 1 Xbee module with the board and other with the PC.
STEP 5. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 6. The keys that are pressed in the board will be displayed in the PC.

OUTPUT:
Xbee board are connected to P2 connector.
Input is using matrix keyboard.
View the output in onboard LED.

KINGS COLLEGE OF ENGINEERING PAGE 81 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. What are the features of XBee ZNet 2.5 Modules.

2.How do you interface Zigbee with LPC2148.

3,What are the applications of Zigbee.

4.What are the pins used to interface Zigbee with LPC2148.

5.Mention the features of LPC2148.

RESULT:
Thus the implementation of ZigBee protocol with ARM7 processor board using embedded C
program has been done.

KINGS COLLEGE OF ENGINEERING PAGE 82 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 9
INTERFACING EEPROM AND INTERRUPT.
Date:
AIM:
To develop a C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt
APPARATUS & SOFTWARE REQUIRED:
S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,
telecommunication, medical, industrial and PC related markets. Primarily used to store
personal preference data and configuration/setup data, Serial EEPROM’s are the most
flexible type of nonvolatile memory utilized today. Compared to other NVM solutions, Serial
EEPROM devices offer a lower pin count, smaller packages, lower voltages, as well as lower
power consumption.
EEPROM (electrically erasable programmable read - only memory) is user-modifiable read-
only memory (ROM) that can be erased and reprogrammed (written to) repeatedly through
the application of higher than normal electrical voltage. It is a type of non-volatile memory
used in computers and other electronic devices to store small amounts of data that must be
saved when power is removed, e.g., calibration tables or device configuration.

KINGS COLLEGE OF ENGINEERING PAGE 83 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig. 9.1 Interfacing I2C - EEPROM to Microcontroller


PROCEDURE:

1. Create a New project


2. Type the code and save it with the name (anyname.c)
3. Compile and build the program
4. Burn the program in controller.
PROGRAM:
/* - - - - - Header Files - - - - - */
#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "intrinsics.h"
void TIMER0(void);

KINGS COLLEGE OF ENGINEERING PAGE 84 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

void TIMER1(void);
#include "int.h"
#include "uart.h"
#include "timer.h"
/* - - - - - main function starts here - - - - - */
void main()
{
uart_init(); /* call the uart initialization function. Function definition is in “uart.h” */
timer_config(); /* call the timer configuration function. Function definition is in
“timer.h”*/
timerenable(); /* call the timer interrupt function. Function definition is in “int.h” */
while(1)
{
printf("\n Welcome... ");
}
}

PROCEDURE TO SEE OUTPUT:


STEP 1. Compile, Debug & Simulate the above code in IAR.
STEP 2. Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK -
2148 Syllabus Board, and Power on the Board.
STEP 3. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.
STEP 4. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 5. Open Win X – Talk and select the COM port and the Desired Baud rate as 9600.
STEP 6. The main function will execute continuously. The Timer Interrupt function will
execute for every 1 second.
STEP 7. For every 1 second the Interrupt data will be printed in the PC

OUTPUT:

View the output in PC-Hyper Terminal.

KINGS COLLEGE OF ENGINEERING PAGE 85 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1.Write a short note on interrupts.

2.What are ports used for interfacing interrupt.

3.What are the ports used for interfacing EEPROM.

4.What are the applications of EEPROM.

5. Define watchdog timer.

RESULT:

Thus the interfacing of interrupt and Interrupt was verified successfully.

KINGS COLLEGE OF ENGINEERING PAGE 86 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.:10
INTERRUPT PERFORMANCE CHARACTERISTICS OF ARM AND FPGA
Date:

AIM:
To study about the Interrupt performance characteristics between ARM and FPGA

APPARATUS & SOFTWARE REQUIRED:


S.No Description Specification Quantity
1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No
5. Xbee modules -- 2 Nos
6. Xilinx FPGA Spartan 6 -- --
7. Xilinx ISE Design suite -- --
8. JTAG 5.5 -- 1 No
9. CRO (0-30) Mhz 1 No

THEORY;
The ARM7 CPU has two external interrupt lines for the fast interrupt request (FIQ) and
general purpose interrupt IRQ request modes. As a generalization, in an ARM7 system there
should only be one interrupt source which generates an FIQ interrupt so that the processor
can enter this mode and start processing the interrupt as fast as possible. This means that all
the other interrupt sources must be connected to the IRQ interrupt. In a simple system they
could be connected through a large OR gate. This would mean that when an interrupt was
asserted the CPU would have to check each peripheral in order to determine the source of
the interrupt. This could take many cycles. Clearly a more sophisticated approach is
required. In order to handle the external interrupts efficiently an on-chip module called the
Vector Interrupt Controller (VIC) has been added.

PROCEDURE FOR ARM:


STEP 1. Create a New project

KINGS COLLEGE OF ENGINEERING PAGE 87 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

STEP 2. Type the below code and save it with the name led.c (anyname.c)
STEP 3. Compile and build the program
STEP 4. Burn the program in controller.

PROGRAM:
#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "intrinsics.h"
#define led1 IO0PIN_bit.P0_12
#define led2 IO0PIN_bit.P0_13
void TIMER0(void);
void TIMER1(void);
#pragma vector=0x18
__irq __arm void irq_handler (void)
{
void (*intrrupt_function)();
unsigned int vector;
vector = VICVectAddr;
intrrupt_function = (void(*)())vector;
(*intrrupt_function)();
VICVectAddr = 0;
}
__fiq __arm void fiq_handler(void)
{
while(1);
}
void timerenable()
{
VICIntSelect&=~(1<<VIC_TIMER0);
VICVectAddr0=(unsigned int)& TIMER0;
VICVectCntl0=0X20|(VIC_TIMER0);
VICIntEnable|=(1<<VIC_TIMER0);
VICIntSelect&=~(1<<VIC_TIMER1);
VICVectAddr1=(unsigned int)& TIMER1;
VICVectCntl1=0X20|(VIC_TIMER1);
VICIntEnable|=(1<<VIC_TIMER1);
__enable_interrupt();
}

KINGS COLLEGE OF ENGINEERING PAGE 88 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

void TIMER0(void)
{
led2=0;
printf("\n vimicrosystem \n");
T0IR=1;
}
void TIMER1(void)
{
led1=0;
led2=0;
printf("\n chennai \n");
T1IR=1;
}
int putchar(int ch)
{
if (ch=='\n')
{while ((U0LSR&0x20)!=0x20); //wait until Transmit Holding Register is empty
U0THR=0x0d; //then store to Transmit Holding Register
}
U0THR=ch;
while ((U0LSR&0x20)!=0x20) ; //wait until Transmit Holding Register is empty
return(ch); //then store to Transmit Holding Register
}
void main()
{
PINSEL0=0X00000005;
IO0DIR=0X00003000;
VPBDIV=0X01;
U0LCR=0X83;
U0DLL=0X4E;
U0DLM=0X00;
U0LCR=0X03;
T0IR=0XFF;
T0TC=0;
T0PR=0;
//T0MR0=0X00000000C;
T0MR0=0X002255100;
T0MCR=3;
T0TCR=1;

KINGS COLLEGE OF ENGINEERING PAGE 89 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

T1IR=0XFF;
T1TC=0;
T1PR=0;
T1MR0=0X000002EE0;
T1MCR=3;
T1TCR=1;
while(1)
{
timerenable();
printf("\n working... \n");
led1=1;
}}

PROCEDURE TO VIEW RESULT IN ARM:


STEP 1. Compile, Debug & Simulate the above code in IAR.
STEP 2. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in board using Flash Magic through UART0.
STEP 3. Now change the Mode-Selection-Switch to EXEC position and reset the board.
STEP 4. Run/Execute the program on the VSK – 2148 board and observe the variation
in the main process as an interrupt occurred.
STEP 5. The variations can be viewed in the CRO.
INTERRUPT PERFORMANCE IN FPGA:
PROCEDURE FOR FPGA:
STEP1. Create a “New project” in Xilinx ISE Project Navigator from File Button.
STEP2. Assign a “Name” of the project and click “Next”
STEP3. Check/ modify the properties for the FPGA hardware and click “Next”.
STEP4. Click “Finish” for the Summary window.(Now the new project window has
been displayed in the ISE Project Navigator.)
STEP5. Right click on the Xilinx FPGA hardware in the Hierarchy window pane and
select add “New Source”.
STEP6. Select “VHDL Module” and enter the file name before clicking “Next”.
STEP7. Define the “port details” of the VHDL module and click “Next”.
STEP8. Now click “Finish” the Summary window pane.

KINGS COLLEGE OF ENGINEERING PAGE 90 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

STEP9. Now copy and paste the below program in the module.
STEP10. (Follow the same procedure from “Step 5 to Step 8” for adding the VHDL
modules for the below program.)
STEP11. Right click on the Xilinx FPGA hardware in the Hierarchy window pane and
select add “New Source”.
STEP12. Select “Implementation Constraint File” and enter the file name before
clicking “Next”.
STEP13. Copy and Paste the Implementation Constraint File module in the appropriate
module.
STEP14. Click “Generate Programming File” in the Processes pane for the entire
project (Now the .bit file has been generated for the project)
STEP15. Before continuing with the further process please Connect the FPGA hardware
kit with the CPU by using serial cable and Switch “ON”.
STEP16. Now Open the JTAG 5.5 software from Start menu in your computer and
initialize the FPGA device for dumping the program into it.
STEP17. While initializing please “Assign” the “.bit file” and “Program” your FPGA by
in the JTAG 5.5 application. (Now the coded instructions have been loaded in
the FPGA hardware kit.
PROGRAM:
Top module
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTION
ENTITY TOP_MODULE IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC;
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC

KINGS COLLEGE OF ENGINEERING PAGE 91 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

);
END TOP_MODULE;
ARCHITECTURE BEHAVIORAL OF TOP_MODULE IS
-- DECLARATION OF THE PORT DETAILS IN INPUT SIGNAL MODULE--
COMPONENT CLK_GEN IS PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC
);
END COMPONENT;
-- DECLARATION OF THE PORT DETAILS IN INTERRUPT ROUTINE MODULE--
COMPONENT INTERRUPT IS PORT ( CLK : IN STD_LOGIC;
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC
);
END COMPONENT;
BEGIN
--DECLARING THE SIGNAL DETAILS OF THE COMPONENTS FOR PORT MAPPING --
CLK_SECTION :CLK_GEN PORT MAP
(CLK,GEN_CLK1,GEN_CLK2,GEN_CLK3);
INTERRUPT_SECTION :INTERRUPT PORT MAP
(CLK,INPUT1,INPUT2,INPUT3,RISING_INTERRUPT,RISING_INTERRUPT1,RISING_INT
ERRUPT2);
END BEHAVIORAL;
CLK_GEN
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF PORT DETAILS --
ENTITY CLK_GEN IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC);
END CLK_GEN;
ARCHITECTURE BEHAVIORAL OF CLK_GEN IS

KINGS COLLEGE OF ENGINEERING PAGE 92 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

SIGNAL FREQ :INTEGER :=0; -- SIGNAL DECLARATION OF FREQ


BEGIN
PROCESS(CLK) -- INPUT CLOCK SIGNAL FOR GENERATING 3 INPUT SIGNALS
BEGIN
IF RISING_EDGE (CLK) THEN -- ROUTINE FOLLOWS WITH REFERENCE TO THE CLOCK
SIGNAL
FREQ <= FREQ +1; -- GENGERATING THE COUNTER FOR THE SIGNAL FREQ
IF(FREQ >0 AND FREQ <= 10000)THEN -- FOR GETTING 1KHZ SIGNAL WE ARE
EQUALLY SPLITTING UP THE TIMING VALUES '0' FOR 10000 COUNTS AND '1' FOR
10000 COUNTS
GEN_CLK1 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ >10000 AND FREQ <= 20000)THEN
GEN_CLK1 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ > 20000)THEN
FREQ <= 0; -- COUNTER RESETS TO '0' IT IT EXCEEDS 20000 COUNTS
END IF;
END IF; -- PROCESS ENDS BY GENERATING THE 3 INPUT SIGNALS
END PROCESS;
END BEHAVIORAL;
Interrupt
-------------------------------------------------------------------------
-- LIBRARY PART --
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --
-------------------------------------------------------------------------
ENTITY INTERRUPT IS
PORT ( CLK : IN STD_LOGIC ; -- INPUT CLOCK
INPUT1 : IN STD_LOGIC; -- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; -- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; -- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC; -- INTERRUPT OUTPUT 1
RISING_INTERRUPT1 : OUT STD_LOGIC; -- INTERRUPT OUTPUT 2

KINGS COLLEGE OF ENGINEERING PAGE 93 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

RISING_INTERRUPT2 : OUT STD_LOGIC -- INTERRUPT OUTPUT 3


);
END INTERRUPT ;
-------------------------------------------------------------------------
--DESIGN ARCHITECTURE BEGIN'S --
-------------------------------------------------------------------------
ARCHITECTURE BEHAVIORAL OF INTERRUPT IS
SIGNAL C1,C2,C3 : INTEGER :=0 ; --
INTERNAL INTEGER SIGNAL DECLARATION FOR GLOBAL PURPOSE
SIGNAL RISING,RISING1,RISING2,X,Y,Z: STD_LOGIC:='0'; --INTERNAL BINARY OR
SINGLE BIT SIGNAL FOR GLOBAL USE
BEGIN
--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT1) --SENSITIVITY LIST FOR
INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT<= RISING;
-- ASSIGNING RISING_INTERRUPT AS RISING VALUE
CASE X IS
-- SUBJECTING X VALUE WITH THE STANDARD LOGIC FUNCTION '0'
AND '1'
WHEN '0' =>
IF INPUT1='1' THEN --ROUTINE WILL CONINUE IF INPUT1 IN
ON CONDITION
RISING<='1'; -- RISING VALUE SHOULD BE ON
& X VALUE SHOULD BE ON
X<='1';
END IF;
WHEN '1'=>
IF INPUT1='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1
IN OFF CONDITION
X<='0'; -- VALUE OF X TENDS TO
'0'
END IF;

KINGS COLLEGE OF ENGINEERING PAGE 94 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

WHEN OTHERS=> -- IF ANY CONDITION OTHER


THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING='1' THEN -- IF THE SIGNAL FOUND AS RISING EDGE
THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR
A := 30000+300000; -- ADDITION OPERATION
B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION
C1<=C1+1; -- HERE THE COUNTER STARTS TO SUPPORT THE DELAY
IF C1>= 9000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR CONVENIENCE
RISING<='0'; -- ONCE THE COUNTER EXCEEDS
THE VALUE OF 9000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINE
WILL END UP.
C1<=0; --ONCE THE COUNTER
EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; -- RISING = '1' CONDITION
ENDS HERE.
END IF;
END IF; -- ENTIRE PROCESS ENDS
UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN
ARITHMETIC
OPERATIONS..
END PROCESS; -- THESE ABOVE CONDITIONS
PROVIDE US THE INTERRUPT PERFORMANCE OFTHE GIVEN INPUT SIGNAL THRU
RISING_INTERRUPT SIGNAL.
--------------------------------------------------------------------------
-- SECOND INTERRUPT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT2) --SENSITIVITY LIST FOR INPUT USE

KINGS COLLEGE OF ENGINEERING PAGE 95 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N:INTEGER :=0; --INTERNAL VARIABLE'S


DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT1<= RISING1; -- ASSIGNING RISING_INTERRUPT AS RISING
VALUE
CASE Y IS WHEN '0' => -- SUBJECTING Y VALUE WITH THE
STANDARD LOGIC FUNCTION '0' AND '1'
IF INPUT2='1' THEN --ROUTINE WILL CONINUE IF
INPUT1 IN ON CONDITION
RISING1<='1'; -- RISING VALUE SHOULD BE '1' & X
VALUE SHOULD BE ON
Y<='1';
END IF;
WHEN '1'=>
IF INPUT2='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1 IN '0'
CONDITION
Y<='0'; -- VALUE OF X
TENDS TO '0'
END IF;
WHEN OTHERS=> -- IF ANY CONDITION OTHER
THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING1 ='1' THEN -- IF THE SIGNAL FOUND AS
RISING EDGE THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR
A := 30000+300000; -- ADDITION OPERATION
B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION
OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION

KINGS COLLEGE OF ENGINEERING PAGE 96 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

C2<=C2+1; -- HERE THE COUNTER


STARTS TO SUPPORT THE DELAY OF THE SIGNAL
IF C2>= 6000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR
CONVENIENCE
RISING1<='0'; -- ONCE THE COUNTER EXCEEDS
THE VALUE OF 6000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINE
WILL END UP.
C2<=0; --ONCE THE
COUNTER EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; --THE RISING =
'1' CONDITION ENDS HERE.
END IF; -- ENTIRE PROCESS
ENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN
ARITHMETIC OPERATIONS..
END IF; -- THESE ABOVE
CONDITIONS PROVIDE US THE INTERRUPT PERFORMANCE OF THE GIVEN INPUT SIGNAL
THRU RISING_INTERRUPT SIGNAL.
END PROCESS;
END BEHAVIORAL;

PROCEDURE TO VIEW RESULT IN FPGA:


By connecting the probes of CRO/MSO/DSO to the Desired Input and Output pins of the I/O
connectors we will acquire the result of the Interrupt performance of FPGA device.

PROCEDURE TO VIEW RESULT IN SIMULATION:


STEP1. Run the Simulation process of the Project by selecting “Simulation” in the
STEP2. “View” pane and select the Simulator (ModelSim) in the Processes pane.
STEP3. Force clock input to the CLK variable by right clicking the variable
STEP4. Now you can observe the Input and output result in the Simulator.

OUTPUT:
View the output in PC-Hyper Terminal.

KINGS COLLEGE OF ENGINEERING PAGE 97 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIONS:
1. What are the components of embedded system?

2. Why we use embedded systems?

3.. What are the languages used in embedded system?

4. What is meant by VLSI Design ?

5. What can be the various uses of VHDL ?

RESULT
Thus the interrupt performance characteristics of ARM and FPGA are studied. On
comparison, ARM counts at slow speed because it consumes more instruction cycles and
FPGA is more efficient for servicing and processing external interrupt pulses.

KINGS COLLEGE OF ENGINEERING PAGE 98 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Expt. No.: 11
MAIL BOX
Date:

AIM:
To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.

APPARATUS & SOFTWARE REQUIRED:

S.No Description Specification Quantity


1. ARM Processor LPC2148 1 No
2. PC with IAR Embedded --
workbench software.
3. Flash magic --
4. RS232 Cable -- 1 No

THEORY:
Real-time and embedded systems operate in constrained environments in which
computer memory and processing power are limited. They often need to provide their
services within strict time deadlines to their users and to the surrounding world. It is these
memory, speed and timing constraints that dictate the use of real-time operating systems in
embedded software.
The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer"
that hides from application software the hardware details of the processor (or set of
processors) upon which the application software will run. In providing this "abstraction
layer" the RTOS kernel supplies five main categories of basic services to application software

KINGS COLLEGE OF ENGINEERING PAGE 99 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

Fig 7.1: Illustration of RTOS

The most basic category of kernel services is Task Management. This set of services
allows application software developers to design their software as a number of separate
"chunks" of software -- each handling a distinct topic, a distinct goal, and perhaps its own
real-time deadline. Each separate "chunk" of software is called a "task." The main RTOS
service in this category is the scheduling of tasks as the embedded system is in operation.
The second category of kernel services is Intertask Communication and
Synchronization. These services make it possible for tasks to pass information from one to
another, without danger of that information ever being damaged. They also make it possible
for tasks to coordinate, so that they can productively cooperate with one another. Without
the help of these RTOS services, tasks might well communicate corrupted information or
otherwise interfere with each other.
Since many embedded systems have stringent timing requirements, most RTOS
kernels also provide some basic Timer services, such as task delays and time-outs. Many
(but not all) RTOS kernels provide Dynamic Memory Allocation services. This category of
services allows tasks to "borrow" chunks of RAM memory for temporary use in application
software. Often these chunks of memory are then passed from task to task, as a means of
quickly communicating large amounts of data between tasks. Some very small RTOS kernels
that are intended for tightly memory-limited environments, do not offer Dynamic memory
allocation.
Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of
services. These services, if available, provide a uniform framework for organizing and
accessing the many hardware device drivers that are typical of an embedded system.

KINGS COLLEGE OF ENGINEERING PAGE 100 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

PROCEDURE:
STEP1. Create RTOS Programs
STEP2. Type the below code and save it with the name main.c (anyname.c)
STEP3. Compile and build the program
STEP4. Burn the program into the controller.
PROGRAM MAIN.C
/* - - - - - Header Files - - - - - */
#include <includes.h>
#include <intrinsics.h>
#include<stdio.h>
#include “uart.h”
/* - - - - - User Defined Variables - - - - - */
OS_EVENT *comm;
INT8U err;
/* - - - - - OS TASK STACK ALLOCATION - - - - - */
OS_STK Task1stk[100];
OS_STK Task2stk[100];
/* - - - - - TASK FUNCTION - - - - - */
void Task1(void *pdata)
{
pdata = pdata;
INT32U temp;
while(1)
{
temp=123;
OSMboxPost(comm,(void *)&temp);
OSTimeDlyHMSM(0, 0, 0, 10);
}
}
void Task2(void *pdata)
{
INT8U err;
INT8U *msg;
char val1;
while(1)
{

KINGS COLLEGE OF ENGINEERING PAGE 101 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

msg = OSMboxPend(comm,0,&err);
val1 = *msg;
printf("\n data = %d ",val1);
OSTimeDlyHMSM(0, 0, 0, 100);
}
}
void main (void)
{
uart_init(); /* call the Uart initialization functions */
BSP_Init(); /* Call Board Supporting packages */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreate(Task1,0,&Task1stk[99],0);
OSTaskCreate(Task2,0,&Task2stk[99],1);
comm = OSMboxCreate((void *)0);
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}

PROCEDURE TO SEE OUTPUT:


1. Compile, Debug & Simulate the above code in IAR.
2. Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK -2148
Syllabus Board, and Power on the Board.
3. For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.
4. Now change the Mode-Selection-Switch to EXEC position and reset the board.
5. Open Win X – Talk and select the COM port and the Desired Baud rate as 9600.
6. The tasks will run alternatively. The first task will post a data whereas the second task
will receive the data and display it in PC.

KINGS COLLEGE OF ENGINEERING PAGE 102 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

OUTPUT:
View the output in PC-Hyper Terminal.

KINGS COLLEGE OF ENGINEERING PAGE 103 OF 104


SUB.CODE/NAME:EC6711/EMBEDDED LABORATORY

VIVA QUESTIOS:
1.Define MAILBOX.

2. How does combination of functions reduce memory requirement in embedded


system?

3.What is the significance of watchdog timer in ES?

4. What is the difference between mutexes and semaphores?

5.What are the routines used to modify the contents of a mailbox.

RESULT:
Thus the concept of Mailbox with ARM7 processor using embedded C program was done and
verified the message successfully.

KINGS COLLEGE OF ENGINEERING PAGE 104 OF 104

Potrebbero piacerti anche