Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

SSM COLLEGE OF ENGINEERING

KOMARAPALAYAM – 638 183

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING

LABORATORY MANUAL

EMBEDDED SYSTEMS AND IOT


DESIGN LAB

Name of the Student: ______________________________________

Register Number: ____________________ Roll Number: _____

Year: ____ Semester: __ Section: _________

Academic Year:___________
INDEX
Exp. Page Marks Faculty
Date Name of the Experiment
No. No. Awarded Signature

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.
EXPERIMENTS USING 8051.

1. Programming Arithmetic and Logical Operations in 8051.

2. Generation of Square waveform using 8051.

3. Programming using On – Chip ports in 8051.

4. Programming using Serial Ports in 8051.

5. Design of a Digital Clock using Timers/Counters in 8051.

EXPERIMENTS USING ARM

6. Interfacing ADC and DAC

7. Blinking of LEDs and LCD

8. Interfacing keyboard and Stepper Motor.

MINIPROJECTS FOR IOT

1. Garbage Segregator and Bin Level Indicator

2. Colour based Product Sorting

3. Image Processing based Fire Detection

4. Vehicle Number Plate Detection

5. Smart Lock System


PROGRAMMING ARITHMETIC AND LOGICAL

OPERATIONS in 8051

EXPT NO:
DATE:

8 BIT ADDITION
AIM:
To write a program to add two 8-bit numbers using 8051 microcontroller.

ALGORITHM:

1. Clear Program Status Word.


2. Select Register bank by giving proper values to RS1 & RS0 of PSW.
3. Load accumulator A with any desired 8-bit data.
4. Load the register R 0 with the second 8- bit data.
5. Add these two 8-bit numbers.
6. Store the result.
7. Stop the program.

FLOW CHART:

START

Clear PSW

Select Register

Load A and R 0 with


8- bit datas

Add A & R 0

Store the sum

STOP
8 Bit Addition (Immediate Addressing)
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 CLR C C3 Clear CY Flag

4101 MOV A, data1 74,data1 Get the data1 in


Accumulator
4103 ADDC A, # data 2 24,data2 Add the data1 with
data2
4105 MOV DPTR, # 90,45,00 Initialize the memory
4500H location
4108 MOVX @ DPTR, A F0 Store the result in
memory location
4109 L1 SJMP L1 80,FE Stop the program

OUTPUT
MEMORY LOCATION DATA

4500

RESULT:

Thus the 8051 ALP for addition of two 8 bit numbers is executed.
8 BIT SUBTRACTION
AIM:
To perform subtraction of two 8 bit data and store the result in memory.

ALGORITHM:
a. Clear the carry flag.
b. Initialize the register for borrow.
c. Get the first operand into the accumulator.
d. Subtract the second operand from the accumulator.
e. If a borrow results increment the carry register.
f. Store the result in memory.

FLOWCHART:
START

CLEAR CARRY
FLAG

GET I’ST
OPERAND IN
ACCR

SUBTRACT THE
2’ND OPERAND
FROM ACCR

N
IS CF=1

Y
INCREMENT
THE BORROW
REGISTER

STORE
RESULT IN
MEMORY

STOP
8 Bit Subtraction (Immediate Addressing)
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 CLR C C3 Clear CY flag

4101 MOV A, # data1 74, data1 Store data1 in


accumulator
4103 SUBB A, # data2 94,data2 Subtract data2 from
data1
4105 MOV DPTR, # 4500 90,45,00 Initialize memory
location
4108 MOVX @ DPTR, A F0 Store the difference
in memory location
4109 L1 SJMP L1 80,FE Stop

OUTPUT
MEMORY LOCATION DATA

4500

RESULT:

Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
8 BIT MULTIPLICATION
AIM:
To perform multiplication of two 8 bit data and store the result in memory.

ALGORITHM:
a. Get the multiplier in the accumulator.
b. Get the multiplicand in the B register.
c. Multiply A with B.
d. Store the product in memory.

FLOWCHART:

START

GET
MULTIPLIER
IN ACCR

GET
MULTIPLICAND
IN B REG

MULTIPLY A
WITH B

STORE
RESULT IN
MEMORY

STOP
8 Bit Multiplication
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A ,#data1 74, data1 Store data1 in
accumulator
4102 MOV B, #data2 75,data2 Store data2 in B reg

4104 MUL A,B F5,F0 Multiply both

4106 MOV DPTR, # 90,45,00 Initialize memory


4500H location
4109 MOVX @ DPTR, A F0 Store lower order
result
401A INC DPTR A3 Go to next memory
location
410B MOV A,B E5,F0
Store higher order
410D MOV @ DPTR, A F0 result

410E STOP SJMP STOP 80,FE Stop

INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA

4500 4502

4501 4503

RESULT:

Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
8 BIT DIVISION

