73
List of Experiments 1. Study of ARM Evaluation System 2. Interfacing ADC and DAC 3. Interfacing PWM and LED 4. Interfacing Real-time clock and Serial Port 5. Interfacing Keypad and LCD 6. Interfacing EEPROM and Interrupt 7. Mailbox 8. Interrupt performance characteristics of ARM and FPGA 9. Flashing of LED 10. Interfacing Stepper motor and Temperature sensor 11. Interfacing Zig-bee Protocol and ARM

List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Embed Size (px)

Citation preview

Page 1: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

List of Experiments

1. Study of ARM Evaluation System

2. Interfacing ADC and DAC

3. Interfacing PWM and LED

4. Interfacing Real-time clock and Serial Port

5. Interfacing Keypad and LCD

6. Interfacing EEPROM and Interrupt

7. Mailbox

8. Interrupt performance characteristics of ARM and FPGA

9. Flashing of LED

10. Interfacing Stepper motor and Temperature sensor

11. Interfacing Zig-bee Protocol and ARM

Page 2: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Overview of the Board

VSK – 2148

The ARM7 LPC2148 Syllabus Board based on a 32/16 Bit ARM7TDMI-s CPU withreal time Emulation and Embedded Trace support, that combines with microcontroller withembedded high speed 512KB flash memory. It can also work in 16-bit Thumb Mode.

Page 3: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

With the interfaced peripherals and on board peripherals, plentiful practical codes can beimplemented with ARM7 LPC2148 Syllabus Board. The board has fast and reliable toolsthat can satisfy the needs of experienced engineers and beginners alike.

ARM7 LPC2148 Syllabus Boards achieve their small size through Modern SMDtechnology and Multilayer Design. All Controller signals and ports extend from thecontroller to high density pitch Connectors of the board.

ARM7 LPC2148 Syllabus Board Hardware Manual Describes the board’s design andfunctions. Precise Specifications for the NXP LPC2148 Microcontroller can be found inthe enclosed Micro-controller Data sheet/User’s Manual. In this hardware manual,schematic diagrams and Block Diagrams are attached.

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

VLEDD – 02

The VLEDD – 02 boards is having 12 LEDs. The LEDs are controlled by twotransistors. The operating voltage can be varied as per the industrial requirement. The possiblevoltages are 3.3V, 5V and 12V. The operational voltage can be selected depending on thehardware design.

The LED sequence D1, D2, D3, D7, D8 and D9 are controlled by the transistor Q1 andthe sequence D4, D5, D6, D10, D11 and D12 are controlled by the transistor Q2.The board is also having an LDR. The LEDs can be used to lighten the zone with this output of

Page 4: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

the LDR.Vi –XBB

The Xbee board is a Wireless board that has to be interfaced with the controller. It can beinterfaced either by RS232 cable or USB cable. A switch is provided to select the modeof communication.

Page 5: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

About the Software

IAR EMBEDDED WORKBENCH FOR ARM

The IAR Embedded Workbench® IDE is a very powerful Integrated DevelopmentEnvironment, which allows you to develop and manage complete embedded applicationprojects.

The IAR Embedded Workbench IDE

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 ILINK Linker, including accompanying tools A powerful editor A project manager A command line build utility The IAR C-SPY® Debugger, a state-of-the-art high-level language debugger.

IAR Embedded Workbench is available for many microprocessors and micro-controllersin the 8-, 16-, and 32-bit segments, allowing you to stay within a well-known development environment also for your next project. It provides an easy-to-learn and highly efficient development environment with maximum code inheritance capabilities, comprehensive and specific target support. IAR Embedded Workbench promotes a useful working methodology, and you can reduce your development time significantly by using the IAR Systems tools.

FEATURES

The IDE is a flexible integrated development environment, allowing you to developapplications for a variety of target processors. It provides a convenient Windows interface forrapid development and debugging.

PROJECT MANAGEMNET

The IDE comes with functions that will help you to stay in control of all project modules,for example, C or C++ source code files, assembler files, include files, and other relatedmodules. You create workspaces and let them contain one or several projects. Files canbe grouped, and options can be set on all levels—project, group, or file. Changes are tracked sothat a request for rebuild will retranslate all required modules, making sure that no executablefiles contain out-of-date modules. This list shows some additional

Page 6: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

features:

Project templates to create a project that can be built and executed out of the box for a smooth development startup Hierarchical project representation Source browser with a hierarchical symbol presentation Options can be set globally, on groups of source files, or on individual source files The Make command automatically detects changes and performs only the required operations. Text-based project files Custom Build utility to expand the standard tool chain in an easy way Command lines build with the project file as input.

FLASH MAGIC

NXP Semiconductors produce a range of Microcontrollers that feature both on-chipFlash 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 providedby the devices. These features include:

Erasing the Flash memory (individual blocks or the whole device) Programming the Flash memory and Reading Flash memory Modifying the Boot Vector and Status Byte Performing a blank check on a section of Flash memory Reading the signature bytes and Reading and writing the security bits Direct load of a new baud rate (high speed communications) Sending commands to place device in Boot loader mode

Flash Magic provides a clear and simple user interface to these features and more asdescribed in the following sections. Under Windows, only one application may haveaccess the COM Port at any one time, preventing other applications from using the COMPort. Flash Magic only obtains access to the selected COM Port when ISP operations arebeing performed. This means that other applications that need to use the COM Port, suchas debugging tools, may be used while Flash Magic is loaded.

Win X talk

Win X talk software is windows software that allows send and receives the data fromserial port. COM port configuration is variable.

Page 7: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Working with IAR Embedded Workbench

HOW TO CREATE A NEW PROJECT

1. CREATING A NEW PROJECT:

IAR Embedded Workbench Installation is completed; Shortcut ICON is placed at yourDesktop. Just make a double click on that ICON. New Window is open as given below.

1. To create a new project, choose Project>Create New Project. The Create NewProject Dialog box appears, which lets you base your new project on a project template.

Page 8: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

2. Make sure the Tool chain is set to ARM, and click OK.3. Select the project template Empty project, and click ok button. This simplycreates an empty project that uses default project setting.4. In the standard Save As dialog box that appears, specify where you want toplace your project file, that is, in your newly created projects directory. Typeyour project name in the File name box, and click Save to create the newproject. E.g. LED.

The project will appear in the Workspace window

Page 9: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

To Creating your Application ‘C’ file, Choose FILE menu and select NEW>File

