100% found this document useful (1 vote)
1K views

18ecl66 - Embedded Systems Laboratory

This document provides information for the 6th semester Embedded Systems Laboratory course including 13 experiments covering ARM Cortex M3 assembly language programming and interfacing external devices using C programming. It lists the course objectives, experiments, evaluation details, and lab rules. The experiments include programming ARM Cortex M3 using assembly language to perform tasks like multiplication and using C to interface devices like DC motors, keyboards and displays.

Uploaded by

tefflon trolegdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

18ecl66 - Embedded Systems Laboratory

This document provides information for the 6th semester Embedded Systems Laboratory course including 13 experiments covering ARM Cortex M3 assembly language programming and interfacing external devices using C programming. It lists the course objectives, experiments, evaluation details, and lab rules. The experiments include programming ARM Cortex M3 using assembly language to perform tasks like multiplication and using C to interface devices like DC motors, keyboards and displays.

Uploaded by

tefflon trolegdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

2021-22

6TH SEM EMBEDDED SYSTEMS LAB


EMBEDDED SYSTEMS LABORATORY

18ECL66
FOR

VI SEMESTER B.E. (E & CE)


(For private circulation only)

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

NAME………………………….

USN……………………………

BATCH………………………..

DEPARTMENT OF ELECTRONICS & COMMUNICATION

CITY ENGINEERING COLLEGE


Kanakapura Road, near METRO Station, Doddakallasandra, Bengaluru, Karnataka 560061.
EMBEDDED SYSTEMS LABORATORY

Course Code :18ECL66 CIE Marks:40 SEE Marks :60


Lecture Hours/Week: 02 Hours Tutorial (Instructions) + 02 Hours Laboratory
RBT Level: Ll, L2, L3 Exam Hours :03
CREDITS--02

Course Learning Objectives: This course will enable students to:


• Understand the instruction set of ARM Cortex M3, a 32-bit microcontroller and the
software tool required for programming in Assembly and C language.
• Program ARM Cortex M3 using the various instructions in assembly level language
for different applications.
• Interface external devices and I/O with ARM CortexM3.
• Develop C language programs and library functions for embedded system
applications.

Laboratory Experiments
Conduct the f o l l o w i n g experiments on a n ARM C O R T E X M3 evaluation board
t o learn ALP and u s i n g evaluation version of Embedded 'C' & Keil uVision-4
tool/compiler.

PART A:
1. ALP to multiply two 16-bit binary numbers.
2. ALP to find the sum of first 10 integer numbers.
3. ALP to find the number of 0’s and 1 ‘s in a 32- b i t data
4. ALP to find determine whether the given 16 bit is even or odd
5. ALP to write data to RAM

PART B:
6. Display ''Hello world" message using internal UART
7. Interface and Control the speed of a DC Motor.
8. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
9. Interface a DAC and generate Triangular and Square waveforms.
10. Interface a 4x4 keyboard and display the key code on an LCD.
11. Demonstrate the use of an external interrupt to toggle an LED On/Off.
12 Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay.
13. Measure Ambient temperature using a sensor and SPIADC IC.

Course outcomes: After studying this course, students will be able to:
1. Understand the instruction set of32 bit microcontroller ARM Cortex M3, and the
software tool required for programming in Assembly and C language.
2. Develop assembly language programs using ARM Cortex M3 for different
applications.
3. Interface external devices and1/0 with ARM Cortex M3.
4. Develop C language programs and library functions for embedded system
applications.
5. Analyze the functions of various peripherals, peripheral registers and power saving
modes of ARM Cortex M3

Conduction of Practical Examination:


• One Question from PART A and one Question from PART B to be asked in the
examination.
• Strictly follow the instructions as printed on the cover page of answer script for breakup
of marks.
• Change of experiment is allowed only once and Marks allotted to the
• procedure part to be made zero.

VK
18ECL66 Embedded Systems Laboratory

Lab Rule of conduct, DO’s & DON’Ts

• Conduct yourself in a responsible manner at all times in the laboratory. Don’t


