embs final manual

89
SRINIVASAN ENGINEERING COLLEGE DEPT OF ELECTRONICS AND COMMUNICATION ENGINEERING ANNA UNIVERSITY TRICHY REGULATION 2008 IV YEAR/ VII SEMESTER EC1404 EMBEDDED SYSSTEMS LABORATORY LAB MANUAL ISSUE:01 REVISION:00 APPROVED BY PREPARED BY Prof. B. REVATHI C.SATHISH KUMAR, Assistant Professor. HOD/ECE R.KEERTHANA, Assistant Professor.

Upload: phaniabk

Post on 30-Dec-2015

45 views

Category:

Documents


2 download

DESCRIPTION

emblab, emlabs,embedded lab

TRANSCRIPT

Page 1: Embs Final Manual

SRINIVASAN ENGINEERING COLLEGE

DEPT OF ELECTRONICS AND COMMUNICATION ENGINEERING

ANNA UNIVERSITY TRICHY

REGULATION 2008

IV YEAR/ VII SEMESTER

EC1404 – EMBEDDED SYSSTEMS LABORATORY

LAB MANUAL

ISSUE:01 REVISION:00

APPROVED BY PREPARED BY

Prof. B. REVATHI C.SATHISH KUMAR, Assistant Professor.

HOD/ECE R.KEERTHANA, Assistant Professor.

Page 2: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 2

Preface

This laboratory manual is prepared by the Department of Electronics and communication

engineering for Embedded systems (EC1404). This lab manual can be used as instructional book for

students, staff and instructors to assist in performing and understanding the experiments. This

manual will be available in electronic form from College’s official website, for the betterment of

students.

Acknowledgement

We would like to express our profound gratitude and deep regards to the support offered

by the Chairman Shri. A.Srinivasan. We also take this opportunity to express a deep sense of

gratitude to our Principal Dr.B.Karthikeyan,M.E, Ph.D, for his valuable information and

guidance, which helped us in completing this task through various stages. We extend our hearty

thanks to our head of the department Prof.B.Revathi M.E, (Ph.D), for her constant

encouragement and constructive comments.

Finally the valuable comments from fellow faculty and assistance provided by the

department are highly acknowledged.

Page 3: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 3

INDEX

S.No TOPIC PAGE

NO

1 Syllabus 4

2 Lab Course Handout 5

3 Experiments

1. Study of ARM evaluation system 7

2. Interfacing ADC and DAC 13

3. Interfacing Keyboard and LCD 15

4. Interfacing EEPROM and Interrupt 22

5. Interfacing Read toggle switch and Relay 27

6. Interfacing LED and PWM 29

7. Interfacing Seven segment LED 33

8. Interfacing Real time clock and Serial port 37

9. Interfacing Stepper motor and Temparature sensor 42

10. Flashing two LEDs 48

11. Reading LM35 and plotting in LCD. 51

12. Two messages on LCD. 54

13. Serial port 57

14. Mail box 61

15. Design and implementation of Traffic light controller in FPGA

65

16. Design and implementation of 4 bit Updown counter in FPGA

72

17. Interrupt processing performance characterstics of ARM& FPGA

77

18. Hardware and software partioning between FPGA and ARM

80

19. Implementation of Zigbee protocol with ARM 7

86

Page 4: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 4

SYLLABUS

EC 1404 – EMBEDDED SYSTEMS LABORATORY

LIST OF EXPERIMENTS

• Open source software such as linux flavors will be used. Ability to use industry

standard tools for verification and validation

• High level language programming (C, C++) and porting it on a processor

• Create FSM of a typical application and implement on an FPGA

• Application development, download partition between FPGA and ARM on

performance characteristics

• Application development. Hardware and software partitioning

• Projects (implementation of a wireless communication protocol on an embedded

system).

Total: 45

LIST OF EQUIPMENTS

(For a batch of 30 students)

Sl. No. Description of Equipments Quantity

1. Embedded trainer kits with ARM board 3

2. Embedded trainer kits suitable for wireless

communication 3

3. With adequate quantities of Hardware, software and consumables

Page 5: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 5

LAB COURSE HANDOUT

Subject code : EC 1404

Subject Title : Embedded systems Lab

Staff name : C.Sathish kumar & R.Keerthana

Scope and Objective of the Subject: To write the program and verify the output in ARM & FPGA kit.

Course Plan / Schedule:

S.No Topics to be covered Learning objectives Page No*

No. of hours

1 Study of ARM evaluation system To study of ARM evaluation kit 7 3 hrs

2 Interfacing ADC and DAC To interface ADC & DAC using

ARM evaluation kit 13 3hrs

3 Interfacing Keyboard and LCD To interface Keyboard and LCD

using ARM evaluation kit 15 3hrs

4 Interfacing EEPROM and Interrupt To interface Keyboard and LCD

using ARM evaluation kit 22 3hrs

5 Interfacing Read toggle switch and Relay To interface Keyboard and LCD

using ARM evaluation kit 27 3hrs

6 Interfacing LED and PWM To interface Keyboard and LCD

using ARM evaluation kit 29 3hrs

7 Interfacing Seven segment LED To interface Keyboard and LCD

using ARM evaluation kit 33 3hrs

8 Interfacing Real time clock and Serial port To interface Keyboard and LCD

using ARM evaluation kit 37 3hrs

9 Interfacing Stepper motor and Temparature

sensor

To interface Keyboard and LCD

using ARM evaluation kit 42 3hrs

10 Two Flashing LEDs Flashing Two LEDs in RTOS 48 3hrs

11 Reading LM35 and plotting in LCD. Reading LM35 and observe the

graph in LCD 51 3hrs

12 Two messages on LCD. To observe two messages in LCD

display 54

13 Serial port To connect serial port in ARM

evaluation and transfer the data 57 3hrs

14 Mail box To connect mail box in ARM kit

and transfer data 61 3hrs

15 Design and implementation of Traffic light

controller in FPGA

To write a program for traffic light

controller using FPGA kit 65 3hrs

16 Design and implementation of 4 bit Updown

counter in FPGA

To design and implementation of 4

Bit Updown counter in FPGA kit 72 3hrs

17 Interrupt processing performance characterstics

of ARM& FPGA

To create an interrupt and perform

the characterstics of ARM & FPGA 77 3hrs

Page 6: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 6

18 Hardware and software partioning between

FPGA and ARM

To make Hardware and software

portioning between ARM & FPGA 80 3hrs

19 Implementation of Zigbee protocol with ARM 7

To Implimentation of Zigbee

protocol with ARM 86

*-As in Lab Manual

Evaluation scheme – Internal Assessment

Timings for chamber consultation: Students should contact the Course Instructor in her/his

chamber during lunch break.

STUDENTS GUIDELINES

There are 3 hours allocated to a laboratory session in Embedded systems Lab. It is a necessary

part of the course at which attendance is compulsory.Here are some guidelines to help you

perform the Programs and to submit the reports:

Read all instructions carefully and proceed according to that.

1. Ask the faculty if you are unsure of any concept.

2. Write the program, and give connections.

3. Get the output from the kit.

4. After completing the experiment complete the observation and get signature from the

staff.

5. Before coming to next lab make sure that you complete the record and get sign from the

faculty.

STAFF SIGNATURE HOD

EC

No.

Evaluation

Components

Duration Weightage

1 Observation Continuous 20%

2 Record Continuous 30%

3 Attendance Continuous 30%

4 Model lab 3hr 20%

Page 7: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 7

STUDY OF ARM EVALUATION SYSTEM

AIM:

To study ARM evaluation system.

DESCRIPTION:

The top view NXP 2148 ARM evaluation system gives the required hardware platform to study

and apply on-chip peripheral function of the LPC 2148 microcontroller. The hardware is complete to

provide all the required interfacing facilities on board to make the task easy and motivating one.

HARDWARE DESCRIPTION:

The ARM evaluation board has following modules for studying the internal peripherals of the device.

NXP LPC2148 operating at 60 MHz

8 numbers of point LEDs.

8 numbers of toggle switches.

4 digits of seven segment multiplexed display interfaced using IIC bus.

2 lines by 16 characters LCD module.

4 X 4 keyboard matrix

On-board buzzer

IIC RTC with battery backup and IIC EEPROM.

On-board variable voltage source for ADC input.

On-board temperature sensor using LM35.

On-board stepper motor operating at 5v.

Two numbers of on-board 5v relay with LED indicators.

Serial port facility.

USB facility

128 X 64 pixels LCD

5v power supply.

MICROCONTROLLER SECTION:

The microcontroller ARM NXP 2148 operates with external crystal of 10MHz.this section

consists of the controller device, reset circuit, oscillator circuit.LPC2148 ARM controller can be operated

in four different modes namely trace, debug, program and normal mode. On-board jumpers JP1, JP2 and

JP3 are used to select the operating mode for the controller.

NORMAL OPERATION:

Disable all the three jumpers JP1, JP2 and JP3 to select normal mode operation. Controller

executes user application program present in the flash during this mode.

Page 8: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 8

IN SYSTEM PROGRAMMING OPERATION:

Enable jumperJP3 and disable jumpers JP1 and JP2 to select in-system programming (ISP) mode.

After selecting jumper, press reset button S1 in evaluation board once to activate ISP mode. LED D27

glows to indicate the ISP mode.

TRACE MODE:

Enable jumper JP2and disable jumpers JP1 and JP3 to select the trace mode. After selecting

jumper, press reset button once to activate trace mode.in this mode program debugging can be performed

through trace port line.

DEBUG MODE:

LPC 2148 has facility to debug the program execution through dedicated JTAG debug port.

Enable jumper JP1 and disable JP2 and JP3 jumper to select debug mode. After selecting jumper, press

reset button once to activate debug mode. Connect JTAG emulator through connecter P6 to debug

program execution in real time.

EIGHT NUMBERS OF POINT LEDs:

Eight numbers of point LEDs are interfaced to the microcontroller through the common data bus

linesDB0 toDB7. Since common data bus lines DB0 –DB7 are used for the interface, a eight-bit

latch74HC273 is used to drive the LEDs.

EIGHT NUMBERS OF TOGGLE SWITCHES:

The toggle switches are interfaced to the microcontroller through the common data bus line DB0

toDB7. Since common data bus lines DB0 –DB7 are used for the interface, a eight-bit buffer 74HC244 is

used to interface the switches with data bus.

FOUR DIGITS OF SEVEN SEGMENT MULTIPLEXER DISPLAY:

The display module consists of four number of common anode green colour displays. The

displays are connected to the IIC bus lines of the controller through a four digit LED driver with IIC

interface. IC SAA1064 is a four digit LED driver with IIC interface. The IIC channel0 of the controller is

used here.

TWO LINES BY 16 CHARACTERS LCD MODULE:

A 2 line X 16 characters LCD module is provide on the evaluation board. The data lines are

connected to the data bus DB0-DB7.

4 X 4 KEYBOARD MATRIX:

16 push button switches are provided to get a 4X 4 keyboard n matrix format. The Keyboard has

4 row and 4 colums.The rows are connected to port lines P0.15, P0.16, P0.17 and P0.18. The column

Page 9: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 9

lines are connected to P0.11, P0.12, P0.13 and P0.14. All the four column lines are pulled up to Vcc using

10K resistors.

BUZZER:

A buzzer is available on board and it driven by a NPN transistor. The base of the transistor is

connected to the port line P0.25. This port line is also the output of the 10 bit DAC, the on chip peripheral

of the controller. Hence the buzzer can be used to test the peripheral, DAC of the controller. A high level

to the base of the transistor switches the buzzer on.

IIC RTC WITH BATTERY BACKUP AND EEPROM:

The IIC devices IIC RAM and IIC EEPROM are provided on board to study the IIC interface.

Both the devices are connected to same two wire bus, where the seven segment LED driver (SAA1064) is

connected. IIC devices are connected to the IIC peripheral of the controller board.

ANALOG VOLTAGE SOURCE TO EXPERIMENT WITH ADC:

A variable analog voltage source is made available on the board to experiment with ADC part of

the microcontroller. The voltage source is connecting to the P0.29, which is the channel 2 of the ADC. A

potentiometer is connected to the voltage to adjust the input voltage to ADC.

TEMPERATURE SENSOR:

The LM35 is precision integrated circuit temperature sensor, whose output voltage is linearly

proportional to the Celsius temperature. Hence LM35 has advantage over other linear temperature sensors

calibrated in degree kelvin, as the user is not required to subtract a large constant voltage from its output

to obtain convenient centigrade reading.

STEPPER MOTOR:

A unipolar stepper motor is connected on-board for experimental purpose. For each winding, 2

Darlington drivers of IC ULN2803 are used as power driver. Each Darlington driver IC is capable of

sinking 500mA current. Hence two Darlington drivers are connected in parallel to increase the current

capacity to 1A

5V RELAY:

Two number of 5v relays are used in the board for experimental purpose. The relays are driven by

the NPN transistors BC547. The port lines used for the driving the relays are P0.30 and P0.10

SERIAL PORT:

The controller has two on chip serial port. The serial port 0 of the controller is used for

programming the flash of the controller. The serial port 1 is terminated separately for user.

Page 10: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 10

USB:

USB port lines of the microcontroller is terminated in a separate connected marked as USB1. For

programming purpose another USB connector (USB 2) is provided. This can be connected to the USB

port of the PC for programming purpose.

GRAPICS LCD:

A graphics LCD with 128X64 pixels is interfaced on the evaluation board. The data lines are

connect to the data bus DB0-DB7. The control lines RS is connect to the port line P1.25. The R/W line is

connecting to the port line P1.24. The CS line of the LCD is controlled by the decoder IC 74HC138 (U3).

The port lines used by the decoder are set to correct levels to enable the LCD. The port linesP0.19, P0.20

is set to 0 and the port line P0.22 is set to 1 level. The active level of the decoder output line CS4_GLCD

will be 0.since the LCD enable line is at active high level, an inversion of the CS4_GLCD is carried out

using a NAND gate.

RESULT:

Thus the ARM evaluation system is studied.

Page 11: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 11

PROGRAMMING IN EMBEDDED C AND PORTING IT ON THE PROCESSOR

PROCEDURE

1. Open Embest IDE software

2. Go to file->new workspace. a window will appear. In that window give the project

name & the location to be stored.

3. Copy the support file from the original folder to the created folder

4. Right click on project source files & click on add files to folder->select files & add it.

5. Go to file -> new -> type the program & save the program with the extension .c

6. Click project ->settings

In processor:

CPU mode: ARM 7

CPU family: ARM 7

Member: ARM 7

Build tools: GNC tools for ARM

In remote:

Remote device: SIM ARM 7

In compiler:

Category: target specific option

Click on little endian

Specify the name of the target: ARM 7TDMI

In assembler:

Category: target specific option

Click on little endian

In linker:

Category : general

Linker script file-> browse->select flash.id

Page 12: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 12

Category : image entry option

Select vector.0

Category : code generation operation

Click->link little endian object

7. Then click ok

8. Click build->rebuild all

9. Click tools->elf to hex

10. Minimize the window