Edit the application code in C Language. E.g. Led.c

Page 10: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

To Save your ‘C’ file, Choose File>Save As. In the standard Save As dialog box thatappears, specify where you want to place your project file, that is, in your projectdirectory. Type your filename in the File name box, and click Save to create the newproject. E.g. Led.c

2. 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.2. Choose Project>Add Files to open a standard browse dialog box. Locate the files

Page 11: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

led.c Select them in the file selection list, and click Open to add them to the project.

To save your work space, Choose File>Save Workspace and specify where youwant to place your workspace file. In this tutorial, you should place it in your newlycreated project directory. Type LED in the File name box, and click save button.

3. SETTING PROJECT OPTIONS

Now you will set the project options. For application projects, options can be set on alllevels of nodes. First you will set the general options to suit the processor configurationin this tutorial. Because these options must be the same for the whole build configuration,they must be set on the project node.

Page 12: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

1. Select the project folder icon LED - Debug in the Workspace window and choose Project>Options. Then select Output Converter in the Category list to display the linker option pages.

The Output options are used for specifying details about the output format and the levelof debugging information included in the output file.

Select “option” on the popup menu. After selecting popup menu window shows as givenbelow. Select output format as “Intel Extended”, output file in the format of .hex format.

Page 13: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Select the linker file menu, linker configuration file available at project directory. ToCompile your Project, Choose Project>Rebuild ALL

Page 14: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

If your project has no error, then it will show Building successfully and the Hex file willbe generated.

Page 15: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

HOW TO CREATE RTOS PROGRAMS

μC/OS-II Porting with IAR Embedded Workbench

1. Create a New Project

1. To create a new project, choose Project>Create New Project. The Create NewProjectDialog box appears, which lets you base your new project on a project template.

2. Make sure the Tool chain is set to ARM, and click OK.3. Select the project template Empty project, and click ok button. This simply createsan empty project that uses default project settings.4. In the standard Save As dialog box that appears, specify where you want to placeyour project file, that is, in your newly created projects directory. Type yourproject name in the File name box, and click Save to create the new project. E.g.

LED.

Page 16: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

RTOS Package comprises set of ‘C’ files and headed files. C Files are classified asApplication file, CPU files, μC/OS-II Files and BSP.

In this project, we have to split the C files according to the functions. So these files areintegrated under separate folder.

Project Group Names are

APP BSP CPU UCOS-II

- PORT- SOURCE

2. ADDING Groups TO THE PROJECT

1. Creating several groups is a possibility for you to organize your source fileslogically according to your project needs.2. To create new group Choose Project>Add Group.3. Type your group name and click ok button.

Page 17: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Now create APP group

Add files to APP group

Page 18: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Create new group

Add files to BSP Group

Page 19: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Create new group

Add Files to CPU

Page 20: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Create new group

Under ucos-ii group, create two group named as source and ports.

Page 21: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Add Corresponding files to above mentioned group

Page 22: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

3. SETTING PROJECT OPTIONSNow you will set the project options. For application projects, options can be set

on all levels of nodes. First you will set the general options to suit the processorconfiguration in this tutorial. Because these options must be the same for the whole buildconfiguration, they must be set on the project node.

1. Select the project folder icon UART - Debug in the Workspace window and choose Project>Options. Then select C/C++ Compiler where you have select CODE menu, enable ARM Processor Mode.

Page 23: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

After that Select Preprocessor menu from same window.At Preprocessor, we have to include all the directories as given below$PROJ_DIR$$PROJ_DIR$\..\uCOS-II\ports$PROJ_DIR$\..\uCOS-II\source$PROJ_DIR$\..\BSP$PROJ_DIR$\..\CPU

For Creating the Hex file, we choose output file format as given below.

Page 24: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Select Linker file as given below.

To Compile this Project, Choose Project>Rebuild ALL

If there is no error, Message window shows like this. Now Hex file is created.

ISP UTILITYNXP Semiconductors produce a range of Microcontrollers that feature both onchip

Flash memory and the ability to be reprogrammed using In-System Programmingtechnology. Flash Magic is Windows software that allows easy access to all the ISPfeatures provided by the devices. These features include:

Page 25: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

• Erasing the Flash memory (individual blocks or the whole device)• Programming the Flash memory• Modifying the Boot Vector and Status Byte• Reading Flash memory• Performing a blank check on a section of Flash memory• Reading the signature bytes• Reading and writing the security bits• Direct load of a new baud rate (high speed communications)• Sending commands to place device in Boot loader mode

Under Windows, only one application may have access the COM Port at any onetime, preventing other applications from using the COM Port. Flash Magic only obtainsaccess to the selected COM Port when ISP operations are being performed. This meansthat other applications that need to use the COM Port, such as debugging tools, may beused while Flash Magic is loaded. Note that in this manual third party Compilers arelisted alphabetically. No preferences are indicated or implied.

HOW TO DOWNLOAD A CODE TO OUR CONTROLLER

Procedure:1. Select the COM Port2. Select the Baud Rate3. Select Device ( Eg.LPC2148)4. Interface – None ISP5. Select Osc. Frequency – 12Mhz6. Enable “ Erase Blocks used by Hex files”7. Select the Hex File to be downloaded.8. Click start

Page 26: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Processing……..

After downloaded completely, window shows like this

Page 27: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Syllabus Programs in ‘C’

Hardware and software Requirements

1. VSK-2148 Development board2. IAR Embedded workbench version 5.40 or above3. Flash Magic4. Win X-Talk5. PC/Laptop

Instruction:

Follow the given steps for getting started with the syllabus experiments:1. Install IAR Embedded Workbench IDE software and Win X-Talk software.2. After successful installation of IAR, Install Flash Magic.3. Connect the RS232 cable/USB cable provided to the PC and the LPC2148 Syllabus Board, and Power on the VSK-2148 Development Board.4. If you are using USB cable, then install the required USB to Serial driver (FTDI

for on beard converter).5. Search/Set the COM Port no here :

Start >> My Computer >> Manage (on right click) >> Device Manager >> Ports (COM & LPT).6. Now, Identify the Mode-Select-Switch provided on the VSK 2148 Board marked

with the text PROG & EXEC. PROG: Programming Mode used for downloading the code/program intothe flash memory. EXEC: Execution Mode used for executing program after downloading.

7. After selecting any position (PROG / EXEC) press the reset switch provided on the board.