talk aloud or crack jokes in lab.
• A lab coat should be worn during laboratory experiments. Dress properly during
a laboratory activity. Long hair, dangling jewelry and loose or baggy clothing are
a hazard in the laboratory.
• Observe good housekeeping practices. Replace the materials in proper place after
work to keep the lab area tidy.
• Do not wander around the room, distract other students, startle other students or
interfere with the laboratory experiments of others.
• Do not eat food, drink beverages or chew gum in the laboratory and do not use
laboratory glassware as containers for food or beverages. Smoking is strictly
prohibited in lab area.
• Do not open any irrelevant internet sites on lab computer
• Do not use a flash drive on lab computers.
• Do not upload, delete or alter any software on the lab PC.

Dept. of E&CE, CEC

VK
18ECL66 Embedded Systems Laboratory

Rules & Guidelines for conducting Lab-Work

✓ Students are not allowed to touch any equipment, chemicals or other materials in
the laboratory area until you are instructed by Teacher or Technician.
✓ Before starting Laboratory work follow all written and verbal instructions
carefully. If you do not understand a direction or part of a procedure, ASK YOUR
CONCERN TEACHER BEFORE PROCEEDING WITH THE ACTIVITY.
✓ Before use equipment must be read carefully Labels and instructions. Set up and
use the equipment as directed by your teacher.
✓ If you do not understand how to use a piece of equipment, ASK THE TEACHER
FOR HELP!
✓ Perform only those experiments authorized by your teacher.
✓ Carefully follow all instructions, both written and oral.
✓ Unauthorized experiments are not allowed in the Laboratory.
✓ Students are not allowed to work in Laboratory alone or without presence of the
teacher.
✓ Any failure / break-down of equipment must be reported to the teacher.
✓ Protect yourself from getting electric shock.

Dept. of E&CE, CEC

VK
18ECL66 Embedded Systems Laboratory

Project Creation in Keil uvision4 IDE:

❖ Create a project folder before creating NEW project.


❖ Use separate folder for each project
❖ Open Keil uVision4 IDE software by double clicking on “Keil Uvision4” icon.
❖ Go to “Project” then to “New Project” and save it with a name in the Respective
Project folder, already you created.
❖ Select the device as “NXP (founded by Philips)” In that “LPC1768” then Press OK
and then press “NO” button to add “system_LPC17xx.s” file.
❖ Go to “File” In that “New” to open an editor window. Create your source file and use
the header file “LPC17xx.h” in the source file and save the file. Color syntax
highlighting will be enabled once the file is saved with a Recognized extension such
as “.C ”.
❖ Right click on “Source Group 1” and select the option “Add Files to Group 'Source
Group 1 ” add the. C source file(s) to the group.
❖ Again right click on Source Group 1 and select the option “Add Existing Files to Group
'Source Group 1” add the library file start.lib : So it is recommended to copy the file
CD: ALS-SDA-ARMCTXM3-06 \SOFTWARE\library\standard_library\start.lib to
the project folder and add to the source group.
❖ Then go to “Project” in that “Translate” to compile the File (s).
❖ Go to “Project” in that “Build Target” for building all source files such as
“.C”,”.ASM”, “.h”, files, etc…This will create the hex file if no warnings & no Errors.
❖ In Project Window Right click “TARGET1” and select “options for target
TARGET1’
❖ Then go to option “Target” in that
• Xtal 12.0MHz and Use MicroLIB
• Select IROM1 (starting 0×0 size 0×8000).
• Select IRAM1 (starting 0×10000000 size 0×8000).
❖ Then go to option “Output”
• Select “Create Hex file”.
❖ Then go to option “Linker”
• Select use memory layout from target dialog

Dept. of E&CE, CEC

VK
18ECL66 Embedded Systems Laboratory

1. ALP to multiply two 16-bit binary numbers.

Aim: To multiply two 16-bit binary numbers

Objectives:

• To write an ALP in ARM LPC1768.


• To multiply two 16-bit binary numbers.

ALGORITHM

1. load two to numbers to be multiplied into R1 & R2 multiply the numbers


in R1 & R2
2. store the result in R3