AIM:
To perform division of two 8 bit data and store the result in memory.

ALGORITHM:
1. Get the Dividend in the accumulator.
2. Get the Divisor in the B register.
3. Divide A by B.
4. Store the Quotient and Remainder in memory.

FLOWCHART:

START

GET DIVIDEND
IN ACCR

GET DIVISOR IN
B REG

DIVIDE A BY B

STORE
QUOTIENT &
REMAINDER
IN MEMORY

STOP
8 Bit Division
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A, # data1 74,data1 Store data1 in
accumulator
4102 MOV B, # data2 75,data2 Store data2 in B reg

4104 DIV A,B 84 Divide

4015 MOV DPTR, # 4500H 90,45,00 Initialize memory


location
4018 MOVX @ DPTR, A F0 Store remainder

4109 INC DPTR A3 Go to next memory


location
410A MOV A,B E5,F0
Store quotient
410C MOV @ DPTR, A F0

410D STOP SJMP STOP 80,FE Stop

INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 (dividend) 4502 (remainder)

4501 (divisor) 4503 (quotient)

RESULT:

Thus the 8051 ALP for division of two 8 bit numbers is executed.
LOGICAL AND BIT MANIPULATION
AIM:

To write an ALP to perform logical and bit manipulation operations using 8051
microcontroller.

APPARATUS REQUIRED:
8051 microcontroller kit

ALGORITHM:

1. Initialize content of accumulator as FFH


2. Set carry flag (cy = 1).
3. AND bit 7 of accumulator with cy and store PSW format.
4. OR bit 6 of PSW and store the PSW format.
5. Set bit 5 of SCON.
6. Clear bit 1 of SCON.
7. Move SCON.1 to carry register.
8. Stop the execution of program.

FLOWCHART:

START

Set CY flag, AND CY with MSB of

Store the PSW format, OR CY with bit 2 IE reg

Clear bit 6 of PSW, Store PSW

Set bit 5 of SCON , clear bit 1 and store


SCON

Move bit 1 of SCON to CY and store PSW

STOP
PROGRAM TABLE

ADDRESS HEX LABEL MNEMONICS OPERAND COMMENT


CODE
4100 90,45,00 MOV DPTR,#4500 Initialize memory
location
4103 74,FF MOV A,#FF Get the data in
accumulator
4105 D3 SETB C Set CY bit

4016 82,EF ANL C, ACC.7 Perform AND with 7th


bit of accumulator
4018 E5,D0 MOV A,DOH
410A F0 MOVX @DPTR,A Store the result

410B A3 INC DPTR Go to next location

410C 72,AA ORL C, IE.2 OR CY bit with 2nd bit


if IE reg
410E C2,D6 CLR PSW.6 Clear 6th bit of PSW

4110 E5,D0 MOV A,DOH


4112 F0 MOVX @DPTR,A Store the result

4113 A3 INC DPTR Go to next location

4114 D2,90 SETB SCON.5 Set 5th of SCON reg


4116 C2,99 CLR SCON.1 Clear 1st bit of SCON
reg
4118 E5,98 MOV A,98H
411A F0 MOVX @DPTR,A Store the result

411B A3 INC DPTR Go to next location

411C A2,99 MOV C,SCON.1 Copy 1st bit of SCON


reg to CY flag
411E E5,D0 MOV A,DOH
Store the result
4120 F0 MOVX @DPTR,A

4122 80,FE L2 SJMP L2 Stop


MEMORY SPECIAL FUNCTION REGISTER FORMAT BEFORE AFTER
LOCATION EXECUTION EXECUTION
4500H (PSW) CY AC FO RS1 RS0 OV - P 00H 88H

4501H (PSW) CY AC FO RS1 RS0 OV - P 40H 88H

4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H

4503H (PSW) CY AC FO RS1 RS0 OV - P FFH 09H

RESULT:

Thus the bit manipulation operation is done in 8051 microcontroller.


SQUARE AND CUBE PROGRAM, FIND 2’S COMPLEMENT OF A
NUMBER

EXPT NO:
DATE:

AIM:
To convert Square and Cube program, Find 2’s complement of a number using 8051
micro controller

RESOURCES REQUIERED:
8051 microcontroller
kit Keyboard
Power supply

PROGRAM:
Org 0000h; sets the program counter to 0000h

Mov a,#n;assign value 'n' in decimal to a which is converted to it's equivalent


hexadecimal value

Mov b,#n;assign value 'n' in decimal to b which is converted to it's equivalent


hexadecimal value

Mov r0,#n;assign value 'n' in decimal to r0 which is converted to it's equivalent


hexadecimal value
Mul ab; multiplying 'a' with 'b'

Mov 40h,a; lower byte is stored in address 40h mov


41h,b; higher byte is stored in address 41h mov r1,a;
move value of 'a' to r1

Mov a,b; move value of 'b' to 'a' mov