8. After setting the proper COM port number & selecting the Mode-Select-Switch position properly, Extract the “VSK-2148 SOURCE CODES V 1.0” (WinRAR archive) file.

9. Open the project and follow the instructions given in each experiment.

Page 28: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 1Study of ARM Evaluation System

AimTo 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 withrealtime emulation and embedded trace support, that combines the microcontroller withembedded high speed flash memory ranging from 32 kB to 512 kB. A 128-bit widememory interface and unique accelerator architecture enable 32-bit code execution at themaximum clock rate. For critical code size applications, the alternative 16-bit Thumbmode reduces code by more than 30 % with minimal performance penalty.

Due to their tiny size and low power consumption, LPC2148 are ideal for applicationswhere miniaturization is a key requirement, such as access control and point-of-sale. Ablend of serial communications interfaces ranging from a USB 2.0 Full Speed device,multiple UARTS, SPI, SSP to I2Cs and on-chip SRAM of 8 kB up to 40 kB, make thesedevices very well suited for communication gateways and protocol converters, softmodems, voice recognition and low end imaging, providing both large buffer size andhigh 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 externalinterrupt pins make these microcontrollers particularly suitable for industrial control andmedical systems.

FEATURES 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package. 8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program memory. 128 bit wide interface/accelerator enables high speed 60 MHz operation. In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software. Single flash sector or full chip erase in 400 ms and programming of 256 bytes in 1ms. Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the on-chip Real Monitor software and high speed tracing of instruction execution. USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM. In addition, the LPC2146/8 provides 8 kB of on-chip RAM accessible to USB by DMA. One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14 analog inputs, with conversion times as low as 2.44 s per channel. Single 10-bit D/A converter provide variable analog output.

Page 29: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Two 32-bit timers/external event counters (with four capture and four compare channels each), PWM unit (six outputs) and watchdog. Low power real-time clock with independent power and dedicated 32 kHz clock input. Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 Kbit/s), SPI and SSP with buffering and variable data length capabilities. Vectored interrupt controller with configurable priorities and vector addresses. Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package. Up to nine edge or level sensitive external interrupt pins available. 60 MHz maximum CPU clock available from programmable on-chip PLL withsettling time of 100s 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 Power saving modes include idle and Power-down. Individual enable/disable of peripheral functions as well as peripheral clock scaling for additional power optimization. Processor wake-up from Power-down mode via external interrupt, USB, Brown- Out Detect (BOD) or Real-Time Clock (RTC). Single power supply chip with Power-On Reset (POR) and BOD circuits: o CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O

ARCHITECTURE OVERVIEW

The LPC2148 consists of an ARM7TDMI-S CPU with emulation support, the ARM7Local Bus for interface to on-chip memory controllers, the AMBA Advanced HighperformanceBus AHB for interface to the interrupt controller, and the VLSI PeripheralBus (A compatible superset of ARM’s AMBA Advanced Peripheral Bus) for connectionto on-chip peripheral functions. The LPC2148 configures the ARM7TDMI-S processorin little-endian byte order. AHB peripherals are allocated a 2 megabyte range ofaddresses at the very top of the 4 gigabyte ARM memory space. Each AHB peripheral isallocated a 16 kB address space within the AHB address space. LPC2148 peripheralfunctions are connected to the VPB bus. The AHB to VPB Bridge interfaces the VPB busto the AHB bus. VPB peripherals are also allocated a 2 megabyte range of addresses,beginning at the 3.5 gigabyte address point. Each VPB peripheral is allocated a 16 kBaddress space within the VPB address space. The connection of on-chip peripherals todevice pins is controlled by a Pin Connect Block. This must be configured by software tofit specific application requirements for the use of peripheral functions and pins.

ARM7TDMI PROCESSOR

The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers highperformance and very low power consumption. The ARM architecture is based onReduced Instruction Set Computer (RISC) principles, and the instruction set and relateddecode mechanism are much simpler than those of micro programmed ComplexInstruction Set Computers. This simplicity results in a high instruction throughput and

Page 30: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

impressive real-time interrupt response from a small and cost-effective processor core.Pipeline techniques are employed so that all parts of the processing and memory systemscan operate continuously. Typically, while one instruction is being executed, its successoris being decoded, and a third instruction is being fetched from memory. TheARM7TDMI-S processor also employs a unique architectural strategy known asTHUMB, which makes it ideally suited to high-volume applications with memoryrestrictions, or applications where code density is an issue. The key idea behind THUMBis that of a super-reduced instruction set. Essentially, the ARM7TDMI-S processor hastwo instruction sets:

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

The THUMB set’s 16-bit instruction length allows it to approach twice the density ofstandard ARM code while retaining most of the ARM’s performance advantage over atraditional 16-bit processor using 16-bit registers. This is possible because THUMB codeoperates on the same 32-bit register set as ARM code. THUMB code is able to provideup to 65% of the code size of ARM, and 160% of the performance of an equivalent ARMprocessor connected to a 16-bit memory system.

BLOCK DIAGRAM

Page 31: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 2

Interfacing ADC and DACAim

To develop a C-Language program for reading an on-chip ADC, convert into decimaland to display it in PC and to generate a square wave depending on this ADC reading. TheADC input is connected to any analog sensor/ on board potentiometer.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.4. CRO5. USB cable.

Theory 1. ADC

The LPC 2148 has 10-bit successive approximation analog to digital converter. Basicclocking for the A/D converters is provided by the VPB clock. A programmable divideris included in each converter, to scale this clock to the 4.5 MHz (max) clock needed bythe successive approximation process. A fully accurate conversion requires 11 of theseclocks. 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 outputsare in the range of 0V to 3.3V. Short the J4 jumper for reading the Potentiometervalue by ADC.

Procedure1. Follow the steps 1 of How to create a New project2. Type the below code and save it with the name dac.c (anyname.c)3. Follow the steps 2 and 3 of How to create a New Project to compile and build theprogram4. Follow the procedures in How to Download a Code to Our Controller todownload your code.

Page 32: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Program

/* - - - - - HEADER FILES - - - - - */

#include<nxp/iolpc2148.h>#include<stdio.h>#include "uart.h"#include "adc.h"/* - - - - - User defined Variables - - - - - */

unsigned int val=0,volt;/* - - - - - MAIN FUNCTION STARTS HERE - - - - - */