AREA FILENAME, CODE


ENTRY
EXPORT __main

__main
LDR R1,=0XFFFF
LDR R2,=0XFFFF
MUL R3,R1,R2
NOP
Stop
END

Dept. of E&CE, CEC 1

VK
18ECL66 Embedded Systems Laboratory

2. ALP to find the number of 0’s and 1‘s in a 32-bit data

Aim: To determine the 1’s and 0’s in the given 32-bit data using assembly level
language.

Objectives:

1. To Learn assembly level program (ALP) using ARM cortex M3 microcontroller


(LPC 1768).
2. To Efficiently use data transfer instructions and Shift instructions.

Materials:

Software: Keil microvision4 IDE.

AREA mull, CODE, READONLY


EXPORT __main

__main

MOVS R1, #0x00000001 ; Register Rd


MOVS R2, #0X0000001F ; Counter register
MOVS R3, #0x00000000
MOVS R4, #0x00000000; ZEROES
label MOVS R1, R1, LSR#1
MRS R5, APSR
CMP R5, #0x60000000
BNE L1
ADDS R3, #0x00000001
L1 B L
L ADDS R4, #0x00000001
SUBS R2, # X00000091
CMP R2, #0x00000000
BNE label
L2 B L2
END

Dept. of E&CE, CEC 2

VK
18ECL66 Embedded Systems Laboratory

3. ALP to find determine whether the given 16 bit is even or odd

Aim: To determine whether the given 16 bit is even or odd using assembly level
language.

Objectives:

1. To Learn assembly level program (ALP) using ARM cortex M3 microcontroller


(LPC 1768).
2. To Efficiently use data transfer instructions and Shift instructions.

Materials:

Software: Keil microvision4 IDE.

ALGORITHM

1. Start
2. Initialize the number to find it even or odd(0x91)
3. Load this number in R1 register.
4. Check the LSB of the number by logical shirt right by 1 time.
5. Move to branch if LSB= 1.
6. If the number if Even store 0xEEEE in R1 register.
7. If the number if Odd store Ox1111 in R1 register.
8. End

AREA CODE1, CODE, READONLY


EXPORT __main
NUM DCD 0x91; initialize the number
__main
LDR RO, NUM
LSRS RO, #1
BCS NEXT
MOV R1,#0xEEEE
B stop
NEXT MOV R1, #0x1111
stop B stop
END

Dept. of E&CE, CEC 3

VK
18ECL66 Embedded Systems Laboratory

4. ALP to write data to RAM

Aim: To write data to RAM using assembly level language.

Objectives:

1. To Learn assembly level program (ALP) using ARM cortex M3 microcontroller


(LPC 1768).
2. To efficiently use Load & Store instructions.

Materials:

Software: Keil microvision4 IDE.

ALGORITHM
1. Start
2. Initialize the data 0x12345678
3. Load this data to RO register.
4. Load R1 register with Address of Destination Location.
5. Write the contents of RO into RAM location.
6. Find the RAM location and its content.
7. End

AREA datatransfer, CODE, READONLY


EXPORT__main
DATA DCD 0x12345678

__main
LDR R0, DATA
LDR R1, =RAMLOC
STR R0, [R1]
AREA RAM, DATA, READWRITE
RAMLOC DCD 0

END

Dept. of E&CE, CEC 4

VK
18ECL66 Embedded Systems Laboratory

5. ALP to find the sum of first 10 integer numbers.

Aim: To Find the Sum of First 10 Integer Numbers.

AREA sum,CODE,READONLY
EXPORT __main
__main
MOV R0,#10 ; load 10 to register
MOV R1,#0 ; empty the register to store result
loop
ADD R1,R0 ; add the content of R1 with result at R0
SUBS R1,#1 ; Decrement R1 by 1
BNE loop ; repeat till r1 goes 0
LDR R0,=0x10000000 ; load the addrs of var into R0
STR R1,[R0] ; store the result into addrs location

NOP
NOP
end

Dept. of E&CE, CEC 5

VK
18ECL66 Embedded Systems Laboratory

1. Display ''Hello world" message using internal UART


