Sie sind auf Seite 1von 74

Embedded Systems

Laboratory Manual

Enrollment No.:_______________
Name of the student:_________________________________

Government Engineering College, Rajkot


Mavadi-Kankot Road, Near Hanuman Temple, Opp. Kankot Village, Rajkot
www.gecrajkot.org

GOVERNMENT ENGINEERING COLLEGE, RAJKOT

CERTIFICATE

This is to certify that Mr/Miss ________________________________________


Enrollment No. ______________of B.E. (E.C.) SEM-VIII has satisfactorily
completed the term work of the subject Embedded Systems prescribed by
Gujarat Technological University during the academic term _______________
.

Date:

Signature of the faculty

INDEX
Sr.
No.
1.
2.
3.

4.

5.

6.

7.
8.

9.
10.
11.

12.
13.
14

Name of Experiment
To understand architecture of ARM7TDMI
architecture
To understand ARM32 and Thumb instruction set
of ARM microcontroller and write simple programs
To understand features and block diagram of LPC2129 ARM processor. To download and execute
program to blink 8 LEDs connected at Port P0 of
LPC-2129 ARM7TDMI chip using LPC2000 flash
utility
To understand features of LPC-2294 ARM
processor and download programs to flash 8 LEDs
connected at Port P1 of LPC-2294 ARM Processor
Write program to blink LEDs one by one.
Download and execute program in LPC-2129 chip.
Modify this program according to given instruction
in exercise
To write and execute program to display message
display WELCOME GEC RAJKOT on LCD screen
for ARM7
To read analog input voltage and display it on LCD
using LPC-2129
To understand embedded system development
using ADSP-2181 kit
To generate sine wave, square wave and other
complex waveforms using ADSP-2181
To filter input signal using FIR filter
implementation with ADSP-2181
To understand features of Cypress Programmable
System on Chip (PSoC). To download and execute
demo programs to display vertical bar graph using
LEDs depending on analog input voltage.
To read analog voltage and display it on LCD using
cypress kit
To become familiar with GCC compiler, WinARM
and crossware development tools
To interface GSM modem with PC and
microcontroller
Assignment

Page
No.
4
11
17

24

26

29

33
39

50
54
58

62
64
66
74

Experiment No.1
Aim: To understand architecture of ARM7TDMI architecture
Brief Theory:
The ARM7TDMI is a member of the Advanced RISC Machines (ARM)
family of general purpose 32-bit microprocessors, which offer high
performance for very low power consumption and price. 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. This simplicity results in a high instruction throughput and
impressive real-time interrupt response from a small and cost-effective chip.
Pipelining is employed so that all parts of the processing and memory
systems can operate continuously. Typically, while one instruction is being
executed, its successor is being decoded, and a third instruction is being
fetched from memory.
The ARM memory interface has been designed to allow the
performance potential to be realized without incurring high costs in the
memory system. Speed-critical control signals are pipelined to allow system
control functions to be implemented in standard low-power logic, and these
control signals facilitate the exploitation of the fast local access modes
offered by industry standard dynamic RAMs.
The ARM7TDMI processor 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.
Thumb Concept:
The key idea behind THUMB is that of a super-reduced instruction set.
Essentially, the ARM7TDMI processor has two instruction sets:
Standard 32-bit ARM set
16-bit THUMB set
The THUMB sets 16-bit instruction length allows it to approach twice the
density of standard ARM code while retaining most of the ARMs
performance advantage over a traditional 16-bit processor using 16-bit
registers. This is possible because THUMB code operates on the same 32-bit
register set as ARM code.

THUMB code is able to provide up to 65% of the code size of ARM, and 160%
of the performance of an equivalent ARM processor connected to a 16-bit
memory system.
THUMB instructions operate with the standard ARM register configuration,
allowing excellent interoperability between ARM and THUMB states. Each
16-bit THUMB instruction has a corresponding 32-bit ARM instruction with
the same effect on the processor model.
The major advantage of a 32-bit (ARM) architecture over a 16-bit
architecture is its ability to manipulate 32-bit integers with single
instructions, and to address a large address space efficiently. When
processing 32-bit data, a 16-bit architecture will take at least two
instructions to perform the same task as a single ARM instruction. However,
not all the code in a program will process 32-bit data (for example, code that
performs character string handling), and some instructions, like Branches,
do not process any data at all.
If a 16-bit architecture only has 16-bit instructions, and a 32-bit
architecture only has 32-bit instructions, then overall the 16-bit
architecture will have better code density, and better than one half the
performance of the 32-bit architecture. Clearly 32-bit performance comes at
the cost of code density.
THUMB breaks this constraint by implementing a 16-bit instruction length
on a 32-bit architecture, making the processing of 32-bit data efficient with
a compact instruction coding. This provides far better performance than a
16-bit architecture, with better code density than a 32-bit architecture.
THUMB also has a major advantage over other 32-bit architectures with 16bit instructions. This is the ability to switch back to full ARM code and
execute at full speed. Thus critical loops for applications such as fast
interrupts and DSP algorithms can be coded using the full ARM instruction
set, and linked with THUMB code. The overhead of switching from THUMB
code to ARM code is folded into sub-routine entry time. Various portions of a
system can be optimized for speed or for code density by switching between
THUMB and ARM execution as appropriate.
Core diagram of the ARM7TDMI is shown in the following figure.

ARM7TDMI has a total of 37 registers - 31 general-purpose 32-bit


registers and six status registers - but these cannot all be seen at once. The
processor state and operating mode dictate which registers are available to
the programmer.
In ARM state, 16 general registers and one or two status registers are
visible at any one time. In privileged (non-User) modes, mode-specific
banked registers are switched in. Register organization shown below. In
ARM state shows which registers are available in each mode: the banked
registers are marked with a shaded triangle. The ARM state register set
contains 16 directly accessible registers: R0 to R15. All of these except R15

are general-purpose, and may be used to hold either data or address values.
In addition to these, there is a seventeenth register used to store status
information

Register 14 is used as the subroutine link register. This receives a


copy of R15 when a Branch and Link (BL) instruction is executed. At all
other times it may be treated as a general-purpose register. The
corresponding banked registers R14_svc, R14_irq, R14_fiq, R14_abt and
R14_und are similarly used to hold the return values of R15 when
interrupts and exceptions arise, or when Branch and Link instructions
are executed within interrupt or exception routines.

Register 15 holds the Program Counter (PC). In ARM state, bits [1:0] of
R15 are zero and bits [31:2] contain the PC. In THUMB state, bit [0] is
zero and bits [31:1] contain the PC.

Register 16 is the CPSR (Current Program Status Register). This


contains condition code flags and the current mode bits.

FIQ mode has seven banked registers mapped to R8-14 (R8_fiq-R14_fiq).


In ARM state, many FIQ handlers do not need to save any registers. That
is the reason for fast execution of interrupts.

User, IRQ, Supervisor, Abort and Undefined each have two banked
registers mapped to R13 and R14, allowing each of these modes to have a
private stack pointer and link registers.

Address bus of ARM7TDMI has 32 address If ALE (address latch enable)


is HIGH and APE (Address Pipeline Enable) is LOW, the addresses
become valid during phase 2 of the cycle before the one to which they
refer and remain so during phase 1 of the referenced cycle.

ABE (Address Bus Enable) pin is LOW, it puts the address bus into a
high impedance state. ABE must be tied HIGH when there is no system
requirement to turn off the address drivers.

The ARM7TDMI contains a Current Program Status Register (CPSR), plus


five Saved Program Status Registers (SPSRs) for use by exception
handlers. These registers
[1] Hold information about the most recently performed ALU operation
[2] Control the enabling and disabling of interrupts
[3] Set the processor operating mode

The arrangement of bits is in CPSR is shown below:

Load and Store architecture:


ARM employs load and store architecture. Instruction set will only process
values which are in registers and place result of process into register.
Process may be addition, subtraction, etc. Example: ADD R1,R2,R3 (This
8

instruction adds content of registers R2 and R3 and saves result into R1).
Operations related to memory are load and store operations only. Copy
memory values into registers are called load instructions and copy register
values into memory are called store instructions. ARM does not support
memory to memory operations.
ARM Exceptions: ARM architecture supports range of interrupts, traps and
supervisor calls. All these are grouped under general heading ARM
Exceptions Exceptions are handled in following ways:

The current state is saved by copying PC into register R14_Exc

CPSR (Current Program Status Register) is saved into SPSR (Saved


Program Status Register)

Processor operating mode is changed to appropriate exception mode

PC is forced to a value between 00h to 1Ch depending on type of


exception

ARM I/O (Input/output) system: ARM handles input-output peripherals


as memory mapped devices with interrupt support. The internal registers of
these peripheral devices are addressable locations within the ARMs memory
map. Input and output data transfer is done by same load and store
instructions which are used for memory locations.

WORKSHEET
[1] What are the differences between ARM and 51 Family microcontrollers?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
9

[2] What is the difference between RISC machine and CISC machine?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] What is load and store architecture? What kind of operations are not
permitted in load and store archictecture?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[4] List ARM development tools available for the development of ARM
applications.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

10

Experiment No.2
Aim: To understand ARM32 and Thumb instruction set of ARM
microcontroller and write simple programs
ARM instruction is 32 bit long. All operands are 32 bit wide and come
from registers or are specified as literals in the instruction itself. Thumb
instruction set is 16 bit. It is compressed form of subset of ARM
instructions. It provides more code density. ARM processor which supports
Thumb instruction set, also executes standard 32 bit instruction set.
Instruction stream at particular time is determined by bit 5 of CPSR (T bit).
If T bit is set, ARM processor interprets instruction as 16 bit Thumb
instruction otherwise it interprets as standard 32 bit instruction. ARM core
start up after reset, executes normal 32 bit ARM instructions. The normal
way to switch into Thumb mode is by executing branch and exchange
instruction (BX).
ARM instructions fall into one of following three categories.
1. Data processing instructions: These instructions are used to change
register values by various arithmetic and logical operations
2. Data transfer instructions: Copy memory values into registers (load
instructions) and copy register values into memory (store instructions)
3. Control flow instructions: Control flow instructions cause execution to
switch to different address. Conditional and unconditional jump
instructions, interrupts, supervisor calls falls into this category.
4. Instruction set:
Data processing instructions:

Multiply Instructions

11

Load and store instructions:

Load and store multiple data bytes

Condition code Mnemonics:

Some Examples:
Data transfer instructions (Load and Store)
[1] MOV R1,R2
Explanation: Content of register R2 copied into R1 R1 R2
[2] MOV R1,#0x55
Explanation: Move hexadecimal value 0x55 to register R1
[3] MVN R1,R2
Explanation: Content of R2 complemented and than transferred to R1
R1R2`
[5] MOV PC,R14
Explanation: Copy content of register R14 into PC. Return from subroutine
because R14 is the link register.
[5] LDR R1,[R2]
Explanation: Load R1 from memory address pointed by R2 R1 *R2
Data stored at the address pointed by register R2 is loaded into register R1.
[6] LDR R1,[R2,#8]
Explanation: Load register R2 from the memory address pointed by R2+8.
R1 *(R2+8)
[7] STR(R5,#8),R1
Explanation: Store content of register R1 at the memory location specified by
R5+8. *(R5+8) R1
12

[8] MOVS R0,#0


Explanation: Move value 0 in the register R0. S indicates that it will affect
CPSR also. Zero flag will set, negative flag reset, Carry and overflow flag not
effected.
Data Processing (Arithmetic and logical instructions):
[1] ADD R1,R2,R3
Explanation: Add content of registers R2 and R3, result is stored in R1
R1R2+R3
[2] ADD R1,R2,#0x55
Explanation: Add content of register R2 and immediate value 0x55 and store
result in the register R1. R1R2+0x55
[3] ADDC R1,R2,R3
Explanation: Consider carry during addition. R1=R2+R3+Carry
[4] SUB R1,R2,R3
Explanation: Subtract content of register R3 from R2 and store result in
register R1.
R1 R3-R2
[5] RSB R2,R2,R5
Explanation: Reverse subtraction. Subtract R2 from R5 and store result
back in R2. R2 R5-R2
[6] SBC R1,R2,R3
Explanation: Subtraction with carry. R1=R2-R3-NOT(carry)
[7] RSC R0,R1,R2
Explanation: R0 = R2-R1+C-1 { R2-R1-NOT(carry)}
[8] MUL R1,R2,R3
Explanation: Multiply registers R2 and R3. Store result in the register R1.
[9] ADD R1,R2,R3,LSL #2
Explanation: Addition combined with barrel shifting. It shifts content of
register R3 to the left two times and than adds with the register R2. Store
result in the register R1. Logical shift left multiplies the number by two. Two
time shifting multiplies the number by 4.
R1 R2+4R3
[10] SUB R4,R5,R7,LSR R2
Explanation: Logical right shift R7 by the number in the bottom byte of R2,
subtract result from R5, and put the answer into R4.
[11] MLA R1,R2,R3,R4
Explanation: Multiply and accumulate. R1 R2*R3+R4
Branch Instructions:
[1] B label
: Branch unconditionally to label
[2] BCC label
: Branch to label if carry flag is cleared
[3] BEQ label
: Branch to label if zero flag is set
[4] MOV PC,#0
: Branch to location 0
[5] BL delay
: Subroutine call to delay

13

Conditional Execution instructions:


[1] MOVCS R0,R1
Explanation: This instruction will move value of register R1 to register R0
only if carry flag is set.
[2] MOVEQ R0,R1
Explanation: This instruction will move value of register R1 to register R0
only if zero flag is set.
[3] Consider following sequence of instructions:
MOVS R0,R1
MOVEQS R0,R2
MOVEQ R0,R3
Explanation:
The first instruction moves content of register R1 into R0 and change N
and Z flag depending on value stored in R0.
Second instruction will transfer R2 to R0 only if zero flag is set. That
means if during first instruction R1=0, second instruction will execute. If
second instruction is executed it will change N and Z flag depending on
value stored in R2.
Third instruction transfer register R3 to R0 only if zero flag is set. That
means R2=0 during second instruction. Thus, third instruction will be
executed only of R1 and R2 both were 0.
CMP R1,#0
; Compare R1 with 0.
BNE LOOP
; Branch if not equal
Explanation:
The first instruction compares R1 with 0. The second instruction is branch
instruction, program will jump to location specified by label LOOP if R1 is
not equal to 0.
Sequence of instructions to change operating mode of ARM:
MRS R0,CPSR; Take a copy of the CPSR.
BIC R0,R0,#0x1F; Clear the mode bits.
ORR R0,R0,#new_mode; Select new mode
MSR CPSR,R0; Write back the modified CPSR

WORKSHEET
[1] What are the advantages of THUMB mode of ARM microcontroller?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

14

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] For what type of applications full arm instructions are better compared to
thumb and switching is required from thumb mode to full arm mode?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] Write instructions for the following operations
[a] Move content of register R6 into R5

_____________________________________________________________________
[b] Move immediate data #66 in the register R4

_____________________________________________________________________
[c] Add content of register R3 and R4. Save result in register R6

_____________________________________________________________________
[d] Multiply content of register R1 and R2. Save result in register R3.

_____________________________________________________________________
[e] Write instruction to multiply content of register R4 with 5. Use ADD
instruction in combination with logical shift instruction.

_____________________________________________________________________
_____________________________________________________________________
[f] Write instruction to multiply and accumulate. Use registers R4,R5,R6 and
R7.

_____________________________________________________________________
_____________________________________________________________________

15

[g] Write instruction to copy CPSR register into register R0.

_____________________________________________________________________
[4] Write a program to add elements of array. Consider three elements in the
array. Load data from the array using instruction LDR and add it. Store
the result in register R0.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

[5] Explain execution of following instructions:


[a] MOV R0,R1,ASR #2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[b] MOV R0,R1,ROR #2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

16

[c] AND R0,R1,R2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[d] ORR R0,R1,R2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[e] EOR R0,R1,R2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[f] BIC R0,R1,R2

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[g] CMP R0,#5

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[h] AND R8,R7,#&FF

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

17

Experiment No.3
Aim: To understand features and block diagram of LPC-2129 ARM
processor. To download and execute program to blink 8 LEDs connected at
Port P0 of LPC-2129 ARM7TDMI chip using LPC2000 flash utility

Brief Theory:
The ARM microcontrollers are high-performance, 16/32 bit RISC Core
devices. The ARM market is one of the fastest growing market for
microcontrollers. TheLPC2119/LPC2129 are based on a 16/32bit
ARM7TDMI-S CPU with 256 kB of embedded high speed flash memory. A
128-bit wide memory interface and a unique accelerator architecture enable
32-bit code execution at maximum clock rate. For critical code size
applications, the alternative 16-bit Thumb Mode reduces code by more than
30% with minimal performance penalty.
LPC2129 comes with 64 pin package, low power consumption, various
32-bit timers, 4-channel 10-bitADC, 2 advanced CAN channels, PWM
channels and 46 GPIO lines with up to 9 external interrupt pins these
microcontrollers are particularly suitable for automotive and industrial
control applications as well as medical systems and fault-tolerant
maintenance buses. With a wide range of additional serial communications
interfaces, they are also suited for communication gateways and protocol
converters as well as many other general-purpose applications.
The advantage of ARM microcontrollers are:
It is very fast: ARM7 core run at 60 MHz and ARM9 runs at 150 MHz
Low power dissipation: Typical power dissipation for ARM7 is 0.5-1
mA/MHz
Great range of peripherals: ADC, DAC, USB, SPI,UART, I2C, CAN,
Ethernet, SDRAM
Internal Flash (32 KB to 1 MB depending on chip) and RAM (4 to 256 KB)
The salient features of LPC-2129 are listed below:
16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package. 16kB
on-chip Static RAM. 128/256kB on-chip Flash Program Memory.
128-bit wide interface/accelerator enables high speed 60MHz operation.
In-System Programming (ISP) and In-Application Programming (IAP) via
on-chip boot-loader software. Flash programming takes 1 ms per 512
byte line. Single sector or full chip erase takes 400ms.
Embedded ICE-RT interface enables breakpoints and watch points.
Interrupt service routines can continue to execute whilst the foreground
task is debugged with the on-chip Real Monitor software.
Embedded Trace Macrocell enables non-intrusive high speed real-time
tracing of instruction execution. Two interconnected CAN interfaces with
advanced acceptance filters.
Four channel 10-bit A/D converter with conversion time as low as 2.44
s.
Multiple serial interfaces including two UARTs (16C550), Fast I2c 400
kbps and two SPIs.

18

60MHz maximum CPU clock available from programmable on-chip


Phase-Locked Loop.
Vectored Interrupt Controller with configurable priorities and vector
addresses.

Block diagram of the LPC2129 ARM Chip:

Two 32-bit timers(with 4 capture and 4 compare channels), PWM unit(6


outputs), Real Time Clock and Watchdog.
Up to forty-six 5V tolerant general purpose I/O pins. Up to 9 edge or level

19

sensitive external interrupt pins available.


On-chip crystal oscillator with an operating range of 1MHz to 30MHz.
Two low power modes, Idle and Power-down.
Processor wake-up from Power-down mode via external interrupt.
Individual enable/disable of peripheral functions for power optimization.
Dual power supply:
o CPU operating voltage range of 1.65V to 1.95V (1.8V 0.15V).
o I/O power supply range of 3.0V to 3.6V (3.3V 10%) with 5V tolerant
I/O pads.
Pin Diagram of LPC2129:

Features of LPC2129:

It is 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.


16kB on-chip Static RAM. 128/256kB on-chip Flash Program Memory.
128-bit wide interface/accelerator enables high speed 60MHz operation.
20

In-System Programming (ISP) and In-Application Programming (IAP) via


on-chip boot-loader software. Flash programming takes 1 ms per 512
byte line. Single sector or full chip erase takes 400ms.

Embedded ICE-RT interface enables breakpoints and watch points.


Interrupt service routines can continue to execute whilst the foreground
task is debugged with the on-chip Real Monitor software.

Embedded Trace Macrocell enables non-intrusive high speed real-time


tracing of instruction execution.

Two interconnected CAN interfaces with advanced acceptance filters.

4 channel 10-bit A/D converter with conversion time as low as 2.44 s.

Multiple serial interfaces including two UARTs (16C550), Fast I2C 400
kbps two SPIs.

60MHz maximum CPU clock available from programmable on-chip


Phase-Locked Loop.

Vectored Interrupt Controller with configurable priorities and vector


addresses.

Two32 bit timers(with 4 capture and 4 compare channels), PWM unit (6


outputs),

Real Time Clock and Watchdog.

Up to 46 general purpose I/O pins.

Up to 9 edge or level sensitive external interrupt pins available.

On-chip crystal oscillator with an operating range of 1MHz to 30MHz.

Two low power modes, Idle and Power-down.

Processor wake-up from Power-down mode via external interrupt.


Individual enable/disable of peripheral functions for power optimization.

Dual power supply: CPU operating voltage range of 1.65V to 1.95V (1.8V
0.15V).

I/O power supply range of 3.0V to 3.6V (3.3V 10%) with 5V tolerant I/O
pads.

To download and execute program to blink 8 LEDs connected with


LPC2129 ARM7TDMI using LPC2000 flash utility
LEDs are connected with LPC-2129 chip with port pins P0.2 to P0.7, P0.22
and P0.9. Bit Configuration is shown below. First row is bit position, second
row is corresponding bit and third row is equivalent hexadecimal value.

21

31

24

23

22

21

20 .. 17

16

15

14 10

2 1 0

00

0 .. 0

0 0

1 0 0

00

40

02

FC

Program:
/ *********** Program to blink LEDs **********/
#include <LPC21xx.h>
/* LPC21xx definitions in header file */
#include "Timer.h"
extern long volatile timeval;
void wait (void)
/* wait function */
{
unsigned long i;
i = timeval;
while ((i +100 ) != timeval);
/* wait 100ms */
}
int main (void)
{
unsigned int j;
/* LED var */
IODIR0 = 0x004002FC;
/* Define I/O pins */
init_timer();
while (1)
/* Loop forever */
{
j== 0x004002FC;
/* bit pattern for LEDs connected at GPIO port 0*/
IOSET0=j;
/* turn LEDs ON */
wait();
/* Delay */
IOCLR0=j;
/* turn LEDs OFF */
wait();
/* Delay */
}
}

Downloading program to flash memory of the chip LPC2129:

Create project and write above program using KEIL IDE tool. (Create New
Project, write C program in new file, Add C file in your project, Add
necessary header files such as LPC21xx.h, timer.c and timer.h in your
project). Build program to generate HEX file.

Use Philips LPC2000 flash utility to download your program HEX file in
the chip. Screen looks as shown in the figure in the next page

Philips LPC2000 Flash utility connects PCs serial port (COM port) to the
serial port of LPC2129 chip and provides in system flash programming
(ISP).

Select device LPC2129, Change crystal frequency 12000 KHz (12 MHz)
(Or press Read device Id command button, it will select device
automatically)

Select hex file and press button upload to the flash.

22

Before downloading HEX file in the chip, ensure that switch SW5 of the
ARM board is in left position. Press RESET key before downloading

After downloading the program, make switch SW5 in the right side and
press the reset key to start execution.

You can use stand-alone Philips LPC2000 Flash utility or it can be


embedded into your KEIL compiler. In Keil compiler use FLASH menu.

WORKSHEET
[1] Modify program of this practical to change blinking interval. Generate
HEX file of modified program, download it and observe the result

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

23

[2] What is use of watchdog timer?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] What is brown out reset?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] Why interrupt execution is fast in ARM processor in FIQ mode?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[4]Write key features of LPC2129 microcontroller

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

24

Experiment No.4
Aim: To understand features of LPC-2294 ARM processor and download
programs to flash 8 LEDs connected at Port P1 of LPC-2294 ARM Processor
Features of LPC-2294:
The LPC-2294 microcontroller is based on a 16-bit/32-bit ARM 7 TDMI-S
It has 256 KB of embedded high - speed flash memory. It has 16 KB on
chip static RAM. 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.
LPC-2294 ARM chip has 144-pin, low power consumption, various 32-bit
timers, 8-channel 10-bit ADC, 2 advanced CAN channels, PWM channels
and up to nine external interrupt pins these microcontrollers are
particularly suitable for automotive and industrial control applications
as well as medical systems and fault-tolerant maintenance buses. The
number of available GPIO's ranges from 76 (with external memory)
through 112 (single-chip). With a wide range of additional serial
communications interfaces, they are also suited for communication
gateways and protocol converters as well as many other general-purpose
applications.
Procedure:
1.

To program IC via serial port, short the 1-2 pin of the jumpers J7 &
J6 (left side). Connect the serial cable to any functional COM port of
your PC and SP2 (DB-9 Connector) port of the trainer (in PC interface
& ISP section).

2.

To program IC via USB, short the 2-3 pin of the jumpers J7 &
J6 (right side). Connect the USB cable with PC

3.

Change the position of Run/ISP switch 'On' the trainer to ISP mode.

4.

Connect the power cable to the trainer and switch 'On' the power
switch.

5.

Compile program using KEIL compiler and generate hex file LED.hex

6.

Start the Philips flash utility LPC210x_ISP.exe

7.

Program LED.hex in LPC-2294 using programmer.

8.

Switch 'Off the power supply and change the position of Run/ISP
switch 'On' the trainer to Run mode.

9.

Switch 'On' the supply, then press reset switch.

10. Observe the blinking of LED's according to program.

25

Program:
/ *********** Program to blink LEDs **********/
#include <LPC22xx.h>
#include "LED.h"

/* LPC22xx definitions */

//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void main(void)
{
initilise_led();
while (1)
{
blink_led();
}
}
To compile above program, it is necessary to include library file Nvis2294.LIB where
routines blink_led() and initialize_led() are written.
LEDs are connected with port pins P1.16 to P1.23 of LPC-2294 chip. Following
program will also work without using library file Nvis2294.LIB

/ *********** Program to blink LEDs **********/


#include <LPC22xx.h>
/* LPC22xx definitions in header file */
#include "Timer.h"
extern long volatile timeval;
void wait (void)
/* wait function */
{
unsigned long i;
i = timeval;
while ((i +100 ) != timeval);
/* wait 100ms */
}
int main (void)
{
unsigned int j;
/* LED var */
IODIR0 = 0x00FF0000;
/* Define I/O pins P1.16 to P1.23 */
init_timer();
while (1)
/* Loop forever */
{
j=0x00FF0000;
/* bit pattern for LEDs connected at GPIO port 1*/
IOSET0=j;
/* turn LEDs ON */
wait();
/* Delay */
IOCLR0=j;
/* turn LEDs OFF */
wait();
/* Delay */
}
}

26

Experiment No.5
Aim: Write program to blink LEDs one by one. Download and execute
program in LPC-2129 chip. Modify this program according to given
instruction in exercise
Program:
#include <LPC21xx.h>

/* LPC21xx definitions in header file */

extern long volatile timeval;


void wait (void)
/* wait function */
{
unsigned long i;
i = timeval;
while ((i +100 ) != timeval);
/* wait 100ms */
}
int main (void)
{
unsigned int j;
/* LED var */
IODIR0 = 0x000003FC;
/* Define I/O pins */
init_timer();
while (1)
{
for (j = 0x00000004; j < 0x00000800; j <<= 1) /* Blink LED one by
one*/
{
IOSET0 = j;
/* Turn on LED */
wait ();
/* call wait function */
IOCLR0 = j;
/* Turn off LED */
wait();
}
}
}

WORKSHEET
Modify above program in such a way that first four LED glow and other four
LEDs remains OFF for a while and then first four LED switched OFF and
other four LEDs becomes ON as shown in following figure (Alternate Nibble
ON-OFF).

27

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Modify program to use pure software delay instead of time delay

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

28

Buzzer is connected at pin number P0.20 via buffer at LPC-2129. Write a


program to get beep on the buzzer. Compile and execute program. Change
beep duration
(Hint: IODIR0 = 0x00300000 and short jumper R35 to get beep in buzzer)

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

29

Experiment No.6
Aim: To write and execute program to display message display
WELCOME GEC RAJKOT on LCD screen for ARM7

Interfacing details of LCD:

LCD data lines are connected with port pins P1.16 to P1.23

RS connected with P0.18

EN connected with P0.19

RW pin is grounded (always write operation)

Program:
#include <LPC21XX.H>
#define
uchar unsigned char
#define uint unsigned int
#define RS 18
#define EN 19
unsigned char const mcu123[]="WELCOME GEC RAJKOT"

void Io_Set(uchar pin)


{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}

void Sent_Byte(unsigned char data)

30

{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}
void delay(unsigned int i)
{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
void
{

/* Delay function */

delay1s(unsigned char i)
while(i>1)
{
i--;
delayms(20);
}

}
void init_port(void)
{
//port initialized
IODIR1=0x00FF0000;
IODIR0=0x000C0000;
}

//LCD data lines are connected to P1.23 to P1.16


// RS to P0.18 and EN to P0.19

void LcdWrite_CMD( uchar CMD)


{
Io_Clr(RS);
/* Select Command Register of LCD*/
delay(1);
Sent_Byte(CMD);
delay(1);
Io_Set(EN);
/* Enable LCD*/
delay(1);
Io_Clr(EN);
/* Disable LCD */
delay(2);
delayms(10);
}
void LcdWrite_D( char dataW )
{
Io_Set(RS);
/* Select Data Register of LCD*/
delay(1);
Sent_Byte(dataW);

31

delay(1);
Io_Set(EN);
delay(1);
Io_Clr(EN);
delay(2);
delayms(10);

/* Enable LCD*/
/* Disable LCD */

}
void DispOneChar(uchar x,uchar y,uchar Wdata) {
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void lcdreset(void)
{
LcdWrite_CMD(0x38);
delayms(50);
LcdWrite_CMD( 0x08);
LcdWrite_CMD( 0x01);
LcdWrite_CMD( 0x06);
LcdWrite_CMD( 0x0c);

/* Initialize LCD

2 lines, 5X7 matrix*/

/* Display OFF cursor OFF */


/*Clear LCD*/
/*Shift cursor right*/
/* Display ON */

}
int main(void)
{
init_port();
delayms(1);
lcdreset();
delay1s(1);
LcdWrite_CMD( 0x80);
disp(0,0,mcu123);
LcdWrite_CMD( 0xC0);
disp(0,1,"E.C. Department");
while(1)
{
}
}

Compile and build above program with Keil compiler and generate
HEX file. Download HEX file in the chip LPC2129 and execute the program
by pressing RESET key

32

WORKSHEET
[1] What are the pins available on the LCD for interfacing with ARM
processor? Describe functions of the pins.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[1] Modify LCD program to display character string Saurashtra on the first
line and University on the second line. Write modified program again.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

33

Experiment No.7
Aim: To read analog input voltage and display it on LCD using LPC-2129
ADC introduction and interfacing details:
10 bit ADC is interfaced with LPC-2294. It is successive approximation type
analog to digital converter with conversion time greater than 2.44 us.
Basic clocking for the A/D converter is provided by the VPB clock. A
programmable divider is included 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. Seven analog input pins are
in LPC2294. The A/D converter includes two registers ADDR and ADCR.
The ADCR register must be written to select the operating mode
before A/D conversion can occur. This ADDR register contains the end of
conversion bit.
Functions of various bits of ADDR and ADCR registers are explained below:
A/D Control Register (ADCR) :
Reset
Value

ADCR
bit

Name

Description

7:0

Sel

Select which of the Ain3:0 (LPC2119/2129/2194) or Ain 7: 0


(LPC2292/2294) pins is (are) to be sampled and converted.
Only bits 3: 0 should be set to 1 in the 48 or 64 pin package. In
software-controlled mode, only one of these bits should be 1. In
hardware scan mode, any value containing 1 to 8 ones (1 to 4
ones in the 48 or 64 pin package) can be used. All zeroes is
equivalent to 0x01.

0x01

15.8

CLKDIV

The VPB clock (PCLK) is divided by (this value plus one) to


produce the clock for the A/D converter, which should be less
than or equal to 4.5 MHz. Typically, software should program the
smallest value in this field that yields a clock of 4.5 MHz or
slightly less, but in certain cases (such as a high -impedance
analog source) a slower clock may be desirable.

16

Burst

If this bit is 0, conversions are software controlled and require 11


clocks. If this bit is 1, the AD converter does repeated conversions
at the rate selected by the CLKS field, scanning (if necessary)
through the pins selected by 1s in the SEL field. The first
conversion after the start corresponds to the least - significant 1
in the SEL field, then higher numbered 1 -bits (pins) if applicable.
Repeated conversions can be terminated by clearing this bit, but
the conversion that's progress when this bit is cleared will be
completed.

34

19:17

CLKS

This field selects the number of clocks used for each conversion
in Burst mode, and the number of bits of accuracy of the result in
the LS bits of ADDR, between 11 clocks (10 bits) and 4 clocks
(3bits): 000=11 clocks/9 bits.... 111=4 clocks/3 bits

21

PDN

1: the A/D converter is operational 0: the A/D


converter is in power down mode

23:22

Test1:0

These bits are used in device testing. 00=normal operation,


01= digital test mode, 10=DAC test mode, and 1 1=simple
conversion test mode

000

When the Burst bit is 0, these bits control whether and when an
A/D conversion is started:000: no start (this value should be
used clearing PDN to 0
001: Start conversion now
26:24

Start

010: Start conversion when the edge selected by bit 27 occurs


on P0.16/EINT0/MAT0.2/CAP0.2

000

011: Start conversion when the edge selected by bit 27 occurs


on P0.22/TD3/CAP0.0/MAT0.0
Note: for choices 100-111 the MAT signal need not be pinned
out:
100: Start conversion when the edge selected by bit 27 occurs
on MAT0.1
101: Start conversion when the edge selected by bit 27 occurs
on MAT0.3

27

Edge

110: Start conversion when the edge selected by bit 27 occurs


on MAT 1.0
This bit is significant only when the start field contains 010-111.
In there cases:

0: Start conversion on a falling edge on the selected


CAP/MAT signal
1: Start conversion on a rising edge on the selected
CAP/MAT signal

35

A/D Data Register (ADDR) :


ADDR
bit

Name

Description

31

Done

This bit is set to 1 when an A/D conversion


completes. It is cleared when this registered is read
and when the ADCR is written. If the ADCR is
written while a conversion is still in progress, this bit is
set and a new conversion is started.

30

OVERUN

This bit is 1 in burst mode if the results of one or


more conversion that produced that the result in the
LS bits. In non -FIFO operation, this is cleared by
reading this register.

These bits always read as zeroes. They could be used


for expansion of the CHN field in future compatible
A/D converters that can convert more channels

These bits contain the channel from which the LS


bits were converted

These bits always read as zeroes. They allow


accumulation of successive A/D values without and masking, for at least 256 values without overflow
into thedone
CHNisfield
When
1, this field contains a binary fraction
representing the voltage on the Ain pin selected by
the SEL field, divided by the voltage on the VddA
pin. Zero in the field in the indicates that the voltage
on the Ain pin was less than, equal to, or close to that
on VssA, while 0x3 FF indicates that the voltage on Ain
was close to, equal to, or greater than that on VddA

29:27

26:24

CHN

23:16

15:6

V/VddA

Reset
Value

For testing, data written to this field is captured in a


shift register that is clocked by the A/D converter
clock. The MS bit of this register sources the
DINSERI input of the A/D converter which is used is
used only when Test 1:0 are 10.
5:0

These bits always read as zeroes. They provide 0


compatible expansion room for future higher resolution A/D converters

36

Procedure:
1.

To program IC via serial port, short the 1-2 pin of the jumpers J7 &
J6 (left side). Connect the serial cable to any functional COM port of
your PC and SP2 (DB-9 Connector) port of the trainer (in PC interface
& ISP section).

2.

To program IC via USB, short the 2-3 pin of the jumpers J7 &
J6 (right side). Connect the USB cable with PC

3.

Change the position of Run/ISP switch 'On' the trainer to ISP mode.

4.

Connect the power cable to the trainer and switch 'On' the power
switch.

5.

Compile program using KEIL compiler and generate hex file


ADC_Interface.hex

6.

Start the Philips flash utility LPC210x_ISP.exe

7.

Program ADC_Interface.hex in LPC-2294 using programmer.

Switch 'Off the power supply and change the position of Run/ISP
switch 'On' the trainer to Run mode.
9. Close 1-2 pin of jumper J1 (left side).
10. Switch On the supply, then press reset switch.
8.

11. Observe display coming on LCD.


12. Rotate the DC Voltage potentiometer located in ADC Interface
block and observe the change in readings on LCD also measure the
voltage comes on TP1 test point.
12. Examine the voltage on TP1, when voltage on TP1 is 0V, LCD shows
0000 in decimal and when TP1 is 3.3V, LCD shows 1024 in decimal
on LCD (10 bit ADC).
Pin P0.27 (Pin No. 23 is analog input pin) used for this program. There are
total four ADC input pins are available (P0.27, P0.28, P0.29 and P0.30)
Program:
#include
#include
#include
#include

<LPC22xx.H>
<LCD.h>
<ADC.h>
<Delay.h>

/* LPC2294 definition */

//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void main(void)
{
adc_initialise();
37

while (1)
{
adc_runmode();
}
}
// Adc.h file
#ifndef ADC_H
#define ADC_H
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void binbcd(unsigned int );
void adc_initialise(void );
void adc_runmode(void );
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
static unsigned int a,b,c,d,x,y,z;
static unsigned int adcdata;
#endif

:: WORKSHEET ::
[1] What is the advantage of 10 bit ADC over 8 bit ADC?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] How many ADC channels are available in LPC-2294 IC?

_____________________________________________________________________
_____________________________________________________________________
[3] Write decimal value displayed on LCD for following input voltage
0.0 V = _________

0.1V = _______________ 0.5V = ____________

1 V = ___________

2V=

Resolution of ADC:

3.3V = ____________

______
38

Experiment No.8
Aim: To understand embedded system development using ADSP-2181
kit
Objectives:

To understand architecture of Digital Signal Processor ADSP-2181.

To understand installation procedure of ADSPLite software & ADSP2181 Kit.

To download and run sample programs on ADSP kit.

Architecture of ADSP-2181:
The ADSP-2181 is a single-chip microcomputer optimized for digital
signal processing (DSP) and other high speed numeric processing
applications. The ADSP-2181 combines the ADSP-2100 family base
architecture (three computational units, data address generators and a
program sequencer) with two serial ports, a 16-bit internal DMA port, a byte
DMA port, a programmable timer, Flag I/O, extensive interrupt capabilities,
and on-chip program and data memory.
The ADSP-2181 integrates 80K bytes of on-chip memory configured as
16K words (24-bit) of program RAM, and 16K word (16-bit) of data RAM.
Power-down circuitry is also provided to meet the low power needs of battery
operated portable equipment. The ADSP-2181 is available in 128-lead TQFP
and 128 lead PQFP packages.
In addition, the ADSP-2181 supports new instructions, which include
bit manipulationsbit set, bit clear, bit toggle, bit test, new ALU constants,
new multiplication instruction (x squared), biased rounding, result free ALU
operations, I/O memory transfers and global interrupt masking for
increased flexibility.
Fabricated in a high speed, double metal, low power, CMOS process,
the ADSP-2181 operates with a 25 ns instruction cycle time. Every
instruction can execute in a single processor cycle. The ADSP-2181s flexible
architecture and comprehensive instruction set allow the processor to
perform multiple operations in parallel.
In one processor cycle the ADSP-2181 can perform following tasks:
Generate the next program address
39

Fetch the next instruction


Perform one or two data moves
Update one or two data address pointers
Perform a computational operation
Functional block diagram of the ADSP-2181 is shown in the following
figure.

The ADSP-2181 instruction set provides flexible data moves and


multifunction (one or two data moves with a computation) instructions.
Every instruction can be executed in a single processor cycle. The ADSP2181 assembly language uses an algebraic syntax for ease of coding and
readability. A comprehensive set of development tools supports program
development.
As shown in the block diagram, ADSP-2181 contains three
independent computational units: the ALU, the multiplier/accumulator
(MAC) and the shifter. The computational units process 16-bit data directly
and have provisions to support multi-precision computations. The ALU performs a standard set of arithmetic and logic operations; division primitives
are also supported. The MAC performs single-cycle multiply, multiply/add
and multiply/subtract operations with 40 bits of accumulation. The shifter
performs logical and arithmetic shifts, normalization, denormalization and
derive exponent operations. The shifter can be used to efficiently implement
numeric format control including multiword and block floating point
40

representations. The internal result (R) bus connects the computational


units so that the output of any unit may be the input of any unit on the next
cycle.
A powerful program sequencer and two dedicated data address
generators ensure efficient delivery of operands to these computational
units. The sequencer supports conditional jumps, subroutine calls and
returns in a single cycle. With internal loop counters and loop stacks, the
ADSP-2181 executes looped code with zero overhead; no explicit jump
instructions are required to maintain loops. Two data address generators
(DAGs) provide addresses for simultaneous dual operand fetches (from data
memory and program memory). Each DAG maintains and updates four
address pointers. Whenever the pointer is used to access data (indirect
addressing), it is post-modified by the value of one of four possible modify
registers. A length value may be associated with each pointer to implement
automatic modulo addressing for circular buffers.
Efficient data transfer is achieved with the use of five internal buses:
Program Memory Address (PMA) Bus
Program Memory Data (PMD) Bus
Data Memory Address (DMA) Bus
Data Memory Data (DMD) Bus
Result (R)

Bus

41

The two address buses (PMA and DMA) share a single external
address bus, allowing memory to be expanded off-chip, and the two data
buses (PMD and DMD) share a single external data bus. Byte memory space
and I/O memory space also share the external buses.
Program memory can store both instructions and data, permitting the
ADSP-2181 to fetch two operands in a single cycle, one from program
memory and one from data memory. The ADSP-2181 can fetch an operand
from program memory and the next instruction in the same cycle. In
addition to the address and data bus for external memory connection, the
ADSP-2181 has a 16-bit Internal DMA port (IDMA port) for connection to
external systems. The IDMA port is made up of 16 data/address pins and
five control pins. The IDMA port provides transparent, direct access to the
DSPs on-chip program and data RAM. An interface to low cost byte-wide
memory is provided by the Byte DMA port (BDMA port). The BDMA port is
bidirectional and can directly address up to four megabytes of external RAM
or ROM for off-chip storage of program overlays or data tables.
Interrupts:
The ADSP-2181 can respond to 13 possible interrupts, eleven of which
are accessible at any given time. There can be up to six external interrupts
(one edge-sensitive, two level-sensitive and three configurable) and seven
internal interrupts generated by the timer, the serial ports (SPORTs), the
Byte DMA port and the power-down circuitry. There is also a master signal.
The two serial ports provide a complete synchronous serial interface
with optional companding in hardware and a wide variety of framed or
frameless data transmit and receive modes of operation. Each port can
generate an internal programmable serial clock or accept an external serial
clock.
The ADSP-2181 provides up to 13 general-purpose flag pins. The data
input and output pins on SPORT1 can be alternatively configured as an
input flag and an output flag. In addition, there are eight flags that are
programmable as inputs or outputs and three flags that are always outputs.
A programmable interval timer generates periodic interrupts. A 16-bit count
register (TCOUNT) is decremented every n processor cycles, where n is a
scaling value stored in an 8-bit register (TSCALE). When the value of the
count register reaches zero, an interrupt is generated and the count register
is reloaded from a 16-bit period register (TPERIOD).

42

Serial Ports:
The ADSP-2181 incorporates two complete synchronous serial ports
(SPORT0 and SPORT1) for serial communications and multiprocessor
communication. Brief list of the capabilities of the ADSP-2181 SPORTs is
given below:
SPORTs are bidirectional and have a separate, double- buffered
transmit and receive section.
SPORTs can use an external serial clock or generate their own serial
clock internally.
SPORTs have independent framing for the receive and transmit
sections. Sections run in a frameless mode or with frame synchronization
signals internally or externally generated. Frame sync signals are active high
or inverted, with either of two pulse widths and timings.
Overview of ADSP-2181 Kit:
ADSP2181 Kit has following features:
Analog Devices ADSP-2181SK-133 processor
Operating at an instruction rate of 33MHz (16.667 external clock)
Analog Audio Interface
- AD1847 Analog Devices stereo codec
Analog Inputs
o One stereo pair of 2V RMS AC coupled line-level inputs
o One stereo pair of 20mV RMS AC coupled microphone
inputs
Analog Outputs
o One stereo pair of 1V RMS AC coupled line-level outputs
Power Source
o 8 to 10V DC at 300mA
RS-232 Interface

43

ADSP Kit System diagram:

Board Layout;

44

Installation of ADSP-2181 Kit :

Remove the EZ-KIT Lite board from the package. Be careful while
handling the board to avoid the discharge of static electricity, which may
damage some components.

Connect the RS-232 cable to an available COM Port on the PC and to J3


on the ADSP-2181 evaluation board.

Plug the provided cord into a 230 Volt AC receptacle and plug the
connector at the other end of the cable into J4 on the evaluation board.

Visually verify that all of the LEDs light up briefly. The power FL1 blinks.
If the LED does not light (green) LED remains on and up, check the
power connections.

To configure the ADSP-2181 board, we can take advantage of the audio


capabilities of the demos, use the following procedure.

Plug a set of self-powered computer speakers into jack J1 on the board.


Turn on the speakers and set the volume to an adequate level.

Connect the line out of an electronic audio device to jack J2 on the


board. Set jumper JP2 to LINE.

Open Jumper JP2 to GND to enable the AD1847 codec. (This is the board
default).

Install EZ-KIT Lite software to download software in the ADSP-2181 chip.


After installation of the software, click on the short cut. Following screen will
appear.

45

To load the program, we can use following procedure:

From the File menu, select Load.


The Open a Processor Program dialog box appears.

Navigate to the folder where your DSP executable file resides.


The demos supplied with the EZ-KIT Lite are located in the

..\218x\EZ-KITs\2181\Examples subdirectory of the harddisk where you


have installed the program

Select the file and click Open.

The file loads and the Load Complete message appear in the Output window
when the load process has completed.
Procedure to write and execute program:

Write ADSP program using any text editor and than save it using .dsp
extension.

Assemble program by giving following command at command prompt.

> asm21 <filename> -2181 -C


After assembly assembler generates three files:
- .INT : Initialization data file
-

.CDE : Code File

.OBJ : Object File

If we specify listing option l it will also generate list file .LST


For example, if we want to assemble test.dsp file
> asm21 test.dsp -2181 -C
After assembly assembler generates three files:
- test.int
- test.cde
- test.obj
If we specify option l it will also generate test.lst
asm21 test.dsp -2181 C l
To know more options type asm21 -help
46

To link object file to create exe (binary image) file, give following command
>ld21 <object file name> -a <architecture file name with path> -e <output
file name>
For example: >ld21 test -a c:\adi_dsp\macros\2181kit.ach -e test
Example program:
This program generates amplitude modulated waveform using lookup table
{--- choose sampling rate in kHz: ----------------------------------------}
{0xc850 = 8
| 0xc851 = 5.5125 | 0xc852 = 16 }
{0xc853 = 11.025 | 0xc854 = 27.42857 | 0xc855 = 18.9 }
.const fs = 0xc850; {0xc856 = 32
| 0xc857 = 22.05 | 0xc859 = 37.8 }
{0xc85b = 44.1 | 0xc85c = 48
| 0xc85d = 33.075}
{0xc85e = 9.6 | 0xc85f = 6.615
}
.include <c:\adi_dsp\macros\begin.dsp>;

{initializations and DSP macros}

{--- define constants, variables, and buffers ----------------------------}


.const D = 4000;
.var/dm/circ sine[D];

{min frequency f1 = fs/D = 8/4 = 2 Hz}

.init sine: <sinetbl.hex>;


{load one period of the wavetable}
{generated by sinetbl.c}
.const Aenv = 0x7fff;
{Aenv = 1 = envelope amplitude}
.const cenv = 1;
{envelope fenv = cenv * f1 = 2 Hz}
i5 = ^sine; L5 = %sine;
.const c = 100;
i6 = ^sine; L6 = %sine;

{pointer for envelope generator}


{signal frequency f = c * f1 = 200 Hz}
{pointer for signal generator}

{--- start processing input samples --------------------------------------}


wait: idle; jump wait;

{wait for interrupt and loop forever}


{interrupt service routine starts here}
input_samples: ena sec_reg;
{enable secondary register set}
{--- sample processing algorithm -----------------------------------------}
wavgen(i5, m5, Aenv, cenv, ax1);
wavgen(i6, m6, ax1, c, mx1);

{A(t) = Aenv * sin(2*pi*fenv*t)}


{A(t) * sin(2*pi*f*t)}

{--- write output samples to codec ---------------------------------------}


dm(tx_buf + 1) = mx1;
dm(tx_buf + 2) = mx1;

{left output sample}


{right output sample}

{--- return from interrupt -----------------------------------------------}


rti;
.include <c:\adi_dsp\macros\end.dsp>;

{wrapup}

Assemble and link above program to generate ROM image


47

QUESTIONS
[1] What is the difference between Digital Signal Processor and General
Purpose Microprocessor?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] How many pins are there in ADSP-2181. What types of packages are
available?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] Which fabrication technology is used for ADSP-2181?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[4] List five internal bus used for efficient data transfer

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
48

[5]What are the interrupts available in ADSP-2181?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[7] Write features of serial port available in ADSP-2181

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[8] What is function of MAC unit?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[9] Write steps to generate ROM image from the assembly language file

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[10] How DSP programs are downloaded from PC to ADSP-2181 ?

_____________________________________________________________________
_____________________________________________________________________

49

Experiment No. 9
Aim: To generate sine wave, square wave using ADSP-2181
Brief Theory:
To generate sine wave using DSP, look up table is prepared. Magnitude of
samples of sine wave is stored in the look up table hex format. Hex value is
transferred to output port one by one. Output port is connected to digital to
analog converter which provides analog output. Accuracy of sine wave
depends on how many number of samples are used to create it. To smooth
the sine wave output of DAC is passed through low pass filter.

Program:
{
Sine wave generation program
}
.module/RAM/ABS=0
wavegen;
.include <c:\adi_dsp\macros\wavgen.dsp>;
{--- define sampling rate in Khz: ----------------------------------------}
{0xc850 = 8
| 0xc851 = 5.5125 | 0xc852 = 16 }
{0xc853 = 11.025 | 0xc854 = 27.42857 | 0xc855 = 18.9 }
.const fs = 0xc850; {0xc856 = 32
| 0xc857 = 22.05 | 0xc859 = 37.8 }
{0xc85b = 44.1 | 0xc85c = 48
| 0xc85d = 33.075}
{0xc85e = 9.6 | 0xc85f = 6.615 |
}
{-------------------------------------------------------------------------}
.include <c:\adi_dsp\macros\begin.dsp>; { processor initialization.}
{--- define constants, variables, and buffers ----------------------------}
.const D = 4000;
.var/dm/circ sine[D];
.init sine: <sinetbl.hex>;
.const A = 0x1a00;
.const c = 1000;
i6 = ^sine; L6 = %sine;
imask = b#0000110000;

{ Min frequaency f1 = fs/D = 8/4 = 2Hz}


{ Load one period of the wave table}
{ A = 0.5 = signal amplitude}
{ Signal frequency f = c * f1 = 1000Hz}
{ Pointer for signal generator}
{ Enable rx0 interrupt}

{--- start processing input samples --------------------------------------}


wait: idle; jump wait;

{wait for interrupt and loop forever}


50

{interrupt service routine starts here}


input_samples: ena sec_reg;
{enable secondary register set}
{--- sample processing algorithm -----------------------------------------}
wavgen(i6, m6, A, c, mx1); {mx1 = A * sin(2*pi*f*t)}
{--- write output samples to codec ---------------------------------------}
dm(tx_buf+1) = mx1;
dm(tx_buf+2) = mx1;

{left output sample}


{right output sample}

{--- return from interrupt -----------------------------------------------}


rti;
.include <c:\adi_dsp\macros\end.dsp>;
.endmod;
Sine Table:
0000,0033,0067,009a,00ce,0101,0135,0168,019c,01cf,0203,0236,026a,029d,02d1,0304,
0337,036b,039e,03d2,0405,0439,046c,04a0,04d3,0506,053a,056d,05a1,05d4,0608,063b,
066e,06a2,06d5,0709,073c,076f,07a3,07d6,080a,083d,0870,08a4,08d7,090a,093e,0971,0
9a4,09d8,0a0b,0a3e,0a72,0aa5,0ad8,0b0b,0b3f,0b72,0ba5,0bd8,0c0c,0c3f,0c72,0ca5,0cd9
,0d0c,0d3f,0d72,0da5,0dd9,0e0c,0e3f,0e72,0ea5,0ed8,0f0b,0f3f,0f72,0fa5,0fd8,100b,103e,
1071,10a4,10d7,110a,113d,1170,11a3,11d6,1209,123c,126f,12a2,12d5,1308,133b,136d,
13a0,13d3,1406,1439,146c,149f,14d1,1504,1537,156a,159c,15cf,1602,1634,1667,169a,
16cc,16ff,1732,1764,1797,17ca,17fc,182f,1861,1894,18c6,18f9,192b,195e,1990,19c3,19f5,
1a27,1a5a,1a8c,1abe,1af1,1b23,1b55,1b88,1bba,1bec,1c1e,1c51,1c83,1cb5,1ce7,1d19,
1d4b,1d7d,1daf,1de2,1e14,1e46,1e78,1eaa,1edc, 1f0d,1f3f,1f71,1fa3,1fd5,2007,2039,206b
.7fff,
7fff,7fff,7ffe,7ffd,7ffd,7ffc,7ffb,7ffa,7ff9,7ff8,7ff7,7ff6,7ff4,7ff3,7ff1,7ff0,7fee,7fec,7feb,7fe9,
7fe7,..,009a,0067,0033,0000
{
Square.dsp Square wave generated from a wavetable
}
.module/RAM/ABS=0
wavegen;
.include <c:\adi_dsp\macros\wavgen.dsp>;
{--- define sampling rate in khz: ----------------------------------------}
.const fs = 0xc850;
.include <c:\adi_dsp\macros\begin.dsp>; {processor initialization.}
.const D = 4000;
.var/dm/circ square[D];
{min frequaency f1 = fs/D = 8/4 = 2Hz}
.init square: <squartbl.hex>;
{load one period of the wave table}
.const A = 0x5a82;
{A = 0.5 = signal amplitude}
.const c = 100;
{signal frequency f = c * f1 = 1000Hz}
i6 = ^square; L6 = %square;

{pointer for signal generator}

51

imask = b#0000110000;
{enable rx0 interrupt}
{--- start processing input samples --------------------------------------}
wait: idle; jump wait;

{wait for interrupt and loop forever}


{interrupt service routine starts here}
input_samples: ena sec_reg;
{enable secondary register set}
{--- sample processing algorithm -----------------------------------------}
wavgen(i6, m6, A, c, mx1); {mx1 = A * sin(2*pi*f*t)}
{--- write output samples to codec ---------------------------------------}
dm(tx_buf+1) = mx1;
{left output sample}
dm(tx_buf+2) = mx1;
{right output sample}
{--- return from interrupt -----------------------------------------------}
rti;
.include <c:\adi_dsp\macros\end.dsp>;
.endmod;
squartbl.hex file contains ox7fff and 0x8000 (Two levels +V and V)

WORKSHEET
Observations and waveforms:
Observe sine wave output from the kit at ADC output and plot it in the
following space. Measure amplitude and frequency and mention it on the
waveform.

Observe square output from the kit:

52

Change sine wave hex table, assemble and link program file again and
observe change in the waveform. Plot modified waveform in the following
space.

QUESTIONS
[1] Explain following instructions for ADSP-2181 processor.

AR=AX0+AY0, AX0=MR2;

AX0=DM(I2,M0), AY0=PM(I4,M6);

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

53

Experiment No.10
Aim: To filter input signal using FIR filter implementation with ADSP-2181
Brief Theory:
In FIR filter, response to impulse becomes zero after a finite number of
samples. Finite duration impulse response filter (FIR) has a system function
of the form:
M 1

H ( z ) b0 b1 z 1 .......... bM 1 z 1 M bn z n
n 0

Impulse response of FIR filter is:


h(n)= bn
=0

for 0 n M-1
else where

The difference equation representation can be given by


y(n) = b0x(n)+ b1x(n-1)+ .+ bM-10x(n-M+1)
Where b0,b1, ......bM-1 are the filter coefficients
x(n), x(n-1), are input samples.
M is length of filter (Number of filter coefficients)
Order of the FIR filter is M-1 and number of filter coefficients i.e.
length of the filter is M. If we use four coefficients, order of filter is 3. FIR
filter structures are always stable and relatively simple compared to IIR
structures. Furthermore, FIR filters can be designed to have linear phase
response, which is desirable in certain applications.
To implement FIR filter, convolution of filter coefficients is done with
the input signal.
Procedure:

Assemble FIR filter


lowpass.exe file

program

lowpass.dsp

and

link

to

generate

Download program into ADSP2181 kit using ADSPLite software

Connect function generator at the audio input terminal

Connect C.R.O. at the audio output terminal

Vary frequency from the function generator and note down amplitude of
the output waveform at different frequency.

Amplitude of output voltage reduces as frequency increases. Note down


the readings and plot the frequency response

54

Program:
{ FIR Low pass filter: lowpass.dsp }
for each input x do:
sD = tap(D, w, p, D)
v0 = a * v1 + sD
u = b0 * v0 + b1 * v1
y=x+u
v1 = v0
*p = y
cdelay(D, w, &p)

get D-th tap


input to unit delay
output of feedback filter
filter output
update unit delay
input to D-fold delay
update D-fold delay

}
.const fs = 0xc850;

{ Sampling rate 8 KHz}

.include <c:\adi_dsp\macros\begin.dsp>;

{initializations and DSP macros}

{--- define constants, variables, and buffers ----------------------------}


.var/dm v1;
.const a = 0x4000;
.const b0 = 0x199a;
.const b1 = 0x0ccd;

{state of first-order feedback filter}


{a = 0.50}
{b0 = 0.20}
{b1 = 0.10}

.const D = 3000;
.var/dm/circ w[D+1];

{TD = D/fs = 3/8 = 0.375 sec}


{ circular delay line}

i2 = ^w; L2 = %w;

{ delay-line buffer pointer and length}

ax0 = 0;
dm(v1) = ax0;
zero(i2, m2, L2);

{ clear feedback delay, v1 = 0}


{ clear delay line}

{--- start processing input samples --------------------------------------}


wait: idle; jump wait;

{ wait for interrupt and loop forever}


{ Interrupt service routine starts here}
input_samples: ena sec_reg;
{enable secondary register set}
{--- read input samples from codec ---------------------------------------}
ax1 = dm(rx_buf + 1);
mx1 = dm(rx_buf + 2);

{left input sample}


{right input sample}

{--- sample processing algorithm --- process right channel only ----------}
tap(i2, m2, D, mr1);
mx0 = a;
my1 = dm(v1);

{mr1 = sD = D-th tap}

{state v1}
55

mr = mr + mx0 * my1 (rnd);


{mr = v0 = sD + a * v1}
if mv sat mr;
sr0 = mr1;
{ Save v0 for later updating v1}
my0 = b0;
mr = mr1 * my0 (ss);
mx0 = b1;
mr = mr + mx0 * my1 (rnd);
if mv sat mr;
ay1 = mx1;
ar = mr1 + ay1;

{mr = b0 * v0}
{mr = u = b0 * v0 + b1 * v1}

{ ay1 = x = input}
{ ar = y = x + u = output}

dm(v1) = sr0;
{ update lowpass filter, v1 = v0}
tapin(i2, m2, ar);
{ put y in tap-0}
cdelay(i2, m2);
{ update delay}
{--- write output samples to codec ---------------------------------------}
dm(tx_buf + 1) = ar;
{ left output sample}
dm(tx_buf + 2) = ar;
{ right output sample}
{--- return from interrupt -----------------------------------------------}
rti;
.include <c:\adi_dsp\macros\end.dsp>;
{wrapup}

WORKSHEET
Observations and waveforms:
Input signal amplitude: Vi = 0.5 Volt
Sr.
No.

Input signal Output Voltage


(Vo)
frequency

Attenuation
(Vo/Vi)

Attenuation
in dB
10log(Vo/Vi)

56

:: WORKSHEET::
[1] Change filter coefficients in the program:
Instead of b0 = 0.2 and b1=0.1 use b0=0.5 and b1=-0.5. Assemble and link
program again. Download ROM image in ADSP kit and run it. Observe
variation in amplitude with frequency.
As per observation by you answer the following question.
What type of filter is implemented? : __________________________________.

[2] What is the difference between FIR filter and IIR filter?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] What is the advantage of increasing number of filter coefficients? What is
the disadvantage?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
57

Experiment No. 11
Aim: To understand features of Cypress Programmable System on Chip
(PSoC). To download and execute demo programs to display vertical bar
graph using LEDs depending on analog input voltage.

Introduction:
PSoC is a true programmable embedded system-on-chip integrating
configurable analog and digital peripheral functions, memory and a
microcontroller on a single chip.
It has following features:

Programmable routing and interconnect:

Using this feature it is possible to re-route signals to user selected pins,


shedding the constraints of a fixed-peripheral controller. In addition, global
buses allow for signal multiplexing and logic operations, eliminating the
need for a complicated digital-logic gate design.

Configurable analog and digital blocks:

Configurable analog and digital circuitry is the basis of the PSoC platform.
We can configure these blocks using pre-built library functions or by
creating our own. By combining several digital blocks, we can create 16-,
24-, or even 32-bit wide logic resources. The analog blocks are composed of
switch capacitor, op-amp, comparator, ADC, DAC, and digital filter blocks,
allowing complex analog signal flows

CPU Subsystem:

PSoC has sophisticated CPU subsystem with SRAM , EEPROM, and flash
memory, multiple core options and a variety of essential system resources
including:
Internal main and low-speed oscillator
Connectivity to external crystal oscillator for precision, programmable
clocking
Sleep and watchdog timers
Multiple clock sources that include a PLL
PSoC devices also have dedicated communication interfaces like I2C, FullSpeed USB 2.0, CAN 2.0, and on-chip debugging capabilities using JTAG
58

and Serial Wire Debug. The newest members of the PSoC family offer
industry-standard processors like the 8051 and ARM Cortex-M3.
We will use PSoC designer software to execute and download programs into
PSoC Device CY8C24894. Program reads analog input voltage which given
by preset available on the board. Depending on preset value, LEDs as
glowing.
Board Section:
PSoC Device:
Project Location:

Top Right
CY8C24894
\Projects\AnalogInputDriveLEDs.app

Procedure:
Step 1. Create a new Project
1.
2.
3.
4.
5.

Click on File->New Project


Enter any desired name for the project. Here AnalogInputDriveLEDs.
Click Ok
Select the target device from Catalog as CY8C24894-24LTXI
Click Ok. A new project will be created.

Step 2. Add User Modules


1. Go to the User Module Window.
2. Right Click on Misc Digital->LED. Select Place. This needs to be done six
times for six leds.
3. Right Click on Amplifiers->PGA. Select Place
4. Right Click on ADCs->ADCINC. Select Place. Select Single Stage
Modulator.
Step 3. Set Parameters for User Modules
1. LED_1
Select the Port, Pin and Drive
a. PORT -> Port_2
b. PIN -> Port_2_4
c. Drive -> Active High
2. LED_2
Select the Port, Pin and Drive
a. PORT -> Port_2
b. PIN -> Port_2_0
c. Drive -> Active High
3. LED_3
Select the Port, Pin and Drive
a. PORT -> Port_2
b. PIN -> Port_2_1
c. Drive -> Active High
4. LED_4
Select the Port, Pin and Drive

mode

mode

mode

mode
59

a. PORT -> Port_2


b. PIN -> Port_2_2
c. Drive -> Active High
5. LED_5
Select the Port, Pin and Drive mode
a. PORT -> Port_2
b. PIN -> Port_2_3
c. Drive -> Active High
6. LED_6
Select the Port, Pin and Drive mode
a. PORT -> Port_2
b. PIN -> Port_2_5
c. Drive -> Active High
7. ADCINC_1
Select the parameters as below
a. DataFormat -> UnSigned
b. Resolution -> 10bit
c. Data Clock -> VC1
d. ClockPhase -> Normal
e. PosInput -> ACB00
8. PGA_1
Select the parameters as below
a. Gain -> 1.000
b. Input -> AnalogColumnMuxBusSwitch_0
c. Reference -> VSS
d. AnalogBus -> Disable
Step 4. Connecting and Routing
1. In the Chip level Design Window Click on AnalogColumn_InputMux_0
2. Select Input as Port_0_1
Step 5. Add Code to void main(void)
WORD wData;
M8C_EnableGInt;
// Enable Global Interrupts
PGA_1_Start(PGA_1_HIGHPOWER); // Apply power to the CT Block
ADCINC_1_Start(ADCINC_1_HIGHPOWER); // Apply power to the SC Block
ADCINC_1_GetSamples(0);
// Have ADC run continuously
for(;;)
{
while(ADCINC_1_fIsDataAvailable() == 0); // Loop until value ready
wData = ADCINC_1_iClearFlagGetData(); // Clear ADC flag and get data
if(wData>20) // Decision Control to decide which LEDs to be kept
LED_1_On(); // On or Off
else
LED_1_Off();
if(wData>186)
LED_2_On();

60

else
LED_2_Off();
if(wData>352)
LED_3_On();
else
LED_3_Off();
if(wData>518)
LED_4_On();
else
LED_4_Off();
if(wData>684)
LED_5_On();
else
LED_5_Off();
if(wData>850)
LED_6_On();
else
LED_6_Off();
}

Step 6. Build the Project


1. Click on Build->Generate/Build AnalogInputDriveLED Project
Step 7. Programming the PSoC Device
1. Remove the jumpers between J12 and J13
2. Install the MiniProg on J13
3. Click the Programming tab.
4. Click Program at the top of the window. This will open the PSoC
Programmer application.
5. Select MINIProg1/ in the Port pull down list
6. Click Power Cycle under Programming Mode
7. Click the Program button on the top toolbar
8. Wait for the Programming Succeeded at . status message to be
displayed.
Step 8. Test your project on the Demonstration Board
9. Click Toggle Device Power
The red Target Power LED on the MiniProg will light.
Change the Potentiometer setting to observe the LEDs light up

61

Experiment No. 12
Aim: To read analog voltage and display it on LCD using cypress kit
Description:

This project displays a voltage input as a numeric value and as


a bar graph on an LCD display.
Board Section:
Bottom Left
PSoC Device:
CY8C27643
Project Location: \Projects\AnalogInputDriveLCD

Procedure for experiment:


Step 1. Create a new Project
1.
2.
3.
4.
5.

Click on File->New Project


Enter any desired name for the project. Here AnalogInputDriveLCD.
Click Ok
Select the target device from Catalog as CY8C27643-24LFXI
Click Ok. A new project will be created.

Step 2. Add User Modules


1.
2.
3.
4.

Go to the User Module Window.


Right Click on ADCs->ADC. Select Place. Select Single Stage Modulator.
Right Click on Misc Digital->LCD. Select Place.
Right Click on Amplifiers->PGA. Select Place.

Step 3. Set Parameters for User Modules


1. ADCINC_1
Select the parameters as below
a. DataFormat -> Unsigned
b. Resolution -> 10bit
c. Data Clock -> VC1
d. ClockPhase -> Normal
e. PosInput -> ACB00
2. PGA_1
Select the parameters as below
a. Gain -> 1.000
b. Input -> AnalogColumn_InputMux_0
c. Reference -> VSS
d. AnalogBus -> Disable
3. LCD_1
Select the parameters as below
a. LCDPort -> Port_4
b. BarGraph -> Enable
Step 4. Add Code to void main(void)
WORD wData;
BYTE bBarPos

62

M8C_EnableGInt;
// Enable Global Interrupts
PGA_1_Start(PGA_1_LOWPOWER);
ADCINC_1_Start(ADCINC_1_LOWPOWER); // Apply power to the SC Block
ADCINC_1_GetSamples(0); // Have ADC run continuously
LCD_1_Init();
LCD_1_Start();
// Initialize LCD
LCD_1_Position(1,0); // Place LCD cursor at row 0, col 5.
LCD_1_InitBG(LCD_1_SOLID_BG);
while(1)
{
while(ADCINC_1_fIsDataAvailable() == 0); // Loop until value ready
wData = ADCINC_1_iClearFlagGetData(); // Clear ADC flag and get data
bBarPos = ((float)wData/1024)*80;
LCD_1_DrawBG(0,0,16,bBarPos);
LCD_1_Position(1,0);
// Place LCD cursor at row 1, col 0.
LCD_1_PrHexInt(wData);
}

Step 5. Build the Project


Click on Build->Generate/Build AnalogInputDriveLCD Project
Step 6. Programming the PSoC Device
1. Remove the jumpers between J1 and J2
2. Install the MiniProg on J1
3. Click the Programming tab.
4. Click Program at the top of the window. This will open the PSoC
Programmer application.
5. Select MINIProg1/ in the Port pull down list
6. Click Power Cycle under Programming Mode
7. Click the Program button on the top toolbar
8. Wait for the Programming Succeeded at . status message to be
displayed.
Step 7. Test your project on the Demonstration Board
Click Toggle Device Power
The red Target Power LED on the MiniProg will light.
Adjust the potentiometer. The input voltage will be displayed as being
presented on a horizontal bar graph.

63

Experiment No.13
Aim: To become familiar with GCC compiler, WinARM and crossware
development tools. To assemble and run programs using crossware
tools
Write your program in the text editor provided in the Linux and save it with
extension .c for C .cpp for C++ and .s for assembly language
Give following command on command line (Dollar sign $ is shell prompt)
$ g++ test.cpp
This command will compile test.cpp file and generates binary file a.out because
we have not specified target file name
To run the program type:
$./a.out
We can also give output file option like following:
$ g++ -o test.o test.cpp
It will generate output file test.o
To run this file in shell prompt:
$ ./test
Write any c++ program and try above commands
Similarly C programs can be compiled by GNU GCC compiler
$ gcc test.c
$ gcc o test test.c
-c option can be specified to compile only (It will compile but not link)
$ gcc c test.c
Stop after assembling. Do not link
(It will not generate executable file. This will check syntax error in the program)
Another option is S.
$ gcc s test.c
This will compile but not assemble and link the program.
-Wall option turn on all warning levels.
$ gcc Wall W test.c
To turn off all the warning use following command (Actually do not use it because it
will not give any warning which is dangerous during programming)
$ gcc w test.c
$ g++ -w test.cpp (For C++)

64

$ as test.s
This will generate a.out file
$ as o test.o test.s (Assembling)
This will generate object file test.o
$ld o test.elf test.o (Linking)
This will generate HEX file test.elf which can be further programmed into
the chip
$ arm-elf-as o test.o test.s (Assemble)
$ arm-elf-ld o test.elf test.o (Link)
We can also define target cpu
$ arm-elf-as cpu=arm7tdmi o test.o test.s
Write following sequence in assembly language for ARM processor and
simulate it using Crossware tool and verify the result.
Program 1:

LOOP:
Program 2:

LOOP:

HERE:

MOV R1,#0x55
MOV R2,#0x33
ADD R3,R1,R2
SUB R4,R1,R2
B LOOP

MOV R0,#0x64
MOV R1,#0x10
ADD R1,R1,#1
CMP R1,R0
BLT LOOP
B HERE

Write your comments after executing the above programs

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
65

EXPERIMENT NO. 14
Aim: To interface GSM Modem with PC and Microcontroller.
Objectives:

To understand interfacing of GSM modem with PC

To understand interfacing of GSM modem with microcontroller

To issue AT commands using computer and microcontroller

To control electrical device using SMS

Introduction:
A GSM modem is a specialized type of modem which accepts a SIM card,
and operates over a subscription to a mobile operator, just like a mobile
phone. From the mobile operator point of view, a GSM modem is just like a
mobile phone.
When a GSM modem is connected to a computer, this allows the computer
to use the GSM modem to communicate over the mobile network. While
these GSM modems are most frequently used to provide mobile internet
connectivity, many of them can also be used for sending and receiving SMS
and MMS messages.
GSM modems support an extended set of AT commands. These extended AT
commands are defined in the GSM standards. With the extended AT
commands, we can do things like:

Reading, writing and deleting SMS messages.


Sending SMS messages.
Monitoring the signal strength.
Monitoring the charging status and charge level of the battery.
Reading, writing and searching phone book entries.

Procedure:

Connect serial cable between RS-232 connector of GSM modem and


serial port of PC.

Start Hyper terminal (for windows) or serial transmission-reception


program in C.

Give following AT commands and see response form GSM modem

66

[1] Give call from another mobile to GSM and see response
Response: ___________
Meaning:
[2] AT+CPAS=?
Response: ______________
Meaning:
[3] AT+CSQ=?
Response: _______________
Meaning:
[4] AT+CBC
Response: ________________
Meaning:
[5] AT+CMGR=1
Response:
_______________________________________________________________
_______________________________________________________________
Meaning:
_______________________________________________________________
_______________________________________________________________
[6] AT+CBC
Response: ________________
Meaning:
_______________________________________________________________
_______________________________________________________________
[7] AT+CMGL
Response:
_______________________________________________________________
_______________________________________________________________
67

Meaning:
_______________________________________________________________
_______________________________________________________________
Interface GSM modem with microcontroller and issue AT command
GSM modem is interfaced to microcontroller for wireless control
applications. Once we interface GSM modem with the microcontroller, we
can control devices remotely via another mobile handset. We can also send
data collected by microcontroller to remote place through GSM network.
Circuit diagram:
Vcc
10uF

R/W

4
RS

D0

21
22
23

P3.0(RxD)
P3.1(TxD)

P2.0
P2.1
P2.2

10
12
11

D8

11

R1OUT
T1IN

22 PF
X2

18

X1
20

19

22uF

C1-

15

GND

22 PF

C1+

22uF

1 16

39
38
37
36
35
34
33
32

V+

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7

P1.7
P1.6
P1.5
P1.4
P1.3
P1.2
P1.1
P1.0

16

RING

8
7
6
5
4
3
2
1

VCC

D7

R1IN

MAX232

D1
1K X 8

T1OUT
C2+
C2-

RxD
13

14

GSM
MODEM

TxD

5
5

22uF

V-

89C51

15

RST

GND

DB9 Connector
Serial Port of PC

RESET

10K

31
40

150

EA
VCC

10K

22uF

Program:
;This program sends AT+CMGR=1 command to GSM Modem
;It receives response from GSM Modem and display it on LCD
;Mobile Communication Lab GEC Rajkot
RS EQU P2.1
EN EQU P2.0
RW EQU P2.2
_DATA EQU P1
org 00h
ajmp START
org 03h
reti
org 0bh
reti
org 13h
reti
org 1bh
reti

;Start main program


;Vector location for External interrupt 0
;Vector location for Timer 0 interrupt
;Vector location for External interrupt 1
;Vector location for Timer 1 interrupt
68

org 23h
;Vector location for serial Interrupt
ajmp serial
reti
START:
MOV TMOD,#20h
MOV TH1,#0fdh ;Load TH1 with FDh to achieve baud rate 9600
MOV SCON,#50h ;8 bit, 1 stop bit, REN Enabled.
MOV IE,#90h
;Enable serial interrupt
SETB TR1
MOV P1,#00h
;Configure Port 1 as output port
MOV P3,#0ffh
; P3 input port
MOV P0,#00h
; P0 output port
MOV P2,#00h
; P2 output port
MOV A,#38h
;Initialize LCD, 2 lines, 5X7 matrix
lcall command ;Issue command to the LCD
MOV A,#0EH
acall command ;LCD ON, Cursor ON
MOV A,#01H
acall command ;Clear LCD
MOV A,#06H
acall command ;Shift cursor right
MOV A,#01H
acall command ;Clear LCD
acall s_delay
MOV A,#80H
acall command ;Force cursor at begining of the first line
MOV DPTR,#msg1 ;Point to initial message
acall disp_msg
MOV A,#0C0H
acall command
MOV DPTR,#msg2 ;Point to AT Command
send_msg:
acall delay
clr a
movc a,@a+dptr
jz wait
mov sbuf,a
inc dptr
sjmp send_msg
wait:
sjmp wait
command:
push dph
push dpl
mov _data,a
clr RW
acall delay ;Write when when display not busy
clr RS
;Select command register
setb EN
;Set Enable terminal of LCD
nop
nop
clr EN
pop dpl
pop dph
69

ret
disp_data:
push dph
push dpl
clr RW
acall delay
mov _data,a
;Get data for display
setb RS
;Select data register
setb EN
;Enable LCD (Strobe LCD)
nop
nop
clr EN
;Clear Enable and latch data
pop dpl
pop dph
ret
disp_msg:

exit:

acall delay
clr a
movc a,@a+dptr
jz exit
acall disp_data
inc dptr
sjmp disp_msg
ret

serial:
JB TI,transmit
MOV A,SBUF
acall disp_data
CLR RI
RETI

;Return if interrupt is due to transmission


;Get received character into accumulator
;Display received characater
;Clear RI flag

transmit:
CLR TI
RETI
delay:
loop2:

mov r7,#02h
acall s_delay
djnz r7,loop2
ret

s_delay:
loop1:

msg1:
msg2:

mov R6,#0ffh
djnz R6,loop1
ret
db 'GEC RAJKOT',0
db 'AT+CMGR=1',0
END

:: WORKSHEET ::
70

[1] Modify program to dial number 9374836390 automatically when switch


connected at external interrupt 0 pressed (No need to write LCD routine)

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

71

[2] Write program to flash all LEDs connected at port P0, when somebody
give call to GSM Modem.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
72

[3] Draw interfacing diagram to connect 230V Single phase AC motor with
port pin P2.7. Write a program so that motor should start when incoming
call is coming for the SIM used in GSM modem.
Interfacing diagram:

Program:

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
73

:: ASSIGNMENT ::
[1] What is meaning of load and store architecture?
[2] What are the performance matrices for DSP processors?
[3] Why interrupt response is fast in ARM processor?
[4] What is the meaning of T and M in ARM7TDMI architecture?
[5]What is the difference between fixed point and floating point
representation? Explain IEEE floating point format.
[6] Explain how three stage pipeline works
[7] What are the variants of ARM processor?
[8] What do you mean by hardwired implementation?
[9] Which technology is used in ARM7TDMI? What is typical die size?
[10] What is CAN?
[11] Which ARM chip you have used in your practical? What is the size of
RAM and ROM in that chip ?
[12] Give example of two data transfer instructions
[13] What is post indexing and pre indexing?
[14]How exception handling is done in ARM?
[15]Explain branch operations in ARM
[16] Explain instructions LDR r4,[r5,#8]! And LDR r4,[r5,#8]
[17] What is difference between ASR and LSR?
[18] What is the difference between real time operating system and
general purpose operating system?
[19] What is the difference between CISC and RISC processor?
[20] ARM processor is based on which architecture?
[21] What is CPSR and SPSR?
[22] What is the difference between ARM processor and DSP processor?
[23] Explain following instructions:
[a] RSC R1,R2 [b] ADD R1,R2,R2,LSL#1 [c] MLA R1,R2,R3,R4
[24] What is real time operating system?
[25] List applications of Embedded systems
[26] What is watchdog timer?
[27] What is brown out reset?
[28] Write commands to compile C language file and assemble assembly
language file using GNU C compiler and GNU assembler.
[29] What is priority inversion? How it occurs?
[30] Explain deadlock situation. How to prevent deadlock situation?
[31] What is round-robbin scheduling? Is it suitable for real time
applications?
[32] What is job of scheduler?
[33] What is context switching?
[34] What is yield?
[35] What are the special functions of R13, R14 and R15 in ARM
processor?

Note: Write answers in separate notebook

74

Das könnte Ihnen auch gefallen