void main(void){ PINSEL1_bit.P0_28=1; init(); /* Call the initialization function. Function definition is in “uart.h” */

uart_inital(); /* Call the uart function. Function definition is in “uart.h” */

adc(); /* Call adc function. Function definition is in “adc.h” */

PINSEL1=0X01000000; /*ADC0.1*/

while(1) {

while(AD0DR_bit.DONE==0); /* Start A/D Conversion */

val=AD0DR1_bit.RESULT;printf("adc = %d \r\n",val);

}}

Procedure to View the Result:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK- 2148 Board, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Open Win X-Talk, and select the COM port and the baud rate as 9600. Now vary the on board potentiometer knob and observe the values displayed in PC. 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. 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

Page 33: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

ii) DACTheoryThe two 10-bit buffered DAC channels can be used to convert digital signals into analogvoltage 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

Procedure

Follow the steps 1 of How to create a New project Type the below code and save it with the name dac.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build theprogram Follow the procedures in How to Download a Code to Our Controller todownload your code.

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

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)) */

Page 34: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

DACR = (0 << 6) | DAC_BIAS;delay(100000);delay(100000);delay(100000);delay(100000);}

}

Procedure to View the Result:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-2148 Board, and Power on the Board. For seeing the output in real-time, select the PROG mode, reset the board anddownload the code on to the board using Flash Magic through UART0/USB. Now change the Mode-Selection-Switch to EXEC position and reset the board. Connect the +ve terminal of the CRO probe to Aout and _ve terminal to AGNDpins on the board to see the variation in the pulse.

Outputoutput pin are connect in P9.view the output in CRO .

Page 35: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 3Interfacing LED and PWM

AimTo write a C program to generate a PWM and to vary the brightness of the LED

depending on the duty cycle.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.4. CRO5. LED board Setup

Theory

The PWM is based on the standard timer block and inherits all of its features, althoughonly the PWM function is pinned out on the LPC2148. The timer is designed to countcycles of the peripheral clock (PCLK) and optionally generate interrupts or perform otheractions when specified timer values occur, based on seven match registers. The PWMfunction is also based on match register events. VLEDD-02 board conned to VSK-2148 usingport P4,P5.

Procedure1. Follow the steps 1 of How to create a New project2. Type the below code and save it with the name (anyname.c)3. Follow the steps 2 and 3 of How to create a New Project to compile and build the program4. Follow the procedures in How to Download a Code to Our Controller to download your code.

Page 36: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

pwm(x);delay();x=x+1;

if(i>=1200){

x=0; } } }}

Page 37: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Procedure To View the Result

VLEDD-02 external board connect J2 to P5(i/p).take output in VSK2148 board. Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-2148 Board, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. 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 its (VLEDD-02) work base on condition.view the output in VLEDD-02.

Page 38: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 4Interfacing Real Time Clock and Serial Port

Aim

To develop a C-Language program for reading the RTC, convert into decimal and todisplay it.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.

Theory

RTCThe 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 theLPC2141/2/4/6/8, the RTC can be clocked by a separate 32.768 KHz oscillator, or by aprogrammable prescale divider based on the VPB clock. Also, the RTC is powered by itsown power supply pin, VBAT, which can be connected to a battery or to the same 3.3 Vsupply used by the rest of the device.

Serial CommunicationSerial communication takes a byte of data and transmits the 8 bits in the byte one at a

time. The advantage is that a serial port needs only one wire to transmit the 8 bits (whilea parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit thedata than it would if there were 8 wires. Serial ports lower cable costs and make cablessmaller.

Procedure

Follow the steps 1 of How to create a New project Type the below code and save it with the name rtc.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program Follow the procedures in How to Download a Code to Our Controller to download your code.

Page 39: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Program /* - - - - - Header Files - - - - - */#include<nxp/iolpc2148.h>#include<stdio.h>#include<string.h>#include "uart.h"/* - - - - - Real Time Clock Initialization - - - - - */void RTC_Init(){

ILR = 3; /* Disable 32'768 interrupt */CCR = 0x11; /* Clock enable + 32'767Hz quartz enable; starts the RTC */CIIR = 0x01; /* Interupt every second */PREINT = 0x0000016D; /* the integer portion of the prescale value */PREFRAC = 0x00001B00; /* fractional portion of the prescale value */YEAR = 2015; /* Year */MONTH = 05; /* Month */DOM = 09; /* Day of month loads the date as 09.05.2015 */DOY = 129; /* Day of year */DOW = 04; /* Day of week */HOUR = 10; /* Hours */MIN = 21; /* Minutes loads the time as 10:21:00 */SEC = 00; /* Seconds */

}/* Hint: ARM processor crystal freq. = 12 MHz = 12,000,000 HzRTC crystal freq. = 32.768 KHz = 32,768 HzCalculate,PREINT = (12,000,000 / 32,768)-1 = 365 in Decimal = 0x16D in Hex.PREFRAC = 12,000,000 - (365+1)*32,768 = 6912 in Decimal = 0x1B00 in Hex.And, forCIIR = Counter Increment Interrupt Register,CCR = Clock Control RegisterILR = Interrupt Location RegisterRefer, "Volume 1: LPC214x User Manual" PDF Document */

/* - - - - - Start the Clock - - - - - */void RTCStart( void ){

CCR |= 0x01; /* CTC Reset */ILR = 0x01; /* Interrupt location Register */

}

/* - - - - - Read Clock - - - - - */void Read_rtc( void ){

printf("TIME--->%d:%d:%d\t",HOUR,MIN,SEC);printf("DATE--->%d:%d:%d\n",DOM,MONTH,YEAR);

}

Page 40: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

/* - - - - - main function starts - - - - - */void main(){

baudrate_settings(); /* call function baudrate_settings */RTC_Init(); /* call function RTC_Init */RTCStart(); /* call function RTCStart */while(1){

Read_rtc(); /* call function Read_rtc */}

}

Procedure to View the Result:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK - 2148 Board, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Open Win X- Talk, Select COM port and Baud rate as 9600 Now observe the output data in the PC, it should display the digital clock running with Hr., Min., & Sec. Digits following format: “HH:MM:SS “. along with the Day as “DD:MM:YYYY” Digital Clock will start running from 10:21:00 as programmed by default, you can modify the code and you can load your desired timing also. Apart from timing it can be programmed to display AM-PM (12Hr mode) also.

Outputview the output in PC-Hyper Terminal

Page 41: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 5Interfacing Keyboard and LCD

Aim