b,r0; move value of r0 to b mul ab;
multiply 'a' and 'b'

Mov b,a; lower byte obtained is moved from 'a' to 'b' mov
r2,b; move value of 'b' to r2

Mov a,r1; move value of r1 to 'a' mov


b,r0; move value of r0 to 'b' mul ab;
multiplying 'a' and 'b'
Mov 50h,a; lower byte obtained is stored in address 50h
Mov r3,b; higher byte obtained is stored in r3
Mov a,r2; move value from r2 to 'a'
Add a,r3; add value of 'a' with r3 and store the value in 'a'
Mov b,a; move value from 'a' to 'b'
Mov 51h,b; store value obtained in address 51h
End
SQUARE PGM USING 8051
ORG 00h
02 LJMP MAIN
03 DELAY:
04 ;MOV R0,#2
05 MOV TMOD, #01H
06 MOV TH0, #HIGH (-50000)
07 MOV TL0, #LOW (-50000)
08 SETB TR0
09 JNB TF0,
10 CLR TF0
12 ;DJNZ R0,DELAY
13 RET
14 MAIN:
15 MOV DPTR,#300H
16 MOV A,#0FFH
17 MOV P1,A
18 BACK:
19 LCALL DELAY
20 MOV A,P1
21 MOVC A,@A+DPTR
22 ;MOV P2,#00H
23 ;LCALL DELAY
24 MOV P2,A
25 SJMP BACK
26 ORG 300H
27 XSQR_TABLE:
28 DB 0,1,4,9,16,25,36,49,64,81
29 END

RESULT:
Thus the Square and Cube program, Find 2’s complement of a number is done in 8051
microcontroller
PROGRAMMING USING ON – CHIP PORTS IN 8051

EXPT NO:
DATE:
AIM:

i. Conduct an experiment to generate 1second delay continuously using on chip


timer
ii. Write an ALP to toggle the content of port 0 continuously using timer delay in
between.

RESOURCES REQUIERED:
8051 microcontroller kit
Keyboard
Power supply

PROGRAM:
i. To generate 1second delay continuously using on chip

MOV TMOD,#02H

MOV TH0,#00H

CLR P1.0

CLR A

SETB TR0

AGAIN: MOV R7,#0FFH

LOOP: MOV R6,#14D

WAIT: JNB TF0, WAIT

CLR TF0

DJNZ R6,WAIT

DJNZ R7,LOOP

CPL P1.0

SJMP AGAIN

END
ii.Write an ALP to toggle the content of port 0 continuously using timer delay in

between.

Label Opcode and

Operands Comments

ORG 0000H

LJMP 8000H

ORG 8000H

MOV R0, #0AH ; R0=0AH

GO: MOV A, #55H ; A=55H

MOV P0, A ; Move the content of A in P0

ACALL DELAY ; Call delay program

MOV A, #0AAH ; A=AAh

MOV P0, A ; Move the content of A in P0

ACALL DELAY ; Call delay program

DJNZ R0, GO ; R0=R0-1, if R0 is not equal to zero then jump to go

LCALL 0003H ; End of main program

DELAY: MOV TMOD, #01H ; Load TMOD

START: MOV TL0, #00H ; Load TL0

MOV TH0, #00H ;Load TH0

SETB TR0 ; TR0=1;

HERE: JNB TF0, HERE ;if TF0 is not equal 1 then jump to here

CLR TR0 ; TR0=0

CLR TF0 ;TF0=0

RET ;Return to main program

RESULT:

Thus the programming operation was done in 8051 microcontroller.


PROGRAMMING USING SERIAL PORTS IN 8051.

EXPT NO:
DATE:

AIM:

To write a program to verify 8051 UART and check transmission and reception

APPARATUS REQUIRED:

1. Two 8051 MC kits

2. Power supply

3. Interface cable

ALGORITHM:

1. Select the timer and the mode

2. Select the baudrate by loading timer and cocenter

3. Select the serial communication mode

4. Start the timer

5. Wait for receiver interrupt

6. Clear RI after processing the data.


PROGRAM:

8051 TRANSMITTER:
ADDRESS LABEL MNEMONICS COMMENTS
4100 MOV TMOD,#20H
4103 MOV THI,#0A0H
4106 MOV TLI,#00H
4109 MOV TCON,#40H
410C MOV SCON,#58H
410F MOV DPTR,#4500H
4112 RELOAD MOV R5,#05H
4114 REPEAT MOVX A,@DPTR
4115 MOV SBUF,A
4117 CHECK JNB SCON.1,CHECK
411A CLR SCON.1
411C INC DPTR
411D CJNE A,#3FH,RELOAD
4120 DJNZ R5,REPEAT
4122 CLR A
4123 LCALL 0020H
4126 HERE SJMP HERE

RECEPTION