11. Open flash magic.

12. Click browse ->select file name.hex from your project -> open

13. Switch on the kit -> press reset button -> click start in the flash magic window

14. After download finished, switch off the kit-> press reset button.

Output will be executed in the kit.

Page 13: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 13

INTERFACING ADC AND DAC

AIM:

To write an embedded C program for interfacing ADC and DAC and verify the output in the

ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

ADC:

Step 1: Start the program

Step 2: Initialize the LCD.

Step 3: intialise the ADC.set the port line P0.29 to have the special function ADC input, using the

PINSEL1 register

Step 4: call the routine message_display1 to display message”ADC demo” on line 1 of the LCD.

Call the routine message_display2 to display message”channel2;” on line 2 of the LCD.

Step 5:a)set the control register of the ADC with the following specifications;

Channel number=2;

ADC clock=3 MHz.

Select burst mode,

Conversion clocks required =11 clocks

b) start the ADC conversion

Step 6: wait for EOC signal. Once the EOC signal is obtained read the ADC valve.

Step 7: Display the ADC value on the LCD.

Repeat from step 4.

Step8: Stop the program

DAC:

Step 1: Start the program

Step 2: Initialize the DAC.Set the port line P0.25 to have the special function DAC, using the

PINSEL1 register

Step 3: Set the value 0 to DAC

Call a delay

Step 4: Set the value 0xFFC0 to DAC

Call a delay.

Step 5: Repeat from step 2.

Step 6: Stop the program

PROGRAM:

ADC

#include "LPC214x.h" /* LPC21xx definitions */

int ReadADC(char ChannelNumber);

int main(void)

{

int a;

unsigned char Channel = 2;

PINSEL1 = 0x04000000; // Select ADC to pin P0.29

InitializeLCD(); // Initialize LCD

DisplayLCD(0," ADC DEMO "); // Display message

DisplayLCD(1,"Channel 2: "); // Display message

while(1)

Page 14: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 14

{

a=ReadADC(Channel); // Read ADC channel 2

DisplayLCD2Digit(1,10, (a >> 8)); // Display it on 2nd line of LCD

DisplayLCD2Digit(1,12, (a & 0xff));

LCDDelay1600();

}

} //Read ADC data from given channel number

int ReadADC(char ChannelNumber)

{

int val,ch;

ch = 1<<ChannelNumber;

AD0CR = 0x00210400 | ch; // Setup A/D: 10-bit AIN @ 3MHz

AD0CR |= 0x01000000; // Start A/D Conversion

do

{

val = AD0DR2; // Read A/D Data Register

}

while ((val & 0x80000000) == 0); // Wait for the conversion to

complete

val = ((val >> 6) & 0x03FF); // Extract the A/D result

AD0CR &= ~0x01000000; // Stop A/D Conversion

return(val); // Return the Data Read

}

DAC

#include "LPC214X.H"

void InitializeDAC(void);

int main (void)

{ long c;

InitializeDAC(); //Initialize DAC

while(1)

{ DACR = 0x00; // Set DAC = 0

for(c=0;c<0xf0000;c++); // Delay

DACR = 0x0000ffc0; // Set DAC = (0x3ff << 6)

for(c=0;c<0xf0000;c++); // Delay

}

}

void InitializeDAC(void)

{

PINSEL1 = 0x00080000; // Set P0.25 for DAC output

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for interfacing ADC and DAC is written and executed. The output is

verified in the ARM kit.

Page 15: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 15

INTERFACING KEYBOARD AND LCD

AIM:

To write an embedded C program for interfacing keyboard and LCD and to verify the output in

the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

KEYBOARD:

Step 1: Start the program

Step 2:a)Initialize the IO lines

b) Initialize LCD

Step 3: Display the messages on both lines of LCD

Step 4: Initialize keyboard lines

a) Set P0.11 to P0.14 as input lines

b) Set P0.15 to P0.18 as output lines

Step 5: Initialize timer 0 to generate interrupt for every millisecond

Step 6: Check the keyboard flag for 1 level. Read the key from the keyboard code. Clear the

Keyboard flag variable.

Step 7: Display the pressed key valve on the 2 line of the LCD using display byte routine.

Repeat from step 5

Step 8: Stop the program.

LCD:

Step 1: Start the program

Step 2: Initialize the IO port lines

Step 3: a) IntializeP0.19 (A0), P0.20 (A1), P0.22 (A2) as output port.

b) Initialize data lines P.16 (DB0) to P1.23 (DB7) as output lines

c) Initialize the control lines of LCD, P1.24(R/W) and P 1.25(RS) as output lines.

Step 4: initialize LCD

Step 5:a)send command 0x80 to display string on line 1 of LCD.

b) Send character one by one until all 16 characters are displayed.

Step 6:a)send command 0xC0 to display string on line 2 of LCD.

b) Send character one by one until all 16 characters are displayed.

c)halt

Step 7:Stop the program.

PROGRAM:

KEYBOARD

#include "LPC214x.H" // LPC214x definitions

extern void irq_T0(void); // Interrupt process

void T0_Srv(void);

void InitializeTIMER0(void);

void InitializeKeyboard(void);

void ScanKeyboard(void);

unsigned char ReadColumn(void);

void SetRow(unsigned char dat);

Page 16: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 16

void DisplayLCD(char LineNumber,char *Message);

char KeyboardFlag;

unsigned char KeyboardCode=0;

char Counter=0,ReleaseFlag=0,StatusFlag=0,IdentificationFlag=0;

int main(void)

{

KeyboardFlag =0; //Clear keyboard flag

InitializeLCD();

IODIR0 |= 0x00078000; //Initialize Port lines for keyboard

InitializeTIMER0(); //Initialize TIMER0, Keyboard scan timer

DisplayLCD(0,"Matrix Keyboard ");

DisplayLCD(1,"Key Pressed: ");

while(1)

{

if(KeyboardFlag ==1) //wait for key press

{ DisplayLCD2Digit(1,12,KeyboardCode);

KeyboardFlag=0; //reset keyboard flag

}

}

}

//Scan keyboard

void ScanKeyboard(void)

{

unsigned char a,b,c;

unsigned char f;

if(ReleaseFlag == 1)

{ //debounce time for release

Counter++;

if(Counter ==10)

{ ReleaseFlag = 0;

}

return;

}

if(StatusFlag ==1)

{

if(IdentificationFlag == 1)

{ //Wait for key Release

SetRow(0x00);

if(ReadColumn() == 0x0f) //Check the keyboard status

{ //No key pressed

Counter = 0;

ReleaseFlag = 1;

IdentificationFlag = 0;

StatusFlag = 0;

} return;

}else

{

Counter++;

if(Counter == 10)

{ //Check key press

Page 17: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 17

KeyboardCode = 0;

SetRow(0x00); //Set all rows to 0

if(ReadColumn() != 0x0f) //Read column levels

{ //any one key pressed

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

{ //Row Setting

f = ~(0x01 << a); //set one row to 0

SetRow(f);

b = ReadColumn(); //read column levels

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

{ //Column checking

f = 0x01 << c;

if(( b & f) == 0)

{ //Pressed Key identified

IdentificationFlag = 1;

StatusFlag = 1;

KeyboardFlag=1;

KeyboardCode &= 0x0f;

return;

}

KeyboardCode++;

}

}

}

IdentificationFlag = 0;

StatusFlag = 0;

return;

}

else

{

return;

}

}

}

SetRow(0x00);

if(ReadColumn() != 0x0f) //Check for any key press

{ // key press detected

Counter=0;

StatusFlag=1;

IdentificationFlag=0;

}

}

/* Sets the given data to Row */

void SetRow(unsigned char dat)

{

if(dat & 0x01)

IOSET0 = 0x00008000;

else

IOCLR0 = 0x00008000;

if(dat & 0x02)

Page 18: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 18

IOSET0 = 0x00010000;

else

IOCLR0 = 0x00010000;

if(dat & 0x04)

IOSET0 = 0x00020000;

else

IOCLR0 = 0x00020000;

if(dat & 0x08)

IOSET0 = 0x00040000;

else

IOCLR0 = 0x00040000;

}

/* Reads the Column status and returns the same */

unsigned char ReadColumn(void)

{

unsigned char a=0;

a = (IOPIN0>>11) & 0x0f;

return(a);

}

//Initialise timer0 used in keyboard scanning

void InitializeTIMER0(void)

{ //for 1msec delay

VPBDIV = 0x00000002; //Configure the VPB divider

//CCLK/2 = PCLK = 30MHz

T0PR = 0x0000012B; //Load prescaler = 300, 30MHz/300=100KHz

T0TCR = 0x00000002; //Reset counter and prescaler

T0MCR = 0x00000003; //On match reset the counter and

generate an interrupt

T0MR0 = 0x00000064; //Set the cycle time, 100KHZ/100 = 1KHZ =

1ms

T0TCR = 0x00000001; //enable timer

VICVectAddr4 = (unsigned long)irq_T0;//Set the timer ISR vector address

VICVectCntl4 = 0x00000024; //Set channel

VICIntEnable |= 0x00000010; //Enable the interrupt

}

/* Timer0 interrupt service routine */

void T0_Srv(void)

{

ScanKeyboard(); //Check and update keyboard

status

T0IR |= 0x00000001; //Clear match 0 interrupt

VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

}

LCD

#include "LPC214x.h" /* LPC214x definitions */

void WriteCommandLCD(unsigned char CommandByte);

void WriteDataLCD(unsigned char DataByte);

void LCDDelay(void);

void LCDDelay1600(void);

Page 19: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 19

void SendByte(unsigned char Value);

void InitializeLCD();

void DataAddressDirection(void);

void DisplayLCD(char LineNumber,char *Message);

void DisplayLCD2Digit(char LineNumber,char CharPosition,char Data);

int main(void)

{

InitializeLCD(); //Initialize graphics LCD

DisplayLCD(0," NXP2148 ARM ");

DisplayLCD(1,"Evaluatin System");

while(1);

}

/* Initializes LCD */

void InitializeLCD()

{

DataAddressDirection();

IOSET0 = 0x00580000; // Set A0, A1, A2

WriteCommandLCD(0x38); //Command to select 8 bit interface

LCDDelay1600();

WriteCommandLCD(0x38); //Command to select 8 bit interface

LCDDelay(); //Small delay

WriteCommandLCD(0x38); //Command to select 8 bit interface

LCDDelay();

WriteCommandLCD(0x0c); //Command to on cursor,blink cursor

LCDDelay();

WriteCommandLCD(0x06); //Command for setting entry mode

LCDDelay();

WriteCommandLCD(0x01); //Clear LCD

LCDDelay1600();

}

/* Writes a command byte to LCD */

void WriteCommandLCD(unsigned char CommandByte)

{

IOCLR1 = 0x03000000; // Clear RS and RW

SendByte(CommandByte);

LCDDelay(); //Small delay

}

/* Send a byte of data to LCD */

void SendByte(unsigned char Value)

{

IOPIN1 &= 0xff00ffff;

IOPIN1 |= Value << 16; /* Write data to data bus */

IOSET0 = 0x00100000; /* Generate chip enable signal for LCD */

IOCLR0 = 0x00480000;

LCDDelay();

IOSET0 = 0x00580000; /* Set A0, A1 & A2 to disable LCD */

LCDDelay();

}

/* Writes a Data byte to LCD */

void WriteDataLCD(unsigned char DataByte)

Page 20: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 20

{

IOCLR1 = 0x01000000; /* clear RW */

IOSET1 = 0x02000000; /* Set RS */

SendByte(DataByte);

LCDDelay(); //Small delay

}

/* Small delay */

void LCDDelay(void)

{

int a;

for(a=0;a<0x1000;a++);

}

/* Big delay */

void LCDDelay1600(void)

{

long a;

for(a=0;a<0x050000;a++);

}

/* Makes cursor visible */

void CursorON(void)

{

WriteCommandLCD(0x0f); //Command to switch on cursor

}

/* Makes cursor invisible */

void CursorOFF(void)

{

WriteCommandLCD(0x0c); //Command to switch off cursor

}

void DisplayLCD2Digit(char LineNumber,char CharPosition,char Data)

{

unsigned char a;

if(LineNumber ==0)

{ //First Line

a = 0x80; //command for first line selection

}

else

{ //Second line

a = 0xc0; //command for second line selection

}

a+=(CharPosition); //Calculate the character position

WriteCommandLCD(a); //Send command to select the given digit

if( (Data & 0xf0) < 0xa0) //Check for less than 0xa0

{

a = ((Data & 0xf0) >> 4) + '0'; //Get the ASCII character

}

else

{

a = ((Data & 0xf0) >> 4) + 'A'- 0x0a;

Page 21: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 21

//Get the ASCII

character

}

WriteDataLCD(a); //Display the first character

if( (Data & 0x0f) < 0x0a) //Check for less tham 0x0a

{

a = (Data & 0x0f)+'0'; //Get the ASCII character

}

else

{

a = (Data & 0x0f)+'A' - 0x0a; //Get the ASCII character

}

WriteDataLCD(a);

}

/* Displays a message on LCD */

void DisplayLCD(char LineNumber,char *Message)

{

int a;

if(LineNumber ==0)

{ //First Line

WriteCommandLCD(0x80); //Select the first line

}

else

{ //Second line

WriteCommandLCD(0xc0); //Select the second line

}

while(*Message)

{

WriteDataLCD(*Message); //Display a character

Message++; //Increment pointer

}

}

void DataAddressDirection(void)

{

IODIR0 |= 0x00580000; // Set A0, A1, A2 output lines

IODIR1 |= 0x03ff0000;

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for for interfacing keyboard and LCD is written and executed. The

output is verified in the ARM kit.

Page 22: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 22

INTERFACING EEPROM AND INTERRUPT

AIM:

To write an embedded C program for interfacing EEPROM and interrupt and to verify the

output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

EEPROM:

Step 1: Start the program

Step 2: Initialize the LCD

Step 3: Initialize IIC interface

Step 4:a)Set the address location of EEPROM as 0x00

b) Set the data as 0x12

c) Call routine to write byte to EEPROM.

d) Call the delay

Step 5:a)Set the address as 0x00 for reading from EEPROM

b) Call routine to read from EEPROM

Step 6:a)Display the address

b) Halt

Step 7: Stop the program

INTERRUPT:

Step 1: Start the program

Step 2: a) Initialize the IO lines

b) Initialize an eight bit counter to 0.

Step 3: a) Allocate vector interrupt controller slot 0 for EINT0 by programming VICVectCntIO

Register with 0x2e.

b) Allocate vector interrupt controller slot 1 for EINT2 by programming VICVectCntI1

Register with 0x30.

c) VICVectAddr0 register is initialized with address of the interrupt service routine for

EINT0

d) ) VICVectAddr1 register is initialized with address of the interrupt service routine for

EINT2

e) Slot 1 and slot 0 are enabled by writing VICIntEnable register with valve 0x00014000.

Step 4: Stop the program

Page 23: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 23

PROGRAM:

EEPROM

#include "LPC214x.h" // LPC21xx definitions

