Upload
ajay-bhalerao
View
35
Download
3
Tags:
Embed Size (px)
DESCRIPTION
SSSSSSSSS
Citation preview
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 1
MRR2148SB Development Board
User Manual
MRR Embedded Systems Pvt. Ltd., B56/1, Vallalar Street,
MMDA Colony Arumbakkam,
Chennai - 600106, INDIA.
Ph: 91- 44-42078785,
Mail: [email protected]
Web: www.mrrembedded.com
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 2
CONTENTS 1. INTRODUCTION 3 2. LPC 2148SB CPU DETAILS 4 3. LPC2148 ARCHITECTURE 6 4. HARDWARE DESCRIPTION 12 5. SOFTWARE –GETTING STARTED 14
6. HARDWARE – GETTING STARTED 38 7. SOFTWARE – EXAMPLE PROGRAMS 53
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 3
INTRODUCTION First of all sales and R&D Team of MRR Embedded Systems Pvt Ltd thanking you for buying MRR’s Embedded LPC214x Development KIT. The LPC214x Development KIT is a complete development platform for NXP ARM7 LPC214x series processors. It is a cost effective, flexible and highly integrated board, useful for develop custom embedded applications and evaluate all features of the new powerful ARM7 processor. The LPC2148 Microcontroller is based on a 32/16 Bit ARM7TDMI-s CPU with real time Emulation and Embedded Trace support, That combines with the microcontroller with embedded high speed 512KB flash memory. It can work with 16-bit Thumb Mode. With Useful Implemented peripherals, plentiful practical code examples and a broad set of additional on board Peripherals MRR’s ARM Development boards make fast and reliable tools that can satisfy the needs of experienced engineers and beginners alike. Modern SMD technology and Multilayer Design makes our board compact and of good quality. All Controller signals and ports extend from the controller to high density pitch Connectors of the board. MRR2148SB Hardware Manual Describes the board’s design and functions. Precise Specifications for the NXP LPC2148 Microcontroller can be found in the enclosed Microcontroller Data sheet/User’s Manual. In this hardware manual, schematic diagrams and Block Diagrams are attached.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 4
Getting around the LPC214x Development KIT
The figure above shows the major parts of the LPC214x Development KIT. Diagrams and wiring descriptions for all connectors are provided in schematic. The board has the optional feature of Graphical LCD and USB Connector for developing these applications.
LPC2148SB CPU DETAILS
The LPC2148 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with real-time 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. For critical code size
applications, the alternative 16-bit Thumb mode reduces code by more than 30% with minimal
performance penalty. Due to their tiny size and low power consumption, LPC2148 are ideal for
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 5
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 8 kB up to 40 kB, 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:
6/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.
28 bit wide interface/accelerator enables high speed 60 MHz operation.
In-System/In-Application Programming (ISP/IAP) via on-chip bootloader
software.
Single flash sector or full chip erase in 400 ms & 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 provide 8 kB of on-chip RAM accessible to USB by DMA.
One or two (LPC2141/2 vs LPC2144/6/8) 10-bit A/D converters provide a total of 6/14
analog inputs, with conversion times as low as 2.44 s per channel.
Single 10-bit D/A converter provides variable analog output.
Two 32-bit timers/external event counters (with four capture and four compare channels
each), PWM unit (six outputs) and watchdog.
Low power real-time clock with independent power and dedicated32 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 nine edge or level sensitive external interrupt pins available.
60 MHz maximum CPU clock available from on-chip PLL with settling time of 100s.
On-chip integrated oscillator operates with an external crystal range from 1 MHz 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.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 6
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:
– CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %)
– with 5 V tolerant I/O pads.
Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.
Application
Industrial control
Medical systems
Access control
Point-of-sale
Communication gateway
Embedded soft modem
General purpose applications
LPC2148 Architecture Overview
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 (CISC). This simplicity results in a
high instruction throughput and 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 systems to 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. Essentially, the ARM7TDMI-S processor has two instruction sets:
• The standard 32-bit ARM set.
• A 16-bit Thumb set.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 7
On-Chip Flash Memory:
The LPC2148 incorporate 512 kB flash memory system. This memory may be used for both code
and data storage. Programming of the flash memory may be accomplished in several ways. It may
be programmed In System via the serial port. The application program may also erase and/or
program the flash while the application is running, allowing a great degree of flexibility for data
storage field firmware upgrades, etc. Due to the architectural solution chosen for an on-chip boot
loader, flash memory available for user’s code on 500 kB. The LPC2148 flash memory provides a
minimum of 100000 erase/write cycles and 20 years of data-retention.
On-chip Static RAM:
On-chip static RAM may be used for code and/or data storage. The SRAM may be accessed as 8-
bit, 16-bit, and 32-bit. The LPC2148 provide 32 kB of static RAM. Also an 8 kB SRAM block intended
to be utilized mainly by the USB can also be used as a general purpose RAM for data storage and
code storage and execution.
General purpose parallel I/O (GPIO):
Device pins that are not connected to a specific peripheral function are controlled by the GPIO
registers. Pins may be dynamically configured as inputs or outputs. Separate registers allow setting
or clearing any number of outputs simultaneously. The value of the output register may be read
back, as well as the current state of the port pins.
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 (VPB, 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. AHB peripherals are
allocated a 2 megabyte range of addresses at the very top of the 4 gigabyte ARM memory space.
Each AHB peripheral is allocated a 16 kB address space within the AHB address space. LPC2148
peripheral functions (other than the interrupt controller) are connected to the VPB bus. The AHB
to VPB bridge interfaces the VPB bus to 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 kB address space
within the VPB address space. The connection of on-chip peripherals to device pins is controlled by
a Pin Connect Block(see chapter "Pin Connect Block" on page 74). This must be configured by
software to fit specific application requirements for the use of peripheral functions and pins.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 8
Vectored Interrupt controller:
The Vectored Interrupt Controller (VIC) accepts all of the interrupt request inputs and categorizes
them as Fast Interrupt Request (FIQ), vectored Interrupt Request (IRQ), and non-vectored IRQ as
defined by programmable settings. The programmable assignment scheme means that priorities of
interrupts from the various peripherals can be dynamically assigned and adjusted. Fast interrupt
request (FIQ) has the highest priority. Vectored IRQs have the middle priority. Non-vectored IRQs
have the lowest priority.
External interrupt inputs:
The LPC2148 include up to nine edge or level sensitive External Interrupt Inputs as selectable pin
functions. When the pins are combined, external events can be processed as four independent
interrupt signals. The External Interrupt Inputs can optionally be used to wake-up the processor
from Power-down mode. Additionally capture input pins can also be used as external interrupts
without the option to wake the device up from Power-down mode.
General purpose timers/external event counters:
The Timer/Counter is designed to count cycles of the peripheral clock (PCLK) or an externally
supplied clock and optionally generate interrupts or perform other actions at specified timer
values, based on four match registers. It also includes four capture inputs to trap the timer value
when an input signal transitions, optionally generating an interrupt. Multiple pins can be selected
to perform a single capture or match function, providing an application with ‘or’ and ‘and’, as well
as ‘broadcast’ functions among them. The LPC2148 can count external events on one of the
capture inputs if the minimum external pulse is equal or longer than a period of the PCLK. In this
configuration, unused capture lines can be selected as regular timer capture inputs, or used as
external interrupts.
A 32-bit timer/counter with a programmable 32-bit prescaler
External event counter or timer operation
Four 32-bit capture channels per timer/counter that can take a
Snapshot of the timer value when an input signal transition occurs.
A capture event may also optionally generate an interrupt.
Four 32-bit match registers that allow :
– Continuous operation with optional interrupt generation on match.
– Stop timer on match with optional interrupt generation.
- Reset timer on match with optional interrupt generation.
Four external outputs per timer/counter corresponding to match registers, with the
following capabilities
o Set LOW on match.
o Set HIGH on match.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 9
o Toggle on match.
o Do nothing on match.
UARTs:
The LPC2148 contains two UARTs. In addition to standard transmit and receive data lines, the
LPC2148 UART1 also provide a full modem control handshake interface. Compared to previous
LPC2000 microcontrollers, UARTs in LPC2148 introduce a fractional baud rate generator for both
UARTs, enabling these microcontrollers to achieve standard baud rates such as 115200 with any
crystal frequency above 2 MHz. In addition, auto-CTS/RTS flow-control functions are fully
implemented in hardware (UART1).
16 Bit Receive and Transmit FIFO
Register locations conform to 16C550 industry standard
Receiver FIFO trigger points at 1 B, 4 B, 8 B, and 14 B
Built-in fractional baud rate generator covering wide range of baud rates without a need for
external crystals of particular values
Transmission FIFO control enables implementation of software
(XON/XOFF) flow control on both UARTs
LPC2148 UART1 equipped with standard modem interface signals.
This module also provides full support for hardware flow control (auto-CTS/RTS)
I2C-bus serial I/O controller:
The LPC2148 contains two I2C-bus controllers. The I2C-bus is bidirectional, for inter-IC control
using only two wires: a serial clock line (SCL), and a serial data line (SDA). Each device is recognized
by a unique address and can operate as either a receiver-only device. Transmitters and/or
receivers can operate in either master or slave mode, depending on whether the chip has to
initiate a data transfer or is only addressed. The I2C-bus is a multi-master bus; it can be controlled
by more than one bus master connected to it. The I2C-bus implemented in LPC2148 supports bit
rates up to 400 Kbit/s (Fast I2C-bus).
Compliant with standard I2C-bus interface
Easy to configure as master, slave, or master/slave
Programmable clocks allow versatile rate control
Bi-directional data transfer between masters and slaves
Multi-master bus (no central master)
Arbitration between simultaneously transmitting masters without
corruption of serial data on the bus
Serial clock synchronization allows devices with different bit rates to communicate via one
serial bus
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 10
Serial clock synchronization can be used as a handshake mechanism to suspend and resume
serial transfer
The I2C-bus can be used for test and diagnostic purposes
10-bit ADC:
The LPC2148 contains two analog to digital converters. These converters are single 10-bit
successive approximation analog to digital converters. While ADC0 has six channels, ADC1 has
eight channels. Therefore, total numbers of available ADC inputs are 14.
10-bit successive approximation analog to digital converter
Measurement range of 0 V to VREF (2.0 V ? VREF ? VDDA)
Each converter capable of performing more than 400000 10-bit samples per second
Every analog input has a dedicated result register to reduce interrupt overhead
Burst conversion mode for single or multiple inputs
Optional conversion on transition on input pin or timer match signal
Global Start command for both converters
10-bit DAC: The DAC enables the LPC2148 to generate a variable analog output. The maximum DAC output
voltage is the VREF voltage.
10-bit DAC
Buffered output
Power-down mode available
Selectable speed versus power
Real-time clock:
The RTC is designed to provide a set of counters to measure time when normal or idle operating
mode is selected. The RTC has been designed to use little power, making it suitable for battery-
powered systems where the CPU is not running continuously (Idle mode).
Measures the passage of time to maintain a calendar and clock.
Ultra-low power design to support battery powered systems.
Provides Seconds, Minutes, Hours, Day of Month, Month, Year, Day of Week, and Day of
Year.
Can use either the RTC dedicated 32 kHz oscillator input or clock derived from the external
crystal/oscillator input at XTAL1.
Programmable reference clock divider allows fine adjustment of the
RTC.
Dedicated power supply pin can be connected to a battery or the main 3.3 V.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 11
Pulse width modulator:
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.
Crystal oscillator:
On-chip integrated oscillator operates with external crystal in range of 1 MHz to 25 MHz. The
oscillator output frequency is called fosc and the ARM processor clock frequency is referred to as
CCLK for purposes of rate equations, etc. fosc and CCLK are the same value unless the PLL is
running and connected.
PLL:
The PLL accepts an input clock frequency in the range of 10 MHz to 25 MHz. The input frequency is
multiplied up into the range of 10 MHz to 60 MHz with a Current Controlled Oscillator (CCO). The
multiplier can be an integer value from 1 to 32 (in practice, the multiplier value cannot be higher
than 6 on this family of microcontrollers due to the upper frequency limit of the CPU). The CCO
operates in the range of 156 MHz to 320 MHz, so there is an additional divider in the loop to keep
the CCO within its frequency range while the PLL is providing the desired output frequency. The
output divider may be set to divide by 2, 4, 8, or 16 to produce the output clock. Since the
minimum output divider value is 2, it is insured that the PLL output has a 50 % duty cycle. The PLL
is turned off and bypassed following a chip reset and may be enabled by software. The program
must configure and activate the PLL, wait for the PLL to Lock, then connect to the PLL as a clock
source. The PLL settling time is 100 ms.
On-chip Flash memory Organization
The LPC2148 incorporate a 512 kB Flash memory system. This memory may be used for both code
and data storage. Programming of the Flash memory may be accomplished in several ways: over
the serial built-in JTAG interface, using In System Programming (ISP) and UART0, or by means of In
Application Programming (IAP) capabilities. The application program, using the IAP functions, may
also erase and/or program the Flash while the application is running, allowing a great degree of
flexibility for data storage field firmware upgrades, etc. When the LPC2148 on-chip boot loader is
used, 500 kB of Flash memory is available for user code. The LPC2148 Flash memory provides
minimum of 100,000 erase/write cycles and 20 years of data-retention.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 12
On-chip Static RAM (SRAM) Organization
On-chip Static RAM (SRAM) may be used for code and/or data storage. The on-chip SRAM may be
accessed as 8-bits, 16-bits, and 32-bits. The LPC2148 provide 32 kB of static RAM. The LPC2148
SRAM is designed to be accessed as a byte-addressed memory. Word and half word accesses to
the memory ignore the alignment of the address and access the naturally aligned value that is
addressed (so a memory access ignores address bits 0 and 1 for word accesses, and ignores bit 0
for half word accesses). Therefore valid reads and writes require data accessed as half words to
originate from addresses with address line 0 being 0 (addresses ending with 0, 2, 4, 6, 8, A, C, and E
in hexadecimal notation) and data accessed as words to originate from addresses with address
lines 0 and 1 being 0 (addresses ending with 0, 4, 8, and C in hexadecimal notation). This rule
applies to both off and on-chip memory usage. The SRAM controller incorporates a write-back
buffer in order to prevent CPU stalls during back-to-back writes. The write-back buffer always
holds the last data sent by software to the SRAM. This data is only written to the SRAM when
another write is requested by software (the data is only written to the SRAM when software does
another write). If a chip reset occurs, actual SRAM contents will not reflect the most recent write
request (i.e. after a "warm" chip reset, the SRAM does not reflect the last write operation). Any
software that checks SRAM contents after reset must take this into account. Two identical writes
to a location guarantee that the data will be present after a Reset. Alternatively, a dummy write
operation before entering idle or power-down mode will similarly guarantee that the last data
written will be present in SRAM after a subsequent Reset.
Hardware Description
MRR2148SB features a number of peripheral Devices. In order to enable these devices before
programming, you need to check if appropriate jumpers have been properly set.
Board Features:
8 Nos. Digital Input 4x4 Matrix Keypad 8 Nos. Point LEDs 4 Nos. Analog Input 16*2 Character LCD with back light Temperature Sensor Stepper Motor Driver 2 Relays I2C - 6 Nos. 7-Segment Display I2C – Real Time Clock with Battery-Backup I2C -EEPROM 2 Nos. UART (RS232)
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 13
Buzzer (Alarm) Interrupt Switches DAC Port out Power Supply connector out Relay terminal out External Analog input JTAG Debugger ISP programming through Serial port
Package Contents: The box received when ordering LPC214x Development KIT includes: LPC214x Development Board. USB A-B cable. DB25 Parallel Cable for debugging Serial extension cable DB9-male DB9-femail for debugging and programming purpose. 12V DC SMPS Power Supply An optional Wiggler JTAG adapter for debugging. CD-ROM that includes datasheet’s, software examples, useful drivers end etc.
How these elements fit together The core of the package around which everything else fits is Keil RealView ARM compiler and uVision3 IDE. This is a platform that lets you write code and assemble it for the microcontroller. It includes a Simulator and debugger that allows you to step through your code to find basic errors. Once your code is written, the next step is to connect up the ISP Programmer or JTAG debugger to the MRR2148SB Development board, and run the code on the microcontroller. Again, this is done from the Flash Magic ISP Utility or HJTAG Flasher, which allows you to run the code but this time it is running on the Board instead of being simulated by the PC. The ISP software and the JTAG Software can run on its own or it can be integrated into Keil IDE. The other elements in the package are Real view ARM/WINARM C Compiler Flash magic and JTAG. Debugger.
The application Builder is a wizard that helps set up peripherals such as the serial port
without having to know all the details in the ARM device datasheet. The C Compiler is included for those who want to progress beyond assembly language.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 14
Software - Getting Started The CD Package contains the worked examples, so before starting on these you have to load some software. The steps outlined here cover a range of activities. It is easier to install all the Software and come back to details later or you may want to work through each step as you come to it – it is up to you. 1) Install Flash Magic ISP, Keil IDE and JTAG Software 2) Copy code sample files, data sheets, schematics, softwares to your hard drive Now open Keil. Follow the steps in this guide to familiarize yourself with creating projects, writing code and other basics. Create an application in Keil or open a Sample program given in the CD. We recommend that you run some sample programs on the hardware board (MRR2148SB) using the Flash Magic or JTAG programmer to see something happening.
Loading a sample file into Keil IDE Now we can run a program in KEIL IDE
1. Open KEIL IDE 2. Create a New Project in KEIL IDE and give it a name and save. Note the path to the
project. 3. On next screen, select NXP and select LPC21248 click Ok. 4. The next screen shows the project browser which adds the startup code for the project
itself. 5. Now you can create new file. Right click on the Source browser and add files to the
target and compile it. 6. Right click on the targetoptions for the targetoutput and select create hex file for
generating the hex file. 7. Press F7 or Go to Project menu > Build to assemble the file. The output file is a .hex file
for the programmer – this will be stored in the same folder as the Project. 8. Now Flash Magic or JTAG can be used to program the hex code to the processor. 9. For Simulating the output or debugging the target, In the project browseroptions for
the targetdebug and select simulator or debugger Now compile the program and go to debug to enter into simulator or debugger mode and debug the code line by line.
These following Steps are mentioned clearly in pictorial representation.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 15
Getting Started with Keil Once Keil is loaded, an empty workspace is displayed. If any project was opened previously, then the previously opened project will be displayed.
To create a New Project, goto Project. Drop down menu and select New Project
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 16
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 17
Once you select New Project, it asks you where to save the project. Specify the Path. Once you specify the Path, select the Chip to be programmed.
Choose LPC2148 from NXP
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 18
Once you select the chip, a message box will be displayed. It asks whether to load Startup code into the Project.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 19
To write start writing code, select new file from file drop down menu. On Right Hand Side is the editor where the code can be written...
Once the code is written, it has to be added to the Project. To do that right click on the Source group and select .add files to source group. Option. Then select the file to be added. You can see the file added on Left Hand side in the Source group.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 20
To Build the project, goto Project Drop Down menu and select Build.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 21
Once the project is built, the result can be seen at the bottom. If any errors are present the list of errors will be displayed or if the project has no errors the build is said to be successful.
When the project is built, it only compiles and links all the files in project. If the same code is to be loaded onto the chip flash memory, we need the hex file. Hex file is the downloadable file which is used to load onto the flash memory of the chip. In order to generate the Hex file, right click on target folder in Project workspace (the first folder visible) and select .Options for Target .LPC 2100. Check the check box.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 22
Create Hex file and press OK Once the option is selected to create Hex file, once again build the Project. This time the .Hex file is created. You can see the hex file in the folder where the Project is saved. If you want to check for the correctness of the code, then goto Debug Drop Down Menu and select .Start/Stop Debug Session.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 23
Here you simulate the program in SIMULATOR mode here you can see Yellow arrow mark that will move step while pressing F11
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 24
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 25
Board Layout
The figure predicts the exact hardware features of the board which are clearly marked such as POWER, UART0ISP, UART1 etc.,
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 26
Power Supply The kit is supplied with a 12V/1A SMPS Power Supply. The board contains two LM317
Regulators U1 and U2. U1 is tuned for 5V and U2 is tuned for 3.3V. The maximum output current of the voltage regulator is 1.5A. All elements of the board use the +3.3V power supply except relays and ULN2003 that uses +5V. Stepper Motor use +12V Power Supply. ULN2803 used for Stepper Motor uses +12V Power Supply that can be fed from the external Power source or the same power source used to power up the board. For using the same power source for the stepper motor jumper JP51 must be closed. Jumpers JP3 and JP4 must be closed to supply the board with proper power for errorless operation of the board.
Programming the device using ISP The LPC2148 Processor can be programmed by two methods. One is by using the ISP
port (UART0) and the other through JTAG (Parallel port). For Programming through ISP, the
serial cable has to be connected to DB9 Connector P2. The other end of the serial port has to
be connected to the COM port of the PC. The COM port to which it is connected should be
noted. The jumpers JP25, JP29 and JP50 must be closed in order to work with ISP. Also jumper
JP38 must be opened to disable JTAG while using ISP.
In System Programming is programming or reprogramming the on-chip flash memory,
using the boot loader software and a serial port. The LPC2148 Microcontroller provides on-chip
boot loader software that allows programming of the internal flash memory over the serial
channel. The boot loader is activated by pulling port pin P0.14 low during reset of the
Microcontroller. MRR2148SB Board contains circuits for Controlling Pin P0.14 over Toggle
switch. For now, it is assumed that the program to be downloaded is already developed and
there exist a HEX-file to be downloaded. This HEX-file represents the binary image of the
application program.
Now open the Flash magic software. Set the Processor (LPC2148), baud rate
(38400), Interface (None ISP) and Crystal (12Mhz). Select the hex file to be programmed and
program the processor. Make sure the Programadvanced optionsthe DTR and RTS are
used for controlling the ISP.
For using the ISP,
Open the Flash Magic,
Select the chip LPC2148
Select the com port as COM1
Set Baud rate to 38400
Interface as NONE(ISP)
Oscillator as 12Mhz
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 27
Erase All flash
Select the hex file using Browse
Verify after programming
Click Start to program the flash
Programming and Debugging the device using JTAG
For Programming the device using JTAG the following jumpers JP25, JP50 and JP38 must be closed and the jumper JP29 has to be removed. The Serial cable should not be connected to P2 (ISP Port). The H JTAG Server and H Flasher has to be set to program the Processor using JTAG. For Debugging the Processor the IDE must be configured for Debugger mode. The user has to configure HJTAG Server and HJTAG Flasher for using the JTAG Programming features. The configurations steps are as follows.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 28
HTAG Configuration
1.Open the H-Jag from Start Programs H-Tag
2. From the Menu Select Operations Detect Target
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 29
3. Once the Processor is deducted the Red color will change into Blue
H-Flasher Configuration
Open H-Falsher.exe and follow the configuration steps as follows.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 30
1) Select 1) Flash Selection NXP
2) Click the + sign to expand NXP
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 31
3. NXP Choose LPC2148
4. Select 2) Configuration
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 32
5. Ext XTAL(Mhz) Enter (12)
6. Select 4) Pgm Options
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 33
7. Select Reset Verification NXP LPC2000
8. Select 5) Programming
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 34
Step -1 Click Check to verify your board has been deducted.
Step-2 Select Type and click Intel Hex Format
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 35
Step-3 Select Src File: where your program has been saved
Step-4 Select Program to write the hex files into flash Memory
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 36
This will be the window which will be displayed when selected Debug Tab.
Now select RDI Interface Driver from the dropdown menu. Use on Right Hand Side of the window
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 37
Select the check box to select .Run to Main. And check box .Load Application at Startup.. Then click the Settings button
Now click utilities and deselect target driver. Select external tool and change the command option to link with H-Flasher. Delete contents in Arguments. Now start the keil debug mode and start debugging
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 38
Processor and memory devices. The NXP LPC214x processor (DD6) provided with the Development KIT is a high-end device with advanced ADC and DAC features, USB 2.0 Full Speed interface, PWM features, have SPI, SSP and two I2C interfaces. An 12 MHz crystal provides the clock signal to the microcontroller. This crystal is used for develop USB applications. The maximum execution speed is 12.000*5 = 60 MHz The crystal frequency may be changed to any desired value, see LPC214x datasheet for detail. The board also contains a 32.768 kHz crystal that is used by the on-chip real-time clock, and +3V backup battery for save time register values in power down mode. Board comes with placed 512Kbytes I2C EEPROM AT24C04 IC connected to the MCU I2C0 bus (SCL pin 22, SDA pin 26). HARDWARE – GETTING STARTED LEDs: Therefore, when interfacing an LED to a TTL output, the maximum current through the LED is 16 mA. The features of LEDs are listed below
Lower power consumption Require series resistors to limit the current Displaying decimal digits
LED lighting is an emerging technology with many home applications such as LED Christmas lights, LED rope lights, LED spotlights, etc. LED bulbs last over 50,000 hours. For Running the LED applications you have to close the jumper JP6 to JP15. Remove Jumpers related to Stepper Motor and Relays for safe operation, but not mandatory.
SWITCHES: An electrical switch is any device used to interrupt the flow of electrons in a circuit. Switches are essentially binary devices: they are either completely on ("closed") or completely off ("open").. In the simplest case, a switch has two pieces of metal called contacts that touch to make a circuit, and separate to break the circuit. DIP switch is one of the mostly used type. The MRR2148SB Development Board has one 8-Way Dip Switch. When the switch is open, no
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 39
current flows through the resistor and therefore the voltage on the microcontroller pin is 3.3 V. When the switch is closed the pin is connected directly to ground. As before, when the TTL input is HIGH practically no current flows in the circuit and when the input is LOW there is a direct current for the 3mA that may flow from the pin. J12 and J7 must be closed to work with DIP Switch. A 10Pin FRC Connector is used to close these two connectors. Disconnect J7 from J9 and connect to J12.
DSW1 DSW5
DSW4
DSW2DSW7DSW3DSW8
DSW6
J12
CON_SW
13579
2468
10
P1.17P1.20
P1.22P1.21
P1.23P1.19P1.18
P1.16J7
CON_KEY/SW
13579
2468
10
DSW6
DSW2
DSW7
DSW3
DSW8
DSW4DSW5
DSW1SW18
SW DIP-8
12345678
161514131211109
Matrix KEY The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to connect only one key or switch with a I/O line. If the number of keys in the system exceeds the more I/O lines are required. To reduce the number of I/O lines the keys are connected in the matrix circuit. Keyboards use a matrix with the rows and columns made up of wires. Each key act like a switch. When a key is pressed a column wire makes contact with row wire and completes a circuit. For example 16 keys arranged in a matrix circuit uses only 8 I/O lines. For using the Matrix keypad, the Connectors J7 and J9 has to be closed one to one using a 10Pin FRC Connector given as an accessory with the development kit. Disconnect J7 from J12 and connect to J9. The ports P1 of the Microcontroller are configured as port 1 input port in the software for using the matrix keypad. The Output can be viewed on the Serial port. The Software can be changed to view the output on LCD as well as per your wish.
K5
K7K6K2
K1
K4K3
K8
J9
CON_KEY
13579
2468
10
P1.17P1.20
P1.22P1.21
P1.23P1.19P1.18
P1.16J7
CON_KEY/SW
13579
2468
10
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 40
K7
K8
K2
K1
K5
K6
K4
K3
SW1
KEY1
1 3
2 4
SW3
KEY3
1 3
2 4
SW2
KEY2
1 3
2 4
SW4
KEY4
1 3
2 4
SW5
KEY5
1 3
2 4
SW8
KEY8
1 3
2 4
SW7
KEY7
1 3
2 4
SW6
KEY6
1 3
2 4
SW10
KEY10
1 3
2 4
SW11
KEY11
1 3
2 4
SW15
KEY15
1 3
2 4
SW12
KEY12
1 3
2 4
SW13
KEY13
1 3
2 4
SW9
KEY9
1 3
2 4
SW16
KEY16
1 3
2 4
SW14
KEY14
1 3
2 4
LCD (Liquid Crystal Display) Liquid crystals are a phase of matter whose order is intermediate between that of a liquid and that of a crystal. The molecules are typically rodshaped organic matters about 25 Angstroms in length and their ordering is a function of temperature. The molecular orientation can be controlled with applied electric fields. LCD is made up of two sheets of polarizing material with the liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them, which results in display of character as per the applied voltage in its data lines. The driver is provided to drive the LCD. It stores the display data transferred from the microcontroller in the internal display RAM and generates dot matrix liquid crystal driving signals. Each bit data of display RAM corresponds to on/off state of a dot of a liquid crystal display. LCD is used in widespread applications due to the following reasons: 1. The declining prices of LCDs. 2. The ability to display numbers, characters, and graphics. 3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. 4. Ease of programming for characters and graphics. Character Based LCD A standard character LCD is probably the most widely used data Visualization component. Character LCDs are available in various kinds of models. 1. No. Of characters and line 2. Color: Yellow, Green, Gray, Blue…
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 41
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; V0 is 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. 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. For working with the LCD, the jumpers JP44 has to be closed and the potentiometer R74 can be adjusted for contrast variation.
P1.1
7
P1.1
9P1
.18
P1.2
0
P1.2
1
VCC
_LC
D
VCC
_LC
D
VCC_LCD
P1.1
6
R7410K
1 3
2
R71100E
J15LCD_CON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 42
RS-232 Communication Serial port is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). The name "serial" comes from the fact that a serial port "serializes" data. That is, it 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 (while a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8 wires. Serial ports lower cable costs and make cables smaller. There are two basic types of serial communications, synchronous and 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.
Synchronous Data Transfer 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. When a character is about to be transmitted, a start bit is sent. A start bit has a value of 0 (also called a space state). Thus, when the line switches from a value of 1 to a value of 0, the receiver is alerted that a data character is about to be sent.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 43
Asynchronous Data Transfer
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. The LPC2148 will automatically let us know when it has finished sending the character we wrote and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about transmission at the bit level--which saves us quite a bit of coding and processing time. UART or Serial ports, also called communication (COM) ports, RS-232 ports are bi-directional. The LPC2148 contain two UARTs. In addition to standard transmit and receive data lines, the UART1 also provides a full modem control handshake interface. The hardware schematic of the RS232 conversion for UART1 is shown below. Fro Serial port working, o jumper selection is required. Mind it, Jumper selection is for only GPIOs.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 44
Baud Rate Calculation The UART0 Divisor Latch is part of the UART0 Fractional Baud Rate Generator and holds the value used to divide the clock supplied by the fractional prescaler in order to produce the baud rate clock, which must be 16x the desired baud rate. The U0DLL and U0DLM registers together form a 16 bit divisor where U0DLL contains the lower 8 bits of the divisor and U0DLM contains the higher 8 bits of the divisor. The Divisor Latch Access Bit (DLAB) in U0LCR must be one in order to access the UART0 Divisor Latches. The UART0 Fractional Divider Register (U0FDR) controls the clock prescaler for the baud rate generation and can be read and written at user’s discretion. This presale takes the VPB clock and generates an output clock per specified fractional requirements.
SFRs Associated with UART0
All of the SFRs associated with UART0 most important SFRs are explainedin detail.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 45
UART0 Fractional Divider Register
UART0 baud rate can be calculated as:
Where PCLK is the peripheral clock, U0DLM and U0DLL are the standard UART0 baud rate divider registers, and DIVADDVAL and MULVAL are UART0 fractional baud rate generator specific parameters. The value of MULVAL and DIVADDVAL should comply to the following Conditions: 1. 0 < MULVAL = 15 2. 0 = DIVADDVAL = 15
For more information refer to LPC2148 User Manual.
A/D Converter Input Analog to Digital converter (ADC) is a device that converts continuously varying analog signals from instruments that monitor such conditions as movement, temperature, sound, etc., into binary code for the computer. It may be contained on a single chip or can be one circuit within a chip. Analog to Digital conversion is the process of changing continuously varying data, such as voltage, current, or shaft rotation, into discrete digital quantities that represent the magnitude of the data compared to a standard or reference at the moment the conversion is made. According to the method of conversion ADCs can be classified into Direct-Conversion ADCs, Successive Approximation ADCs, Integrating ADC and Sigma-Delta ADCs. 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. Note that these analog inputs are always connected to their pins, even if
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 46
the Pin function Select register assigns them to port pins. A simple self-test of the ADC can be done by driving these pins as port outputs. While the ADC pins are specified as 5 V tolerant More than 3.3 V (VDDA) +10 % should not be applied to any pin that is selected as an ADC input, or the ADC reading will be incorrect. If for example AD0.0 and AD0.1 are used as the ADC0 inputs and voltage on AD0.0 = 4.5 V while AD0.1 = 2.5 V, an excessive voltage on the AD0.0 can cause an incorrect reading of the AD0.1, although the AD0.1 input voltage is within the right range. MRR2148 -SB has one potentiometers for working with A/D Converter. Potentiometer outputs are in the range of 0V to 3.3V.
Sensor Interfacing: Interfacing computer systems to the outside world is an important issue in a large number of computer-related disciplines, from human computer interaction, to robotics, to interactive multimedia, to computer music. In order to do this, the computer systems require some form of sensors. A sensor is a device that measures a physical quantity and converts it into a signal, which can be read by an observer or by an instrument. Capturing the data from sensors is applied in industrial processes. Temperature sensor, Pressure sensor, Humidity sensor, Acceleration sensor, Flow sensor, level sensor, velocity sensor, Solar radiation sensor, Wind direction sensor, Fire/Smoke Sensor and proximity sensor are the types of Sensors used. Temperature Sensor –LM35 A signal conditioner is a device that converts one type of electronic signal into another type of signal. Its primary use is to convert a signal that may be difficult to read by conventional instrumentation into a more easily read format. In performing this conversion a number of functions may take place.
Jumpers JP45 has to be closed for using the thermistor and JP42 has to be closed for using any external sensor. But JP45 and JP42 can be used alternately. Both should not be closed together.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 47
Relay A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation, a light-emitting diode (LED) is used with a photo transistor. For making the relay1 ON, P1.16 has to be made high and for making it off P1.16 has be made low. Similarly for relay2, P1.17 is used. Jumpers JP40 and JP43 has to be closed for the operation of onboard relays. If Relay is used make sure the input applications such as matrix keypad and digital inputs are not in use and the 10PIN FRC connectors are removed, because using the port as output and pressing the keypad may damage the ports pins and the processor. The relay connection diagram is shown in the figure below.
+5VDC
+5VDC
+5VDC
P1.16
RLY1
RELAY1
35
7
46
812R67
1K
L11
LED
J14
RELAY1_TM_B
123
Q4BC547
32
1
D4
1N4007
R581K
R661K
JP40
REL1_JP
1 2
I2C Peripherals I2C Stands for Inter Integrated Circuit Communications. This module is built into many arm Controllers. It allows I2C serial communication between two or more devices at a high speed. I2C is a synchronous protocol that allows a master device to initiate communication with a slave device.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 48
Data is exchanged between these devices. I2C is also Bi-Directional. This is implemented by an “Acknowledge” System. In MRR2148-SB there are three I2C based Peripherals. 1. I2C Based Real Time Clock 2. I2C Based Serial EEPROM 3. I2C Based Seven Segment Display Real Time Clock Communication : Two Wire Communication Protocol : I2C Hardware IC : PCF8563 Application : Clock and calendar U6 is the real time clock used in the board, it can be used for storing the time and the time can be retrieved whenever required. The Time runs properly without failure and backed up by a 3V CMOS battery. For operation of the RTC, JP2 and JP5 jumpers has to be in closed condition. If RTC is not in use you can remove JP2 for saving the life of the battery. But the main feature of RTC is battery backup operation. You can use the jumper during demo and development time alone.
EEPROM 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 non-volatile 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.
U4 is the I2C based EEPROM available on the board which operates at 100 to 400 kHz. Jumper JP5 must be closed to write and read from the EEPROM device as the I2C Power supply will be flowing if and only if JP5 is closed. If Communication error is there between the Processor and the EEPROM make sure the JP5 jumper is closed. If error occurs reset the processor after the jumper is closed.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 49
I2C Based Seven Segment Display A seven-segment display, less commonly known as a seven-segment indicator, is a form of display device that is an alternative to the more complex dot-matrix displays. Seven-segment displays are commonly used in electronics as a method of displaying decimal numeric feedback on the internal operations of devices. A seven-segment display, as its name indicates, is composed of seven elements. Individually on or off, they can be combined to produce simplified representations of the Hindu-Arabic numerals. Each of the numbers and may be represented by two or more different glyphs on seven-segment displays. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top and bottom. Additionally, the seventh segment bisects the rectangle horizontally. There are also fourteen-segment displays and sixteen-segment displays (for full alphanumeric); however, these have mostly been replaced by dot-matrix displays. Often the seven segments are arranged in an oblique, or italic, arrangement, which aids readability. The letters A to G refers to the segments of a 7-segment display. The Schematic of the PCF8574 IO expander used for Seven Segment Interface is shown in the figure.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 50
Jumpers JP30 to JP37 and Jumpers JP17 to JP22 has to be closed in order to work with Seven Segment. Also make sure that I2C jumper JP5 is closed previously. If not close it as well.
Buzzer A buzzer or beeper is a signaling device, usually electronic, typically used in automobiles and
handheld appliances. It most commonly consists of a number of switches or sensors connected to a control unit that determines if and which button was pushed or a preset time has lapsed, and usually illuminates a light on the appropriate button or control panel, and sounds a warning in the form of a continuous or intermittent buzzing or beeping sound. Initially this device was based on an electro mechanical system which was identical to an electric bell without the metal gong (which makes the ringing noise). Often these units were anchored to a wall or ceiling and used the ceiling or wall as a sounding board.
Jumper JP23 has to be closed to work with Buzzer.
Stepper Motor Stepper motors operate differently from normal DC motors, which simply spin when voltage is applied to their terminals. Stepper motors, on the other hand, effectively have multiple "toothed" electromagnets arranged around a central metal gear, as shown at right. 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 is turned 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 a precise angle. There are two basic arrangements for the electromagnetic coils: bipolar and unipolar. Jumper JP46, JP47, JP48, JP49 and JP51 has to be closed for the operation of Stepper motor.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 51
The following figure shows the wiring diagram and the stepping sequence of the motor.
For More information on Stepper motor please refer to MRR’s Stepper Motor User Manual in the CD.
External interrupt inputs: The LPC2148 include up to nine edge or level sensitive External Interrupt Inputs as selectable pin functions. When the pins are combined, external events can be processed as four independent interrupt signals. The External Interrupt Inputs can optionally be used to wake-up the processor from Power-down mode. Additionally capture input pins can also be used as external interrupts without the option to wake the device up from Power-down mode
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 52
Jumpers JP39 has to be closed for working with external Interrupt 0 and JP42 has to be closed to work with external interrupt 1.
+3.3V
+3.3V
EXINT1
EXINT0
JP41 EXINT11 2
R6922K
R6422K
JP39 EXINT01 2
SW20
EXINT0_SW
1 3
2 4C27
0.1MFD
R6522K
SW21
EXINT1_SW
1 3
2 4C28
0.1MFD
R7022K
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 53
MRR2148SB Software Manual
Exercises
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 54
Exercise 1:
AIM: Write a Program for ADDITION, SUBTRACTION, MULTIPLICATION
AND DIVISION
HARDWARE:
OUTPUT: Connect RS2322 cable to UART1 and PC COM1
ANS:
/**************************************************************
/*ADDITION PROGRAM – ASSEMBLY */
/**************************************************************
#include <LPC21XX.h>
NAME main
PUBLIC main
COMMON INTVEC:CODE
CODE32
B main
RSEG ICODE:CODE
CODE32
#include "uart.asm"
main:
LDR R0,=0X11111111
LDR R1,=0X12345678
//output value display in a serial window.
ADD R8,R1,R0
//serial window language is hex.
BL UART
stop: B stop
END main
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 55
/**************************************************************
/*SUBTRACTION PROGRAM – ASSEMBLY */
/**************************************************************
#include <lpc21xx.h>
NAME main
PUBLIC main
COMMON INTVEC:CODE
CODE32
B main
RSEG ICODE:CODE
CODE32
#include "uart.asm"
main:
LDR R1,=0X0000ffff
LDR R0,=0X0000eeee
SUB R8,R1,R0
BL UART
stop: B stop
END main
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 56
/**************************************************************
/*MULTIPLICATION PROGRAM – ASSEMBLY */
/**************************************************************
#include <lpc21xx.h>
NAME main
PUBLIC main
COMMON INTVEC:CODE
CODE32
B main
RSEG ICODE:CODE
CODE32
#include "uart.asm"
main:
LDR R0,=0X00001000
LDR R1,=0X00000100
MOV R8,#0
loop: CMP R1,#0
BEQ ERR
CMP R0,R1
BLT DONE
ADD R8,R8,#1
SUB R0,R0,R1
B loop
ERR: MOV R8,#0XFFFFFFFF
DONE: BL UART
stop: B stop
END main
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 57
/*************************************************************/
/*DIVISION PROGRAM – ASSEMBLY */
/************************************************************/
#include <lpc21xx.h>
NAME main
PUBLIC main
COMMON INTVEC:CODE
CODE32
B main
RSEG ICODE:CODE
CODE32
#include "uart.asm"
main:
LDR R0,=0X00000123
LDR R1,=0X00000234
MUL R8,R1,R0
BL UART
stop: B stop
END main
OUTPUT: SERIAL PORT DISPLAYING THE RESULT
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 58
Exercise 2 (a):
AIM: Write a Program for LED (8 Digital Output) Interface
MRR’s 2148 Syllabus Board has 8 LED’s Connected to
microcontroller’s PORT P1.16 – P1.23
HARDWARE CONFIGURATION:
LED0-LED7 : P1.16 to P1.23
JUMPER CLOSE : JP6, JP7,JP8, JP9,JP10,JP11,JP12,JP13,JP14,JP15
JUMPER OPEN : JP17-JP22, J40&JP43, and JP46 – JP49
SCHEMATIC:
ANS:
/**************************************************************
General Learning Program for GPIO configuration in LPC2100
/**************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
/**************************************************************
Wait function - LED Flashing Delay Routine
/**************************************************************
void wait (void) {
unsigned long d;
for (d = 0; d < 2000000; d++);
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 59
/***************************************************************
LED Flashing Main Routine LED0 – LED7 Connected to P1.16 – P1.23
/***************************************************************
int main (void)
{
PINSEL2= 0x00000004; //Port1 Config - GPIO, Debug Enabled
IODIR1 = 0x00FF0000; //P1.16..23 Configured as Outputs
while (1){ /* Loop forever*/
IOSET1 = 0x00ff0000; // Turn on LED
wait (); // call wait function
IOCLR1 = 0x00ff0000; // Turn on LED
wait (); // call wait function
}
}
OUTPUT:
You can find the Output as LED blinking from 1st
LED to 8th
LED one by one with the delay time defined in the wait function.
CONCLUSION:
♣ For longer or reduced delay change the value of the
variable d in the wait function.
♣ IOSET1 and IOCLR1 can be changed to play with the GPIO’s.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 60
Exercise 2 (b):
AIM: Write a Program for 8 bit Switch Interface
MRR’s 2148 Syllabus Board has 8 Switches Connected to
microcontroller’s PORT P1.16 – P1.23
HARDWARE CONFIGURATION:
DIP SWITCH SW18 : P1.16 to P1.23
JUMPER CLOSE : J12 Connected to J7 using 10PIN FRC CONNECTOR
JUMPER OPEN : JP6 – JP15, JP17-JP22, J40&JP43, JP46 – JP49
OUTPUT DEVICE : UART1 (Connect RS232 Cable to P1 and PC COM1)
SCHEMATIC:
DSW1 DSW5
DSW4
DSW2DSW7DSW3DSW8
DSW6
J12
CON_SW
13579
2468
10
P1.17P1.20
P1.22P1.21
P1.23P1.19P1.18
P1.16J7
CON_KEY/SW
13579
2468
10
DSW6
DSW2
DSW7
DSW3
DSW8
DSW4DSW5
DSW1SW18
SW DIP-8
12345678
161514131211109
ANS:
/***************************************************************
/*General Learning Program for GPIO configuration in LPC2100 */
/***************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.H> // Standard IO Function
unsigned char digital_ip(void); // Routine to accept digital input
extern int sendchar1 (int ch); // Sends a character in serial port1
/**************************************************************
/* Main Program that reads a digital input and displays in */
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 61
/* the serial port 1 (UART1) */
/**************************************************************
int main(void)
{
unsigned char digi;
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate */
U1LCR = 0x03; // DLAB = 0
PINSEL2 = 0x00000004; //Port1 Config - GPIO, Debug Enabled
IODIR1 = 0x00000000;
printf("\nMake any digital input pin low....");
while(1)
{
digi = digital_ip(); // Routine to read Digital Input
if(digi!='0') // Display if digital input is valid
{
printf("\nDigital Input:");
sendchar1(digi); // Display which digital input is given
}
}
}
/**************************************************************
/*Digital input subroutine that reads a digital input and */
/*returns a value according to the given input */
/**************************************************************
unsigned char digital_ip(void)
{
// Check if Port 1.16 through P1.23 is made low using Switch
And return characters ‘1’ through ‘8’ respectively
// Return ‘0’ if no switch is closed and so display nothing
in the serial port
if((IO1PIN & 0x000F0000)==0x000e0000)
return '1';
else if((IO1PIN & 0x000F0000)==0x000d0000)
return '2';
else if((IO1PIN & 0x000F0000)==0x000b0000)
return '3';
else if((IO1PIN & 0x000F0000)==0x00070000)
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 62
return '4';
else if((IO1PIN & 0x00F00000)==0x00e00000)
return '5';
else if((IO1PIN & 0x00F00000)==0x00d00000)
return '6';
else if((IO1PIN & 0x00F00000)==0x00b00000)
return '7';
else if((IO1PIN & 0x00F00000)==0x00700000)
return '8';
else
return '0';
}
/****************************************************************************
/* SERIAL.C: Low Level Serial Routines
/****************************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
#define CR 0x0D
/* implementation of putchar (also used by printf function to output data)*/
int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
/***************************************************************************/
/* RETARGET.C: 'Retarget' layer for target-dependent low level functions */
/***************************************************************************/
#include <stdio.h>
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int sendchar1(int ch); /* in serial.c */
struct __FILE { int handle; /* Add whatever you need here */
};
FILE __stdout;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 63
int fputc(int ch, FILE *f) {
return (sendchar1(ch));
}
int ferror(FILE *f) { /* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch) {
sendchar1(ch);
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}
OUTPUT:
You can find the Output in the serial port UART1 display
the corresponding values for the 8 Switches closed using the DIP
Switch.
CONCLUSION:
♣ You can change the character returned in the digital_ip()
function to see the displayed characters as you wish.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 64
Exercise 3 (a):
AIM: Write a Program for Beeping a Buzzer
MRR’s 2148 Syllabus Board has Onboard Buzzer Connected to P0.10
HARDWARE CONFIGURATION:
Buzzer : 5V Buzzer Connected to P0.10
JUMPER CLOSE : JP23
JUMPER OPEN : DON’T CARE
OUTPUT DEVICE : Buzzer Beeping with a delay
SCHEMATIC:
BUZZER
+5VDC
J6
BUZZER
12
ANS:
/**************************************************************/
/*General Learning Program for GPIO configuration in LPC2100 */
/**************************************************************/
#include <LPC21xx.H> /* LPC21xx definitions */
void wait(void); // Delay loop for producing beep sound
/**************************************************************/
/*Main Program to beep the buzzer */
/**************************************************************/
int main(void)
{
PINSEL0 = 0xffCfffff; // P0.10 GPIO Configured
IODIR0 = 0x00000400; // P0.10 Output Configured
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 65
while(1)
{
IOSET0 = 0x00000400; // Turn ON Buzzer
wait();
IOCLR0 = 0x00000400; // Turn OFF Made
wait();
}
}
void wait(void)
{
unsigned long i;
char x;
for(x=1;x<=20;x++)
for(i=0;i<=300000;i++);
}
OUTPUT:
You can find the Output as buzzer beeping with a delay
specified.
CONCLUSION:
♣ You can change the value of the variable i in the wait
function to set the beep delay as your wish
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 66
Exercise 3 (b):
AIM: Write a Program to ON and OFF Relays
MRR’s 2148 Syllabus Board has Onboard Relay Connected to P1.16
And P1.17
HARDWARE CONFIGURATION:
Relay : P1.16 & P1.17
JUMPER CLOSE : J40 and JP 43
JUMPER OPEN : JP6 – JP15, JP17-JP22 & JP46 – JP49
OUTPUT : TERMINAL BLOCKS J14 & J16
SCHEMATIC:
+5VDC
+5VDC
+5VDC
P1.16
RLY1
RELAY1
35
7
46
812R67
1K
L11
LED
J14
RELAY1_TM_B
123
Q4BC547
32
1
D4
1N4007
R581K
R661K
JP40
REL1_JP
1 2
ANS:
/**************************************************************/
/*Program to control relays connected to P1.16 & P1.17 */
/**************************************************************/
#include <LPC21xx.H> /* LPC21xx definitions */
/**************************************************************/
/*Delay Routine to make relays ON and OFF */
/*Reducing the delay may damage relays due to abrupt ON & OFF */
/**************************************************************/
void wait (void) { /* wait function */
char i;
unsigned long d;
for(i=0;i<=2;i++)
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 67
for (d = 0; d < 2000000; d++);
}
/**************************************************************/
/*Main Routine to control relays */
/**************************************************************/
int main (void) {
IODIR1 |= 0x00030000; /* P1.16..23 defined as Outputs */
while (1) { /* Loop forever */
IOSET1 = 0x00030000; // Making P1.16 & P1.17 High
wait();
IOCLR1 = 0x00030000; // Making P1.16 & P1.17 low
wait ();
}
}
OUTPUT:
You can find the Output as the relays 1 and 2 connected to
Port P1.16 & P1.17 are made ON and OFF with a delay specified.
CONCLUSION:
♣ You can change the value of the variable i in the wait
function to set the ON/OFF delay as your wish
♣ Do not reduce the delay very low as it can damage the
relays or external devices connected to it due to abrupt ON
and OFF.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 68
Exercise 3 (c):
AIM: Write a Program to Rotate the Stepper Motor
MRR’s 2148 Syllabus Board has Onboard Stepper driver Connected
to P1.16 to P1.19 ( 4 Bit interface)
HARDWARE CONFIGURATION:
Stepper Motor : P1.16 to P1.19
JUMPER CLOSE : J46 to JP 49, J51(Power Jumper)
JUMPER OPEN : JP6 – JP15, JP17-JP22, JP40 & JP43
OUTPUT : Stepper Motor Rotation
SCHEMATIC:
ANS:
#include <LPC21xx.H> /* LPC21xx definitions */
void forward(void); // Function to rotate the motor forward
void reverse(void); // Function to rotate the motor reverse
void motor_delay(void); // Motor Delay Function
void motor_delay1(void);
void wait (void) { /* wait function */
char i;
unsigned long d;
/* Motor delay for Forward and reverse Rotation*/
for (i = 0; i <=10; i++)
for (d = 0; d < 2000000; d++);
}
/**************************************************************/
/*Main Routine to Rotate the motors */
/**************************************************************/
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 69
int main (void) {
char rot;
IODIR1 |= 0x00FF0000; /* P1.16..23 defined as Outputs */
while (1) { /* Loop forever */
for(rot=0;rot<=25;rot++)
forward();
wait();
for(rot=0;rot<=25;rot++)
reverse();
wait();
}
}
/**************************************************************/
/*Rotate the stepper motor in forward direction */
/**************************************************************/ void forward(void)
{
IOSET1=0x00f60000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1();
IOSET1=0x00f50000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1();
IOSET1=0x00f90000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1();
IOSET1=0x00fa0000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1();
}
/**************************************************************/
/*Rotate the stepper motor in reverse direction */
/**************************************************************/
void reverse (void)
{
IOSET1=0x00fa0000;
motor_delay ();
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 70
IOCLR1=0x000f0000;
motor_delay1();
IOSET1=0x00f90000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1();
IOSET1=0x00f50000;
motor_delay();
IOCLR1=0x000f0000;
motor_delay1 ();
IOSET1=0x00f60000;
motor_delay ();
IOCLR1=0x000f0000;
motor_delay1();
}
/**************************************************************/
/*Delay routine for motor rotation */
/**************************************************************/
void motor_delay(void)
{
unsigned long d;
for (d = 0; d <90000; d++); /* only to delay for Motor rotation */
}
/**************************************************************/
/*Delay routine for motor rotation */
/**************************************************************/
void motor_delay1(void)
{
unsigned long d;
for (d = 0; d <20; d++); /* only to delay for Motor rotation*/
}
OUTPUT:
The stepper motor rotates in forward direction for a while
and once again rotates in the reverse direction.
CONCLUSION:
♣ You can change the value of the variable d in the motor_
delay() and motor_delay1() function to vary the spped of
rotation of the stepper motor.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 71
Exercise 5:
AIM: Write a Program to execute external interrupt
MRR’s 2148 Syllabus Board has Onboard external interrupt
switches connected to P0.15 and P0.20
HARDWARE CONFIGURATION:
External Int0 : P0.15
External Int1 : P0.20
JUMPER CLOSE : J39 and JP 41 (Int0 and Int1 resp)
JUMPER OPEN : Don’t care
OUTPUT : UART1(PC Com1 port)
SCHEMATIC:
R6422K
C27
0.1MFD
+3.3V
EXINT0JP39 EXINT0
1 2
SW20
EXINT0_SW
1 3
2 4
JP41 EXINT11 2
C28
0.1MFD
SW21
EXINT1_SW
1 3
2 4
EXINT1
R7022K
R6522K
+3.3V
R6922K
ANS:
/*************************************************************/
/*General Learning Program for External interrupt */
/* configuration in LPC2148 */
/************************************************************1*/
#include <LPC21xx.H>
void FIQ_Handler (void) __fiq; //declare FIQ ISR
void initFiq (void);
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 72
/************************************************************/
/* Main Program for external interrupt */
/************************************************************/
void main (void)
{
initFiq();
//Initilise the Fast interrupt source
IOCLR1 = 0x00FF0000;
while(1){}
}
/************************************************************/
/* ISR Routine */
/************************************************************/
void FIQ_Handler (void) __fiq
{
IOSET1 = 0x00FF0000; //Set the LED pins
EXTINT = 0x00000002; //Clear the peripheral interrupt flag
}
/************************************************************/
/* Interrupt initialization */
/************************************************************/
void initFiq(void)
{
IODIR1 = 0x00FF0000; //Set the LED pins as outputs
PINSEL0 = 0x20000000;
//Enable the EXTINT1 interrupt
VICIntSelect = 0x00008000;
//Enable a Vic Channel as FIQ
VICIntEnable = 0x00008000;
}
OUTPUT:
You can find the Output as LED flashing if interrupt
occurs.
CONCLUSION:
♣ You can change the LED flashing speed as you wish.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 73
Exercise 6:
AIM: Write a Program to display a number in seven segment
display
MRR’s 2148 Syllabus Board has 6 Onboard Seven segment LEDs
controlled by P1.16 to P1.21 and connected to I2C Io expander
HARDWARE CONFIGURATION:
PCF8574 : P0.2(SCL) and P0.3(SDA)
CONTROL PINS : P1.16 to P1.21 (ULN2003 Darlington Array)
JUMPER CLOSE : JP5 (I2C Power), JP30 to JP37,JP17 to JP22
JUMPER OPEN : JP6– JP15, JP40, JP43 & JP51, JP46 to JP49
OUTPUT : Seven segment 1
SCHEMATIC:
ANS:
/**************************************************************/
/*LPC2148 header */
/**************************************************************/
#include <LPC21xx.H>
/**************************************************************/
/*I2C driver constants */
/**************************************************************/
#define START 0x08
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 74
#define REP_START 0x10
#define SLA_ACK 0x18
#define SLA_NACK 0x20
#define DATA_ACK 0x28
#define DATA_NACK 0x30
#define ARB_LOST 0x38
#define SLA_READ_ACK 0x40
#define SLA_READ_NACK 0x48
#define DATA_READ_ACK 0x50
#define DATA_READ_NACK 0x58
#define MAX_TRIES 10
/**************************************************************/
/*I2C driver Functions */
/**************************************************************/
void write_delay(void);
void Init_I2C(void);
int pcf8574_write_byte(char buf);
void delay(void);
/**************************************************************/
/*Main Program to write a numeral in Seven Segment Display */
/**************************************************************/ int main(void)
{
Init_I2C(); // I2C Routine Initialization
IODIR1 |= 0x00FF0000; /* P1.16..23 defined as Outputs */
while(1)
{
IOSET1 = 0x00010000; //Select Segment 1 i.e P0.16=1
IOCLR1 = 0xfffeffff; //Other Segments deselect
pcf8574_write_byte(0xff);
delay();
pcf8574_write_byte(0x00);
}
}
/**************************************************************/
/*I2C port setup function
/**************************************************************/ void Init_I2C()
{
VPBDIV=0;
PINSEL0 |= 0x50; // Set Pin 22 as SCL and Pin 26 as SDA
I2CONCLR = 0x000000FF;
I2CONSET = 0x00000040; //Enable the I2C interface
I2SCLH = 0x00;
// Set count for SCL High period
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 75
// FF for about 100 kHz I2C clock, High and Low time equal
I2SCLL = 0x93;
// Set count for SCL Low period
// FF for about 100 kHz I2C clock
}
/**************************************************************/
/*Write a numeral to io expander PCF8574
/**************************************************************/
int pcf8574_write_byte(char buf) {
unsigned char n = 0;
restart:
if (n++ >= MAX_TRIES)
return -1;
begin:
// start cond.
I2CONSET = 0x60;
while(I2STAT!=START);
if (I2STAT == ARB_LOST) goto begin;
if (( I2STAT != REP_START) && (I2STAT != START)) {
return -1;
}
I2DAT = 0x42;
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag
while (I2STAT!=0x18);
if (I2STAT == SLA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_ACK) goto errorfunc;
// put byte into data register and start transmission
I2DAT = buf;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto quit;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc;
quit:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return 1;
errorfunc:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return -1;
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 76
/**************************************************************/
/*Delay routines for errorless writing – Writing delay
/**************************************************************/ void write_delay(void)
{
char i;
unsigned int j;
for(i=0;i<=5;i++)
for(j=1;j<=20000;j++);
}
/**************************************************************/
/*Delay routines for Seven segment ON/OFF */
/**************************************************************/
void delay(void)
{
unsigned int i;
for(i=0;i<=100000;i++);
}
OUTPUT:
A number 8 is displayed in the first seven segment.
CONCLUSION:
♣ You can change the value to be written to the PCf8574 in
the main function to display some other number.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 77
Exercise 7:
AIM: Write a Program for 4*4 Matrix Interface
MRR’s 2148 Syllabus Board has matrix keypad Connected to
microcontroller’s PORT P1.16 – P1.23
HARDWARE CONFIGURATION:
4*4 Matrix : P1.16 to P1.23
JUMPER CLOSE : J9 Connected to J7 using 10PIN FRC CONNECTOR
JUMPER OPEN : JP6 – JP15, JP17-JP22, J40&JP43, JP46 – JP49
OUTPUT DEVICE : UART1 (Connect RS232 Cable to P1 and PC COM1)
SCHEMATIC:
K3
SW16
KEY16
1 3
2 4
K4
SW3
KEY3
1 3
2 4
K5
SW7
KEY7
1 3
2 4
SW10
KEY10
1 3
2 4
K7
SW8
KEY8
1 3
2 4
K6
SW6
KEY6
1 3
2 4
K8
SW13
KEY13
1 3
2 4
SW1
KEY1
1 3
2 4
SW15
KEY15
1 3
2 4
SW9
KEY9
1 3
2 4
K2
SW4
KEY4
1 3
2 4
SW5
KEY5
1 3
2 4
SW2
KEY2
1 3
2 4
SW12
KEY12
1 3
2 4
SW14
KEY14
1 3
2 4
K1
SW11
KEY11
1 3
2 4
ANS:
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 78
/***************************************************************
/*General Learning Program for GPIO configuration in LPC2100 */
/***************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.H> // Standard IO Function
unsigned char digital_ip(void); // Routine to accept digital input
extern int sendchar1 (int ch); // Sends a character in serial port1
/**************************************************************
/* Main Program that reads a digital input and displays in */
/* the serial port 1 (UART1) */
/**************************************************************
int main(void)
{
unsigned char digi;
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate */
U1LCR = 0x03; // DLAB = 0
PINSEL2 = 0x00000004; //Port1 Config - GPIO, Debug Enabled
IODIR1 = 0x00000000;
printf("\nMake any digital input pin low....");
while(1)
{
digi = digital_ip(); // Routine to read Digital Input
if(digi!='0') // Display if digital input is valid
{
printf("\nDigital Input:");
sendchar1(digi); // Display which digital input is given
}
}
}
/**************************************************************
/*Digital input subroutine that reads a digital input and */
/*returns a value according to the given input */
/**************************************************************
unsigned char digital_ip(void)
{
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 79
// Check if Port 1.16 through P1.23 is made low using Switch
And return characters ‘1’ through ‘8’ respectively
// Return ‘0’ if no switch is closed and so display nothing
in the serial port
if((IO1PIN & 0x000F0000)==0x000e0000)
return '1';
else if((IO1PIN & 0x000F0000)==0x000d0000)
return '2';
else if((IO1PIN & 0x000F0000)==0x000b0000)
return '3';
else if((IO1PIN & 0x000F0000)==0x00070000)
return '4';
else if((IO1PIN & 0x00F00000)==0x00e00000)
return '5';
else if((IO1PIN & 0x00F00000)==0x00d00000)
return '6';
else if((IO1PIN & 0x00F00000)==0x00b00000)
return '7';
else if((IO1PIN & 0x00F00000)==0x00700000)
return '8';
else
return '0';
}
/****************************************************************************
/* SERIAL.C: Low Level Serial Routines
/****************************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
#define CR 0x0D
/* implementation of putchar (also used by printf function to output data)*/
int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
/***************************************************************************/
/* RETARGET.C: 'Retarget' layer for target-dependent low level functions */
/***************************************************************************/
#include <stdio.h>
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 80
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int sendchar1(int ch); /* in serial.c */
struct __FILE { int handle; /* Add whatever you need here */
};
FILE __stdout;
int fputc(int ch, FILE *f) {
return (sendchar1(ch));
}
int ferror(FILE *f) { /* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch) {
sendchar1(ch);
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}
OUTPUT:
You can find the Output in the serial port UART1 display
the corresponding values for the 8 Switches closed using the DIP
Switch.
CONCLUSION:
♣ You can change the character returned in the digital_ip()
function to see the displayed characters as you wish.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 81
Exercise 8:
AIM: Write a Program to display a Multi digit in seven segment
display
MRR’s 2148 Syllabus Board has 6 Onboard Seven segment LEDs
controlled by P1.16 to P1.21 and connected to I2C Io expander
HARDWARE CONFIGURATION:
PCF8574 : P0.2(SCL) and P0.3(SDA)
CONTROL PINS : P1.16 to P1.21 (ULN2003 Darlington Array)
JUMPER CLOSE : JP5 (I2C Power), JP30 to JP37,JP17 to JP22
JUMPER OPEN : JP6– JP15, JP40, JP43 & JP51, JP46 to JP49
OUTPUT : Seven segment 1
SCHEMATIC:
ANS:
/**************************************************************/
/*LPC2148 header */
/**************************************************************/
#include <LPC21xx.H>
/**************************************************************/
/*I2C driver constants */
/**************************************************************/
#define START 0x08
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 82
#define REP_START 0x10
#define SLA_ACK 0x18
#define SLA_NACK 0x20
#define DATA_ACK 0x28
#define DATA_NACK 0x30
#define ARB_LOST 0x38
#define SLA_READ_ACK 0x40
#define SLA_READ_NACK 0x48
#define DATA_READ_ACK 0x50
#define DATA_READ_NACK 0x58
#define MAX_TRIES 10
/**************************************************************/
/*I2C driver Functions */
/**************************************************************/
void write_delay(void);
void Init_I2C(void);
int pcf8574_write_byte(char buf);
void delay(void);
/**************************************************************/
/*Main Program to write a numeral in Seven Segment Display */
/**************************************************************/ int main(void)
{
Init_I2C(); // I2C Routine Initialization
IODIR1 |= 0x00FF0000; /* P1.16..23 defined as Outputs */
while(1)
{
IOSET1 = 0x00010000; //Select Segment 1 i.e P0.16=1
IOCLR1 = 0xfffeffff; //Other Segments deselect
pcf8574_write_byte(0xff);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00020000; //Select Segment 2 i.e P0.17=1
IOCLR1 = 0xfffdffff; //Other Segments deselect
pcf8574_write_byte(0x6f);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00040000; //Select Segment 3 i.e P0.18=1
IOCLR1 = 0xfffbffff; //Other Segments deselect
pcf8574_write_byte(0x06);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00080000; //Select Segment 4 i.e P0.19=1
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 83
IOCLR1 = 0xfff7ffff; //Other Segments deselect
pcf8574_write_byte(0xab);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00100000; //Select Segment 5 i.e P0.20=1
IOCLR1 = 0xffefffff; //Other Segments deselect
pcf8574_write_byte(0x8f);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00200000; //Select Segment 6 i.e P0.21=1
IOCLR1 = 0xffdfffff; //Other Segments deselect
pcf8574_write_byte(0xc6);
delay();
pcf8574_write_byte(0x00);
}
}
/**************************************************************/
/*I2C port setup function
/**************************************************************/ void Init_I2C()
{
VPBDIV=0;
PINSEL0 |= 0x50; // Set Pin 22 as SCL and Pin 26 as SDA
I2CONCLR = 0x000000FF;
I2CONSET = 0x00000040; //Enable the I2C interface
I2SCLH = 0x00;
// Set count for SCL High period
// FF for about 100 kHz I2C clock, High and Low time equal
I2SCLL = 0x93;
// Set count for SCL Low period
// FF for about 100 kHz I2C clock
}
/**************************************************************/
/*Write a numeral to io expander PCF8574
/**************************************************************/
int pcf8574_write_byte(char buf) {
unsigned char n = 0;
restart:
if (n++ >= MAX_TRIES)
return -1;
begin:
// start cond.
I2CONSET = 0x60;
while(I2STAT!=START);
if (I2STAT == ARB_LOST) goto begin;
if (( I2STAT != REP_START) && (I2STAT != START)) {
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 84
return -1;
}
I2DAT = 0x42;
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag
while (I2STAT!=0x18);
if (I2STAT == SLA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_ACK) goto errorfunc;
// put byte into data register and start transmission
I2DAT = buf;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto quit;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc;
quit:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return 1;
errorfunc:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return -1;
}
/**************************************************************/
/*Delay routines for errorless writing – Writing delay
/**************************************************************/
void write_delay(void)
{
char i;
unsigned int j;
for(i=0;i<=5;i++)
for(j=1;j<=20000;j++);
}
/**************************************************************/
/*Delay routines for Seven segment ON/OFF */
/**************************************************************/
void delay(void)
{
unsigned int i;
for(i=0;i<=100000;i++);
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 85
OUTPUT:
All the six seven segments displays digits at the same
time.
CONCLUSION:
♣ You can change the value to be written to the PCf8574 in
the main function to display some other number.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 86
Exercise 9:
AIM: Write a Program to display a message in the 2*16 Display
LCD
MRR’s 2148 Syllabus Board has 2*16 Character LCD Display
connected to the P1.16 to P1.21 in 4 bit mode
HARDWARE CONFIGURATION:
LCD Interface : P1.16 to P1.21(4 bit interface)
JUMPER CLOSE : JP44
JUMPER OPEN : JP6– JP15, JP40, JP43 & JP51, JP46 to JP49
OUTPUT : Character LCD 2*16
SCHEMATIC:
P1.
16
P1.
19V
CC
_LC
D
P1.
18
VC
C_L
CD
P1.
20
R71100E
VCC_LCD
R7410K
1 3
2
J15LCD_CON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
P1.
21
P1.
17
ANS:
#include <LPC21xx.H>
/**************************************************************/
/*LCD interface functions declarations */
/**************************************************************/ void delay(void);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
/**************************************************************************/
//P1.16 to P1.19 – DATA PINS
//P1.20 – RS
//P1.21 – EN
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 87
// R/W PIN IS CONNECTED TO GROUND
/**************************************************************************/
#define RS_1 IOSET1 | 0x00100000 // RS=P0.11
#define RS_0 IOCLR1 | 0x00100000
#define EN_1 IOSET1 | 0x00200000 //EN=P0.10
#define EN_0 IOCLR1 | 0x00200000
/**************************************************************/
/*Main Program to display a message */
/**************************************************************/ int main(void)
{
//PINSEL2 = (PINSEL2&0xFFFFFFF7); // Port Pin Configuration Reg
IODIR1 = 0xFFFFFFFF; //PORT1 ALL PINS ARE OUTPUT
delay();
lcdcmd(0x28); //2X16 LCD IN 4 BIT MODE
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
while(1)
{
lcdcmd(0x80);
lcddata('A');lcddata('R');lcddata('M');lcddata('7');lcddata('T');
lcddata('D');lcddata('M');lcddata('I');lcddata(' ');
lcddata('L');lcddata('P');lcddata('C');lcddata('2');lcddata('1');
lcddata('4');lcddata('8');
lcdcmd(0xC0);
lcddata('D');lcddata('E');lcddata('V');lcddata(' ’);lcddata('B');
lcddata('O');
lcddata('A');lcddata('R');lcddata('D');lcddata(' ');lcddata(' ');
lcddata(' ');lcddata(' ');
}
}
/**************************************************************/
/*Subroutine for LCD Command */
/**************************************************************/ void lcdcmd(unsigned char value) // LCD COMMAND
{
int data,copy;
data=value;
data=data<<16;
copy=data;
data=((data>>4) & 0x000F0000); //Strobe 4-Bit High Nibble to LCD
IOSET1=IOSET1 | data;
IOCLR1=IOCLR1 |~data;
IOCLR1=RS_0; //COMMAND REGISTER
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 88
IOSET1=EN_1; //LCD TO LATCH THE DATA
delay();
IOCLR1=EN_0; //lower nibble
data=copy;
data=(data & 0x000F0000); //Strobe 4-Bit Low -Nibble to LCD
IOSET1=IOSET1 | data;
IOCLR1=IOCLR1 |~data;
IOCLR1=RS_0; //COMMAND REGISTER
IOSET1=EN_1; //LCD TO LATCH THE DATA
delay();
IOCLR1=EN_0;
}
/**************************************************************/
/*Subroutine for LCD Display */
/**************************************************************/
void lcddata(unsigned char value) //LCD DATA
{
int data,copy;
data=value;
data=data<<16;
copy=data;
data=((data>>4) & 0x000F0000); //Strobe 4-Bit High Nibble to LCD
IOSET1=IOSET1 | data;
IOCLR1=IOCLR1 |~data;
IOSET1=RS_1; //DATA REGISTER
IOSET1=EN_1; //LCD TO LATCH THE DATA
delay();
IOCLR1=EN_0; //lower nibble//
data=copy;
data=(data & 0x000F0000); //Strobe 4-Bit Low Nibble to LCD
IOSET1=IOSET1 | data;
IOCLR1=IOCLR1 |~data;
IOSET1=RS_1; //DATA REGISTER
IOSET1=EN_1; //LCD TO LATCH THE DATA
delay();
IOCLR1=EN_0;
}
/**************************************************************/
/*Subroutine for LCD write Delay */
/**************************************************************/
void delay(void)
{
unsigned int i;
for(i=0;i<=20000;i++);
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 89
OUTPUT:
LCD displays a message “ARM7TDMI LPC2148” in the first line
and “DEV BOARD” in the second line
CONCLUSION:
♣ You can change the message to be displayed in the LCD by
changing the lcddata() function in the the main program.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 90
Exercise 10:
AIM: Write a Program to use ADC and measure temperature sensor
MRR’s 2148 Syllabus Board has onboard ADC and LM35 Temperature
sensor
HARDWARE CONFIGURATION:
ADC0 : ADC1, ADC2(LM35 Sensor) and ADC3
JUMPER CLOSE : Don’t Care
JUMPER OPEN : Don’t Care
OUTPUT : UART1 – PC Com1 port
SCHEMATIC:
ANS:
/***************************************************************************/
/* MEASURE.C: ADC and LM35 Temperature Sensor */
/***************************************************************************/
#include <stdio.h> /* standard I/O .h-file */
#include <LPC214x.H> /* LPC213x definitions */
#define ADCR AD0CR
#define ADDR AD0DR
#include "measure.h" /* global project definition */
struct mrec current; /* current measurements */
unsigned char lm35val;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 91
void LM35(unsigned char val1);
/***************************************************************************/
/*************************** MAIN PROGRAM ***************************/
/***************************************************************************/
int main (void) { /* main entry for program */
char i;
unsigned int val;
unsigned int crval;
PINSEL1 = 0x15400000; /* Select AIN0..AIN3 */
ADCR = 0x002E0401; /* Setup A/D: 10-bit @ 3MHz */
init_serial (); /* initialite serial interface*/
while (1) { /* loop forever */
for (i = 0; i != 4; i++) { /* loop for 4 A/D inputs */
crval = 0x01000000 | (1<<i);
ADCR |= crval; /* Start A/D Conversion */
do {
val = ADDR; /* Read A/D Data Register */
} while ((val & 0x80000000) == 0); /* Wait for end of A/D Convers.*/
ADCR &= ~crval; /* Stop A/D Conversion */
val = (val >> 8) & 0xFF; /* Extract AIN Value */
current.analog[i] = val; /* result of A/D process */
if(i==2)
{
lm35val = val;
}
}
measure_display (current); /* display values */
}
}
/***************************************************************************/
/* Display measurements */
/***************************************************************************/
void measure_display (struct mrec display) {
printf ("\rAnalog Measurements: ");
/* display AD0 through AD3 */
printf (" A%d:%4.2fV", 1, (float) display.analog[1] * 3.3 / 256.0);
LM35(lm35val+5);
printf (" A%d:%4.2fV", 3, (float) display.analog[3] * 3.3 / 256.0);
}
/***************************************************************************/
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 92
/* LM35 Interface */
/**************************************************************************/
void LM35(unsigned char val1)
{
unsigned char i,j,k;
i=val1/100;
j=val1%100;
k=val1%10;
k=k+0x30;
j=(j/10) + 0x30;
i=i+0x30;
printf(" Temp: ");
sendchar(i);
sendchar(j);
sendchar(k);
sendchar(' ');
printf("C");
}
/****************************************************************************
/* SERIAL.C: Low Level Serial Routines
/****************************************************************************
#include <LPC21xx.H> /* LPC21xx definitions */
#define CR 0x0D
int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
OUTPUT:
The value of the ADC Channels and the LM35 Temperature are
displayed via the serial port UART1(COM1) of the PC
CONCLUSION:
♣ You can change the analog values by changing the
Potentiometer R78 on the board and can notice the voltage
changing in the serial port.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 93
Exercise 11:
AIM: Write a Program for I2C Interface – Seven Segment Display
MRR’s 2148 Syllabus Board has 6 Onboard Seven segment LEDs
controlled by P1.16 to P1.21 and connected to I2C Io expander
HARDWARE CONFIGURATION:
PCF8574 : P0.2(SCL) and P0.3(SDA)
CONTROL PINS : P1.16 to P1.21 (ULN2003 Darlington Array)
JUMPER CLOSE : JP5 (I2C Power), JP30 to JP37,JP17 to JP22
JUMPER OPEN : JP6– JP15, JP40, JP43 & JP51, JP46 to JP49
OUTPUT : Seven segment 1
SCHEMATIC:
ANS:
/**************************************************************/
/*LPC2148 header */
/**************************************************************/
#include <LPC21xx.H>
/**************************************************************/
/*I2C driver constants */
/**************************************************************/
#define START 0x08
#define REP_START 0x10
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 94
#define SLA_ACK 0x18
#define SLA_NACK 0x20
#define DATA_ACK 0x28
#define DATA_NACK 0x30
#define ARB_LOST 0x38
#define SLA_READ_ACK 0x40
#define SLA_READ_NACK 0x48
#define DATA_READ_ACK 0x50
#define DATA_READ_NACK 0x58
#define MAX_TRIES 10
/**************************************************************/
/*I2C driver Functions */
/**************************************************************/
void write_delay(void);
void Init_I2C(void);
int pcf8574_write_byte(char buf);
void delay(void);
/**************************************************************/
/*Main Program to write a numeral in Seven Segment Display */
/**************************************************************/ int main(void)
{
Init_I2C(); // I2C Routine Initialization
IODIR1 |= 0x00FF0000; /* P1.16..23 defined as Outputs */
while(1)
{
IOSET1 = 0x00010000; //Select Segment 1 i.e P0.16=1
IOCLR1 = 0xfffeffff; //Other Segments deselect
pcf8574_write_byte(0xff);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00020000; //Select Segment 2 i.e P0.17=1
IOCLR1 = 0xfffdffff; //Other Segments deselect
pcf8574_write_byte(0x6f);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00040000; //Select Segment 3 i.e P0.18=1
IOCLR1 = 0xfffbffff; //Other Segments deselect
pcf8574_write_byte(0x06);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00080000; //Select Segment 4 i.e P0.19=1
IOCLR1 = 0xfff7ffff; //Other Segments deselect
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 95
pcf8574_write_byte(0xab);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00100000; //Select Segment 5 i.e P0.20=1
IOCLR1 = 0xffefffff; //Other Segments deselect
pcf8574_write_byte(0x8f);
delay();
pcf8574_write_byte(0x00);
IOSET1 = 0x00200000; //Select Segment 6 i.e P0.21=1
IOCLR1 = 0xffdfffff; //Other Segments deselect
pcf8574_write_byte(0xc6);
delay();
pcf8574_write_byte(0x00);
}
}
/**************************************************************/
/*I2C port setup function
/**************************************************************/ void Init_I2C()
{
VPBDIV=0;
PINSEL0 |= 0x50; // Set Pin 22 as SCL and Pin 26 as SDA
I2CONCLR = 0x000000FF;
I2CONSET = 0x00000040; //Enable the I2C interface
I2SCLH = 0x00;
// Set count for SCL High period
// FF for about 100 kHz I2C clock, High and Low time equal
I2SCLL = 0x93;
// Set count for SCL Low period
// FF for about 100 kHz I2C clock
}
/**************************************************************/
/*Write a numeral to io expander PCF8574
/**************************************************************/
int pcf8574_write_byte(char buf) {
unsigned char n = 0;
restart:
if (n++ >= MAX_TRIES)
return -1;
begin:
// start cond.
I2CONSET = 0x60;
while(I2STAT!=START);
if (I2STAT == ARB_LOST) goto begin;
if (( I2STAT != REP_START) && (I2STAT != START)) {
return -1;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 96
}
I2DAT = 0x42;
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag
while (I2STAT!=0x18);
if (I2STAT == SLA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_ACK) goto errorfunc;
// put byte into data register and start transmission
I2DAT = buf;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto quit;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc;
quit:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return 1;
errorfunc:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return -1;
}
/**************************************************************/
/*Delay routines for errorless writing – Writing delay
/**************************************************************/
void write_delay(void)
{
char i;
unsigned int j;
for(i=0;i<=5;i++)
for(j=1;j<=20000;j++);
}
/**************************************************************/
/*Delay routines for Seven segment ON/OFF */
/**************************************************************/
void delay(void)
{
unsigned int i;
for(i=0;i<=100000;i++);
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 97
OUTPUT:
All the six seven segments displays digits at the same
time.
CONCLUSION:
♣ You can change the value to be written to the PCf8574 in
the main function to display some other number.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 98
Exercise 12:
AIM: Write a Program for I2C Interface – Serial EEPROM
MRR’s 2148 Syllabus Board has onboard I2c based AT24C04 EEPROM
HARDWARE CONFIGURATION:
AT24C04 : P0.2 (SCL) and P0.3 (SDA)
JUMPER CLOSE : JP5 (I2C Power)
JUMPER OPEN : don’t care
OUTPUT : UART1
SCHEMATIC:
ANS:
/**************************************************************/
/*LPC2148 header */
/**************************************************************/
#include <LPC21xx.H>
/**************************************************************/
/*I2C driver constants */
/**************************************************************/ #include <stdio.h>
#define START 0x08
#define REP_START 0x10
#define SLA_ACK 0x18
#define SLA_NACK 0x20
#define DATA_ACK 0x28
#define DATA_NACK 0x30
#define ARB_LOST 0x38
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 99
#define SLA_READ_ACK 0x40
#define SLA_READ_NACK 0x48
#define DATA_READ_ACK 0x50
#define DATA_READ_NACK 0x58
#define MAX_TRIES 10
void write_delay(void);
void Init_I2C(void);
void write_eeprom(unsigned char address, unsigned char dat);
unsigned char read_eeprom(unsigned char address);
extern int sendchar (int ch);
extern void usart_init(void);
int eeprom_read_byte(unsigned char eeaddr);
int eeprom_write_byte(unsigned char eeaddr, char buf);
void write_ee_string(unsigned char *s, unsigned char length);
/*************************** MAIN ******************************************/
int main()
{
unsigned char eeval[8];
char i;
usart_init();
Init_I2C();
write_ee_string("MRR'ARM7-LPC2148",16);
while(1)
{
printf("I2C AT24C02: ");
for(i=0;i<=15;i++)
eeval[i]=eeprom_read_byte(i);
for(i=0;i<=15;i++)
sendchar(eeval[i]);
printf("\n");
}
}
/**************************************************************/
/*initializing the I2C bus */
/**************************************************************/ void Init_I2C()
{
VPBDIV=0;
PINSEL0 |= 0x50; // Set Pin 22 as SCL and Pin 26 as SDA
I2CONCLR = 0x000000FF;
I2CONSET = 0x00000040; //Enable the I2C interface
I2SCLH = 0x00;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 100
// Set count for SCL High period
// FF for about 100 kHz I2C clock, High and Low time equal
I2SCLL = 0x93;
// Set count for SCL Low period
// FF for about 100 kHz I2C clock
}
/**************************************************************/
/*Reading a byte from EEPROM
/**************************************************************/ int eeprom_read_byte(unsigned char eeaddr)
{
unsigned char n = 0;
unsigned char buf;
restart:
if (n++ >= MAX_TRIES)
return -1;
begin:
// send start cond.
I2CONSET = 0x60;
while(I2STAT!=START);
if (I2STAT == ARB_LOST) goto begin;
if ( (I2STAT != REP_START) && (I2STAT != START)) {
return -1;
}
I2DAT = 0xAC;
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag
while (I2STAT!=0x18);
if (I2STAT == SLA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_ACK) goto errorfunc;
/*I2DAT = 0x00;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc; */
// send low 8 bits of eeaddr
I2DAT = eeaddr;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc;
I2CONCLR = 0x08; // Clear interrupt Flag
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 101
// send start cond.
I2CONSET = 0x60;
while (I2STAT!=REP_START);
if (I2STAT == ARB_LOST) goto begin;
if ( (I2STAT != REP_START) && (I2STAT != START)) {
return -1;
}
I2DAT = 0xad;
I2CONCLR = 0x2C; // Clear Interrup Flag and Start Flag
while (I2STAT!=SLA_READ_ACK);
if (I2STAT == SLA_READ_NACK) goto quit;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_READ_ACK) goto errorfunc;
// start read transmission
I2CONCLR = 0x08;
while (I2STAT!=0x58);
buf=I2DAT;
quit:
//stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return buf;
errorfunc:
//stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return -1;
}
/**************************************************************/
/*Writing a byte to EEPROM
/**************************************************************/ int eeprom_write_byte(unsigned char eeaddr, char buf) {
unsigned char n = 0;
restart:
if (n++ >= MAX_TRIES)
return -1;
begin:
// start cond.
I2CONSET = 0x60;
while(I2STAT!=START);
if (I2STAT == ARB_LOST) goto begin;
if (( I2STAT != REP_START) && (I2STAT != START)) {
return -1;
}
I2DAT = 0xac;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 102
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag
while (I2STAT!=0x18);
if (I2STAT == SLA_NACK) goto restart;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != SLA_ACK) goto errorfunc;
I2DAT = eeaddr;
I2CONCLR=0x08; // Clear interrupt Flag
while (I2STAT!= DATA_ACK);
if (I2STAT == DATA_NACK) goto quit;
if (I2STAT == ARB_LOST) goto begin;
if (I2STAT != DATA_ACK) goto errorfunc;
// put byte into data register and start transmission
I2DAT = buf;
I2CONCLR = 0x08;
while (I2STAT!= DATA_ACK);
//while(1){DISPHEX(I2STAT);}
if (I2STAT != DATA_ACK) goto errorfunc;
quit:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return 1;
errorfunc:
// send stop condition
I2CONSET=0x10;
I2CONCLR=0x0c;
return -1;
}
/**************************************************************/
/*Delay routines for errorless writing – Writing delay
/**************************************************************/ void write_delay(void)
{
char i;
unsigned int j;
for(i=0;i<=5;i++)
for(j=1;j<=20000;j++);
}
/**************************************************************/
/*Writing a string in EEPROM
/**************************************************************/ void write_ee_string(unsigned char *s, unsigned char length)
{
unsigned char i;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 103
for(i=0;i<length;i++)
{
eeprom_write_byte(i,*s++);
write_delay();
}
}
OUTPUT:
The Controller writes a string ”MRR’s LPC2148BRD” to the
EEPROM via I2C bus, reads back and displays in the UART1
CONCLUSION:
♣ You can change the string to be written to the EEPROM in
the main function.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 104
Exercise 13:
AIM: Write a Program for Transmission and reception from the
serial port
MRR’s 2148 Syllabus Board has serial port UART1 than can be
connected to the COM port using Serial cable.
HARDWARE CONFIGURATION:
UART1 : MAX3232
OUTPUT : UART1
/***************************************************************************/
/* HELLO.C: Hello World Example
/***************************************************************************/
#include <stdio.h> /* prototype declarations for I/O functions */
#include <LPC21xx.H> /* LPC21xx definitions */
extern int sendchar (int ch);
int main (void) { /* execution starts here */
/* initialize the serial interface */
PINSEL0 = 0x00050005; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
while (1) {
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 105
printf ("Hello World\n"); /* the 'printf' function call */
}
}
/***************************************************************************/
/* SERIAL.C: Low Level Serial Routines */
/***************************************************************************/
#include <LPC21xx.H> /* LPC21xx definitions */
#define CR 0x0D
int sendchar (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getkey (void) { /* Read character from Serial Port */
while (!(U1LSR & 0x01));
return (U1RBR);
}
/***************************************************************************/
/* RETARGET.C: 'Retarget' layer for target-dependent low level functions */
/**************************************************************************/
#include <stdio.h>
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int sendchar(int ch); /* in serial.c */
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
int fputc(int ch, FILE *f) {
return (sendchar(ch));
}
int ferror(FILE *f) {
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch) {
sendchar(ch);
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 106
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}
OUTPUT:
The Controller writes a string ”Hello World” to serial port
UART1
CONCLUSION:
♣ You can change the string to be written to the serial port
in the main program.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 107
Exercise 14:
AIM: Write a Program for PWM generation
MRR’s 2148 Syllabus Board has J19 for PWM Out
HARDWARE CONFIGURATION:
PWM CONNECTOR : J19
OUTPUT : PWM Pulse
AOUTJ19
DAC_OUT_TB
12
ANS:
#include <LPC21XX.H>
/***************************************************************************/
/* Main Program – PWM Generation */
/**************************************************************************/
int main(void)
{
unsigned int val,delay;
PINSEL0 |= 0x00028000; //Enable pin 0.7 as PWM2
PWMPR = 0x00000001; //Load prescaler
PWMPCR = 0x0000404; //PWM channel 2 double edge control, output
enabled
PWMMCR = 0x00000003; //On match with timer reset the counter
PWMMR0 = 0x000000FF; //set cycle rate to sixteen ticks
PWMMR1 = 0x00000080; //set rising edge of PWM2 to 2 ticks
PWMMR2 = 0x00000080; //set falling edge of PWM2 to 8 ticks
PWMLER = 0x00000007; //enable shadow latch for match 0 - 2
PWMEMR = 0x00000280; //Match 1 and Match 2 outputs set high
PWMTCR = 0x00000002; //Reset counter and prescaler
PWMTCR = 0x00000009; //enable counter and PWM, release counter from reset
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 108
ADCR = 0x00250601; // Setup A/D: 10-bit AIN0 @ 3MHz
ADCR |= 0x01000000; // Start A/D Conversion
while(1) // main loop
{
for (delay=0;delay < 0x100;delay++)
{
;
}
do
{
val = ADDR; // Read A/D Data Register
}
while ((val & 0x80000000) == 0); //Wait for the conversion to
complete
val = ((val >> 8) & 0x00FF); //Extract the A/D result
PWMMR1 = 0x00000000+val; //Modulate PWM
PWMMR2 = 0x000000FF-val;
PWMLER = 0x00000006;
}
}
OUTPUT:
The Controller generates a PWM pulse on DAC Output pin.
CONCLUSION:
♣ You can change the values in the PWM registers for changing
the PWM width.
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 109
RTOS Exercise1:
AIM: Write a RTOS Program for blinking two LED
MRR’s 2148 Syllabus Board has 8 LED’s Connected to
microcontroller’s PORT P1.16 – P1.23
HARDWARE CONFIGURATION:
LED0-LED7 : P1.16 to P1.23
JUMPER CLOSE : JP6, JP7,JP8, JP9,JP10,JP11,JP12,JP13,JP14,JP15
JUMPER OPEN : JP17-JP22, J40&JP43, and JP46 – JP49
SCHEMATIC:
/***************************************************************************/
/* RTOS Program Blinking two leds */
/**************************************************************************/
#include <includes.h>
//#include "includes.h"
//#include "lcd_image.h"
/**************************************************************************/
//VARIABLES
****************************************************************************/
OS_STK Task1stk[1023];
OS_STK Task2stk[1023];
OS_STK Task3stk[1023];
//char arr[]="\nADC0 VALUE --->";
/**************************************************************************/
FUNCTION PROTOTYPES
/**************************************************************************/
void Task1(void *pdata);
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 110
void Task2(void *pdata);
void Task3(void *pdata);
void serial_tr(char );
void adc_serial_tx();
/**************************************************************************/
void main (void)
{
BSP_IntDisAll();
OSInit();
OSTaskCreate(Task1,0,&Task1stk[1023],45);
OSTaskCreate(Task2,0,&Task2stk[1023],35);
OSTaskCreate(Task3,0,&Task3stk[1023],25);
OSStart();
}
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
/****************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the
book's text, you MUST
* initialize the ticker only once multitasking has started.
* Arguments : p_arg is the argument passed to 'Task()' by
'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler
warning because 'p_arg' is not
* used. The compiler should not generate any code for this
statement.
* 2) Interrupts are enabled once the task start because the I-
bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*****************************************************************************
****************************
*/
void Task1(void *pdata)
{
IO1DIR=0XFF000000;
while(1)
{
IO1PIN=0XFF000000;
delay();
IO1PIN=0X00000000;
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 111
delay();
}
}
void Task2(void *pdata)
{
IO1DIR=0XFF000000;
while(1)
{
IO1PIN=0X0F000000;
delay();
IO1PIN=0X00000000;
delay();
}
}
void Task3(void *pdata)
{
IO1DIR=0XFF000000;
while(1)
{
IO1PIN=0XF0000000;
delay();
IO1PIN=0X00000000;
delay();
}
}
OUTPUT : LED Blinking on the board
Exercise RTOS Exercise2:
A: Write a Program to use ADC and measure temperature sensor
MRR’s 2148 Syllabus Board has onboard ADC and LM35 Temperature
sensor
HARDWARE CONFIGURATION:
ADC0 : ADC1, ADC2 (LM35 Sensor) and ADC3
JUMPER CLOSE : Don’t Care
JUMPER OPEN : Don’t Care
OUTPUT : UART1 – PC Com1 port
SCHEMATIC:
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 112
/////////sample RTOS program for Blinking Temperature Sensor///////////
#include "includes.h"
/*--------------------------------- Stack Declaration for 3 tasks -----------
---------*/
OS_STK Task1stk[100];
OS_STK Task2stk[100];
OS_STK Task3stk[100];
// OS_STK Task4stk[1000];
char speed = 30;
/*--------------------------------- TASK Declaration -----------------------
------*/
char data[17] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x
71};
void Task1(void *pdata);
void Task2(void *pdata);
void Task3(void *pdata);
// void task4(void *pdata);
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 113
void i2c(char addr,char dat)
{
char temp;
I2C0CONSET = 0X20;
temp = I2C0STAT;
while(temp != 0x08)
{
temp = I2C0STAT;
}
I2C0DAT = addr;
I2C0CONCLR = 0x28;
temp = I2C0STAT;
while(temp != 0x18)
{
temp = I2C0STAT;
}
I2C0DAT = dat;
I2C0CONCLR = 0x08;
temp = I2C0STAT;
while(temp != 0x28)
{
temp = I2C0STAT;
}
I2C0CONSET = 0x10;
I2C0CONCLR = 0x08;
}
/*--------------------------------- TASK1 Definition -----------------------
------*/
void Task1(void *pdata)
{
LPC2148BSPInit();
for(;;)
{
for(int i = 0; i < 8; i++)
{
IO1SET |= 0x00010000 << i;
OSTimeDly(30);
IO1CLR |= 0x00010000 << i;
OSTimeDly(30);
}
}
}
/*--------------------------------- TASK2 Definition -----------------------
------*/
void Task2(void *pdata)
{
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 114
for(;;)
{
printit("MRR Embedded Systems Pvt Ltd Chennai\r\n");
OSTimeDly(30);
}
}
/*--------------------------------- TASK3 Definition -----------------------
------*/
void Task3(void *pdata)
{
unsigned int adc1000,i,val;
char address = 0x70;
PINSEL0 |= 0x00000050;
I2C0CONCLR = 0x6C;
I2C0CONSET = 0x40;
I2C0SCLH = 110;
I2C0SCLL = 90;
PINSEL1 |= 0x15000000;
AD0CR = 0x01270E06;
for(;;)
{
val = (AD0DR>>6)& 0x3ff;
i=1000;
do
{
adc1000 = val / i;
i2c(address,data[adc1000]);
val = val % i;
i = i / 10;
address = address + 0x02;
if(address > 0x76)
{
address = 0x70;
}
}while(i!=0x00);
OSTimeDly(20);
}
}
// void Task4(void *pdata)
// { unsigned int val1;
// for(;;)
// {
// val1 = (AD0DR >> 6)& 0x3ff;
// speed = val1 / 10;
//
// }
// }
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 115
/*--------------------------------- The MAIN function ----------------------
-------*/
void main (void)
{
LPC2148Dissall();
OSInit();
OSTaskCreate(Task1, 0, &Task1stk[99], 0);
OSTaskCreate(Task2, 0, &Task2stk[99], 1);
OSTaskCreate(Task3, 0, &Task3stk[99], 2);
// OSTaskCreate(Task4, 0, &Task4stk[999], 3);
OSStart();
}
/*--------------------------------- end of file ----------------------------
-*/
//////////////////////// sample RTOS program for Blinking 3 LED from 3
different tasks ///////////
#include "includes.h"
/*--------------------------------- Stack Declaration for 3 tasks -----------
---------*/
OS_STK Task1stk[100];
OS_STK Task2stk[100];
OS_STK Task3stk[100];
// OS_STK Task4stk[1000];
char speed = 30;
/*--------------------------------- TASK Declaration -----------------------
------*/
char data[17] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x
71};
void Task1(void *pdata);
void Task2(void *pdata);
void Task3(void *pdata);
// void task4(void *pdata);
void i2c(char addr,char dat)
{
char temp;
I2C0CONSET = 0X20;
temp = I2C0STAT;
while(temp != 0x08)
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 116
{
temp = I2C0STAT;
}
I2C0DAT = addr;
I2C0CONCLR = 0x28;
temp = I2C0STAT;
while(temp != 0x18)
{
temp = I2C0STAT;
}
I2C0DAT = dat;
I2C0CONCLR = 0x08;
temp = I2C0STAT;
while(temp != 0x28)
{
temp = I2C0STAT;
}
I2C0CONSET = 0x10;
I2C0CONCLR = 0x08;
}
/*--------------------------------- TASK1 Definition -----------------------
------*/
void Task1(void *pdata)
{
LPC2148BSPInit();
for(;;)
{
for(int i = 0; i < 8; i++)
{
IO1SET |= 0x00010000 << i;
OSTimeDly(30);
IO1CLR |= 0x00010000 << i;
OSTimeDly(30);
}
}
}
/*--------------------------------- TASK2 Definition -----------------------
------*/
void Task2(void *pdata)
{
for(;;)
{
printit("MRR Embedded Systems Pvt Ltd\r\n Perungudi\r\n
Chennai\r\n");
OSTimeDly(30);
}
}
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 117
/*--------------------------------- TASK3 Definition -----------------------
------*/
void Task3(void *pdata)
{
unsigned int adc1000,i,val;
char address = 0x70;
PINSEL0 |= 0x00000050;
I2C0CONCLR = 0x6C;
I2C0CONSET = 0x40;
I2C0SCLH = 110;
I2C0SCLL = 90;
PINSEL1 |= 0x15000000;
AD0CR = 0x01270E06;
for(;;)
{
val = (AD0DR>>6)& 0x3ff;
i=1000;
do
{
adc1000 = val / i;
i2c(address,data[adc1000]);
val = val % i;
i = i / 10;
address = address + 0x02;
if(address > 0x76)
{
address = 0x70;
}
}while(i!=0x00);
OSTimeDly(20);
}
}
// void Task4(void *pdata)
// { unsigned int val1;
// for(;;)
// {
// val1 = (AD0DR >> 6)& 0x3ff;
// speed = val1 / 10;
//
// }
// }
/*--------------------------------- The MAIN function ----------------------
-------*/
void main (void)
{
LPC2148Dissall();
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 118
OSInit();
OSTaskCreate(Task1, 0, &Task1stk[99], 0);
OSTaskCreate(Task2, 0, &Task2stk[99], 1);
OSTaskCreate(Task3, 0, &Task3stk[99], 2);
// OSTaskCreate(Task4, 0, &Task4stk[999], 3);
OSStart();
}
OUTPUT: UART1 of the board COM1
Quick Start Guide for MRR2148SB | 2009
MRR Embedded Systems Pvt Ltd | 119
For Further enquiries, service, please feels free to contact us.
MRR Embedded Systems Pvt. Ltd., B56/1, Vallalar Street,
MMDA Colony Arumbakkam,
Chennai - 600106, INDIA.
Ph: 91- 44-42078785,
Mail: [email protected]
Web: www.mrrembedded.com