ADDRESS LABEL MNEMONIC COMMENTS


4100 MOV TMOD,#20H
4103 MOV THI,#0A0H
4106 MOV TLI,#00H
4109 MOV TCON,#40H
410C MOV SCON,#58H
410F MOV DPTR,#4500H
4112 RELOAD MOV R5,#05H
4114 CHECK JNB SCON.0,CHECK
4115 CLR SCON.0
4117 MOV A,SBUF
411A MOVX @DPTR,A
411C INC DPTR
411D CJNE A,#3FH,RELOAD
4120 DJNZ R5,CHECK
4122 CLR A
4123 LCALL 0020H
4126 HERE SJMP HERE
OBSERVATION:

input(transmitter) output (receiver)

4500:23 4500:23

4501:34 4501:34

4502:43 4502:43

4503:12 4503:12

RESULT:

Thus the assembly language program to perform 8051 serial communication was successfully executed and verified
. DESIGN OF A DIGITAL CLOCK USING TIMERS/COUNTERS IN 8051

EXPT NO:
DATE:

AIM:

To write a program to design a digital clock using Timers/Counters in 8051

APPARATUS REQUIRED:

1. Two 8051 MC kits

2. Power supply

3. Interface cable

PROGRAM:

Assembly language program for 8051 microcontroller to display Seconds at Port A, Minutes at port
B and Hours at port C of 8255 PPI.
9100 1day: MOV DPTR,#2023H ; Load DPTR with Control port Address of 1st 8255
9103 MOV A, #80 ; (A) = 80H = control word for all ports as output ports
9105 MOV DPTR, #2022H; Load DPTR with port C Address of 1st 8255
9108 MOV R0, #0 ; (R0) = 00, to display 00 hours
910A MOV A,R0 ; (A) = (R0)
910B MOVX @DPTR,A ; Display 00 hours at port C of 8255
910C BACK3: MOV R4,#0 ; (R4) = 00, to display 00 minute
910E MOV A,R4 ; (A) = (R4)
910F MOV DPTR,#2021H ; Load DPTR with port B Address of 1st 8255
9112 MOVX @DPTR,A ; Display minutes at port B of 1st8255
9113 BACK2: MOV R3,#0 ; (R3) = 00, to display 00 Seconds
9115 MOV A,R3 ; (A) = (R3)
9116 MOV DPTR,#2020H ; Load DPTR with port A Address of 1st 8255
9119 BACK1: MOVX @DPTR,A ; Display Seconds at port A of 1st 8255
911A LCALL DELAY ; Call 1 second DELAY routine
911D ADD A,#01 ; (A) = (A) + 1, to get next second
911F DA A ; Decimal adjusting A to get seconds in BCD format
9120 CJNE A,#60H,BACK1 ; If (A) ≠ 60H, then jum to BACK1
9123 INC R4 ; (R4) = (R4) + 1, to get next minute
9124 MOV DPTR,#2021H ; Load DPTR with port B Address of 1st 8255
9127 MOV A,R4 ; (A) = (R4)
9128 DA A ; Decimal adjusting A to get minutes in BCD format
9129 MOVX @DPTR,A ; Display minutes at port B of 1st 8255
912A CJNE A,#60H,BACK2 ; If (A) ≠ 60H, then jump to BACK1
912D INC R0 ; (R0) = (R0) + 01, to get next hour
912E MOV A,R0 ; (A) = (R0)
912F DA A ; Decimal adjusting A to get hours in BCD format
9130 CJNE A,#24H,BACK2 ; If (A) ≠ 24H, then jump to BACK3
9133 RET ; Return to main program
RESULT:

Thus the assembly language program to perform Digital clock was successfully executed and verified
Ex. No: INTERFACING ADC AND DAC
Date:

AIM:

To develop and verify the interfacing ADC and DAC with LPC 2148 ARM
microcontroller.

APPARATUS REQUIRED:

S.No Apparatus Range Quantity

1 ARM Development Kit LPC 2148 1

2 IAR Workbench - 1

3 Flash magic - 1

4 WINXTALK - 1

5 Serial cable - 1

PROCEDURE:

Step 1: Give a double click on IAR Workbench on the desk top, it will
generate a window as shown below

Step 2: To create new project go to project select new micro vision project.

Step 3: select a drive where you would like to create your project.

Step 4: Create a new folder and name it with your project name.

Step 5: Open that project folder and give a name of your project executable
and save it.

Step 6: After saving it will show some window there you select your
microcontroller company i.e. NXP from Phillips

Step 7: Select your chip as ARM DEVELOPMENT KIT

Step 8: After selecting chip click on OK then it will display some window
asking to add STARTUP. Select YES.

Step 9: A target is created and startup is added to your project target


and is shown below.

Step 10: To write your project code select a new from menu bar.

Step 11: It will display some text editor, to save that select SAVE
option from menu bar.