extern void irq_iic(void); // interrupt process

void Iic_Srv(void);

void InitializeIIC(void);

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data); //Background call to start master send and receive byte transfers

void WriteByte(int addr,unsigned char *data);

void ReadByte(int addr,unsigned char *data);

void delay2(void);

unsigned char *I2CData,

I2Counter,

I2CAddress,

MemAddress,

lock;

int main(void)

{

unsigned char Data=0, Address;

InitializeLCD(); // Initialize LCD

InitializeIIC(); // Initialize IIC Interface

DisplayLCD(0," EEPROM DEMO "); // Display message

DisplayLCD(1,"ADDR: Data: ");

Data = 0x12;

Address = 0x00;

WriteByte(Address,&Data); // Write Data to EEPROM

Data = 0;

ReadByte(Address,&Data); // Read Data from EEPROM

DisplayLCD2Digit(1,5,Address); // Display

DisplayLCD2Digit(1,14,Data);

while(1);

}

void InitializeIIC(void)

{

lock = 0; //Initilise the lock flag

VICVectCntl1 = 0x00000029; //select a priority slot for a given

interrupt

VICVectAddr1 = (unsigned long)irq_iic; //pass the address of the IRQ into the

VIC slot

VICIntEnable = 0x00000200; //enable interrupt

PINSEL0 |= 0x50; //Switch GPIO to I2C pins

I2C0SCLH = 0x104;

I2C0SCLL = 0x104;

}

//Write given data in EEPROM, address(10bit) specified by addr

void WriteByte(int addr,unsigned char *data)

{

I2CTransferByte(0xAc,addr,1,&data[0]); //write data to the I2C Memory

while(lock==1);

delay2();

Page 24: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 24

}

//Read data from EEPROM,addr-10bit EEPROM address

void ReadByte(int addr,unsigned char *data)

{

I2CTransferByte(0xAc,addr,0,&data[0]); //set address to addr

I2CTransferByte(0xAd,addr,1,&data[0]); //read data from the I2C Memory

while(lock==1);

}

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data )

{

while(lock == 1) //Wait for interrupt to signal end of I2C

activity

{

;

}

lock = 1; //Set I2C bus as active

//Place address and data in Globals to be used by the interrupt

I2CAddress = I2CAddr;

I2CData = data;

I2Counter = count;

MemAddress = MemAddr;

I2C0CONCLR = 0x000000FF; //Clear all I2C settings

I2C0CONSET = 0x00000040; //Enable the I2C interface

I2C0CONSET = 0x00000020; //Start condition

}

void Iic_Srv(void) //I2C interrupt routine

{

switch (I2C0STAT) //Read result code and switch to next

action

{

// Start and Send byte conditions

case ( 0x08): //Start bit

I2C0CONCLR = 0x20; //Clear start bit

I2C0DAT = I2CAddress; //Send address and write bit

break;

case (0x18): //Slave address+W, ACK

I2C0DAT = MemAddress; //Write Memory start address to tx register

break;

case (0x20): //Salve address +W, Not ACK

I2C0DAT = I2CAddress; //Resend address and write bi

break;

case (0x28):

if(I2Counter > 0) //Data sent, Ack

{

I2Counter--;

I2C0DAT = *I2CData; //Write data to tx register

I2CData++;

}

Page 25: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 25

else

{

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

case (0x30) : //Data sent, NOT Ack

I2C0DAT = *I2CData; //Write data to tx register

break; //Receive byte conditions

case (0x40) : //Slave Address +R, ACK

I2C0CONSET = 0x04; //Enable ACK for data byte

break;

case (0x48) : //Slave Address +R, Not Ack

I2C0CONSET = 0x20; //Resend Start condition

break;

case (0x50) : //Data Received, ACK

if(--I2Counter>0)

{

*I2CData = I2C0DAT;

I2CData++;

}

else

{

*I2CData = I2C0DAT;

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

case (0x58): //Data Received, Not Ack

I2C0CONSET = 0x20; // Resend Start condition

break;

default :

break;

}

I2C0CONCLR = 0x08; //Clear I2C interrupt flag

VICVectAddr = 0x00000000; //Clear interrupt in

} //Small delay

void delay2(void)

{

long int i;

i=0xffff;

while(i)

{

i--;

}

}

INTERRUPT

#include "LPC214x.H" /* LPC214x definitions */

extern void irq_INT0(void); //interrupt process

extern void irq_INT2(void); //interrupt process

Page 26: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 26

void INT0_Srv(void);

void INT2_Srv(void);

void InitializeInterrupt(void);

unsigned char Counter=0;

int main(void)

{

IODIR0 |= 0x00780000; // Direction setting for Address lines A0, A1 and A2

IODIR1 |= 0x00ff0000; // Direction setting for Data lines D0 to D7

IOCLR0 = 0x00780000; // Clear A0, A1, A2

InitializeInterrupt(); // Initialize interrupts

while(1);

} //Initialize Interrupt

void InitializeInterrupt(void)

{

PINSEL0 = 0x0000C00C;

EXTMODE = 0x05; // edge select enabled for interrupts EINT0 and EINT2

VICVectAddr1 = (unsigned long)irq_INT2; // Set the Interrupt0 ISR vector address

VICVectAddr0 = (unsigned long)irq_INT0; // Set the Interrupt2 ISR vector address

VICVectCntl0 = 0x0000002e; // Set channel 0 to EINT0

VICVectCntl1 = 0x00000030; // Set channel 1 to EINT2

VICIntEnable = 0x00014000; // Enable interrupts EINT0 and EINT2

}

/* Interrupt1 service routine */

void INT0_Srv(void)

{

Counter++; // Increment Counter

IOCLR1 = 0x00ff0000; // Set data lines to 0

IOSET1 = Counter << 16; // Set values for LEDs in data lines D0 to D7

IOCLR0 = 0x00400000; // Clear A3

IOSET0 = 0x00400000; // Set A3

EXTINT |=0x01;

VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

}/* Interrupt2 service routine */

void INT2_Srv(void)

{

Counter--; // Decrement Counter

IOCLR1 = 0x00ff0000; // Set data lines to 0

IOSET1 = Counter << 16; // Set values for LEDs in data lines D0 to D7

IOCLR0 = 0x00400000; // Clear A3

IOSET0 = 0x00400000; // Set A3

EXTINT |=0x04;

VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for interfacing EEPROM and interrupt is written and executed. The

output is verified in the ARM kit.

Page 27: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 27

INTERFACING READ TOGGLE SWITCH AND RELAY

AIM:

To write an embedded C program for interfacing read toggle switch and relay and to verify the

output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

READ TOGGLE SWITHES:

Step 1: Start the program

Step 2: Initialize IO port lines.

Step 3: Initialize P0.19 (A0), P0.20 (A1), and P0.22 (A2) as output port. These three lines are the

Control lines to the decoder, used to generate the chip enable signal for the point LEDs in

The toggle switches. These lines are called as address lines.

Step 4:a) Initialize data lines P1.16(DB0)to P1.23(DB7) as input lines.

b) Set the address lines as A1=0,A2=0 and toggle the address line A0 from 0 to1,to enable

The buffer connected to the switches.

c) Read the data from the data bus.

Step 5: a) Initialize the data lines P1.16(DB0) toP1.23(dDB7) as output lines

b) Write the data read from the switches to the data bus for LEDs.

c) Set the addresses lines as A0=0, A1=0 and A2=0 to enable the latch connect to the

LEDs

Step 6: Repeat from step 3.

Step 7: stop the program.

RELAY:

Step 1: Start the program

Step 2: initialize IO lines required for the relays

Step 3: Intilize P0.30 (relay 1) and P0.10 (relay20) as output lines.

Step 4: Send 1 level to P0.30 and 0 level to P0.10. Call a small delay.

Step 5: Send 0 level to P0.30 and 1 level to P0.10. Call a small delay.

Repeat from step 3

Step 6:Stop the program.

PROGRAM:

READ TOGGLE SWITCH

#include "LPC214X.H"

void InitializeIO(void);

int main (void)

{

unsigned char b;

InitializeIO(); //Initialize the I/O lines

while(1)

{

IOCLR0 = 0x00580000; // Address Lines A0,A1,A2 set as 0

IOSET0 = 0x00080000; // Set A0 to generate chip enable for toggle switches

Page 28: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 28

IODIR1 &= 0xFF00FFFF; // Set the data lines to input

b = IOPIN1 >> 16; // Read from toggle switches

IODIR1 |= 0x00FF0000; // Set the data lines to output

IOPIN1 = b << 16; // Display the data on LEDs

IOCLR0 = 0x00580000; // A0 - A2 set as 0

}

}

void InitializeIO(void)

{

IODIR0 = 0x00580000;

IODIR1 = 0x00ff0000;

}

void __gccmain()

{

}

RELAY

#include "LPC214X.H"

void InitializeIO(void);

int main (void)

{

long a;

IODIR0 = 0X40000400; //Set P0.30 and P0.10 lines as

ouput lines

while(1)

{

IOCLR0 = 0x00000400; // Clear P0.10

IOSET0 = 0x40000000; // Set P0.30 - switch on relay

for(a=0;a<0xF0000;a++); // Delay

IOCLR0 = 0x40000000; // Clear P0.30

IOSET0 = 0x00000400; // Set P0.10 - switch on relay

for(a=0;a<0xF0000;a++); // Delay

}

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for interfacing read toggle switch and relay is written and executed.

The output is verified in the ARM kit.

Page 29: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 29

INTERFACING LED AND PWM

AIM:

To write an embedded C program for interfacing LED and PWM and to verify the output in the

ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

LED

Step 1: Start the program.

Step 2: Enable IO port. Initialize timer 0.

Step 3: a) Initialize P0.19 (A0), P0.20 (A1), P0.22 (A2) as output port. These three lines are the

Control lines to the decoder, use to the generate the chip enable signal for the

LEDs.These line are called as address lines

b) Initialize the data lines P1.16 (DB0) toP1.23 (DB7) as output lines.

Step 4:a) Place the data for the LEDs in the data busDB0 to DB7.Set data to switch on one LED

b) Clear all address lines as A0, A1 and A2. Then set all address lines back to 1 to enable

The latch connected to the LEDs

Step 5: Call a delay.

Step 6:a) Rotate the data for a LEDs to switch on next LED.

b) Repeat from step 2

Step 7: Stop the program.

PWM

Step 1: Start the program.

Step 2: a) Initialize LCD.

b) Display a message on the LCD

Step 3: Initialize PWM. Initialize a variable Var to 900. Set the direction to port lines P0.01 and

P0.07 TO 0in the direction register IODIR0.tjis makes both the port lines as input lines.

Step 4: Check for 0 level in P0.01 lines where a push button switch is connected.

Step 5: Check for 0 level in P0.07 lines where a push button switch is connected.

Step 6: Stop the program

PROGRAM:

LED FLASHING

#include "LPC214X.H"

void InitializeIO(void);

void InitializeTIMER0(void);

void T0_Srv(void);

void Delay(void);

extern void irq_T0(void);

unsigned int Count;

int main (void)

{

Page 30: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 30

long a;

unsigned char b;

InitializeIO(); // Initialize the I/O lines

InitializeTIMER0(); // Initialize Timer 0

while(1)

{

//Sequentially switches from 1st LED to 8th LED with a periodic interval

for(b=0;b<8;b++)

{

IOCLR1 = 0x00ff0000; // Clear all LED lines

IOSET1 = (0x01 << b) << 16; // Switch on any one the line

IOCLR0 = 0x00580000; // Clear A0,A1 and A2

IOSET0 = 0x00580000; // Set A0,A1 and A2

Delay(); // Delay

}

//Sequentially switches from 8th LED to 1st LED with a periodic interval

for(b=0;b<8;b++)

{

IOCLR1 = 0x00ff0000; // Clear all LED lines

IOSET1 = (0x80 >> b) << 16; // Switch on any one the line

IOCLR0 = 0x00580000; // Clear A0,A1 and A2

IOSET0 = 0x00580000; // Set A0,A1 and A2

Delay(); // Delay

}

}

}

void InitializeIO(void)

{

IODIR0 = 0x00580000;

IODIR1 = 0x00ff0000;

}

//Initialise timer0 used in LED Flashing

void InitializeTIMER0(void)

{ //for 1msec delay

VPBDIV = 0x00000002; //Configure the VPB divider

//CCLK/2 = PCLK = 30MHz

T0PR = 0x0000012B; //Load prescaler = 300, 30MHz/300=100KHz

T0TCR = 0x00000002; //Reset counter and prescaler

T0MCR = 0x00000003; //On match reset the counter and

generate an interrupt

T0MR0 = 0x00000064; //Set the cycle time, 100KHZ/100 = 1KHZ =

1ms

T0TCR = 0x00000001; //enable timer

VICVectAddr4 = (unsigned long)irq_T0; //Set the timer ISR vector address

VICVectCntl4 = 0x00000024; //Set channel

VICIntEnable |= 0x00000010; //Enable the interrupt

Count =0;

}

/* Timer0 interrupt service routine */

void T0_Srv(void)

Page 31: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 31

{

Count++; //Counter is incremeted

T0IR |= 0x00000001; //Clear match 0 interrupt

VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

}

void Delay(void)

{

Count = 0;

while(Count < 1000);

}

void __gccmain()

{

}

PWM

#include "LPC214x.H" // LPC214x definitions

#include "string.h"

void InitializePWM(void);

void DisplayPWMData(int dat);

void DisplayLCD(char LineNumber,char *Message);

void InitializeLCD();

void ConvertHextoBCD(unsigned int a);

int main (void)

{

int val=900;

InitializeLCD(); // Initialize LCD

DisplayLCD(0," PWM Testing "); // Display Message

DisplayLCD(1,"PWM Data:0900 ");

InitializePWM(); // Initialize PWM

IODIR0 &= 0xffffff7d;

while (1)

{

if((IOPIN0 & 0x02) == 0)

{ // Increment switch pressed

if((IOPIN0 & 0x02) == 0)

{

if(val > 50)

val -= 50; // Decrement PWM value

ConvertHextoBCD(val);

PWMMR4 = val; // Set value to PWM 4 register

PWMMR5 = 950; // Set value for PWM 5 register

PWMLER = 0x30; // Latch the value

PWMTCR = 0x00000002; // Reset counter and prescaler

PWMTCR = 0x00000009; }

while((IOPIN0 & 0x02) == 0);

}

if((IOPIN0 & 0x80) == 0)

{ // Decrement

if((IOPIN0 & 0x80) == 0)

Page 32: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 32

{

if(val <900)

val += 50;

ConvertHextoBCD(val);

PWMMR4 = val; // Set value to PWM 4 register

PWMMR5 = 950; // Set value for PWM 5 register

PWMLER = 0x30; // Latch the value

PWMTCR = 0x00000002; // Reset counter and prescaler

PWMTCR = 0x00000009;

}

while((IOPIN0 & 0x80) == 0);

}

}

}

void InitializePWM (void)