#include<LPC17xx.h>

void delay(unsigned int r1);


void UART0_Init(void);

unsigned int i;
unsigned char * ptr, arr[] = "Hello world\r";
#define THR_EMPTY 0x20 //U0THR is Empty
int main(void)
{
UART0_Init();
while (1)
{
ptr = arr;
while ( * ptr != '\0')
{
while ((LPC_UART0 -> LSR & THR_EMPTY) != THR_EMPTY); //Is U0THR is EMPTY??
LPC_UART0 -> THR = * ptr++;
}
for (i = 0; i <= 60000; i++);
}
}

Dept. of E&CE, CEC 6


18ECL66 Embedded Systems Laboratory

void UART0_Init(void)
{
LPC_SC -> PCONP |= 0x00000008; //UART0 peripheral enable
LPC_PINCON -> PINSEL0 = 0x00000050;
LPC_UART0 -> LCR = 0x00000083;
//enable divisor latch, parity disable, 1 stop bit, 8bit word length
LPC_UART0 -> DLM = 0X00;
LPC_UART0 -> DLL = 0x1A; //select baud rate 9600 bps for 4Mhz
LPC_UART0 -> LCR = 0X00000003; //Disable divisor latch
LPC_UART0 -> FCR = 0x07; //FIFO enable,RX FIFO reset,TX FIFO reset
}

Dept. of E&CE, CEC 7


18ECL66 Embedded Systems Laboratory

2. Interface and Control the speed of a DC Motor.

#include <LPC17xx.H>

void Clock_Wise(void);
void AClock_Wise(void);

unsigned long i;
int main(void)
{
LPC_PINCON -> PINSEL1 = 0x00000000; //P0.26 GPIO, P0.26 controls dir
LPC_PINCON -> PINSEL3 = 0x00000000; //P1.24 GPIO
LPC_GPIO0 -> FIODIR |= 0x04000000; //P0.26 output
LPC_GPIO1 -> FIODIR |= 0x01000000; //P1.24 output

while (1)
{
Clock_Wise();
for (i = 0; i < 300000; i++);
AClock_Wise();
for (i = 0; i < 300000; i++);
} //end while(1)

} //end main

Dept. of E&CE, CEC 8


18ECL66 Embedded Systems Laboratory

void Clock_Wise(void)
{
LPC_GPIO1 -> FIOCLR = 0x01000000; //P1.24 Kept low to off DCM
for (i = 0; i < 10000; i++); //delay to componsate inertia
LPC_GPIO0 -> FIOSET = 0x04000000; //coil is on
LPC_GPIO1 -> FIOSET = 0x01000000; //motor in on
} //end void Clock_Wise(void)

void AClock_Wise(void)
{
LPC_GPIO1 -> FIOCLR = 0x01000000; //P1.24 Kept low to off DCM
for (i = 0; i < 10000; i++); //delay to componsate inertia
LPC_GPIO0 -> FIOCLR = 0x04000000; //coil is off
LPC_GPIO1 -> FIOSET = 0x01000000; //Motor is on
}

Dept. of E&CE, CEC 9


18ECL66 Embedded Systems Laboratory

3. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.


#include <LPC17xx.H>

void clock_wise(void);
void anti_clock_wise(void);
unsigned long int var1, var2;
unsigned int i = 0, j = 0, k = 0;

int main(void)
{
LPC_PINCON -> PINSEL4 = 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2 -> FIODIR = 0x0000000F; //P2.0 to P2.3 output
while (1)
{
for (j = 0; j < 50; j++) //50 times in Clock wise Rotation
clock_wise();

for (k = 0; k < 65000; k++); //Delay to show anti_clock Rotation

for (j = 0; j < 50; j++) //50 times in Anti Clock wise Rotation
anti_clock_wise();

for (k = 0; k < 65000; k++); //Delay to show clock Rotation


} //End of while(1)
} //End of main

Dept. of E&CE, CEC 10


18ECL66 Embedded Systems Laboratory