Step 12: By giving a name with extension .c and save it.

Step 13: Write the code of your project and save it.
Step 14: To add the c to target give a right click on Source Group,
choose “ADD s to Group” option.

Step 15: It will display some window there select the file and
click on ADD option.

Step 16: It will be added to our target and it shows in the project
window.

Step 17: Select right click on target in the project window and select
“Options for Target.”

Step 18: It will show some window, in that go to output option and choose
Create Hex option by selecting that box.

Step 20: Now to compile your project go to Project select Build Target
option or press F7.

Step 21: Check the concern block of output and observe the results.

PROGRAM:

#include <lpc214x.h>
#include <stdio.h> #define
ESC 0x1B

#define DONE 0x80000000 #define


START 0x01000000 #define
PRESET 0x00230600 void
serial_init(void)

PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0

*/

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


*/

U0DLL = 195; /* 9600 Baud Rate @


12MHz VPB Clock */

U0LCR = 0x03; /* DLAB = 0

*/

void delay(int n)

int i,j; for(i=0;i<n;i++)

for(j=0;j<0x5000;j++)
{;}

}}

void main(void)

unsigned long val[4];


unsigned int ADC_CH;
unsigned char i=0;

PINSEL0 = 0x00000005; //Enable RXD0 and TXD0

PINSEL1 |= 0x01 << 24; //Enable ADC0.1


PINSEL1 |= 0x01 << 26;
PINSEL1 |= 0x01 << 28;
//PINSEL1 = 0x15000000; //Enable ADC0.1 |
ADC0.2 | ADC0.3

VPBDIV = 0x02; //Set the cclk to

30 Mhz

AD0CR = 0x00230602; //ADC

configuration bits CLK = 10clks/9Bit | BURST=1 |


CLKDIV = 0x06

AD0CR |= 0x01000000; //start ADC now


//IO0DIR = 0x0FFF7030;

serial_init(); //serial
initialization

ADC_CH = 1;
printf("%c[2J%c[H",ESC,ESC);