{

PINSEL1 = 0x00000400; // Enable P0.21 - PWM5

PWMPR = 0x00000000; // Load prescaler

PWMPCR = 0x00002020; // PWM channel 5 output enabled, double edge control

PWMMCR = 0x00010000; // On match with timer reset the counter

PWMMR0 = 1000; // set cycle rate to sixteen ticks

PWMMR4 = 900;

PWMMR5 = 950;

PWMLER = 0x30; // enable shadow latch for match 5

PWMTCR = 0x00000002; // Reset counter and prescaler

PWMTCR = 0x00000009; // enable counter and PWM, release counter from reset

}

void ConvertHextoBCD(unsigned int a)

{

unsigned char t[20]="PWM Data:0000";

t[9] = '0';

t[10] = a/100 + '0';

a -= (a/100) * 100;

t[11] = a/10 + '0';

t[12] = a%10 + '0';

DisplayLCD(1,t);

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for interfacing LED and PWM is written and executed. The output is

verified in the ARM kit.

Page 33: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 33

INTERFACING SEVEN SEGMENT LED

AIM:

To write an embedded C program for interfacing seven segment LED and verify the output in the

ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

SEVEN SEGMENT LED:

Step 1: Start the program.

Step 2: Initialize IIC interface

Step 3: Send the instruction byte 0X00 to the IIC device.

Step 4: Send the instruction byte 0X01 to indicate that next byte is segment data for digit 1.

Step 5: Send the instruction byte 0X02 to indicate that next byte is segment data for digit 2.

Step 6: Send the instruction byte 0X03 to indicate that next byte is segment data for digit 3.

Step 7: Send the instruction byte 0X04 to indicate that next byte is segment data for digit 4.

Step 8: Stop the program.

PROGRAM:

7 SEGMENT LED #include "LPC214x.h" // LPC21xx definitions

extern void irq_iic(void); // interrupt process

void Iic_Srv(void);

void InitializeIIC(void);

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data); //Background call to start master send and receive byte transfers

void WriteByte(int addr,unsigned char *data);

void ReadByte(int addr,unsigned char *data);

void delay2(void);

unsigned char *I2CData,

I2Counter,

I2CAddress,

MemAddress,

lock;

int main(void)

{

unsigned char Data=0;

InitializeIIC(); // Initialize IIC Interface

Data = 0x47; // Control byte, adds 12ma to segment current, dynamic mode, digits not blanked

WriteByte(0x00,&Data); // Read Hours from RTC

Data = 0x06; // Segment data for displaying data 1

WriteByte(0x01,&Data); // Display in Digit 1

Data = 0x5b; // Segment data for displaying data 2

Page 34: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 34

WriteByte(0x02,&Data); // Display in Digit 2

Data = 0x4f; // Segment data for displaying data 3

WriteByte(0x03,&Data); // Display in Digit 3

Data = 0x66; // Segment data for displaying data 4

WriteByte(0x04,&Data); // Display in Digit 4

while(1);

}

void InitializeIIC(void)

{

lock = 0; //Initilise the lock flag

VICVectCntl1 = 0x00000029; //select a priority slot for a given interrupt

VICVectAddr1 = (unsigned long)irq_iic; //pass the address of the IRQ into the VIC slot

VICIntEnable = 0x00000200; //enable interrupt

PINSEL0 |= 0x50; //Switch GPIO to I2C pins

I2C0SCLH = 0x104;

I2C0SCLL = 0x104;

}

//Write given data in EEPROM, address(10bit) specified by addr

void WriteByte(int addr,unsigned char *data)

{

I2CTransferByte(0x70,addr,1,&data[0]); //write data to the I2C Memory

while(lock==1);

}

//Read data from EEPROM,addr-10bit EEPROM address

void ReadByte(int addr,unsigned char *data)

{

I2CTransferByte(0x70,addr,0,&data[0]); //set address to addr

I2CTransferByte(0x71,addr,1,&data[0]); //read data from the I2C Memory

while(lock==1);

}

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data )

{

while(lock == 1) //Wait for interrupt to signal end of I2C

activity

{

;

}

lock = 1; //Set I2C bus as active

//Place address and data in Globals to be used by the interrupt

I2CAddress = I2CAddr;

I2CData = data;

I2Counter = count;

MemAddress = MemAddr;

I2C0CONCLR = 0x000000FF; //Clear all I2C settings

I2C0CONSET = 0x00000040; //Enable the I2C interface

I2C0CONSET = 0x00000020; //Start condition

}

void Iic_Srv(void) //I2C interrupt routine

{

Page 35: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 35

switch (I2C0STAT) //Read result code and switch to next

action

{

// Start and Send byte conditions

case ( 0x08): //Start bit

I2C0CONCLR = 0x20; //Clear start bit

I2C0DAT = I2CAddress; //Send address and write bit

break;

case (0x18): //Slave address+W, ACK

I2C0DAT = MemAddress; //Write Memory start address to tx register

break;

case (0x20): //Salve address +W, Not ACK

I2C0DAT = I2CAddress; //Resend address and write bi

break;

case (0x28):

if(I2Counter > 0) //Data sent, Ack

{

I2Counter--;

I2C0DAT = *I2CData; //Write data to tx register

I2CData++;

}

else

{

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

case (0x30) : //Data sent, NOT Ack

I2C0DAT = *I2CData; //Write data to tx register

break; //Receive byte conditions

case (0x40) : //Slave Address +R, ACK

I2C0CONSET = 0x04; //Enable ACK for data byte

break;

case (0x48) : //Slave Address +R, Not Ack

I2C0CONSET = 0x20; //Resend Start condition

break;

case (0x50) : //Data Received, ACK

if(--I2Counter>0)

{

*I2CData = I2C0DAT;

I2CData++;

}

else

{

*I2CData = I2C0DAT;

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

Page 36: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 36

case (0x58): //Data Received, Not Ack

I2C0CONSET = 0x20; // Resend Start condition

break;

default :

break;

}

I2C0CONCLR = 0x08; //Clear I2C interrupt flag

VICVectAddr = 0x00000000; //Clear interrupt in

}

void __gccmain()

{

}

RESULT: Thus the Embedded C program for interfacing seven segment LED is written and executed. The

output is verified in the ARM kit.

Page 37: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 37

INTERFACING REAL TIME CLOCK AND SERIAL PORT

AIM:

To write an embedded C program for interfacing real time clock and serial port and to verify

the output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

REAL TIME CLOCK:

Step 1: Star t the program.

Step 2: Initialize LCD.

Step 3: Initialize IIC interface.

Step 4: Set the address location of RTC as 0X04.

Step 5: Set the address location of RTC as 0X03.

Step 6: Set the address location of RTC as 0X02.

Step 7: Display the read data hours, minutes and seconds on the second line of the LCD.

Repeat from step3.

Step 8: Stop the program.

SERIAL PORT:

Step 1: Star t the program

Step 2:a) Initialize Io lines.

b) Initialize the serial port.

Step 3: Send an initial message through serial port to PC.

Step 4: a) Initialize LCD.

b) Display messages on both lines of LCD.

Step 5: Initialize keyboard lines.

Step 6: Initialize timer 0 to generate interrupt for every millisecond. the keyboard is scanned for

Key press in the timer 0interrupt routine

Step 7: Check for a character from a serial port receiver buffer. Also check for a key press.

Step 8: Repeat from step 6.

Step 9: Stop the program

PROGRAM:

REAL TIME CLOCK

#include "LPC214x.h" // LPC21xx definitions

extern void irq_iic(void); // interrupt process

void Iic_Srv(void);

void InitializeIIC(void);

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data); //Background call to start master send and receive byte transfers

void WriteByte(int addr,unsigned char *data);

void ReadByte(int addr,unsigned char *data);

extern void delay2(void);

unsigned char *I2CData,

I2Counter,

I2CAddress,

Page 38: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 38

MemAddress,

lock;

int main(void)

{

int a;

unsigned char Hour=0,Min=0,Sec=0;

InitializeLCD(); // Initialize LCD

InitializeIIC(); // Initialize IIC Interface

DisplayLCD(0," RTC DEMO "); // Display message

DisplayLCD(1," : : ");

while(1)

{

ReadByte(0x04,&Hour); // Read Hours from

RTC

ReadByte(0x03,&Min); // Read Minutes from RTC

ReadByte(0x02,&Sec); // Read Seconds from RTC

DisplayLCD2Digit(1,4,Hour); // Display

DisplayLCD2Digit(1,7,Min);

DisplayLCD2Digit(1,10,Sec);

}

}

void InitializeIIC(void)

{

lock = 0; //Initilise the lock flag

VICVectCntl1 = 0x00000029; //select a priority slot for a given interrupt

VICVectAddr1 = (unsigned long)irq_iic; //pass the address of the IRQ into the VIC slot

VICIntEnable = 0x00000200; //enable interrupt

PINSEL0 |= 0x50; //Switch GPIO to I2C pins

I2C0SCLH = 0x104;

I2C0SCLL = 0x104;

}

//Write given data in RTC

void WriteByte(int addr,unsigned char *data)

{

I2CTransferByte(0xA0,addr,1,&data[0]); //write data to the I2C Memory

while(lock==1);

}

//Read data from RTC

void ReadByte(int addr,unsigned char *data)

{

I2CTransferByte(0xA0,addr,0,&data[0]); //set address to addr

I2CTransferByte(0xA1,addr,1,&data[0]); //read data from the I2C Memory

while(lock==1);

}

void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,unsigned

char *data )

{

while(lock == 1) //Wait for interrupt to signal end of I2C activity

{

;

Page 39: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 39

}

lock = 1; //Set I2C bus as active

//Place address and data in Globals to be used by the interrupt

I2CAddress = I2CAddr;

I2CData = data;

I2Counter = count;

MemAddress = MemAddr;

I2C0CONCLR = 0x000000FF; //Clear all I2C settings

I2C0CONSET = 0x00000040; //Enable the I2C interface

I2C0CONSET = 0x00000020; //Start condition

}

void Iic_Srv(void) //I2C interrupt routine

{

switch (I2C0STAT) //Read result code and

switch to next action

{

// Start and Send byte conditions

case ( 0x08): //Start bit

I2C0CONCLR = 0x20; //Clear start bit

I2C0DAT = I2CAddress; //Send address and write bit

break;

case (0x18): //Slave address+W, ACK

I2C0DAT = MemAddress; //Write Memory start address to tx register

break;

case (0x20): //Salve address +W, Not ACK

I2C0DAT = I2CAddress; //Resend address and write bi

break;

case (0x28):

if(I2Counter-->0) //Data sent, Ack

{

I2C0DAT = *I2CData; //Write data to tx register

I2CData++;

}

else

{

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

case (0x30) : //Data sent, NOT Ack

I2C0DAT = *I2CData; //Write data to tx register

break;

//Receive byte conditions

case (0x40) : //Slave Address +R, ACK

I2C0CONSET = 0x04; //Enable ACK for data byte

break;

case (0x48) : //Slave Address +R, Not Ack

I2C0CONSET = 0x20; //Resend Start condition

break;

case (0x50) : //Data Received, ACK

Page 40: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 40

if(--I2Counter>0)

{

*I2CData = I2C0DAT;

I2CData++;

}

else

{

*I2CData = I2C0DAT;

I2C0CONSET = 0x10; //Stop condition

lock = 0; //Signal end of I2C activity

}

break;

case (0x58): //Data Received, Not Ack

I2C0CONSET = 0x20; // Resend Start condition

break;

default :

break;

}

I2C0CONCLR = 0x08; //Clear I2C interrupt flag

VICVectAddr = 0x00000000; //Clear interrupt in

}

SERIAL PORT #include "LPC214x.H" // LPC214x definitions

void InitializeSerialPort(void);

void SendMessage(char *Message);

void SendByteSerially(unsigned char a);

unsigned char ReadByteSerially(void);

extern char KeyboardFlag;

extern unsigned char KeyboardCode;

int main(void)

{

unsigned char a;

InitializeSerialPort(); //Initialize Serial port

SendMessage("NXP LPC 2148 ARM Evaluation System\r\n"); //Send message though serial port

SendMessage("Message at baud 9600.\r\n\r\n");

IODIR0 |= 0x00078000; //Initialize Port lines for keyboard

KeyboardFlag =0; //Clear keyboard flag

InitializeLCD();

DisplayLCD(0,"Serial Port Test ");

DisplayLCD(1,"Received Char: ");

InitializeTIMER0(); //Initialize TIMER0, Keyboard scan timer

while(1)

{

a = ReadByteSerially(); // Read a Serial port

DisplayCharacter(1,14,a); // Display the Character

}

}// Sends Message

void SendMessage(char *Message)

{

Page 41: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 41

do

{

SendByteSerially(*Message); //Send a byte of data through serial port

Message++; //Increment pointer

}

while(*Message != 0);

} // Sends Byte

void SendByteSerially(unsigned char a)

{

while (!(U1LSR & 0x20));

U1THR = a;

}// Reads Byte

unsigned char ReadByteSerially(void)

{

while (!(U1LSR & 0x01))

{

if(KeyboardFlag ==1) // Wait for key press

{

if(KeyboardCode < 0x0a)

{

KeyboardCode += 0x30;

}

else

{

KeyboardCode += 0x37;

}

SendByteSerially(KeyboardCode);

KeyboardFlag=0; // Reset keyboard flag

}

}

return (U1RBR);

}// Serial Port Initialization

void InitializeSerialPort(void)

{

PINSEL0 = 0x00050000; // P0.8 to P0.9 Pin function select

U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit

U1DLL = 97; // 9600 Baud Rate @ 15MHz VPB Clock

U1LCR = 0x03; // DLAB = 0

}

void __gccmain()

{

}

RESULT:

Thus the Embedded C program for interfacing Real time clock and serial port is written and

executed. The output is verified in the ARM kit.

Page 42: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 42

INTERFACING STEPPER MOTOR AND TEMPARATURE SENSOR

AIM:

To write an embedded C program for interfacing stepper motor and temperature sensor and to

verify the output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

STEPPER MOTOR

Step 1: Start the program

Step 2: Initialize IO port lines.

Step 3: Initialize P0.19 (A0), P0.20 (A1), and P0.22 (A2) as output port. These three lines are the

Control lines to the decoder, used to generate the chip enable signal for the stepper motor.

These lines are called as address lines.

b) Initialize data lines P1.16 (DB0) to P1.23 (DB7) as output lines.

c) Set the address lines as A0=1, A1=1 and clear the address line A2.

Step 4: Initialize counter 1 to100.

Step 5:a) Initialize a counter to 4.

b) Place a data 0X6666 in the data bus.

Step 6:a)toggle the address line A0 from 0 to 1,to enable the latch connected to the stepper motor

Driver.

b) Call a delay.

Step7:a)shift left the data 0x6666 once

b) Decrement the counter by 1.

c) Repeat from step 5 until the counter becomes 0.

Step 8:a) Decrement the counter1 by 1.

b) This makes the motor rotate in clockwise direction for few seconds.

c) Repeat from step 4 until the counter1 becomes 0.

Step9: Initialize counter 1 to100.

Step 10:a) Initialize a counter to 4.