void clock_wise(void)
{
var1 = 0x00000001; //For Clockwise
for (i = 0; i <= 3; i++) //for A B C D Stepping
{
LPC_GPIO2 -> FIOCLR = 0X0000000F;
LPC_GPIO2 -> FIOSET = var1;
var1 = var1 << 1; //For Clockwise
for (k = 0; k < 15000; k++); //for step speed variation
}
}
void anti_clock_wise(void)
{
var1 = 0x0000008; //For Anticlockwise
for (i = 0; i <= 3; i++) //for A B C D Stepping
{
LPC_GPIO2 -> FIOCLR = 0X0000000F;
LPC_GPIO2 -> FIOSET = var1;
var1 = var1 >> 1; //For Anticlockwise
for (k = 0; k < 15000; k++); //for step speed variation
}
}

Dept. of E&CE, CEC 11


18ECL66 Embedded Systems Laboratory

4. Interface a DAC and generate Triangular and Square waveforms.

//TRIANGULAR WAVE
#include <LPC17xx.H>

int main()
{
unsigned long int temp = 0x00000000;
unsigned int i = 0;

LPC_PINCON -> PINSEL0 &= 0xFF0000FF; // Configure P0.4 to P0.11 as GPIO


LPC_GPIO0 -> FIODIR |= 0x00000FF0;
LPC_GPIO0 -> FIOMASK = 0XFFFFF00F;

while (1)
{
//output 0 to FE
for (i = 0; i != 0xFF; i++)
{
temp = i;
temp = temp << 4;
LPC_GPIO0 -> FIOPIN = temp;
}
// output FF to 1
for (i = 0xFF; i != 0; i--)
{
temp = i;
temp = temp << 4;
LPC_GPIO0 -> FIOPIN = temp;
}
} //End of while(1)
} //End of main()

Dept. of E&CE, CEC 12


18ECL66 Embedded Systems Laboratory

//SQUARE WAVE

#include <LPC17xx.H>

void delay(void);

int main()
{
LPC_PINCON -> PINSEL0 &= 0xFF0000FF; // Configure P0.4 to P0.11 as GPIO
LPC_GPIO0 -> FIODIR |= 0x00000FF0;
LPC_GPIO0 -> FIOMASK = 0XFFFFF00F;
while (1)
{
LPC_GPIO0 -> FIOPIN = 0x00000FF0;
delay();
LPC_GPIO0 -> FIOCLR = 0x00000FF0;
delay();
}
}

void delay(void)
{
unsigned int i = 0;
for (i = 0; i <= 9500; i++);
}

Dept. of E&CE, CEC 13


18ECL66 Embedded Systems Laboratory

5. Interface a 4x4 keyboard and display the key code on an LCD.

#include <LPC17xx.h>

#include "lcd.h"

void scan(void);

unsigned char Msg1[14] = "ALS BENGALURU";


unsigned char Msg2[13] = "KEY PRESSED=";
unsigned char col, row,
var, flag, key, * ptr; /**********************************************************
* Header file for LCD.c file
unsigned long int i, var1, temp, temp3; * Declared the functions and variables related to .c file
**********************************************************/
#ifndef __LCD_H
unsigned char SCAN_CODE[16] = #define __LCD_H
{
#define RS_CTRL 0x00000010 //P2.4
0x1E, #define EN_CTRL 0x00000020 //P2.5
0x1D, #define DT_CTRL 0x000003C0 //P2.6 to P2.9 data lines
0x1B,
0x17, void lcd_init(void);
0x2E, void wr_cn(void);
void clr_disp(void);
0x2D, void delay_lcd(unsigned int);
0x2B, void lcd_com(void);
0x27, void wr_dn(void);
0x4E, void lcd_data(void);
0x4D, void clear_ports(void);
void lcd_puts(unsigned char *);
0x4B,
0x47, extern unsigned long int temp1 , temp2;
0x8E,
0x8D, #endif
0x8B,

Dept. of E&CE, CEC 14


18ECL66 Embedded Systems Laboratory

0x87
};

unsigned char ASCII_CODE[16] =


{
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'
};