printf("%c[4m PS - Primer - ARM ARM DEVELOPMENT KIT

- ADC Demo %c[m%cE%cE",ESC,ESC,ESC,ESC);/*

underline */

printf("\n\nVersion Release v1.0 29/01/09\n");printf("Research


& Development Divison\n");

printf ("(c) Pantech Solutions Pvt


Ltd.,\nwww.pantechsolutions.net\n");

printf ("Chennai - India\n");

printf("\n\nNotes:-\n-------\n\n> ADC0.1 isinterfaced with


Temperature Sensor.\n> Select JP4for ADC0.2 ||
Select JP5 for ADC0.3\n\n"); printf ("*** Adjust
Trim Pot to get the Digital
Values ***\n\n\n");
while(1)

while (ADC_CH <4) {


do

val[ADC_CH] = AD0GDR; // Read


A/D Data Register

while ((val[ADC_CH] & 0x80000000)val[ADC_CH] =


== 0);
((val[ADC_CH] >> 6) &
0x03FF);

ADC_CH++;

delay(10);

} AD0CR = PRESET | (1<<ADC_CH);


AD0CR |= START;

val[1] = (AD0DR1 >> 6) & 0x03FF; val[2] =


(AD0DR2 >> 6) & 0x03FF; val[3] = (AD0DR3 >> 6)
& 0x03FF;

for (i=1;i<4;i++)

{
delay(1); printf("ADC0.%d :
[",i);putchar(0x1B);

printf("[1;31m%4d", val[i]);if (i==1)

printf ("\xF8\F") ;

putchar (0x1B); printf


("[30m] ");if (i<3)

printf(" :: ");

delay(1);

if(ADC_CH > 3/*The number of channels used in PS-


ARMDPK*/)

{
ADC_CH = 1;
AD0CR = PRESET | (1<<ADC_CH);
AD0CR |= START;
//printf ("\b\b"); U0THR =
'\r';

}}
OUTPUT:

RESULT:

Thus the interfacing of ADC and DAC (In-built) with ARM processor has been
verified and observed the output successfully.
Ex. No: INTERFACING LED AND PWM.
Date:

AIM:

To develop and verify the interfacing LED and PWM with ARM DEVELOPMENT
KIT microcontroller using embedded c program.

APPARATUS REQUIRED:

S.No Apparatus Range Quantity

1 ARM Development Kit LPC 2148 1

2 IAR Workbench - 1

3 Flash magic - 1

4 WINXTALK - 1

5 Serial cable - 1

PROCEDURE:

Step 1: Give a double click on IAR Workbench icon on the desk top,
it willgenerate a window as shown below

Step 2: To create new project go to project select new micro vision project.

Step 3: select a drive where you would like to create your project.

Step 4: Create a new folder and name it with your project name.
Step 5: Open that project folder and give a name of your project executable
and save it.

Step 6: After saving it will show some window there you select your
microcontroller company i.e NXP from Phillips

Step 7: Select your chip as LPC 2148.

Step 8: After selecting chip click on OK then it will display some window
asking to add STARTUP. Select YES.

Step 9: A target is created and startup is added to your project target


and is shown below.

Step 10: To write your project code select a new from menu bar.

Step 11: It will display some text editor, to save that select SAVE
option from menu bar.
Step 12: By giving a name with extension .C and save it

Step 13: Write the code of your project and save it.
Step 14: To add our c to target give a right click on Source Group,
choose “ADD s to Group” option.

Step 15:It will display some window there select the file and click on ADD option.

Step 16: It will be added to our target and it shows in the project
window.

Step 17: Select a right click on target in the project window and select
“Options for Target”

Step 18: It will show some window, in that go to output option and choose
Create Hex option by selecting that box

Step 19: In the same window go to Linker option and choose Use Memory
Layout from Target Dialog by selecting the box, and click OK.

Step 20: Now to compile your project go to Project select Build Target
option or press F7.

Step 21: Check the output of LED’s as switching from ON to OFF.

PROGRAM:

LED:

#include <LPC214x.h>
#include <stdio.h> #define
LED 16

#define Switch 24void


Delay(int);int
main(void)

unsigned char Status=1;

PINSEL2 &= 0xFFFFFFF3; //Configure P1.16

- P1.31 as GPIO
IO1DIR = 0x00 << Switch; //Configure P1.24

- P1.31 as Input
IO1DIR |= 0xFF << LED; //Configure P1.16 -P1.23
as Output

IO1PIN = 0;

while(1)

Status = 1;
IOSET1 = 0xFF << LED;

Delay (10);Delay (10); IOCLR1 =


0xFF << LED;

Delay (10);Delay (10);Delay (10);while


(~Status)

Status = ((IO1PIN & (0xFF <<


Switch)) >> Switch);

IO1PIN = ((~Status) << LED);

} } }

void Delay(int n)

int p,q;
for(p=0;p<n;p++)

for(q=0;q<0x9990;q++);

PWM: }}
#include <LPC214x.H> /* LPC21xx
definitions */

#include <stdio.h>

void PWM0_isr(void) irq

PWMIR |= 0x00000001; /* Clear match0


interrupt */

VICVectAddr = 0x00000000;

void init_PWM (void) {

VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWMISR


vector address */

VICVectCntl8 = 0x00000028; /* Set channel

*/

VICIntEnable = 0x00000100; /* Enable the


interrupt */

PINSEL0 |= 0x00008008; /* Enable P0.7

and P0.1 as PWM output */

PWMPR = 0x00000000; /* Load

prescaler */

PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 doubleedge


control, output enabled */

PWMMCR = 0x00000003; /* On match with timerreset


the counter */

PWMMR0 = 0x400; /* set cycle

rate to sixteen ticks */

PWMMR1 = 0; /* set rising

edge of PWM2 to 100 ticks */

PWMMR2 = 0x200; /* set fallingedge of


PWM2 to 200 ticks */

PWMMR3 = 0x100; /* set risingedge


of PWM3 to 100 ticks */

PWMLER = 0xF; /* enable


shadow latch for match 1 - 3 */

PWMTCR = 0x00000002; /* Reset

counter and prescaler */

PWMTCR = 0x00000009; /* enable


counter and PWM, release counter from reset */

}void Delay ()
{

unsigned int i,j; for


(i=0;i<250;i++)

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

int main (void)

{ unsigned long val; unsigned long


oldval = 0; VPBDIV = 0x02;
PINSEL0 |= 0x00050000;
PINSEL1 = 0x15400000;

init_PWM();

U1LCR = 0x83;

U1DLL = 0xC3;

U1LCR = 0x03;

AD0CR = 0x00230608; /* Setup A/D:

10-bit AIN0 @ 3MHz */

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


Conversion */

while (1)

{ /*

Loop forever */

do

val = AD0GDR; /* Read A/D Data Register */

} while ((val & 0x80000000) == 0); /*


Wait for end of A/D Conversion */
val = ((val >> 6) & 0x3FF); /*
Extract AIN0 Value */

Delay (); Delay();if (val


!= oldval)

PWMMR2 = val;

PWMLER = 0xF;

oldval = val;

printf ("Val : %4d \n\r", val);

OUTPUT:

IODIR =ox00 (OFF)


IODIR =oxFF (ON)
Delay =1
RESULT:

Thus the interfacing of LED and PWM with ARM DEVELOPMENT KIT was done
by using embedded C program.
Ex. No: INTERFACING KEYBOARD AND LCD
Date:

AIM:

To develop and verify the interfacing of keyboard and LCD with ARM
DEVELOPMENT KIT ARM microcontroller using embedded C program.

APPARATUS REQUIRED:

S.No Apparatus Range Quantity

1 ARM Development Kit LPC 2148 1

2 IAR Workbench - 1

3 Flash magic - 1

4 WINXTALK - 1

5 Serial cable - 1

PROCEDURE:

Step 1: Give a double click on µvision 4 icon on the desk top, it will
generate a window as shown below

Step 2: To create new project go to project select new micro vision project.

Step 3: select a drive where you would like to create your project.

Step 4: Create a new folder and name it with your project name.

Step 5: Open that project folder and give a name of your project executable
and save it.

Step 6: After saving it will show some window there you select your
microcontroller company i.e NXP from Phillips

Step 7: Select your chip as ARM lpc 2148.

Step 8: After selecting chip click on OK then it will display some window
asking to add STARTUP. Select YES.

Step 9: A target is created and startup is added to your project target


and is shown below.

Step 10: To write your project code select a new from menu bar.

Step 11: It will display some text editor, to save that select SAVE
option from menu bar.
Step 12: By giving a name with extension .C and save it

Step 13: Write the code of your project and save it.
Step 14: To add our c to target give a right click on Source Group,
choose “ADD s to Group” option.

Step 15:It will displays some window there select the you have to add
and click on ADD option.

Step 16: It will be added to our target and it shows in the project
window.

Step 17: Now give a right click on target in the project window and select
“Options for Target”

Step 18: It will show some window, in that go to output option and choose
Create Hex option by selecting that box

Step 19: In the same window go to Linker option and choose Use Memory
Layout from Target Dialog by selecting the box, and click OK.

Step 20: Now to compile your project go to Project select Build Target
option or press F7.

Step 21: Ensure the output of keyboard and display as by pressing the keys simultaneously

PROGRAM:

KEYBOARD:

#include <LPC214x.h> #include


<stdio.h> #include "Keypad.h"
#include "UART_Utility.c"extern
void Delay(void);

unsigned char Row_Data, Col_Data;

unsigned char Msg[4][4] = { '0','1','2','3',

'4','5','6','7',

'8','9','A','B',

'C','D','E','F'

};void Delay(void)

unsigned int i,j;for(i=0;i<35;i++)

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

void main(void)
{

VPBDIV = 0x02;
UART0_Init (9600);
PINSEL2 |= 0x0;

UART0_PutS ("\nPS-primer ARM ARM DEVELOPMENT KIT KeypadDemo\n\r");

UART0_PutC (0xB8);

UART0_PutS (" Pantech Solutions Pvt Ltd., \n\r"); UART0_PutS ("


www.pantechsolutions.net\n\r"); UART0_PutS (" \n\n\r");
UART0_PutS ("Keypad Ports : P1.24 - P1.31 \n\n\n\r");UART0_PutS
("~~~~~~~~~~~~~~~~~~~~~\n\n\r");

while (1)

Delay();

Delay();

KeyScan(&IOPIN1/*KeyPad Port*/,24/*Starting DataPin D0*/,


&Row_Data/*Addr of Row*/,&Col_Data/*Addr of Col*/); UART0_PutS ("The
Key You Pressed is : ");

if (Row_Data < 4 && Col_Data < 4)

U0THR = Msg[Row_Data][Col_Data];
Delay();

Delay(); U0THR =
'\r';
}

LCD:
#include <LPC214x.H>
#define RS 0x10000

#define RW 0x20000

#define EN 0x40000

void lcd_cmd (unsigned char);void


lcd_data (unsigned char);void lcd_initialize
(void); void lcd_display (void);

void LCD4_Convert(unsigned char);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};

//lcd commands
unsigned char msg[] = {">PS-Primer 2148<"}; //msg unsigned char
msg1[]= {":: LCD Demo! ::"}; //msg1 void delay(unsigned int n)

unsigned int i,j;


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

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

{;}

void lcd_cmd(unsigned char data)

IOCLR0 |= RS; //0x1000; //RSIOCLR0 |= RW;


//0x2000; //RW

LCD4_Convert(data);

void lcd_initialize(void)

int i; for(i=0;i<4;i++)

IOCLR0 = 0xF << 19; //IOCLR 0/1


lcd_cmd(cmd[i]);
delay(15);

void lcd_data (unsigned char data)

IOSET0 |= RS; //0x1000; //RS

IOCLR0 |= RW; //0x2000; //RW

LCD4_Convert(data);

void lcd_display (void)

char i;

/* first line message */


lcd_cmd(0x80); delay(15);

i=0;

while(msg[i]!='\0')

delay(5);
lcd_data(msg[i]);i++;

delay(15);

/* second line message */

lcd_cmd(0xc0);
delay(15); i=0;
while(msg1[i]!='\0')

delay(5);
lcd_data(msg1[i]);i++;

delay(15);

void LCD4_Convert(unsigned char c)

if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;

IOSET0 = EN; //0x4000; //EN delay(8);


IOCLR0 = EN; //0x4000; //EN

if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;

//0x4000; //EN
delay(8);

IOCLR0 = EN;

//0x4000; //EN

void main()

PINSEL1 = 0;

//Configure P0.16 - P0.31 as GPIOIODIR0


= 0xFF << 16;

//Configure Pins P0.16 - P0.22 as Output Pins lcd_initialize();


//Initialize LCD!
lcd_display();

//Display Message in LCD


while(1);

OUTPUT:

RESULT:

Thus the interfacing of keyboard and LCD with ARM DEVELOPMENT KIT
microcontroller using embedded C program has been verified successfully.
Ex. No: INTERFACING OF STEPPER MOTOR
Date:

AIM:

To interface and verify the stepper motor with ARM DEVELOPMENT KIT microcontroller
using embedded C program.

APPARATUS REQUIRED:

S.No Apparatus Range Quantity

1 ARM Development Kit LPC 2148 1

2 IAR Workbench - 1

3 Flash magic - 1

4 WINXTALK - 1

5 Serial cable - 1

PROCEDURE:

Step 1: Open a µvision 4 icon on the desk top, it will


generate a window as shown below.

Step 2: To create new project go to project select new micro vision project.

Step 3: select a drive where you would like to create your project.

Step 4: Create a new folder and name it with your project name.

Step 5: Open that project folder and give a name of your project executable
and save it.

Step 6: After saving it will show some window there you select your
microcontroller company i.e NXP from Phillips

Step 7: Select your chip as ARM DEVELOPMENT KIT

Step 8: After selecting chip click on OK then it will display some window
asking to add STARTUP. Select YES.

Step 9: A target is created and startup is added to your project target


and is shown below.

Step 10: To write your project code select a new from menu bar.

Step 11: It will display some text editor, to save that select SAVE
option from menu bar.

Step 12: By giving a name with extension .C for c s and save it


Step 13: Write the code of your project and save it.
Step 14: To add c file to the target give a right click on Source Group,
choose “ADD s to Group” option.

Step 15: It will display some window there select file


and click on ADD option.

Step 16: It will be added to our target and it shows in the project
window.

Step 17: Now give a right click on target in the project window and select
“Options for Target”
Step 18: It will show some window, in that go to output option and choose
Create Hex option by selecting that box

Step 19: In the same window go to Linker option and choose Use Memory
Layout from Target Dialog by selecting the box, and click OK.

Step 20: Compile your project go to Project select Build Target


option or press F7.

PROGRAM:

STEPPERMOTOR:

#include <lpc21xx.h>
#include <stdio.h>

#define SW1 24 //SW1 (P1.24)


#define SW2 25 //SW2 (P1.25) #define SW3
26 //SW3 (P1.26)

#define COIL_A 16 // Change here if you want to change theStepper Motor Port!

void motor_cw(void); void


motor_ccw(void);void
delay(int);

unsigned char STEP[]={0x09, 0x0C, 0x06, 0x03};

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Delay Routine

void delay(int n)

int i,j; for(i=0;i<n;i++)

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

{;}

}}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< counter-clockwiserotate
function

void motor_ccw(void)

unsigned int i=0; while


(STEP[i] != '\0')

IOSET1 = STEP[i] << COIL_A; delay(5);

IOCLR1 = STEP[i] << COIL_A; delay(5);


i++;

}}

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Clock-wise Rotate

Funciton

void motor_cw(void)

int i = 3; while (i >=


0)

IOSET1 = STEP[i] << COIL_A; delay(5); IOCLR1


= STEP[i] << COIL_A; delay(5); i--;

}}

void main(void)

unsigned char i = 0;

PINSEL2 &= 0xFFFFFFF3; //Configure P1.16 - P1.31

as GPIO

IODIR1 = 0x000F0000; //Configure P1.16 - P1.19

as Output Pins

while(1) // Loop

forever..............

if (!(IOPIN1 & (1<<SW1))) //Check Switch SW1 ON/OFF


{

IOCLR0 = 0xFF << COIL_A;

motor_cw();/* Rotate Stepper Motor clockwise */

else if (!(IOPIN1 & (1<<SW2))) //Check Switch SW2


ON/OF
F
{

IOCLR0 = 0xFF << COIL_A;

motor_ccw();/* Rotate Stepper Motor counter

clockwise */

else if (!(IOPIN1 & (1<<SW3))) //Check


Switch SW3 ON/OFF

IOCLR0 = 0xFF << COIL_A;

while (i < 12)

motor_cw ();/* Rotate Motor Clockwise for aparticular


angle */

i++;

else } }

i = 0; } }
RESULT:

Thus, the interfacing of stepper motor with ARM DEVELOPMENT KIT processor has been
done and executed the temperature value.

You might also like