b) Place a data 0X6666 in the data bus.

Step 11:a) toggle the address line A0 from 0 to 1,to enable the latch connected to the stepper

Motor Driver.

b) Call a delay.

Step12:a)shift right the data 0x6666 once

b) Decrement the counter by 1.

c) Repeat from step 10 until the counter becomes 0.

Step 13:a) Decrement the counter1 by 1.

b) This makes the motor rotate in counter clockwise direction for few seconds.

c) Repeat from step 9 until the counter1 becomes 0.

Step 14: Repeat from step 3

Step 15: stop the program

Page 43: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 43

TEMPARATURE SENSOR

Step 1: Start the program.

Step 2: initialize LCD

Step 3: initialize ADC. Set the port lines AD0.1to has a special function using the PINSEL1

Register.

Step 4: Call the routine message_display 1 to display message “room temperature” on line one of

the LCD.

Step 5: a) Set the control register of the ADC with the following specifications

Channel number=2;

ADC clock=3 MHz

Select burst mode.

Conversion clocks required=11 clocks

b) Start the ADC conversion

Step 6: Wait for EOC signal. Once the EOC signal is obtained, read the ADC value

Step 7: Convert the read valve into BCD and then display the room temperature on the LCD

module..Repeat from step4.

Step 8: Stop the program.

PROGRAM:

STEPPER MOTOR

#include "LPC214X.H"

void InitializeIO(void);

int main (void)

{

unsigned char a;

unsigned int b;

long c,d;

InitializeIO(); //Initialize the I/O lines

while(1)

{

for(d=0;d<100;d++)

{ // Rotate clock wise

b=0x6666;

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

{

IOPIN1 = (b & 0xff00) << 8 ;

IOCLR0 = 0x00400000; // Clear A3

IOSET0 = 0x00400000; // Set A3

for(c=0;c<0xa000;c++); // Delay

b = b << 1; // Shift left side one

}

}

for(d=0;d<100;d++)

{ // Rotate counter clock wise

b=0x6666;

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

{

Page 44: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 44

IOPIN1 = (b & 0xff00) << 8 ;

IOCLR0 = 0x00400000; // Clear A3

IOSET0 = 0x00400000; // Set A3

for(c=0;c<0xa000;c++); // Delay

b = b >> 1; // Shift right side one

}

}

}

}

void InitializeIO(void)

{

IODIR0 = 0x00580000;

IODIR1 = 0x00ff0000;

IOCLR0 = 0x00580000;

IOSET0 = 0x00180000;

}

void __gccmain()

{

}

TEMPERATURE SENSOR

#include "LPC214x.h" /* LPC21xx definitions */

int ReadADC(char ChannelNumber);

int main(void)

{

int a;

unsigned char Channel = 1, t[7];

PINSEL1 = 0x01000000; // Select ADC to pin P0.28

InitializeLCD(); // Initialize LCD

DisplayLCD(0,"Room Temperature"); // Display message

while(1)

{

a=ReadADC(Channel); // Read ADC channel 1

t[0] = a/100 + '0';

a -= (a/100) * 100;

t[1] = a/10 + '0';

t[2] = '.';

t[3] = a%10 + '0';

t[4] = 'C';

t[5] = 0;

DisplayLCD(1,t); // Display the room temperature

LCDDelay1600();

}

}//Read ADC data from given channel number

int ReadADC(char ChannelNumber)

{

int val,ch;

ch = 1<<ChannelNumber;

AD0CR = 0x00210400 | ch; // Setup A/D: 10-bit AIN @ 3MHz

AD0CR |= 0x01000000; // Start A/D Conversion

Page 45: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 45

do

{

val = AD0DR1; // Read A/D Data Register

}

while ((val & 0x80000000) == 0); // Wait for the conversion to complete

val = ((val >> 6) & 0x03FF); // Extract the A/D result

AD0CR &= ~0x01000000; // Stop A/D Conversion

return(val); // Return the Data Read

}

RESULT:

Thus the Embedded C program for interfacing stepper motor and temperature sensor is written

and executed. The output is verified in the ARM kit.

Page 46: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 46

PROGRAMMING IN RTOS & PORTING IT ON THE PROCESSOR

PROCEDURE

1. Open Embest IDE software

2. Go to file->new workspace. a window will appear. In that window give the project

name & the location to be stored.

3. Copy the support file from the original folder to the created folder

4. Right click on project source files & click on add files to folder->select files & add it.

5. Go to file -> new -> type the program & save the program with the extension .c

6. Click project ->settings

In processor:

CPU mode: ARM 7

CPU family: ARM 7

Member: ARM 7

Build tools: GNC tools for ARM

In remote:

Remote device: SIM ARM 7

In compiler:

Category: target specific option

Click on little endian

Specify the name of the target: ARM 7TDMI

In assembler:

Category: target specific option

Click on little endian

In linker:

Category : general

Linker script file-> browse->select flash.id

Page 47: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 47

Category : image entry option

Select vector.0

Category : code generation operation

Click->link little endian object

category : include objects &library modules

Select new ->type –lc

Select new ->type -lgcc

category :add library searching path

Select new ->browse ->c:->embest IDE->build ->xgcc arm elf->arm elf->lib

Select new ->browse ->c:->embest IDE->build -> xgcc arm elf->lib->gcc lib-> arm elf

->3.0.2

7. Then click ok

8. Click build->rebuild all

9. Click tools->elf to hex

10. Minimize the window

11. Open flash magic.

12. Click browse ->select file name.hex from your project -> open

13. Switch on the kit -> press reset button -> click start in the flash magic window

14. After download finished, switch off the kit-> press reset button.

15. Output will be executed in the kit.

Page 48: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 48

FLASHING TWO LEDS

AIM:

To write a program in RTOS for flashing two LEDs and verify the output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

Step 1: Start the program

Step 2: Intialize Handlers

Step 3: Initialize uC/OS-II by calling “OSInit ();”

Step 4: Create main task

Step 5: Initialize timer 0

Step 6: Start multitasking by calling “OSStart ();”

Step 5: Stop the program

PROGRAM:

FLASHING TWO LEDS

/**************************************************************************

* Flashing two LEDs connected to relay contacts.

* Relays are connected to port lines P0.9 and P0.10

**************************************************************************/

#include "includes.h"

#include "lpc214x.h"

#define TASK_STK_SIZE 255 // Size of each task's stacks (# of WORDs)

#define TASK_START_ID 0 // Application tasks IDs

#define TASK_1_ID 1

#define TASK_2_ID 2

#define TASK_START_PRIO 0 // Application tasks priorities

#define TASK_1_PRIO 1

#define TASK_2_PRIO 2

OS_STK TaskStartStk[TASK_STK_SIZE]; // Startup task stack

OS_STK Task1Stk[TASK_STK_SIZE]; // Task 1 task stack

OS_STK Task2Stk[TASK_STK_SIZE]; // Task 2 task stack

static void TaskStartCreateTasks (void);

void Task1 (void *pdata);

void Task2 (void *pdata);

void TaskStart (void *pdata)

{

pdata = pdata; // Prevent compiler warning

rIODIR0 = 0X40000400; // Set P0.30 and P0.10 lines as

ouput lines

rIOSET0 = 0X00000400;

TaskStartCreateTasks(); // Create all other tasks

while(1)

{

OSTimeDlyHMSM(0, 0, 1, 0); // Wait one second

Page 49: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 49

}

}

static void TaskStartCreateTasks (void)