int main(void)
{
LPC_PINCON -> PINSEL3 = 0x00000000; //P1.20 to P1.23 MADE GPIO
LPC_PINCON -> PINSEL0 = 0x00000000; //P0.15 as GPIO
LPC_PINCON -> PINSEL1 = 0x00000000; //P0.16 t0 P0.18 made GPIO
LPC_GPIO0 -> FIODIR &= ~0x00078000; //made INput P0.15 to P0.18 (cols)
LPC_GPIO1 -> FIODIR |= 0x00F00000; //made output P1.20 to P1.23 (rows)
LPC_GPIO1 -> FIOSET = 0x00F00000;

Dept. of E&CE, CEC 15


18ECL66 Embedded Systems Laboratory

lcd_init();

temp1 = 0x80; //point to first line of LCD


lcd_com();
delay_lcd(800);
lcd_puts( & Msg1[0]); //display the messsage

temp1 = 0xC0; //point to first line of LCD


lcd_com();
delay_lcd(800);
lcd_puts( & Msg2[0]); //display the messsage

while (1)
{
while (1)
{
for (row = 1; row < 5; row++)
{
if (row == 1)
var1 = 0x00100000;
else if (row == 2)
var1 = 0x00200000;
else if (row == 3)
var1 = 0x00400000;
else if (row == 4)
var1 = 0x00800000;

temp = var1;

LPC_GPIO1 -> FIOSET = 0x00F00000;


LPC_GPIO1 -> FIOCLR = var1;

Dept. of E&CE, CEC 16


18ECL66 Embedded Systems Laboratory

flag = 0;
scan();
if (flag == 1)
break;

} //end for(row=1;row<5;row++)

if (flag == 1)
break;

} //2nd while(1)

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


{
if (key == SCAN_CODE[i])
{
key = ASCII_CODE[i];
break;
} //end if(key == SCAN_CODE[i])

} //end for(i=0;i<16;i++)

temp1 = 0xCC;
lcd_com();
delay_lcd(800);
lcd_puts( & key);

} //end while 1
} //end main

void scan(void)
{

Dept. of E&CE, CEC 17


18ECL66 Embedded Systems Laboratory

unsigned long temp3;


temp3 = LPC_GPIO0 -> FIOPIN;
temp3 &= 0x00078000;
if (temp3 != 0x00078000)
{
for (i = 0; i < 500; i++);
temp3 = LPC_GPIO0 -> FIOPIN;
temp3 &= 0x00078000;
if (temp3 != 0x00078000)
{
flag = 1;
temp3 >>= 15; //Shifted to come at LN of byte
temp >>= 16; //shifted to come at HN of byte
key = temp3 | temp;
} //2nd if(temp3 != 0x00000000)
} //1st if(temp3 != 0x00000000)
} //end scan

Dept. of E&CE, CEC 18


18ECL66 Embedded Systems Laboratory

6. Demonstrate the use of an external interrupt to toggle an LED On/Off.


#include<LPC17xx.h>

void EINT3_IRQHandler(void);

unsigned char int3_flag = 0;

int main(void)
{
LPC_PINCON -> PINSEL4 |= 0x04000000; //P2.13 as EINT3
LPC_PINCON -> PINSEL4 &= 0xFCFFFFFF; //P2.12 GPIO for LED
LPC_GPIO2 -> FIODIR = 0x00001000; //P2.12 is assigned output
LPC_GPIO2 -> FIOSET = 0x00001000; //Initiall LED is kept on

LPC_SC -> EXTINT = 0x00000008; //writing 1 cleares the interrupt, get set if there is
interrupt
LPC_SC -> EXTMODE = 0x00000008; //EINT3 is initiated as edge senitive, 0 for level
sensitive
LPC_SC -> EXTPOLAR = 0x00000000; //EINT3 is falling edge sensitive, 1 for rising edge
//above registers, bit0-EINT0, bit1-EINT1, bit2-EINT2,bit3-EINT3
NVIC_EnableIRQ(EINT3_IRQn); //core_cm3.h

while (1);
}