To develop a C-Language program for displaying the Key pressed in the Keypad in theLCD module. The display should come in the desired line and column.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.

TheoryKeypad

The Matrix keyboard is used to minimize the number of I/O lines. Normally it ispossible to connect only one key or switch with an I/O line. If the number of keys in the systemexceeds the more I/O lines are required. To reduce the number of I/O lines the keys areconnected in the matrix circuit. Keyboards use a matrix with the rows and columns madeup of wires. Each key acts like a switch. When a key is pressed a column wire makescontact with row wire and completes a circuit.

For example 16 keys arranged in a matrix circuit uses only 8 I/O lines.In VSK-2148 board Dip-switch and matrix keypad lines are multiplexed.

Page 42: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

LCDLiquid crystals are a phase of matter whose order is intermediate between that of a liquid

and that of a crystal. The molecules are typically rod-shaped organic matters about 25Angstroms in length and their ordering is a function of temperature. The molecularorientation can be controlled with applied electric fields.CHARACTER BASED LCD

A standard character LCD is probably the most widely used data Visualizationcomponent.Character LCDs are available in various kinds of models.

1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4…2. Color: Yellow, Green, Gray, Blue…

The Character LCD communicates with the microcontroller via 8 bit data bus. The pindescription for character LCD is given below.VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0is 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 onthe LCD.

RW (Read/Write) - RW allows the user to write information to the LCD or readinformation from it. RW=1 when reading; RW=0 when writing.

EN (Enable) - The LCD to latch information presented to its data pins uses the enablepin. When data is supplied to data pins, a high to low pulse must be applied to this pin inorder for the LCD to latch in the data present at the data pins.

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

Procedure

Page 43: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Follow the steps 1 of How to create a New project Type the below code and save it with the name keypad.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program

Follow the procedures in How to Download a Code to Our Controller to download your code.

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 "lcd.h"#include "key.h"/* - - - - - main function starts here - - - - - */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; /* LCD data pins as output */comm(command); /* function to call LCD commands */data1("Press any Key"); /* call the function to display the data in LCD */while(1){

scomm(0xC0); /* function to write single datas in LCD location C0 */key(); /* call the keypad function*/

}}

Procedure to see OUTPUT: Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK - 2148 Boards, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Now observe the LCD output, it should display the Alphabets & Numbers. 1st line (upper line) should display the Alphabets Press any Key and the 2nd line (lower line) should display the corresponding data as the Key is Pressed You can change Address for upper line from 0x80 to 0x8F and for lower line from 0xC0 to 0xCF

OUTPUT:view the output in LCD

Page 44: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Input is 4x4 matrix

Experiment 6Interfacing EEPROM and Interrupt

Aim

To develop a C-Language program to write and read a data in EEPROM and also toanalyze its performance with the interrupt

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.

Theory

Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,telecommunication, medical, industrial and PC related markets. Primarily used to storepersonal preference data and configuration/setup data, Serial EEPROM’s are the mostflexible type of nonvolatile memory utilized today. Compared to other NVM solutions,Serial EEPROM devices offer a lower pin count, smaller packages, lower voltages, aswell as lower power consumption.

Procedure