{

OSTaskCreateExt(Task1, // Create Task 1

(void *)0,

&Task1Stk[TASK_STK_SIZE - 1],

TASK_1_PRIO,

TASK_1_ID,

&Task1Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task2, // Create Task 2

(void *)0,

&Task2Stk[TASK_STK_SIZE - 1],

TASK_2_PRIO,

TASK_2_ID,

&Task2Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

}

/**************************************************************************

* Task 1 : Switches On/Off Relay 2

**************************************************************************/

void Task1 (void *pdata)

{

long a;

pdata = pdata;

while(1)

{

a = rIOPIN0; // Read relay status

if(a & 0x00000400 )

{

rIOCLR0 = 0X00000400; // Switch Off relay 2

}

else

{

rIOSET0 = 0X00000400; // Switch off relay 2

}

OSTimeDlyHMSM(0, 0, 1, 0); // Wait one second

}

}

/**************************************************************************

* Task 2 : Switches On/Off Relay 1

**************************************************************************/

void Task2 (void *pdata )

{

long a;

Page 50: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 50

pdata = pdata;

while(1)

{

a = rIOPIN0; // Read relay status

if(a & 0x40000000 )

{

rIOCLR0 = 0x40000000; // Switch Off relay 1

}

else

{

rIOSET0 = 0x40000000; // Switch On relay 1

}

OSTimeDlyHMSM(0, 0, 1, 0); // Wait two seconds

}

}

/**************************************************************************

* Main Function

**************************************************************************/

void C_vMain(void)

{

OS_STK *ptos;

OS_STK *pbos;

INT32U size;

vInitHaltHandlers(); // Initialize Handlers

pISR_IRQ = (U32)UCOS_IRQHandler;

OSInit(); // Initialize uC/OS-II

ptos = &TaskStartStk[TASK_STK_SIZE - 1];

pbos = &TaskStartStk[0];

size = TASK_STK_SIZE;

OSTaskCreateExt(TaskStart,

(void *)0,

ptos,

TASK_START_PRIO,

TASK_START_ID,

pbos,

size,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

FRMWRK_vStartTicker(OS_TICKS_PER_SEC);

OSStart(); // Start multitasking

}

void __gccmain()

{

}

Result:

Thus the Program for flashing two LEDs is written and the output is verified on an ARM

processor board.

Page 51: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 51

READING LM35 AND PLOTTING IN LCD

AIM:

To write a program in RTOS for reading LM35 and plotting in LCD and verify the output in

the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

Step 1: Start the program

Step 2: Initialize Handlers

Step 3: Initialize uC/OS-II by calling “OSInit ();”

Step 4: Create main task

Step 5: Initialize timer 0

Step 6: Start multitasking by calling “OSStart ();”

Step 5: Stop the program

PROGRAM:

READING LM35 AND PLOTTING LCD

/**************************************************************************

* Reads from Temperature Sensor LM35 and plots the graph on 128 x 64 Graphics Display

* Graph shows the display of temperature (Centrigade) Vs. Time (Seconds)

* The temperature is on the y axix and the Time is on the x axis.

* The display is refreshed for every 2 seconds

**************************************************************************/

#include "includes.h"

#include "GLCD.h"

#define TASK_STK_SIZE 256 // Size of each task's stacks

#define TASK_START_ID 0 // Application tasks IDs

#define TASK_1_ID 1

#define TASK_2_ID 2

#define TASK_START_PRIO 10 // Application tasks priorities

#define TASK_1_PRIO 11

#define TASK_2_PRIO 12

OS_STK TaskStartStk[TASK_STK_SIZE]; // Startup task stack

OS_STK Task1Stk[TASK_STK_SIZE]; // Task 1 task stack

OS_STK Task2Stk[TASK_STK_SIZE]; // Task 2 task stack

static void TaskStartCreateTasks (void);

void Task1 (void *pdata);

void Task2 (void *pdata);

unsigned char tempa;

void TaskStart (void *pdata)

{

pdata = pdata; // Prevent compiler warning

Initialise_GraphicsLCD(); // Initialize Graphics LCD

DisplayOneScreenLCD(); // Display parameters on the

display

TaskStartCreateTasks(); // Create all other tasks

while(1)

{

Page 52: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 52

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

static void TaskStartCreateTasks (void)

{

OSTaskCreateExt(Task1, // Create Task 1

(void *)0,

&Task1Stk[TASK_STK_SIZE - 1],

TASK_1_PRIO,

TASK_1_ID,

&Task1Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task2, // Create Task 2

(void *)0,

&Task2Stk[TASK_STK_SIZE - 1],

TASK_2_PRIO,

TASK_2_ID,

&Task2Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

}

/**************************************************************************

* Task 1 : Read voltage from channel 1 to which the temperature sensor is connected.

**************************************************************************/

void Task1 (void *pdata)

{

unsigned int a;

pdata = pdata;

while(1)

{

a=ReadADCChannel1(); // Read ADC channel 1

tempa = 0x3f-8-a; // Calculate temperature for display

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

/**************************************************************************

* Task 2 : Update the display with the new temperature sensor is connected.

**************************************************************************/

void Task2 (void *pdata )

{

unsigned int i=0;

pdata = pdata;

while(1)

{

SetPixel(tempa,17+i); // Plot the temperature on the LCD

i++;

Page 53: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 53

OSTimeDlyHMSM(0, 0, 2, 0); // Wait for two seconds

}

}

/**************************************************************************

* Main Function

**************************************************************************/

void C_vMain(void)

{

OS_STK *ptos;

OS_STK *pbos;

INT32U size;

vInitHaltHandlers(); // Initialize Handlers

pISR_IRQ = (U32)UCOS_IRQHandler;

OSInit(); // Initialize uC/OS-II

ptos = &TaskStartStk[TASK_STK_SIZE - 1];

pbos = &TaskStartStk[0];

size = TASK_STK_SIZE;

OSTaskCreateExt(TaskStart,

(void *)0,

ptos,

TASK_START_PRIO,

TASK_START_ID,

pbos,

size,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

FRMWRK_vStartTicker(OS_TICKS_PER_SEC);

OSStart(); // Start multitasking

}//Read ADC data from channel 1

int ReadADCChannel1(void)

{

int val;

rAD0CR = 0x00210402; // Setup A/D: 10-bit AIN @

3MHz for channel 1

rAD0CR |= 0x01000000; // Start A/D Conversion

do

{

val = rAD0DR; // Read A/D Data Register

}

while ((val & 0x80000000) == 0); // Wait for the conversion to complete

val = (((val >> 9)-8) & 0x03FF); // Extract the A/D result

rAD0CR &= ~0x01000000; // Stop A/D Conversion

return(val); // Return the Data Read

}

void __gccmain()

{

}

RESULT: Thus the Program for reading LM35 and plotting in LCD is written and the output is

verified on an ARM processor board.

Page 54: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 54

TWO MESSAGES ON LCD

AIM:

To write a program using RTOS for displaying two messages on LCD and verify the output in

the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

Step 1: Start the program

Step 2: Initialize Handlers

Step 3: Initialize uC/OS-II by calling “OSInit ();”

Step 4: Create main task

Step 5: Initialize timer 0

Step 6: Start multitasking by calling “OSStart ();”

Step 5: Stop the program

PROGRAM:

TWO MESSAGES ON LCD

/**************************************************************************

* Display Messages on 2 Line X 16 Characters Text LCD

* A Counter increments in Task 1 and it is displayed on Line 1 of LCD

* A Counter decrements in Task 2 and it is displayed on Line 2 of LCD

**************************************************************************/

#include "includes.h"

#include "LCD.C"

#define TASK_STK_SIZE 256 // Size of each task's stacks (# of WORDs)

#define TASK_START_ID 0 // Application tasks IDs

#define TASK_1_ID 1

#define TASK_2_ID 2

#define TASK_START_PRIO 0 // Application tasks priorities

#define TASK_1_PRIO 1

#define TASK_2_PRIO 2

OS_STK TaskStartStk[TASK_STK_SIZE]; // Startup task stack

OS_STK Task1Stk[TASK_STK_SIZE]; // Task #1 task stack

OS_STK Task2Stk[TASK_STK_SIZE]; // Task #2 task stack

static void TaskStartCreateTasks (void);

void Task1 (void *pdata);

void Task2 (void *pdata);

void TaskStart (void *pdata)

{

pdata = pdata; // To Prevent compiler warning

InitializeLCD();

TaskStartCreateTasks(); // Create all other tasks

Page 55: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 55

while(1)

{

OSTimeDlyHMSM(0, 0, 1, 0); // Wait one second

}

}

static void TaskStartCreateTasks (void)

{

OSTaskCreateExt(Task1, // Create Task 1

(void *)0,

&Task1Stk[TASK_STK_SIZE - 1],

TASK_1_PRIO,

TASK_1_ID,

&Task1Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task2, // Create Task 2

(void *)0,

&Task2Stk[TASK_STK_SIZE - 1],

TASK_2_PRIO,

TASK_2_ID,

&Task2Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

}

/**************************************************************************

* Task 1 : Displays a counter on Line 1 of LCD (Counter increments)

**************************************************************************/

void Task1 (void *pdata)

{

pdata = pdata;

unsigned int Count1=0;

DisplayLCD(0,"Mesg Task1 : "); // Display Message

while(1)

{

DisplayLCD2Digit(0,12, (Count1 >>8));

DisplayLCD2Digit(0,14, (Count1 & 0xff));

// Display the count

value

Count1++; // Increment Counter 1

OSTimeDlyHMSM(0, 0, 0,500); // Delay

}

}

/**************************************************************************

* Task 2 : Displays a counter on Line 2 of LCD (Counter decrements)

**************************************************************************/

void Task2 (void *pdata )

{

Page 56: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 56

pdata = pdata;

unsigned int Count2=0;

DisplayLCD(1,"Mesg Task2 : "); //Display message

while(1)

{

DisplayLCD2Digit(1,12, (Count2 >>8));

DisplayLCD2Digit(1,14, (Count2 & 0xff)); ` // Display the count

value

Count2--; // Decrement Counter 2

OSTimeDlyHMSM(0, 0, 0,500); // Delay

}

}

/**************************************************************************

* Main Function

**************************************************************************/

void C_vMain(void)

{

OS_STK *ptos;

OS_STK *pbos;

INT32U size;

vInitHaltHandlers(); // Initialize Handlers

pISR_IRQ = (U32)UCOS_IRQHandler;

OSInit(); // Initialize uC/OS-II

ptos = &TaskStartStk[TASK_STK_SIZE - 1];

pbos = &TaskStartStk[0];

size = TASK_STK_SIZE;

OSTaskCreateExt(TaskStart,

(void *)0,

ptos,

TASK_START_PRIO,

TASK_START_ID,

pbos,

size,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

FRMWRK_vStartTicker(OS_TICKS_PER_SEC);

OSStart(); // Start multitasking

}

void __gccmain()

{

}

RESULT:

Thus the Program for displaying two messages on LCD is written and the output is verified on an ARM

processor board.

Page 57: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 57

SERIAL PORT

AIM:

To write a program in RTOS for using the serial port and verify the output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

Step 1: Start the program

Step 2: Initialize Handlers

Step 3: Initialize uC/OS-II by calling “OSInit ();”

Step 4: Create main task

Step 5: Initialize timer 0

Step 6: Start multitasking by calling “OSStart ();”

Step 5: Stop the program

PROGRAM:

SERIAL PORT

/******************************************************************************

* Sending Messages through Serial Port by 5 different tasks Using Serial Port 1.

* Connect the serial port cable between the Serial Port (P9) and PC Comm Port.

* Use Hyperterminal utility to receive characters from the serial port.

* Settings for Hyper ternminal - 9600 baud, 8 bits, 1 stop bit, no parity

*- Flow control(none)

*******************************************************************************/

#include "includes.h"

#include "SerialPortRoutines.c"

#define TASK_STK_SIZE 256 // Size of each task's stacks

#define TASK_START_ID 0 // Application tasks IDs

#define TASK_1_ID 1

#define TASK_2_ID 2

#define TASK_3_ID 3

#define TASK_4_ID 4

#define TASK_5_ID 5

#define TASK_START_PRIO 10 // Application tasks priorities

#define TASK_1_PRIO 11

#define TASK_2_PRIO 12

#define TASK_3_PRIO 13

#define TASK_4_PRIO 14

#define TASK_5_PRIO 15

OS_STK TaskStartStk[TASK_STK_SIZE]; // Startup task stack

OS_STK Task1Stk[TASK_STK_SIZE]; // Task 1 task stack

OS_STK Task2Stk[TASK_STK_SIZE]; // Task 2 task stack

OS_STK Task3Stk[TASK_STK_SIZE]; // Task 3 task stack

OS_STK Task4Stk[TASK_STK_SIZE]; // Task 4 task stack

OS_STK Task5Stk[TASK_STK_SIZE]; // Task 5 task stack

static void TaskStartCreateTasks (void);

void Task1 (void *pdata);

void Task2 (void *pdata);

Page 58: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 58

void Task3 (void *pdata);

void Task4 (void *pdata);

void Task5 (void *pdata);

void TaskStart (void *pdata)

{

pdata = pdata; // Prevent compiler warning

InitializeSerialPort(); // Initialize Serial Port

TaskStartCreateTasks(); // Create all other tasks

while(1)

{

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

static void TaskStartCreateTasks (void)

{

OSTaskCreateExt(Task1, // Create Task 1

(void *)0,

&Task1Stk[TASK_STK_SIZE - 1],

TASK_1_PRIO,

TASK_1_ID,

&Task1Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task2, // Create Task 2

(void *)0,

&Task2Stk[TASK_STK_SIZE - 1],

TASK_2_PRIO,

TASK_2_ID,

&Task2Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task3, // Create Task 3

(void *)0,

&Task3Stk[TASK_STK_SIZE - 1],

TASK_3_PRIO,

TASK_3_ID,

&Task3Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task4, // Create Task 4

(void *)0,

&Task4Stk[TASK_STK_SIZE - 1],

TASK_4_PRIO,

TASK_4_ID,

&Task4Stk[0],

TASK_STK_SIZE,

(void *)0,

Page 59: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 59

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task5, // Create Task 5

(void *)0,

&Task5Stk[TASK_STK_SIZE - 1],

TASK_5_PRIO,

TASK_5_ID,

&Task5Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

}

/**************************************************************************

* Task 1 : Send message through serial port

**************************************************************************/

void Task1 (void *pdata)

{

pdata = pdata;

while(1)

{

SendMessage("\r\nThis message is from TASK 1 with Priority 1\r\n");

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

/**************************************************************************

* Task 2 : Send message through serial port

**************************************************************************/

void Task2 (void *pdata )

{

pdata = pdata;

while(1)

{

SendMessage("This message is from TASK 2 with Priority 2\r\n");

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

/**************************************************************************

* Task 3 : Send message through serial port

**************************************************************************/

void Task3 (void *pdata )

{

pdata = pdata;

while(1)

{

SendMessage("This message is from TASK 3 with Priority 3\r\n");

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

/**************************************************************************

* Task 4 : Send message through serial port

**************************************************************************/

void Task4 (void *pdata )

{

Page 60: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 60

pdata = pdata;

while(1)

{

SendMessage("This message is from TASK 4 with Priority 4\r\n");

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

/**************************************************************************

* Task 5 : Send message through serial port

*************************************************************************/

void Task5 (void *pdata )

{

pdata = pdata;

while(1)

{

SendMessage("This message is from TASK 5 with Priority 5\r\n");

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for one second

}

}

/**************************************************************************

* Main Function

**************************************************************************/

void C_vMain(void)

{

OS_STK *ptos;

OS_STK *pbos;

INT32U size;

vInitHaltHandlers(); // Initialize Handlers

pISR_IRQ = (U32)UCOS_IRQHandler;

OSInit(); // Initialize uC/OS-II

ptos = &TaskStartStk[TASK_STK_SIZE - 1];

pbos = &TaskStartStk[0];

size = TASK_STK_SIZE;

OSTaskCreateExt(TaskStart,

(void *)0,

ptos,

TASK_START_PRIO,

TASK_START_ID,

pbos,

size,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

FRMWRK_vStartTicker(OS_TICKS_PER_SEC);

OSStart(); // Start multitasking

}

RESULT:

Thus the RTOS Program for Serial port is written and the output is verified on an ARM processor

board.

Page 61: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 61

MAIL BOX

AIM: To write a program in RTOS for Mail box function and verify the output in the ARM kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM Evaluation kit

ALGORITHM:

Step 1: Start the program

Step 2: Initialize Handlers

Step 3: Initialize uC/OS-II by calling “OSInit ();”

Step 4: Create main task

Step 5: Initialize timer 0

Step 6: Start multitasking by calling “OSStart ();”

Step 5: Stop the program

PROGRAM:

MAIL BOX

/**************************************************************************

* Mail Box Demo

* A character is posted by Task 1 to Task 2 through Mailbox.

* The task 2 gets the character value from Mailbox and acknowledges it.

* The task 2 then displays the character in line 2 of the text LCD and this process is repeated

**************************************************************************/

#include "includes.h"

#include "LCD.c"

#define TASK_STK_SIZE 256 // Size of each task's stacks

#define TASK_START_ID 0 // Application tasks IDs

#define TASK_1_ID 1

#define TASK_2_ID 2

#define TASK_START_PRIO 10 // Application tasks priorities

#define TASK_1_PRIO TASK_START_PRIO+1

#define TASK_2_PRIO TASK_START_PRIO+2

OS_STK TaskStartStk[TASK_STK_SIZE]; // Startup task stack

OS_STK Task1Stk[TASK_STK_SIZE]; // Task #1 task stack

OS_STK Task2Stk[TASK_STK_SIZE]; // Task #2 task stack

OS_EVENT *AckMbox; // Message mailboxes for Tasks #1 and #2

OS_EVENT *TxMbox;

static void TaskStartCreateTasks (void);

void Task1 (void *pdata);

void Task2 (void *pdata);

/*********************************************************************************

Task 1 :

This task sends a message to Task 2. The message consist of a character that needs to be displayed by

Task 2. This task then waits for an acknowledgement from Task 2 indicating that the message has

been displayed.

********************************************************************************/

void Task1 (void *data)

{

Page 62: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 62

char txmsg;

INT8U err;

data = data;

txmsg = 'A' ;

while(1)

{

OSMboxPost(TxMbox, (void *)&txmsg); // Send message to Task 2

OSMboxPend(AckMbox, 0, &err); // Wait for acknowledgement from Task 2

txmsg++; // Next message to send

if (txmsg == 'Z')

{

txmsg = 'A'; // Start new series of messages

}

OSTimeDlyHMSM(0, 0, 1, 0); // Wait for 1 second

}

}

/*******************************************************************************

* TASK 2:

** This task displays messages sent by Task 1. When the message is displayed,

* Task 2 acknowledges Task 1.

*******************************************************************************/

void Task2 (void *data)

{

char *rxmsg;

INT8U err;

data = data;

while(1)

{

rxmsg = (char *)OSMboxPend(TxMbox, 0, &err);// Wait for message from Task 1

DisplayCharacter(1,15,*rxmsg);

OSTimeDlyHMSM(0, 0, 1, 0); // Wait 1 second

OSMboxPost(AckMbox, (void *)1); // Acknowledge reception of message

}

}

void TaskStart (void *pdata)

{

pdata = pdata; // To Prevent compiler warning

InitializeLCD(); // Initialize text LCD

DisplayLCD(0,"Mail box Demo "); // Display messages on text LCD

DisplayLCD(1,"From Task 1 :");

AckMbox = OSMboxCreate((void *)0); // Create 2 message mailboxes

TxMbox = OSMboxCreate((void *)0);

TaskStartCreateTasks(); // Create all other tasks

while(1)

{

OSTimeDlyHMSM(0, 0, 1, 0); // Wait one second

}

}

static void TaskStartCreateTasks (void)

{

Page 63: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 63

OSTaskCreateExt(Task1, // Create Task 1

(void *)0,

&Task1Stk[TASK_STK_SIZE - 1],

TASK_1_PRIO,

TASK_1_ID,

&Task1Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

OSTaskCreateExt(Task2, // Create Task 2

(void *)0,

&Task2Stk[TASK_STK_SIZE - 1],

TASK_2_PRIO,

TASK_2_ID,

&Task2Stk[0],

TASK_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

}

/**************************************************************************

* Main Function

*************************************************************************/

void C_vMain(void)

{

OS_STK *ptos;

OS_STK *pbos;

INT32U size;

vInitHaltHandlers(); // Initialize Handlers

pISR_IRQ = (U32)UCOS_IRQHandler;

OSInit(); // Initialize uC/OS-II

ptos = &TaskStartStk[TASK_STK_SIZE - 1];

pbos = &TaskStartStk[0];

size = TASK_STK_SIZE;

OSTaskCreateExt(TaskStart,

(void *)0,

ptos,

TASK_START_PRIO,

TASK_START_ID,

pbos,

size,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

FRMWRK_vStartTicker(OS_TICKS_PER_SEC);

OSStart(); // Start multitasking

}

void __gccmain()

{

}

RESULT:Thus the RTOS Program for understanding the mail box function is written and the output is

verified on an ARM processor board.

Page 64: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 64

FSM APPLICATION ON FPGA

PROCEDURE FOR TRAFFIC LIGHT CONTROLLER

1. Open Xilinx ISE 9.2i

2. Go to file-> new project

3. Give project name in the new project wizard- create new project dialog box.

4. Click next.

5. Device properties dialog box appears. In that select the following:

Product category : All

Family : Spartan 3E

Device : XC3S250E

Package : PQ208

Speed : -4

Preferred language : Verilog

6. Click next.

7. Click new source.

8. Select source type dialog box appears.

Select Verilog module and give file name.

9. Click next-> next-> finish

10. Click yes-> next-> next -> finish.

11. Type the program.

12. Go to file -> save.

13. In the synthesize-XST, double click check syntax.

14. Go to project-> new source

15. Select implementation constraints file and give file name.

16. Click next -> finish.

17. Select the newly created ucf file.

18. Double click Assign package pins in the User constraints.

19. Type the corresponding Input/ Output pins and save it.

20. Click ok.

21. Double click synthesize-xst, then double click implement design.

22. Double click Programming File Generation Report in Generate Programming File.

23. Switch ON the kit.

24. Double click Configure Device in Generate Programming File.

25. An iMPACT-welcome to iMPACT dialog box appears.

26. Click finish.

27. Right click the mouse -> select file name.bit -> click open.

28. Click ok.

29. Click on the Xilinx device -> Right click -> select Program

30. Check whether pulse PROG is disabled -> Click ok.

31. Output will be executed in the kit.

Page 65: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 65

DESIGN AND IMPLEMENTATION OF TRAFFIC LIGHT CONTROLLER IN FPGA

AIM:

To write a program for implementing traffic light controller and verify the output in FPGA kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

XILINX ISE 9.2i

Spartan 3E FPGA kit

PROGRAM:

module traffic(clk, rst, dir, p1, p2, p3, p4, pt); //module declaration

// input ports

input clk; // system clock frequency is 20 mhz

input rst; // for reset

// output ports

output [2:0] dir;

output [4:0] p1; // d5,d4,d3,d2,d1

output [4:0] p2; // d10,d9,d8,d7,d6

output [4:0] p3; // d15,d14,d13,d12,d11

output [4:0] p4; // d20,d19,d18,d17,d16

output [3:0] pt; // dl1,dl2,dl3,dl4,dl5,dl6,dl7,dl8 (Pedestrain)

// registered ports

reg [4:0] p1;

reg [4:0] p2;

reg [4:0] p3;

reg [4:0] p4;

reg [3:0] pt;

reg [30:0] sig;

//************ TRAFFIC LIGHT CONTROLLLER BLOCK ***************//

always @ (posedge clk or negedge rst)

begin

if (rst == 1'b0) //when reset switch is zero TLC is reset.

begin

p1 <= 5'b00100; //at reset condition

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b00100;

pt <= 4'b1111;

sig <= 8'h00000000;

end

else

begin

sig <= sig + 1;

case (sig[29:24])

6'b000000 : begin

p1 <= 5'b10011;// d5,d4,d3,d2,d1 (Green)

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b00100;

Page 66: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 66

pt <= 4'b1111;

end

6'b000100 : begin

p1 <= 5'b01000; //Yellow

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b00100;

pt <= 4'b1111;

end

6'b001000 : begin

p1 <= 5'b00100; // d10,d9,d8,d7,d6

p2 <= 5'b10011; //Green

p3 <= 5'b00100;

p4 <= 5'b00100;

pt <= 4'b1111;

end

6'b001100 : begin

p1 <= 5'b00100;

p2 <= 5'b01000; //Yellow

p3 <= 5'b00100;

p4 <= 5'b00100;

pt <= 4'b1111;

end

6'b010000 : begin

p1 <= 5'b00100; // d15,d14,d13,d12,d11

p2 <= 5'b00100;

p3 <= 5'b10011; //Green

p4 <= 5'b00100;

pt <= 4'b1111;

end

6'b010100 : begin

p1 <= 5'b00100;

p2 <= 5'b00100;

p3 <= 5'b01000; //yellow

p4 <= 5'b00100;

pt <= 4'b1111;

end

6'b011000 : begin

p1 <= 5'b00100; // d20,d19,d18,d17,d16

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b10011; //Green

pt <= 4'b1111;

end

6'b011100 : begin

p1 <= 5'b00100;

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b01000; //Yellow

pt <= 4'b1111;

Page 67: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 67

end

6'b100000 : begin

p1 <= 5'b00100; //dl1,dl2,dl3,dl4,dl5,dl6,dl7,dl8

p2 <= 5'b00100;

p3 <= 5'b00100;

p4 <= 5'b00100;

pt <= 4'b0000; //Pedestrain

end

6'b100100 : sig <= 8'h00000000;

default : begin

end

endcase

end

end

assign dir = 3'b111;

endmodule

Flowchart:-

Page 68: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 68

State Diagram for Traffic Light Controller

EXPERIMENTAL SET UP:

Page 69: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 69

RESULT:

Thus the traffic light controller was implemented and the output is verified in the FPGA kit.

Page 70: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 70

PROCEDURE FOR 4 BIT UPDOWN COUNTER

1. Open Xilinx ISE 9.2i

2. Go to file-> new project

3. Give project name in the new project wizard- create new project dialog box.

4. Click next.

5. Device properties dialog box appears. In that select the following:

Product category : All

Family : Spartan 3E

Device : XC3S250E

Package : TQ144

Speed : -4

Preferred language : VHDL

6. Click next.

7. Click new source.

8. Select source type dialog box appears.

Select VHDL module and give file name.

9. Click next-> next-> finish

10. Click yes-> next-> next -> finish.

11. Type the program.

12. Go to file -> save.

13. In the synthesize-XST, double click check syntax.

14. Go to project-> new source

15. Select implementation constraints file and give file name.

16. Click next -> finish.

17. Select the newly created ucf file.

18. Double click Assign package pins in the User constraints.

19. Type the corresponding Input/ Output pins and save it.

20. Click ok.

21. Double click synthesize-xst, then double click implement design.

22. Double click Programming File Generation Report in Generate Programming File.

23. Switch ON the kit.

24. Double click Configure Device in Generate Programming File.

25. An iMPACT-welcome to iMPACT dialog box appears.

26. Select Enter a boundary-scan chain manually in configure devices using boundary

scan(JTAG) option.

27. Click finish.

28. Right click the mouse, select Add Xilinx device -> select file name.bit -> click open.

29. Click ok.

30. Right click the mouse -> select output file type -> XSVF file -> Create XSVF file.

31. Give file name and save it.

Page 71: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 71

32. Click ok.

33. Click on the Xilinx device -> Right click -> select Program

34. Enable pulse PROG.

35. click ok.

36. Program Succeeded will appear.

37. Right click the mouse -> select output file type -> XSVF file -> Stop writing to file.

38. Minimize the window.

39. Open Top view programmer.

40. click browse -> select file.xsvf from your project -> open.

41. Press Power reset button.

42. Clicks configure.

43. Output will be executed in the kit.

Page 72: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 72

DESIGN AND IMPLEMENTATION OF 4 BIT UPDOWN COUNTER IN FPGA

AIM:

To write a program for implementing 4 bit up down counter and verify the output in FPGA kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

XILINX ISE 9.2i

Spartan 3E FPGA kit

PROGRAM: library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Counter4Bit is

Port ( CLOCK : in STD_LOGIC;

DIRECTION : in STD_LOGIC;

COUNT_OUT : out STD_LOGIC_VECTOR (3 downto 0));

end Counter4Bit;

architecture Behavioral of Counter4Bit is

signal cnt: std_logic_vector(3 downto 0):="0000";

signal cnt1: integer range 0 to 50000000:=0;

signal clk1: std_logic;

begin

process(CLOCK)--Generate low speed clock

begin

if CLOCK='1' and CLOCK'event then--Check CLOCK transition

if cnt1 = 50000000 then --If cnt1 reaches 50,000,000

cnt1 <= 0; --Clear cnt1 and toggle clk1

clk1 <= not clk1;

else

cnt1 <= cnt1+1; --increment cnt1

end if;

end if;

end process;

process(clk1,DIRECTION) --Counter operation

begin

if clk1='1' and clk1'event then--Check clk1 transition

if DIRECTION = '1' then --Direction is '1',up count

cnt <= cnt+1;

else

cnt <= cnt-1; --otherwise down count

end if;

end if;

end process;

COUNT_OUT <= cnt; --assign COUNT_OUT with cnt.

end Behavioral;

Page 73: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 73

State Diagram:

RESULT:

Thus 4 bit up down counter was implemented and the output is verified in the FPGA kit.

Page 74: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 74

PERFORMANCE CHARACTERSTICS OF ARM & FPGA AND

HARDWARE AND SOFTWARE PARTITIONING

PROCEDURE FOR

INTERRUPT PROCESSING PERFORMANCE CHARACTERSTICS OF ARM & FPGA AND

HARDWARE AND SOFTWARE PARTIONING BETWEEN FPGA AND ARM

1. Open Xilinx ISE 9.2i

2. Go to file-> new project

3. Give project name in the new project wizard- create new project dialog box.

4. Click next.

5. Device properties dialog box appears. In that select the following:

Product category : All

Family : Spartan 3E

Device : XC3S250E

Package : TQ144

Speed : -4

Preferred language : VHDL

6. Click next.

7. Click new source.

8. Select source type dialog box appears.

Select VHDL module and give file name.

9. Click next-> next-> finish

10. Click yes-> next-> next -> finish.

11. Type the program.

12. Go to file -> save.

13. In the synthesize-XST, double click check syntax.

14. Go to project-> new source

15. Select implementation constraints file and give file name.

16. Click next -> finish.

17. Select the newly created ucf file.

18. Double click Assign package pins in the User constraints.

19. Type the corresponding Input/ Output pins and save it.

20. Click ok.

21. Double click synthesize-xst, then double click implement design.

22. Double click Programming File Generation Report in Generate Programming File.

23. Switch ON the kit.

24. Double click Configure Device in Generate Programming File.

25. An iMPACT-welcome to iMPACT dialog box appears.

Page 75: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 75

26. Select Enter a boundary-scan chain manually in configure devices using boundary

scan(JTAG) option.

27. Click finish.

28. Right click the mouse, select Add Xilinx device -> select file name.bit -> click open.

29. Click ok.

30. Right click the mouse -> select output file type -> XSVF file -> Create XSVF file.

31. Give file name and save it.

32. Click ok.

33. Click on the Xilinx device -> Right click -> select Program

34. Enable pulse PROG

35. click ok.

36. Program Succeeded will appear.

37. Right click the mouse -> select output file type -> XSVF file -> Stop writing to file.

38. Minimize the window.

39. Open Embest IDE software

40. Go to file->new workspace. a window will appear. In that window give the project

name & the location to be stored.

41. Copy the support file from the original folder to the created folder

42. Right click on project source files & click on add files to folder->select files & add it.

43. Right click on project header files & click on add files to folder -> select files & add it.

44. Go to file -> new -> type the program & save the program with the extension .c

45. Click project ->settings

In processor:

CPU mode: ARM 7

CPU family: ARM 7

Member: ARM 7

Build tools: GNC tools for ARM

In remote:

Remote device: SIM ARM 7

In compiler:

Category: target specific option

Click on little endian

Page 76: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 76

Specify the name of the target: ARM 7TDMI

In assembler:

Category: target specific option

Click on little endian

In linker:

Category : general

Linker script file-> browse->select flash.id

Category : image entry option

Select vector.0

Category : code generation operation

Click->link little endian object

category : include objects &library modules

Select new ->type –lc

Select new ->type -lgcc

category :add library searching path

Select new ->browse ->c:->embest IDE->build ->xgcc arm elf->arm elf->lib

Select new ->browse ->c:->embest IDE->build -> xgcc arm elf->lib->gcc lib-> arm elf

->3.0.2

46. Then click ok

47. Click build->rebuild all

48. Click tools->elf to hex

49. Minimize the window

50. Open flash magic.

51. Press Power reset button

52. Click browse ->select file name.hex from your project -> open

53. Switch on the kit -> press reset button -> click start in the flash magic window

54. After download finished, switch off the kit-> press reset button.

Page 77: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 77

55. Open Top view programmer

56. click browse -> select file.xsvf from your project -> open

57. Clicks configure.

58. Output will be executed in the kit.

INTERRUPT PROCESSING PERFORMANCE CHARACTERSTICS OF ARM & FPGA

AIM:

To write a program for interrupt processing performance characteristics of ARM& FPGA

and to verify the output in the ARM+FPGA kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

XILINX ISE 9.2i

ARM+FPGA Evaluation kit

PROGRAM

(i)VLSI PROGRAM library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

Library UNISIM;

use UNISIM.vcomponents.all;

entity InterruptTest is

Port ( CLOCK : in STD_LOGIC;INTCLK : in STD_LOGIC;

LED : out STD_LOGIC_VECTOR (7 downto 0);

STATUS : out STD_LOGIC;ARMINT : out STD_LOGIC;

ARMSPEED: in STD_LOGIC);

end InterruptTest;

architecture Behavioral of InterruptTest is

signal clk1: std_logic;

signal stat: std_logic:='0';

signal cnt1: std_logic_vector (23 downto 0);

begin

process(CLOCK)

begin --Generate 100MHZ/2 = 50MHZ Clock

if CLOCK='1' and CLOCK'event then

clk1 <= not clk1;

end if;

end process;

process(INTCLK) --Use INTCLK as External interrupt clock

begin

if INTCLK='1' and INTCLK'event then

cnt1 <= cnt1+1; --Interrupt counter

Page 78: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 78

stat <= not stat; --Generate FPGA status signal, Interrupt process freq/2

end if;

end process;

process(clk1) --Count display process

begin

if clk1='1' and clk1'event then

LED <= cnt1(23 downto 16);--Send scaled counter result to LEDs

end if;

end process;

STATUS <= stat; --FPGA Interrupt processing Speed Indicator

ARMINT <= INTCLK; --Loop INTCLK to Generate ARM Interrupt signal.

end Behavioral;

(ii)EMBEEDED PROGRAM

#include "LPC214x.H" // LPC214x definitions

#include "ARMBoard.h" // ARM FPGA Board I/O Usage Description

extern void irq_INT3(void); // Int0 Interrupt process

void INT3_Srv(void);

void InitializeInterrupt(void);

void Initialize_IO(void);

int Counter=0;

int main (void)

{

Initialize_IO(); // I/O Initialization

APBDIV = 1; // PCLK = CCLK = 50MHz

InitializeInterrupt(); // Initialize Int3 interrupt

while(1){}; // Wait for interrupt

}

void Initialize_IO(void)

{

SCS = 3;

FIO0DIR = ARM_BUS | LED_CS | SW_CS | LCD_CS | LCD_RW | SEG_CS | DG3_EN |

DG4_EN | ROW; // Define Output lines

FIO0DIR |= BUZZER;

FIO1DIR = LCD_RS | FPGA_BUS | FPGA_WR;

FIO0SET = LED_CS | SW_CS | SEG_CS; // Disable all peripherals &

FIO0CLR = ARM_BUS | LCD_CS | BUZZER; // Clear Data Bus lines

FIO0SET |= DG3_EN | DG4_EN; // Disable both DG3 and DG4

FIO1SET = FPGA_WR | LCD_RS;

}

//Initialise Interrupt

void InitializeInterrupt(void)

Page 79: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 79

{

PINSEL1 = 0x20000000; // Enable EINT3 (P0.30)

EXTMODE = 0x08; // edge select enabled for interrupts EINT3

VICVectAddr0 = (unsigned long)irq_INT3; // Set the Interrupt3 ISR vector address

VICVectCntl0 = 0x00000031; // Set channel 0 to EINT3

VICIntEnable = 0x00020000; // Enable interrupt EINT3

}

/* Interrupt3 service routine */

void INT3_Srv(void)

{ // Response: 350KHz with counter and 480KHz without

counter

int val;

Counter++; // Increment Counter

val = (Counter>>14) & ARM_BUS;

FIO0SET = val; // Latch count on LEDs

FIO0CLR = (~val) & ARM_BUS;

FIO0CLR = LED_CS; // Generate LED CS

FIO0SET = LED_CS; //

FIO1CLR = ARM_STAT; // Arm Execution speed status, TP4

FIO1SET = ARM_STAT;

EXTINT |=0x08; // Clear flag

VICVectAddr = 0x00000000; // Dummy write to signal end of interrupt

}

void __gccmain()

{

}

RESULT:

Thus interrupt processing performance characteristics of ARM& FPGA was implemented and the

output is verified in the ARM+FPGA kit.

Page 80: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 80

HARDWARE AND SOFTWARE PARTIONING BETWEEN FPGA AND ARM

AIM:

To write a program for Hardware and Software partitioning between FPGA and ARM and to

verify the output in the ARM+FPGA kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

XILINX ISE 9.2i

ARM+FPGA Evaluation kit

PROGRAM:

ARM TO FPGA

(i)VLSI PROGRAM

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ReadARM is

Port ( CLOCK : in STD_LOGIC; LED : out STD_LOGIC_VECTOR (7 downto 0);

ARM_DATA : inout STD_LOGIC_VECTOR (7 downto 0);

ARM_STRB: in STD_LOGIC);

end ReadARM;

architecture Behavioral of ReadARM is

signal buff: std_logic_vector (7 downto 0);

begin

process(ARM_DATA,ARM_STRB) --Get data from ARM Processor

begin

if ARM_STRB='0' and ARM_STRB'event then

buff <= ARM_DATA; --Store result in buffer

end if;

end process;

process(CLOCK) --Result Display process

begin

if CLOCK='1' and CLOCK'event then

LED<=buff; --Send result to LED's

end if;

end process;

end Behavioral;

(ii)EMBEEDED PROGRAM

#include "LPC214x.H" // LPC214x definitions

#include "ARMBoard.h" // ARM FPGA Board I/O Usage Description

void Initialize_IO(void);

int main (void)

{

int sw;

Initialize_IO(); // I/O Initialization

while(1)

Page 81: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 81

{

IODIR0 &= ~ARM_BUS; // Configure ARM Bus as input

IOCLR0 = SW_CS; // Generate Toggle Switch CS

sw = IOPIN0 & SW_BUS; // Get Switch status

IOSET0 = SW_CS; // Disable Toggle Switch CS

sw = sw<<14; // Align to FPGA BUS

IOSET1 = sw; // Send result to FPGA

IOCLR1 = (~sw) & FPGA_BUS;

IOCLR1 = FPGA_WR; // Generate FPGA Write signal

IOSET1 = FPGA_WR;

}

}

void Initialize_IO(void)

{

IODIR0 = ARM_BUS | LED_CS | SW_CS | LCD_CS | LCD_RW | SEG_CS | DG3_EN |

DG4_EN | ROW; // Define Output lines

IODIR0 |= BUZZER;

IODIR1 = LCD_RS | FPGA_BUS | FPGA_WR;

IOSET0 = LED_CS | SW_CS | SEG_CS | LCD_RS; // Disable all peripherals &

IOCLR0 = ARM_BUS | LCD_CS | BUZZER; // Clear Data Bus lines

IOSET0 |= DG3_EN | DG4_EN; // Disable both DG3 and DG4

IOSET1 = FPGA_WR;

}

void __gccmain()

{

}

FPGA TO ARM

(i)VLSI PROGRAM library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity WriteARM is

Port (CLOCK : in STD_LOGIC; SW_IN: in STD_LOGIC_VECTOR (3 downto 0);

ARM_STRB: in STD_LOGIC;ARM_DATA: inout STD_LOGIC_VECTOR (7 downto 0));

end WriteARM;

architecture Behavioral of WriteARM is

signal buff: std_logic_vector (7 downto 0);

begin

process(CLOCK) --Input Data Processing @ 100Mhz

begin

if CLOCK='1' and CLOCK'event then

buff(3 downto 0) <= SW_IN; --Store digital input in buffer

end if;

end process;

process(ARM_STRB,buff) --ARM Data bus handler

begin

if ARM_STRB='0' and ARM_STRB'event then --Check positive edge

ARM_DATA<=buff; --Send result to ARM processor

end if;

Page 82: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 82

end process;

end Behavioral;

(ii)EMBEEDED PROGRAM

#include "LPC214x.H" // LPC214x definitions

#include "ARMBoard.h" // ARM FPGA Board I/O Usage Description

void Initialize_IO(void);

int main (void)

{

int d;

Initialize_IO(); // I/O Initialization

while(1)

{

IODIR1 &= ~FPGA_BUS; // Configure FPGA Bus as input

IOCLR1 = FPGA_WR; // Generate FPGA Strobe Signal

d = IOPIN1 & FPGA_BUS; // Get input data from FPGA

IOSET1 = FPGA_WR; // Disable FPGA Strobe Signal

d = d>>14; // Align data to ARM Bus

IOSET0 = d; // Latch data on ARM Bus

IOCLR0 = (~d) & ARM_BUS;

IOCLR0 = LED_CS; // Generate LED chip select

IOSET0 = LED_CS;

}

}

void Initialize_IO(void)

{

IODIR0 = ARM_BUS | LED_CS | SW_CS | LCD_CS | LCD_RW | SEG_CS | DG3_EN |

DG4_EN | ROW; // Define Output lines

IODIR0 |= BUZZER;

IODIR1 = LCD_RS | FPGA_BUS | FPGA_WR;

IOSET0 = LED_CS | SW_CS | SEG_CS | LCD_RS; // Disable all peripherals &

IOCLR0 = ARM_BUS | LCD_CS | BUZZER; // Clear Data Bus lines

IOSET0 |= DG3_EN | DG4_EN; // Disable both DG3 and DG4

IOSET1 = FPGA_WR;

}

void __gccmain()

{

}

RESULT:

Thus Hardware and Software partitioning between FPGA and ARM was implemented and the

output is verified in the ARM+FPGA kit.

Page 83: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 83

IMPLEMENTATION OF WIRELESS COMMUNICATION PROTOCOL

PROCEDURE

FOR MASTER

1. Open Embest IDE software

2. Go to file->new workspace. a window will appear. In that window give the project

name & the location to be stored.

3. Copy the support file from the original folder to the created folder.

4. Right click on project source files & click on add files to folder->select files & add it.

5. Right click on project header files & click on add files to folder -> select files & add it.

6. Go to file -> new -> type the program & save the program with the extension .c

7. Click project ->settings

In processor:

CPU mode: ARM 7

CPU family: ARM 7

Member: ARM 7

Build tools: GNC tools for ARM

In remote:

Remote device: SIM ARM 7

In compiler:

Category: target specific option

Click on little endian

Specify the name of the target: ARM 7TDMI

In assembler:

Category: target specific option

Page 84: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 84

Click on little endian

In linker:

Category : general

Linker script file-> browse->select flash.id

Category : image entry option

Select vector.0

Category : code generation operation

Click->link little endian object

8. Then click ok

9. Click build->rebuild all

10. Click tools->elf to hex

11. Minimize the window

12. Open flash magic.

13. Click browse ->select file name.hex from your project -> open

14. Switch on the kit -> press reset button -> click start in the flash magic window.

15. Minimize the window.FOR SLAVE

16. Open another Embest IDE software.

17. Go to file->new workspace. a window will appear. In that window give the project

name & the location to be stored.

18. Copy the support file from the original folder to the created folder.

19. Right click on project source files & click on add files to folder->select files & add it.

20. Right click on project header files & click on add files to folder -> select files & add it.

21. Go to file -> new -> type the program & save the program with the extension .c

22. Click project ->settings

In processor:

CPU mode: ARM 7

Page 85: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 85

CPU family: ARM 7

Member: ARM 7

Build tools: GNC tools for ARM

In remote: Remote device: SIM ARM 7

In compiler:Category: target specific option

Click on little endian

Specify the name of the target: ARM 7TDMI

In assembler:

Category: target specific option

Click on little endian

In linker:

Category : general

Linker script file-> browse->select flash.id

Category : image entry option

Select vector.0

Category : code generation operation

Click->link little endian object

23. Then click ok

24. Click build->rebuild all

25. Click tools->elf to hex

26. Minimize the window

27. Open another flash magic.

28. Click browse ->select file name.hex from your project -> open

29. Switch on the kit -> press reset button -> click start in the flash magic window.

Page 86: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 86

IMPLEMENTATION OF ZIGBEE PROTOCOL WITH ARM7

AIM:

To write a program for zigbee protocol with arm7 and to verify the output in the ARM wireless

sensor network kit.

HARDWARE AND SOFTWARE REQUIRED:

PC

EMBEST IDE

ARM wireless sensor network kit.

PROGRAM:

(i)ZIGBEE MASTER

#include "LPC214X.H"

#include "ARMBoard.h" // ARM Wireless Board I/O Usage Description

#include "WirelessCommands.h"

void Initialize_IO(void);

void delay(void);

int ReadADC(char ChannelNumber);

int main (void)

{

int b;

Initialize_IO(); // I/O Initialization

PINSEL1 = 0x05000000; // Enable ADC input pins P0.28 & P0.29

IOCLR0 = XBEE_RST; // Reset XBEE Module

InitializeLCD(); // Initialize LCD

DisplayLCD(0," WireLess Study "); // Display message

DisplayLCD(1," "); // Display message

InitializeSerialPort(); // Initialize Serial port

IOSET0 = XBEE_RST; // Reset=1, enable XBEE Module

EnterCommandMode(); // Select command mode

SetSelfID("NODE0"); // Self Node name

ExitCommandMode();

SendByteSer(SYNC); // Send sync byte to slave

EnterCommandMode(); // Select command mode

while(1)

{

if(Connect("NODE1")=='O') break; // Connect Destination Node2

}

while(1)

{

b=ReadADC(2); // Read ADC channel 2

SendByteSer(LED_DATA); // Send LED control command to destination node

SendByteSer(b); // Transmit ADC Result to destination node

SendByteSer(ADC); // Send ADC process command to destination node

b=ReadByte()<<16; // Receive ADC Result of Kit2

IOSET1 = b; // Display the data on LEDs

IOCLR1 = (~b) & ARM_BUS;

Page 87: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 87

IOCLR0 = LED_CS; // Generate LED CS

IOSET0 = LED_CS;

SendByteSer(PROX); // Send Object sense command to destination node

if(ReadByte()==0) IOSET0 = BUZZER; / When object found, Turn on Buzzer

else IOCLR0 = BUZZER;

}

}

// Initializes I/O Lines

void Initialize_IO(void)

{

IODIR0 = LED_CS | SW_CS | LCD_CS | LCD_RW | LCD_RS | BUZZER;

IOCLR0 = LCD_CS | LCD_RW | LCD_RS | BUZZER;

IOSET0 = LED_CS | SW_CS; // Disable all peripherals

IODIR1 = ARM_BUS; // Define ARM BUS lines as output

IOCLR1 = ARM_BUS; // Clear Data Bus lines

IODIR0 |= XBEE_TXD1 | XBEE_RST | XBEE_RTS; // XBEE interface lines

IOSET0 = XBEE_TXD1 | XBEE_RST | XBEE_RTS;

}

void delay(void)

{

int i,j,k;

{

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

{

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

{

j++;

}

}

}

}

//Read ADC data from given channel number

int ReadADC(char ChannelNumber)

{

int val,ch;

ch = 1<<ChannelNumber;

AD0CR = 0x00210400 | ch; // Setup A/D: 10-bit AIN @ 3MHz

AD0CR |= 0x01000000; // Start A/D Conversion

do

{

val = AD0DR2; // Read A/D Data Register

}

while ((val & 0x80000000) == 0); // Wait for the conversion to complete

val = ((val >> 6) & 0x03FF); // Extract the A/D result

AD0CR &= ~0x01000000; // Stop A/D Conversion

return(val>>2); // Return upper 8-bits

}

void __gccmain()

{

}

Page 88: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 88

(ii)ZIGBEE SLAVE

#include "LPC214X.H"

#include "ARMBoard.h" // ARM Wireless Board I/O Usage Description

#include "WirelessCommands.h"

void Initialize_IO(void);

void delay(void);

int ReadADC(char ChannelNumber);

int main (void)

{

int b,cmd;

char N0,N1,N2;

Initialize_IO(); // I/O Initialization

PINSEL1 = 0x05000000; // Enable ADC input pins P0.28 & P0.29

IOCLR0 = XBEE_RST; // Reset XBEE Module

InitializeLCD(); // Initialize LCD

DisplayLCD(0," WireLess Study "); // Display message

DisplayLCD(1," "); // Display message

InitializeSerialPort(); // Initialize Serial port

IOSET0 = XBEE_RST; // Reset=1, enable XBEE Module

EnterCommandMode(); // Select command mode

SetSelfID("NODE1"); // Self Node name

ExitCommandMode(); // Exit command mode

ReadByte(); // Get Sync from Node0

EnterCommandMode(); // Select command mode

Connect("NODE0"); // Connect with Node0

while(1)

{

cmd = ReadByte();

if(cmd==LED_DATA) // Check LED control command?

{

b=ReadByte()<<16; // Receive ADC Result of Kit2

IOSET1 = b; // Display the data on LEDs

IOCLR1 = (~b) & ARM_BUS;

IOCLR0 = LED_CS; // Generate LED CS

IOSET0 = LED_CS;

}

if(cmd==ADC) // Check ADC?

{

b=ReadADC(2); // Read ADC channel 2

SendByteSer(b); // Transmit ADC Result to master node

}

if(cmd==PROX)

{

b = ((IOPIN1 & PROX_IN)>>25)&1;

SendByteSer(b); // Transmit Result to master node

}

}

}

// Initializes I/O Lines

Page 89: Embs Final Manual

EMBEDDED SYSTEMS LAB MANUAL SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR

IV YEAR

ISSUE: 01 REVISION: 00 89

void Initialize_IO(void)

{

IODIR0 = LED_CS | SW_CS | LCD_CS | LCD_RW | LCD_RS | BUZZER; IOCLR0 =

LCD_CS | LCD_RW | LCD_RS | BUZZER;

IOSET0 = LED_CS | SW_CS; // Disable all peripherals

IODIR1 = ARM_BUS; // Define ARM BUS lines as output

IOCLR1 = ARM_BUS; // Clear Data Bus lines

IODIR0 |= XBEE_TXD1 | XBEE_RST | XBEE_RTS; // XBEE interface lines

IOSET0 = XBEE_TXD1 | XBEE_RST | XBEE_RTS;

}

void delay(void)

{

int i,j,k;

{

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

{

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

{

j++;

}

}

}

}

int ReadADC(char ChannelNumber)

{

int val,ch;

ch = 1<<ChannelNumber;

AD0CR = 0x00210400 | ch; // Setup A/D: 10-bit AIN @ 3MHz

AD0CR |= 0x01000000; // Start A/D Conversion

do

{

val = AD0DR2; // Read A/D Data Register

}

while ((val & 0x80000000) == 0); // Wait for the conversion to complete

val = ((val >> 6) & 0x03FF); // Extract the A/D result

AD0CR &= ~0x01000000; // Stop A/D Conversion

return(val>>2); // Return upper 8-bits

}

void __gccmain()

{

}

RESULT:

Thus zigbee protocol with arm7 was implemented and the output is verified in the ARM wireless

sensor network kit.