void EINT3_IRQHandler(void)
{
LPC_SC -> EXTINT = 0x00000008; //cleares the interrupt

Dept. of E&CE, CEC 19


18ECL66 Embedded Systems Laboratory

if (int3_flag == 0x00) //when flag is '0' off the LED


{
LPC_GPIO2 -> FIOCLR = 0x00001000;
int3_flag = 0xff;
}
else //when flag is FF on the LED
{
LPC_GPIO2 -> FIOSET = 0x00001000;
int3_flag = 0;
}
}

Dept. of E&CE, CEC 20


18ECL66 Embedded Systems Laboratory

7. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay.
/* Description :
\\\\\\\\\\\\\\\DISPLAY ARE CONNECTED IN COMMON CATHODE MODE\\\\\\\\\\\\\\\\\\\\\
Port0 Connected to data lines of all 7 segement displays
a = P0.04
b = P0.05
c = P0.06
d = P0.07
e = P0.08
f = P0.09
g = P0.10
dot = P0.11
*/

#include <LPC17xx.h>

unsigned int delay, count = 0, Switchcount = 0, j;

unsigned int Disp[16] =


{
0x000003f0,
0x00000060,
0x000005b0,
0x000004f0,
0x00000660,
0x000006d0,
0x000007d0,

Dept. of E&CE, CEC 21


18ECL66 Embedded Systems Laboratory

0x00000070,
0x000007f0,
0x000006f0,
0x00000770,
0x000007c0,
0x00000390,
0x000005e0,
0x00000790,
0x00000710
};

#define ALLDISP 0x00180000 //Select all display


#define DATAPORT 0x00000ff0 //P0.4 to P0.11 : Data lines connected to drive Seven Segments
int main(void)
{
LPC_PINCON -> PINSEL0 = 0x00000000;
LPC_PINCON -> PINSEL1 = 0x00000000;
LPC_GPIO0 -> FIODIR = 0x00180ff0;

while (1)
{
LPC_GPIO0 -> FIOSET |= ALLDISP;
LPC_GPIO0 -> FIOCLR = 0x00000ff0; // clear the data lines to 7-segment displays
LPC_GPIO0 -> FIOSET = Disp[Switchcount];
// get the 7-segment display value from the array

Dept. of E&CE, CEC 22


18ECL66 Embedded Systems Laboratory

for (j = 0; j < 3; j++)


for (delay = 0; delay < 30000; delay++); // delay

Switchcount++;
if (Switchcount == 0x10) // 0 to F has been displayed ? go back to 0
{
Switchcount = 0;
LPC_GPIO0 -> FIOCLR = 0x00180ff0;
}
}
}

Dept. of E&CE, CEC 23


18ECL66 Embedded Systems Laboratory

8. Measure Ambient temperature using a sensor and SPIADC IC. //Header file for SPI.c file
#include <LPC17xx.h>
#ifndef __SPI_H
#include "SPI.h" #define __SPI_H
extern unsigned char spi_flag,temp;
unsigned char spi_flag = 0, temp = 0; void SPI_Init(void); // SPI initialisation
void SPI_IRQHandler(void);//SPI Interrupt routine
void SPI_Init(void) #endif
{
LPC_PINCON -> PINSEL0 |= 0xC0000000; //P0.15 as SCK
LPC_PINCON -> PINSEL1 = 0x0000003C; //select MISO-P0.17,MOSI-P0.18
LPC_SPI -> SPCCR = 0x1E; // SPI CLOCK SELECTED AS 100KHZ
LPC_SPI -> SPCR = 0xA0; //8 bit data, actve high clk, master SPI mode,SPI Int enable
// Master mode and SCK line is active high
LPC_SPI -> SPINT = 0x01; //clear the interrupt flag
NVIC_EnableIRQ(SPI_IRQn);
}

void SPI_IRQHandler(void)
{
spi_flag = 1;
temp = LPC_SPI -> SPSR; // To clear SPIF bit we have to read status register.
temp = LPC_SPI -> SPDR; // Then read the data register(optional)
LPC_SPI -> SPINT = 0x01; // To clear the SPI interrupt
}

Dept. of E&CE, CEC 24

You might also like