Follow the steps 1 of How to create a New project Type the below code and save it with the name (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the

Page 45: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

program Follow the procedures in How to Download a Code to Our Controller to download your code.

Program/* - - - - - Header Files - - - - - */#include<nxp\iolpc2148.h>#include<stdio.h>#include "intrinsics.h"void TIMER0(void);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:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK - 2148 Syllabus Board, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Open Win X – Talk and select the COM port and the Desired Baud rate as 9600. The main function will execute continuously. The Timer Interrupt function will execute for every 1 second. For every 1 second the Interrupt data will be printed in the PC

OUTPUT:View the output in PC-Hyper Terminal.

Page 46: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 7

` MailboxAim

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

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.

Theory

Real-time and embedded systems operate in constrained environments in whichcomputer memory and processing power are limited. They often need to provide their serviceswithin 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 embeddedsoftware.

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 RTOSkernel supplies five main categories of basic services to application software

The most basic category of kernel services is Task Management. This set of servicesallows 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 ownreal-time deadline. Each separate "chunk" of software is called a "task." The main RTOSservice in this category is the scheduling of tasks as the embedded system is in operation.

Page 47: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

The second category of kernel services is Intertask Communication andSynchronization. These services make it possible for tasks to pass information from one toanother, without danger of that information ever being damaged. They also make it possible fortasks to coordinate, so that they can productively cooperate with one another. Without the helpof these RTOS services, tasks might well communicate corrupted information or otherwiseinterfere with each other.

Since many embedded systems have stringent timing requirements, most RTOS kernelsalso 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 allowstasks to "borrow" chunks of RAM memory for temporary use in application software. Oftenthese chunks of memory are then passed from task to task, as a means of quicklycommunicating large amounts of data between tasks. Some very small RTOS kernels that areintended 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 ofservices. These services, if available, provide a uniform framework for organizing andaccessing the many hardware device drivers that are typical of an embedded system.

Procedure

Follow the steps 1 of How To Create Rtos Programs Type the below code and save it with the name main.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program Follow the procedures in How to Download a Code to Our Controller to download your code.

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)

Page 48: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

{temp=123;OSMboxPost(comm,(void *)&temp);OSTimeDlyHMSM(0, 0, 0, 10);

}}void Task2(void *pdata){

INT8U err;INT8U *msg;char val1;while(1){

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:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK - 2148 Syllabus Board, and Power on the Board. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Open Win X – Talk and select the COM port and the Desired Baud rate as 9600. 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.

OUTPUT:View the output in PC-Hyper Terminal.

Page 49: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 8Interrupt Performance Characteristics of ARM and FPGA

Aim

To study about the Interrupt performance characteristics between ARM and FPGA

Apparatus & Software Required1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic4. Xilinx FPGA Spartan 65. Xilinx ISE Design suite6. ModelSim SE7. JTAG 5.58. CRO

Theory

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

Procedure for ARM

Follow the steps 1 of How to create a New project Type the below code and save it with the name led.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program Follow the procedures in How to Download a Code to Our Controller to

download your code

Program

Page 50: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

#include<nxp\iolpc2148.h>#include<stdio.h>#include "intrinsics.h"#define led1 IO0PIN_bit.P0_12#define led2 IO0PIN_bit.P0_13void 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();

}void TIMER0(void){

led2=0;printf("\n vimicrosystem \n");T0IR=1;

}void TIMER1(void){

led1=0;led2=0;printf("\n chennai \n");T1IR=1;

Page 51: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

Compile, Debug & Simulate the above code in IAR. For seeing the output in real-time, select the PROG mode, reset the board anddownload the code in board using Flash Magic through UART0. Now change the Mode-Selection-Switch to EXEC position and reset the board.

Page 52: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Run/Execute the program on the VSK – 2148 board and observe the variation inthe main process as an interrupt occurred. The variations can be viewed in the CRO.

Interrupt performance in FPGAProcedure for FPGAStep 1: Create a “New project” in Xilinx ISE Project Navigator from File Button.Step 2: Assign a “Name” of the project and click “Next”Step 3: Check/ modify the properties for the FPGA hardware and click “Next”.Step 4: Click “Finish” for the Summary window.(Now the new project window has been

displayed in the ISE Project Navigator.)Step 5: Right click on the Xilinx FPGA hardware in the Hierarchy window pane and select add

“New Source”.Step 6: Select “VHDL Module” and enter the file name before clicking “Next”.Step 7: Define the “port details” of the VHDL module and click “Next”.Step 8: Now click “Finish” the Summary window pane.Step 9: Now copy and paste the below program in the module.

(Follow the same procedure from “Step 5 to Step 8” for adding the VHDL modules for thebelow program.)

Step 10: Right click on the Xilinx FPGA hardware in the Hierarchy window pane and select add “New Source”.

Step 11: Select “Implementation Constraint File” and enter the file name before clicking “Next”.

Step 12: Copy and Paste the Implementation Constraint File module in the appropriate module.

Step 13: Click “Generate Programming File” in the Processes pane for the entire project. (Now the .bit file has been generated for the project)

Step 14: Before continuing with the further process please Connect the FPGA hardware kit with the CPU by using serial cable and Switch “ON”.

Step 15: Now Open the JTAG 5.5 software from Start menu in your computer and initialize the FPGA device for dumping the program into it.

Step 16: 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 moduleLIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTIONENTITY TOP_MODULE ISPORT ( CLK : IN STD_LOGIC;GEN_CLK1 : OUT STD_LOGIC;GEN_CLK2 : OUT STD_LOGIC;GEN_CLK3 : OUT STD_LOGIC;INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNALINPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL

Page 53: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNALRISING_INTERRUPT : OUT STD_LOGIC;RISING_INTERRUPT1: OUT STD_LOGIC;RISING_INTERRUPT2: OUT STD_LOGIC);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 SIGNALINPUT2: IN STD_LOGIC; ---- SQUARE SIGNALINPUT3: IN STD_LOGIC; ---- SQUARE SIGNALRISING_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_INTERRUPT2);END BEHAVIORAL;

CLK_GENLIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;-- DECLARATION OF PORT DETAILS --ENTITY CLK_GEN ISPORT ( 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 ISSIGNAL FREQ :INTEGER :=0; -- SIGNAL DECLARATION OF FREQBEGINPROCESS(CLK) -- INPUT CLOCK SIGNAL FOR GENERATING 3 INPUT SIGNALSBEGINIF RISING_EDGE (CLK) THEN -- ROUTINE FOLLOWS WITH REFERENCE TO THE CLOCKSIGNALFREQ <= FREQ +1; -- GENGERATING THE COUNTER FOR THE SIGNAL FREQIF(FREQ >0 AND FREQ <= 10000)THEN -- FOR GETTING 1KHZ SIGNAL WE ARE

Page 54: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

EQUALLY SPLITTING UP THE TIMING VALUES '0' FOR 10000 COUNTS AND '1' FOR10000 COUNTSGEN_CLK1 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZGEN_CLK2 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZGEN_CLK3 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZELSIF (FREQ >10000 AND FREQ <= 20000)THENGEN_CLK1 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZGEN_CLK2 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZGEN_CLK3 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZELSIF (FREQ > 20000)THENFREQ <= 0; -- COUNTER RESETS TO '0' IT IT EXCEEDS 20000 COUNTSEND IF;END IF; -- PROCESS ENDS BY GENERATING THE 3 INPUT SIGNALSEND PROCESS;END BEHAVIORAL;

Interrupt--------------------------------------------------------------------------- LIBRARY PART ---------------------------------------------------------------------------LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;--------------------------------------------------------------------------- PORT DECLARATION PART ---------------------------------------------------------------------------ENTITY INTERRUPT ISPORT ( CLK : IN STD_LOGIC ; -- INPUT CLOCKINPUT1 : IN STD_LOGIC; -- SQUARE SIGNALINPUT2 : IN STD_LOGIC; -- SQUARE SIGNALINPUT3 : IN STD_LOGIC; -- SQUARE SIGNALRISING_INTERRUPT : OUT STD_LOGIC; -- INTERRUPT OUTPUT 1RISING_INTERRUPT1 : OUT STD_LOGIC; -- INTERRUPT OUTPUT 2RISING_INTERRUPT2 : OUT STD_LOGIC -- INTERRUPT OUTPUT 3);END INTERRUPT ;---------------------------------------------------------------------------DESIGN ARCHITECTURE BEGIN'S ---------------------------------------------------------------------------ARCHITECTURE BEHAVIORAL OF INTERRUPT ISSIGNAL C1,C2,C3 : INTEGER :=0 ; --INTERNAL INTEGER SIGNAL DECLARATION FOR GLOBAL PURPOSESIGNAL RISING,RISING1,RISING2,X,Y,Z: STD_LOGIC:='0'; --INTERNAL BINARY ORSINGLE BIT SIGNAL FOR GLOBAL USEBEGIN---------------------------------------------------------------------------- FIRST INTERRUT DESIGN ----------------------------------------------------------------------------PROCESS(CLK,INPUT1) --SENSITIVITY LIST FORINPUT USEVARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL VARIABLE'SDECLARATION FOR INTERNAL PROCESSBEGINIF RISING_EDGE(CLK) THEN --CLOCK SIGNALRISING_INTERRUPT<= RISING;-- ASSIGNING RISING_INTERRUPT AS RISING VALUECASE X IS-- SUBJECTING X VALUE WITH THE STANDARD LOGIC FUNCTION '0'AND '1'WHEN '0' =>

Page 55: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

IF INPUT1='1' THEN --ROUTINE WILL CONINUE IF INPUT1 INON CONDITIONRISING<='1'; -- RISING VALUE SHOULD BE ON& X VALUE SHOULD BE ONX<='1';END IF;WHEN '1'=>IF INPUT1='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1IN OFF CONDITIONX<='0'; -- VALUE OF X TENDS TO'0'END IF;WHEN OTHERS=> -- IF ANY CONDITION OTHERTHAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.END CASE;IF RISING='1' THEN -- IF THE SIGNAL FOUND AS RISING EDGETHEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSORA := 30000+300000; -- ADDITION OPERATIONB:= 5669*6587; --MULTIPLICATION OPERATIONC:= 5456496/564; --DIVISION OPERATIONE:=684986-546657; --SUBTRACTION OPERATIONF:=4858*555; --MULTIPLICATION OPERATIONG:=45587486/6484; --DIVISION OPERATIONH:=5847962-45134; --SUBTRACTION OPERATIONI:=6872678+2587; -- ADDITION OPERATIONJ:=245231+5454; -- ADDITION OPERATIONK:=86748/654; --DIVISION OPERATIONL:=816784*864; --MULTIPLICATION OPERATIONM:=54341/64112; --DIVISION OPERATIONN:=46845*4816; --MULTIPLICATION OPERATIONC1<=C1+1; -- HERE THE COUNTER STARTS TO SUPPORT THE DELAYIF C1>= 9000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR CONVENIENCERISING<='0'; -- ONCE THE COUNTER EXCEEDSTHE VALUE OF 9000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINEWILL END UP.C1<=0; --ONCE THE COUNTEREXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.END IF; -- RISING = '1' CONDITIONENDS HERE.END IF;END IF; -- ENTIRE PROCESS ENDSUP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN ARITHMETICOPERATIONS..END PROCESS; -- THESE ABOVE CONDITIONSPROVIDE US THE INTERRUPT PERFORMANCE OFTHE GIVEN INPUT SIGNAL THRURISING_INTERRUPT SIGNAL.---------------------------------------------------------------------------- SECOND INTERRUPT DESIGN ----------------------------------------------------------------------------PROCESS(CLK,INPUT2) --SENSITIVITY LIST FOR INPUT USEVARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N:INTEGER :=0; --INTERNAL VARIABLE'SDECLARATION FOR INTERNAL PROCESSBEGINIF RISING_EDGE(CLK) THEN --CLOCK SIGNALRISING_INTERRUPT1<= RISING1; -- ASSIGNING RISING_INTERRUPT AS RISINGVALUECASE Y IS WHEN '0' => -- SUBJECTING Y VALUE WITH THESTANDARD LOGIC FUNCTION '0' AND '1'

Page 56: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

IF INPUT2='1' THEN --ROUTINE WILL CONINUE IFINPUT1 IN ON CONDITIONRISING1<='1'; -- RISING VALUE SHOULD BE '1' & XVALUE SHOULD BE ONY<='1';END IF;WHEN '1'=>IF INPUT2='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1 IN '0'CONDITIONY<='0'; -- VALUE OF XTENDS TO '0'END IF;WHEN OTHERS=> -- IF ANY CONDITION OTHERTHAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.END CASE;IF RISING1 ='1' THEN -- IF THE SIGNAL FOUND ASRISING EDGE THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSORA := 30000+300000; -- ADDITION OPERATIONB:= 5669*6587; --MULTIPLICATION OPERATIONC:= 5456496/564; --DIVISION OPERATIONE:=684986-546657; --SUBTRACTION OPERATIONF:=4858*555; --MULTIPLICATIONOPERATIONG:=45587486/6484; --DIVISION OPERATIONH:=5847962-45134; --SUBTRACTION OPERATIONI:=6872678+2587; -- ADDITION OPERATIONJ:=245231+5454; -- ADDITION OPERATIONK:=86748/654; --DIVISION OPERATIONL:=816784*864; --MULTIPLICATION OPERATIONM:=54341/64112; --DIVISION OPERATIONN:=46845*4816; --MULTIPLICATION OPERATIONC2<=C2+1; -- HERE THE COUNTERSTARTS TO SUPPORT THE DELAY OF THE SIGNALIF C2>= 6000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OURCONVENIENCERISING1<='0'; -- ONCE THE COUNTER EXCEEDSTHE VALUE OF 6000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINEWILL END UP.C2<=0; --ONCE THECOUNTER EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.END IF; --THE RISING ='1' CONDITION ENDS HERE.END IF; -- ENTIRE PROCESSENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVENARITHMETIC OPERATIONS..END IF; -- THESE ABOVECONDITIONS PROVIDE US THE INTERRUPT PERFORMANCE OF THE GIVEN INPUT SIGNALTHRU RISING_INTERRUPT SIGNAL.END PROCESS;END BEHAVIORAL;

Procedure to View Result in FPGABy 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:

1. Run the Simulation process of the Project by selecting “Simulation” in the “View” pane and select the Simulator (ModelSim) in the Processes pane.

Page 57: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

2. Force clock input to the CLK variable by right clicking the variable3. Now you can observe the Input and output result in the Simulator.

OUTPUT:View the output in PC-Hyper Terminal.

Experiment 9Flashing of LEDS

Aim

To develop a ‘C’ program to make the LED blink (including delay routine). Uponchange in the delay program the speed should vary.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.

Theory

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 oflight. This effect is called electroluminescence and the color of the light is determined by theenergy gap of the semiconductor. VSK-2148 has 12 LEDs that are connected to the P4,P5Port .

Procedure Follow the steps 1 of How to create a New project Type the below code and save it with the name led.c (anyname.c)

Page 58: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Follow the steps 2 and 3 of How to create a New Project to compile and build the program

Follow the procedures in How to Download a Code to Our Controller to download your code.

Program

/* - - - - Header files - - - - */#include<nxp\iolpc2148.h>/* - - - - variable declaration - - - - */int x;/* - - - - delay routine - - - - */void delay(){for( int i=0;i<=1500;i++);}/* - - - - PWM initialization - - - - */void pwm(int x){

PINSEL0 = 0X000A0005; // To select Port pin P0.8 and also p0.9 as pwm4 and pwm6PWMPR = 0X00000000; // To set Prescaler register value to onePWMPCR = 0X00005000; // To select pwm2 as single edge controlledPWMMCR = 0X00000002; // To Reset pwm timer counter when matches occurPWMMR0 = 12000 ; // To set total time period of pwm outputPWMMR4 = x;PWMMR6 = x;PWMTCR = 0X00000002; // To reset pwm timerPWMTCR = 0X00000009;

}/* - - - - main routine - - - - */void main(){

while(1){for(int i=0;i<=12000;i++){

x=x+10;pwm(x);delay();if(x>=12000)

{x=0;

} } }}

Procedure to View the Result:

Page 59: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Compile, Debug & Simulate the above code in IAR. 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. Now change the Mode-Selection-Switch to EXEC position and reset the board. Run/Execute the program on the VSK – 2148 board and observe the LED blink duration (on/off).

OUTPUT:VLEDD-02 terminal are connect to P5.View the output in VLEDD-02

Page 60: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 10

Interfacing Stepper Motor and Temperature Sensor

Aim

To write C Programs for running stepper motor either in clock-wise or counter-clockwise and the direction of the rotation of the stepper motor depends on the variation in thetemperature sensor.

Apparatus & Software Required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.4. Stepper motor

Theory

Stepper motors, effectively have multiple "toothed" electromagnets arranged around acentral 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. Whenthe gear's teeth are thus aligned to the first electromagnet, they are slightly offset from thenext electromagnet.

So when the next electromagnet is turned on and the first will turn off, the gear rotatesslightly to align with the next one and from there the process is repeated. Each of thoseslight 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.

Page 61: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Jumper Position

Closed 1 and 2 - Internal voltage for stepper motor.Closed 2 and 3 - External voltage for stepper motor.

Procedure

Follow the steps 1 of How to create a New project Type the below code and save it with the name step.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program Follow the procedures in How to Download a Code to Our Controller to download your code.

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();IO0PIN = 0X60;delay();IO0PIN = 0XA0;delay();

}/* - - - - - reverse rotation - - - - - */

Page 62: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

Procedure to see OUTPUT:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK - 2148 Board, and Power on the Board. 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. Now connect/interface the stepper motor at the motor port available in the VSK - 2148 Board with proper polarity. Now change the Mode-Selection-Switch to EXEC position and reset the board. The stepper motor will rotate in the forward and reverse direction.

OUTPUT:stepper motor terminal are connect to P10 connector.

Page 63: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

ii) Temperature Sensor

The temperature sensor that is used here is LM35. The LM35 series are precisionintegrated-circuit temperature sensors, whose output voltage is linearly proportional tothe Celsius (Centigrade) temperature. The LM35 thus has an advantage over lineartemperature sensors calibrated in ° Kelvin, as the user is not required to subtract a largeconstant voltage from its output to obtain convenient Centigrade scaling. The LM35 doesnot require any external calibration.

Procedure

Follow the steps 1 of How to create a New project Type the below code and save it with the name temp.c (anyname.c) Follow the steps 2 and 3 of How to create a New Project to compile and build the program Follow the procedures in How to Download a Code to Our Controller to download your code.

Program

/* - - - - - header files - - - - - */

#include<nxp\iolpc2148.h>#include<stdio.h>

Page 64: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

#include "uart.h"#include "adc.h"/* - - - - - user defined variables - - - - - */

unsigned int val=0,volt;/* - - - - - main function - - - - - */

void main(void){

PINSEL1_bit.P0_28=1;init();uart_inital();adc();PINSEL1=0X01000000; //ADC0.1

while(1){

while(AD0DR_bit.DONE==0); // Start A/D Conversion

val=AD0DR1_bit.RESULT;volt=val/3.07;printf("Temperature = %ddegree \n\r",volt);

}}

Procedure to see OUTPUT:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK - 2148 Board, and Power on the Board. 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. Now connect/interface the stepper motor at the motor port available in the VSK - 2148 Board with proper polarity. Now check the jumpers J4 and J6. Jumper J4 has to be left opened whereas jumper J6 has to be closed. Now change the Mode-Selection-Switch to EXEC position and reset the board. Open Win X- Talk and select the COM port and the desired baud rate as 9600. Heat the temperature sensor to view the variation in the temperature

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

Page 65: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Experiment 11

Implementing Zigbee Protocol with ARM

Aim

To implement the wireless protocol with ARM

Apparatus and software required

1. LPC2148 syllabus board.2. IAR IDE software.3. Flash Magic.4. Xbee modules

Theory

The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RFModules were directed to operate within the ZigBee protocol. The modules providereliable delivery of data between remote devices. Zigbee is the communication protocollike wifi and Bluetooth. Xbee is the module using Zigbee protocol

Some of its features are:

ZigBee is targeted at radio-frequency (RF) applications Low data rate, long battery life, and secure networking Transmission range is between 10 and 75 meters (33~246 feet) 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 The radios use direct-sequence spread spectrum coding, which is managed by the digital stream into the modulator. To ensure reliable data transmission Binary phase shift keying (BPSK) in the 868/915 MHz Offset quadrature phase shift keying (O-QPSK) at 2.4 GHz

Page 66: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Xbee interfacing with PC

Page 67: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

Xbee interfacing with microcontroller

Procedure

1. Follow the steps 1 of How to create a New project2. Type the below code and save it with the name (anyname.c)3. Follow the steps 2 and 3 of How to create a New Project to compile and build

the program4. Follow the procedures in How to Download a Code to Our Controller to download your code.

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

Page 68: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

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

Page 69: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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 : 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 :

Page 70: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

Page 71: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

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

Page 72: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

IO1CLR = 0xff000000; IO1SET = 0x33000000; } if(t==0x34) { IO1CLR = 0xff000000; IO1SET = 0x44000000; } if(t==0x35) { IO1CLR = 0xff000000; IO1SET = 0x55000000; } if(t==0x36) { 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))

Page 73: List of Experiments - chettinadtech.ac.inchettinadtech.ac.in/storage/16-08-06/16-08-06-16-38-37-3839... · List of Experiments 1. ... implemented with ARM7 LPC2148 Syllabus Board

{ IO1CLR = 0xff000000; IO1SET = 0xdd000000; } if(t==0x45) { IO1CLR = 0xff000000; IO1SET = 0xee000000; } if(t==0x46) { IO1CLR = 0xff000000; IO1SET = 0xff000000; } }}

Procedure to see OUTPUT:

Compile, Debug & Simulate the above code in IAR. Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -

2148 Boards, and Power on the Board. 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. Connect 1 Xbee module with the board and other with the PC. Now change the Mode-Selection-Switch to EXEC position and reset the board. 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.