0% found this document useful (0 votes)
19 views

Et3491-Embedded Systems and Iot Design

The document outlines various practical exercises and experiments using 8051 and ARM microcontrollers, including programming arithmetic operations, interfacing devices, and mini projects for IoT applications. It details specific assembly language programs for tasks such as addition, subtraction, multiplication, division, and logical operations, along with flow charts and results for each experiment. Additionally, it includes information on generating square waveforms and programming using on-chip and serial ports in 8051.

Uploaded by

SATHISHKUMAR
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
0% found this document useful (0 votes)
19 views

Et3491-Embedded Systems and Iot Design

The document outlines various practical exercises and experiments using 8051 and ARM microcontrollers, including programming arithmetic operations, interfacing devices, and mini projects for IoT applications. It details specific assembly language programs for tasks such as addition, subtraction, multiplication, division, and logical operations, along with flow charts and results for each experiment. Additionally, it includes information on generating square waveforms and programming using on-chip and serial ports in 8051.

Uploaded by

SATHISHKUMAR
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/ 81

S.

No Date PRACTICAL EXERCISES Page No marks sign

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

MINI PROJECTS FOR IOT

9 Garbage Segregator and Bin Level Indicator

10 Colour based Product Sorting

11 Image Processing based Fire Detection

12 Vehicle Number Plate Detection

13 Smart Lock System


FLOW CHART:
Start

Clear PSW

Select Register

Load A and R0 with 8 – bit data‟s

ADD A & R0

Store the sum

Stop
EXP NO:
BASIC ARITHMETIC AND LOGICAL OPERATIONS USING 8051
DATE:

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

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.

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 CLR C C3 Clear CY Flag
4101 MOV A,#0A 74 0A Get the data1 in Accumulator
4103 ADDC A,#10 34 10 Add the data1 with data 2
4105 MOV DPTR,#4500 90 45 00 Initialize the memory location
4108 MOVX @DPTR,A F0 Store the result in memory location
L1 4109 SJMP L1 80 FE Stop the program

Address Output
4500 1A(LSB)
4501 00(MSB)

RESULT:

Thus the 8051 Assembly Language Program for addition of two 8 bit numbers was
executed.
FLOW CHART:

Start

Clear Carry Flag

Get 1‟st Operation in ACCR

Subtract the 2‟nd operand from


ACCR

IS
CF=1

Increment the Borrow Register

Store Result in Memory

Stop
B. 8 BIT SUBTRACTION
AIM:

To perform subtraction of two 8 bit data and store the result in memory.

ALGORITHM:

1. Clear the carry flag.


2. Initialize the register for borrow.
3. Get the first operand into the accumulator.
4. Subtract the second operand from the accumulator.
5. If a borrow results increment the carry register.
6. Store the result in memory.

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 CLR C C3 Clear CY Flag
4101 MOV A,#0A 74 0A Get the data1 in Accumulator
4103 SUBB A,#05 94 05 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
L1 4109 SJMP L1 80 FE Stop the program

Address Output
4500 05

RESULT:

Thus the 8051 Assembly Language Program for subtraction of two 8 bit numbers was
executed.
FLOW CHART:

Start

Get Multiplier in ACCR

Get Multiplicand in B Register

Multiply A with B

Store Result in Memory

Stop
C. 8 BIT MULTIPLICATION

AIM:

To perform multiplication of two 8 bit data and store the result in memory.

ALGORITHM:

1. Get the multiplier in the accumulator.


2. Get the multiplicand in the B register.
3. Multiply A with B.
Store the product in memory
PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 MOV A,#05 74 05 Store data1 in accumulator
4102 MOV B,#03 75 F0 03 Store data2 in B register
4105 MUL AB A4 Multiply both
4106 MOV DPTR,#4500 90 45 00 Initialize memory location
4109 MOVX @DPTR,A F0 Store lower order result
410A INC DPTR A3 Go to next memory location
410B MOV A,B E5 F0 Store higher order result
410D MOVX @DPTR,A F0
L1 410E SJMP L1 80 FE Stop the program

Address Output
4500 0F(LSB)
4501 00(MSB)

RESULT:
Thus the 8051Assembly Language Program for multiplication of two 8 bit numbers was
executed.
FLOW CHART:

Start

Get Dividend in ACCR

Get Divisor in B Register

Divide A by B

Store Quotient & Remainder in


Memory

Stop
D. 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.
Store the Quotient and Remainder in memory

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 MOV A,#15 74 15 Store data1 in accumulator
4102 MOV B,#03 75 F0 03 Store data2 in B register
4105 DIV AB 84 Divide
4106 MOV DPTR,#4500 90 45 00 Initialize memory location
4109 MOVX @DPTR,A F0 Store remainder
410A INC DPTR A3 Go to next memory location
410B MOV A,B E5 F0 Store quotient
410D MOVX @DPTR,A F0
L1 410E SJMP L1 80 FE Stop the program

Input Output
Memory Location Data Memory Location Data
4500 (dividend) 0F 4502 (remainder) 05
4501 (divisor) 03 4503 (quotient) 00
RESULT:
Thus the 8051 8051Assembly Language Program for division of two 8 bit numbers was
executed.
FLOW CHART:

START

Get the first data

Get the second data

Logically AND first data with


second data

Initialize the memory

Move the resultant value into memory

STOP
D. MASKING BITS IN AN 8 – BIT NUMBER

AIM:
To write an assembly language program to mask bits o and 7 of an 8 – bit number and
store the result in memory using 8051 microcontrollers.

APPARATUS REQUIRED:
8051 microcontroller kit

ALGORITHM:
Masking bits in a 8 bit number
 Start the process
 Get the two data values
 Get the second data
 Logically „AND‟ the two data values.
 Initialize the memory value and store the result in memory.
 Start the process

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START 4100 MOV A,#87 74 87
4102 ANL A,#7E 54 7E
4104 MOV DPTR,#4500 90 45 00
4107 MOVX @DPTR,A F0
L1 4108 SJMP L1 80 FE

Output
Memory Location Data
4500 06

RESULT:

Thus the 8051assembly language program for masking bits was executed and verified
a) 1‟s and 2‟s complement

START

Get the input value

Get the complement

Initialize the data pointer value

Move the data to data pointer

Increment the data value and


data point memory

Move the value to the memory

STOP
E. SQUARE PROGRAM and FIND 2‟S COMPLEMENT OF A NUMBER
AIM:-
To write an assembly language to perform arithmetic, logical and bit manipulation instruction using
8051.
ALOGRITHM:
a) 1‟s and 2‟s complement
 Get the value
 Get the complement value of data.
 Initialize the data pointer value as memory.
 Move the complemented value to memory of data pointer.
 Increment the value and memory.
 Store the result in memory.
 Stop the process.
a) 1‟s and 2‟s complement
PROGRAM:
Label Address Mnemonics Hex code Comments
Opcode Operand
4100 MOV A, #02 74, 02 Get the initial value
4102 CPL A F4 Complement the value
4103 MOV DPTR, # 4200 90, 42, 00 Initialize the memory
4106 MOVX @ DPTR, A F0 Move the data to memory
4107 INC A 04 Increment Accumulator
4108 INC DPTR A3 Increment the memory
4109 MOVX @ DPTR, A F0 Move the value to memory
ECE: 410A SJMP ECE 80, FE Continue the process.

1‟s and 2‟s complement

Output
Memory Location Data
4200 FD (1‟s complement
4201 FE(2‟S Complement)
Square of a number

Input Output
Memory Location Data Memory Location Data
4200 89 4201 51
4202 49
b) SQUARE PROGRAM FOR 8051

$MOD51
ORG 4100H
MOV DPTR,#4200H
MOVX A,@DPTR
MOV B,A
MUL AB
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
L:SJMP L

RESULT:
Thus the assembly language program to find 2‟s complement, Square and cube of a number
was executed and verified successfully using 8051 microcontroller
FLOW CHART:
Start

Clear PSW

Select Register

Load A and R1 with 8 – bit data‟s

ANL A & R1

Store the ANL

Stop
EXP NO:
BASIC LOGICAL OPERATIONS USING 8051

DATE:

AIM:
To write a program to logical operation two 8-bit numbers using 8051 microcontrollers.

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. Logic operation these two 8-bit numbers.
6. Store the result.
7. Stop the program.

logical program
ORG 0000H ; Start of program

; Load test values


MOV A, #0F0H ; A = 11110000
MOV R1, #0AAH ; R1 = 10101010

; AND operation
ANL A, R1 ; A = A AND R1 => A = 10100000
MOV P1, A ; Output result to Port 1
ACALL DELAY ; Wait to view output

; OR operation
MOV A, #0F0H ; Reload A
ORL A, R1 ; A = A OR R1 => A = 11111010
MOV P1, A ; Output result
ACALL DELAY
; XOR operation
MOV A, #0F0H
XRL A, R1 ; A = A XOR R1 => A = 01011010
MOV P1, A
ACALL DELAY

; NOT operation (Complement)


MOV A, #0F0H
CPL A ; A = NOT A => A = 00001111
MOV P1, A
ACALL DELAY

SJMP $ ; Endless loop

; ---------------------
; Delay Subroutine
; ---------------------
DELAY:
MOV R2, #100
D1: MOV R1, #255
D2: DJNZ R1, D2
DJNZ R2, D1
RET

END

RESULT:
Thus the assembly language program of logical operation two 8-bit numbers was
executed and verified successfully using 8051 microcontroller
EXP NO: GENERATION OF SQUARE WAVEFORM
DATE USING 8051

AIM:
To Write & Test the Generation of Square Waveform Using 8051

HARDWARE & SOFTWARE TOOLS REQUIRED:\’

S.No. Hardware & Software Requirements Quantity

1 8051 Microcontroller Trainer Kit 1

PROGRAMME:

RESULT:
Thus the assembly language program of generation of Square Waveform was executed
and verified successfully using 8051 microcontroller
EXP NO: PROGRAMMING USING ON – CHIP PORTS IN 8051
DATE

AIM:
To Write & Test the programming Using On Chip Ports in 8051

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 8051 Microcontroller Trainer Kit 1

PROGRAMME:

ORG 0000H ; Origin – program start address

MAIN:
SETB P1.0 ; Turn ON LED (Set P1.0 high)
ACALL DELAY ; Call delay routine
CLR P1.0 ; Turn OFF LED (Clear P1.0)
ACALL DELAY ; Call delay routine
SJMP MAIN ; Repeat forever

; ---------------------
; Delay Subroutine
; ---------------------
DELAY:
MOV R2, #100 ; Outer loop counter
D1: MOV R1, #255 ; Inner loop counter
D2: DJNZ R1, D2 ; Decrement R1 until zero
DJNZ R2, D1 ; Repeat outer loop
RET

END ; End of program

RESULT:
Thus the assembly language programming Using On Chip Ports was executed and
verified successfully using 8051 microcontroller
EXP NO:

DATE PROGRAMMING USING SERIAL PORTS IN 8051.

AIM:
To Write & Test the programming Using Serial Port in 8051

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 8051 Microcontroller Trainer Kit 1

PROGRAMME:
8051 TRANSMITTER PROGRAM:

8051 RECEIVER PROGRAM:


DELAY PROGRAM:

RESULT:
Thus the assembly language programming Using Serial Port was executed and verified
successfully using 8051 microcontroller
EXP NO: DESIGN OF A DIGITAL CLOCK USING
DATE TIMERS/COUNTERS IN 8051

AIM:
To design of a digital clock using timers/counters in 8051

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 8051 Microcontroller Trainer Kit 1

PROGRAMME:
DIGITAL CLOCK:

ADDRESS LABEL OPCODE MNEMONICS


9000 90 60 03 MOV DPTR, #6003

9003 74 80 MOV A, #80


9005 F0 MOVX @DPTR,A
9006 7A 00 MOV R2, #00

9008 7B 00 MOV R3, #00


900A L1 EC MOV A, R4
900B 90 60 01 MOV DPTR, #6001
900E F0 MOVX @DPTR, A

900F EA MOV A, R2

9010 90 60 00 MOV DPTR, #6000


9013 F0 MOVX @DPTR, A
9014 12 92 00 LCALL 9200

9017 0C INC R4
9018 EC MOV A, R4

9019 12 93 00 LCALL 9300

901C B4 60 EB CJNE A,#60,900A(L1)

901F 0A INC R2

1.27 cm
9020 7C 00 MOV R4,#00

9022 EA MOV A, R2

9023 12 93 10 LCALL 9310


9026 B4 60 E1 CJNE A,#60, 900A(L1)
9029 22 RET

SECONDS SUBROUTINE:
ADDRESS LABEL OPCODE MNEMONICS
9200 7D 00 MOV R5, #00
9202 LOOP1 12 94 00 LCALL 9400
9205 0D INC R5
9206 ED MOV A, R5
9207 B4 60 F8 CJNE A, #60, 9202 (LOOP1)
920A 22 RET
MINUTES SUBROUTINE:
ADDRESS LABEL OPCODE MNEMONICS
9300 94 01 SUBB A, #01
9302 24 01 ADD A, #01
9304 D4 DA A
9305 FC MOV R4, A
9306 22 RET

HOURS SUBROUTINE:
ADDRESS LABEL OPCODE MNEMONICS
9310 94 01 SUBB A, #01
9312 24 01 ADD A, #01
9314 D4 DA A
9315 FA MOV R2, A
9316 22 RET
DELAY SUBROUTINE:
ADDRESS LABEL OPCODE MNEMONICS
9400 79 0A MOV R1,#0AH
9402 LOOP3 74 6F MOV A, #6FH
9404 LOOP4 00 NOP
9405 00 NOP
9406 00 NOP
9407 00 NOP
9408 14 DEC A
9409 70 F9 JNZ 9404
940B D9 F5 DJNZ R1,9402
940D 22 RET

RESULT:
Thus the assembly language of digital clock using timers/counters verified successfully
using 8051 microcontroller
1.27 cm
INTRODUCTION TO KEIL µ VISION 4 SOFTWARE
1.1 WELCOME
Thank you for purchasing the ARM CORTEX Tyro Board from Pantech ProLabs India
Pvt Ltd. The ARM CORTEX Tyro is a development board which demonstrates the
capabilities of the 144-pin LPC4088 devices.

The ARM CORTEX Tyro Board can be used as a stand-alone board built with an in-circuit
USB programmer. Sample programs are provided to demonstrate the unique features of the
supported devices.

The ARM CORTEX Tyro Board Kit comes with the following:
1. ARM CORTEX Tyro Development Board
2. Sample devices (LPC4088)
3. CD-ROM, which contains:
a) Sample programs
b) ARM CORTEX Tyro Development Board User’s Guide
4. 5V Adapter
5. Straight Female to Female serial cable
6. One Hook wire
7. USB Cable

Note: If you are missing any part of the kit, please contact our support executive
ARM CORTEX TYRO DEVELOPMENT BOARD
The ARM CORTEX TYRO development board has the following hardware features:

 8 Nos. Point LEDs (Logic Output)


 8 Nos. Digital Input(SLIDE Switch)
 2 Nos. Analog Input (Potentiometer)
 2x16 Char LCD Interface
 Temperature Sensor(LM35)
 Internal RTC with Battery-Backup
 1 No. UART(RS232)
 1 No. USB UART
 USB 2.0 device (Virtual Port)
 DAC Output
 Interrupts Study, Reset Button
 4x4 Matrix Keyboard
 40-Pin Expansion Connector
 JTAG (Program/Debug) |ISP Programming
 2 Nos. 20pin- I/O Expansion Connector
 PWM Terminations
 Stepper Interface
 Optional Onboard ZIGBEE Interface
 Onboard Buzzer
 Optional SPARTAN3AN FPGA Stick Interface
 SPI/I2C Expansion Connector
 SD card Interface (optional)
 CAN Interface (optional)
1.1 ARM CORTEX TYRO HARDWARE

1.2 SAMPLE DEVICES


One FLASH device (LPC4088) is included on the board itself.

1.3 SAMPLE PROGRAMS


The ARM CORTEX TYRO Kit includes a CD-ROM with sample programs. These programs may be
used with the included sample devices. Demo source code with compiled Hex file is provided.

1.27 cm
CHAPTER 2: Hardware Details
CONNECTORS

40 pin FRC box type connector: Instead of terminating each port separately, this connector has all the
port pins. So More IO lines can be taken by using single cable.
The Ports are arranged as shown in the following figures
Similarly, two no. of 20x2 Connector gives access to various port lines.
GPIO CONNECTORS

J8

EXTENSION CONN
\

2.1 JUMPER SETTINGS

JUMPER DESCRIPTION

JP3 LED ENABLE: Place a Jumper

J6 ADC Selection: Place a jumper for the required channel; this will connect
LPC4088 pins with POT or LM35.

JP7 ISP Enable

JP10 Connects the Buzzer with P0.26 or RTC alarm output pin

JP11 RTS and DTR pin Termination, Jumper not needed

JP13 FT232 Enable: Powers the FT232 IC

GP This General purpose single pin Header connects LED11

CONFIG DIP SWITCH (SW29)

DIP SWITCH PIN PIN DESCRIPTION

5V 1-STEP Power Supply for Stepper Motor

5V 2-LCD Power Supply for LCD

5V 3-EEP Power Supply for I2C EEPROM

ZIGBEE 4-ZBE Power Supply for ZIGBEE

FT232 5 and 6 Connects FT232with P0.0 and P0.1

FT232 7 and 8 Connects FT232with P0.2 and P0.3 (default)

1.27 cm
POWER SUPPLY

The external power should be DC5V, 1A. The ARM board produces +3.3V using an onboard vol-
tage regulator, which provides supply to the ARMcontroler.
Power supply is controlled through slide switch SW1. The 5V volt from USB or DC JACK is used for
Peripherals directly

USB EXT Supply Turned ON


POWER SWITCH EXT
USB USB Supply Turned ON
EX
T

2.1.1 POWER SUPPLY TO THE PERIPHERALS

PERIPHERAL SWITCH PIN DESCRIPTION

LPC4088 SW1 - Turn ON the switch SW1 towards USB or


EXT

FT232 JP13 - Place a Jumper at JP13

STEPPER SW29 1 Turn ON the DIP switch pin

LCD SW29 2 Turn ON the DIP switch pin

I2C EEPROM SW29 3 Turn ON the DIP switch pin

ZIGBEE SW29 4 Turn ON the DIP switch pin


CHAPTER 3: Programming in Flash Magic

3.1 FIVE STEPS PROGRAMMING

3.2 STEP 1 – COMMUNICATIONS:


Click Select…,
1. Expand ARM Cortex from device database
2. Scroll down and Select your IC.
3. Click OK.

1.27 cm
STEP 2 – ERASE

Put a Check Mark on Erase blocks used by Hex File checkbox


STEP 3 – HEX FILE
4.

5. Click Browse…

6.

7. Navigate to the project folder; Select the hex file to be loaded and Click Open.

3.3 STEP 4 – OPTIONS


1. Put a check mark on each options that is required for the project

Generally Verify after programming is required to cross check the burned hex file with the loaded hex
file and the remaining options left unchecked.

3.4 STEP 5 – START


Click Start. This will start programming the chip

1. See the Status bar for current status


Programming:

Programming Finished:

3.5 EXECUTION

Press RESET after programming

1.27 cm
CHAPTER 4: Creating a Project in Keil

STEP1: Open Keil and the environment will be as following

STEP2: Select ProjectNew uvision Project


STEP3: Create a Project folder

STEP4: Name the Project

1.27 cm
STEP5: Select the Processor and Click Ok

STEP 6: Click Yes to the following message box


STEP 7: Create a new source file by Selecting FileNew

STEP8: Write the required source code

1.27 cm
STEP 9: Save this file with “.c” Extension
STEP 11: Right Click on Source group and select add files to group

STEP 12: Select the source code file, click Add and then click close

1.27 cm
STEP 13: Navigate to the folder “C:\Keil\ARM\Startup\NXP\LPC407x_8x_177x_8x” and copy the file
“system_LPC407x_8x_177x_8x.c”

STEP 14: Paste it in your project directory


STEP 15: Right Click on Source group once again and select add files to group

STEP 16: Now add this “system_LPC407x_8x_177x_8x.c” file to your project

1.27 cm
STEP 17: Build the Project

STEP 18: Right Click “Target1” on the Project Tab and select Options for Target

STEP 19: On the Target Tab, Select the Floating point hardware as “Not used”
STEP 20: Select Output Tab and put a check mark on “Create HEX file”. The Name in the Text box “Name of
Executable” will be used to name the Hex file.

STEP 20: Click Rebuild

That’s
all. Now write your hex file into ARM CORTEX-M4 using Flash magicthe editor window.

1.27 cm
EXP NO:

DATE INTERFACING ADC AND DAC

Aim:
To develop and verify the interfacing ADC and DAC with LPC 4088 ARM microcontroller.
Apparatus Required:
PS-CORTEX – M4-TYRO-V4r2
Mini USB cable
Procedure:
1. Open keil
2. Select Project-> New M vision project
3. Create a project folder and name the project.
4. Select the processor and click ok ie, LPC4088 in NXP (For our device)
5. Create a new source file by selecting File-> New
6. Write the required source code.
7. Save the file with c extension
8. Right click on source group and select” add files to group”.
9. Select the source code file, click add and then click close.
10. Navigate the folder “c/keil/ARM/start up/NXP/LPC407x-8x-177x-8x” and
copy the file “System –LPC-407x-8x-177x-8x.c”.
11. Paste it in your project directory.
12. Right click on source group once again and select add files to group.
13. Now add this “System LPC 407x-8x-177x-8x-c”.
14. Build the project (F7).
15. Right click “Target” on the project tag and select optain for target.
16. On the target tag select the floating point hardware as not used.
17. Select output tag and but a check mark on “create hex file”.
18. In the linker tag, put a check mark on “use memory layout”….. and click ok.
19. Now rebuild the target and write your hex file into arm cortex m4 using flash
magic.
Procedure for Flash magic:
Click select
Expand ARM cortex from device database sources down and select your IC (here NxP->
LPC4088)
Click ok
Put a check mark on ”Erase blocks used by hex file check box”
Click browse
Navigate to the project folder, select the hex file to be loaded and click open.
Put a check mark on “verify after programming”.
Click start this will start programming the chip.
Press RESET after programming.
Interfacing ADC:
Power in the PCONP register, set the PCADC bit.
Configure pins p0, 23(CHO), P0,24,(CH1) and po,25 (CH2) as analog pins using their
respective 10CON registers ie., 10 CON-PO-23, to CON-PO-24 and 10 CON-PO-25.
Select ADC conversion check rate using ADC control register.
Enable power down [Normal CPU Mode]
Select the channel and start conversion.
Wait for the DONE bit, if the done bit is HIGH, the con version is completed.
Read the data register and store them in a variable.
Do the steps 5 to 7 for the remaining 2 channels.
Write those datas in hyper terminal via UARTO.
Hardware connection:
HARDWARE PIN CONNECTIONS OUTPUT
OUT

LM35 P0.23 Place all the Jumpers @J6 (ADC)

Turn ON DIP Switch (SW29) Digital Values of all the Three channels
Pins 7-(0.2) and 8-(0.3). will be displayed in UART

POT1 P0.24 Configure HyperTerminal @9600 baud Adjust the POT1 and POT2 or Apply
rate. temperature on LM35 to see the changes

POT2 P0.25 Press RESET.

Program ADC:

#include "LPC407x_8x_177x_8x.h"
#include<stdio.h>

unsigned int CH0, CH1, CH2;


unsigned char Str[5];

unsigned char UART0_Receive(void);


void UART0_Txmt(unsigned char Chr);
void init_serial(void);
void UART0_puts(unsigned char *string);
void init_adc(void);
unsigned int ADC_Getdata(unsigned char channel);
void delay_ms(long ms) ;
void itoa(unsigned int val, unsigned char *str);

int main(void)
{
init_adc();
init_serial();
while(1)
{
CH0=ADC_Getdata(0);
//Get data from channel0
itoa(CH0,Str);
//Convert the val to string
UART0_puts(Str);
//Step 9-Send the string to UART0
UART0_Txmt(' ');
//Space
CH1=ADC_Getdata(1);
//Step 8-Convert the 2nd channel
itoa(CH1,Str);
UART0_puts(Str);
//Step 9-Send ADC data to UART
UART0_Txmt(' ');

CH2=ADC_Getdata(2);
//Step 8-Convert the 3rd channel
itoa(CH2,Str);
UART0_puts(Str);
//Step 9-Send ADC data to UART

UART0_Txmt('\r');
//Carriage return, Enter Key
delay_ms(500);
}
}

void init_adc(void)
{
//1. set the PCADC bit
LPC_SC->PCONP |= (1 << 12);
/* enable power to ADC*/

//2. Configure pins P0.23, P0.24 and P0.25 as ADC input pins
LPC_IOCON->P0_23 = 1;
/* Pin P0.23 used as ADC0, IN0 */
LPC_IOCON->P0_24 = 1;
/* Pin P0.24 used as ADC0, IN1 */
LPC_IOCON->P0_25 = 1;
/* Pin P0.25 used as ADC0, IN2 */

//3. ADC conversion rate = 400Khz


//30MHz/12.4MHz = 2.4-1 = 1 (8 to 15)
//4. Enable PDN bit (21 bit)
LPC_ADC->CR = 0;
LPC_ADC->CR |= ((1<<21) | (1<<8));
}

unsigned int ADC_Getdata(unsigned char channel)


{
//5.Select the Channel and Start conversion
LPC_ADC->CR |= (1<<24) | (1<<channel);
//6. Wait for the DONE bit (31). If the DONE bit is HIGH,
the conversion is completed
while((LPC_ADC->DR[channel] & 0x80000000)==0);
//Deselect the channel and Stop Conversion
LPC_ADC->CR &= ~((1<<24) | (1<<channel));
//7. Read the data
return ((LPC_ADC->DR[channel]>>4)&0xFFF);
}
void init_serial(void)
{
//set bit PCUART0
LPC_SC->PCONP |= (1 << 3);
/* enable power to UART0*/

//Configure pins P0.2 and P0.3 as UART0 TX and RX


LPC_IOCON->P0_2 |= 1;
/* Pin P0.2 used as TXD0 */
LPC_IOCON->P0_3 |= 1;
/* Pin P0.3 used as RXD0 */

//Select Clock source and frequency=PCLK ie 30MHz


/* 8 bits, no Parity, 1 Stop bit */
LPC_UART0->LCR = 0x83;

//Derive baud rate from the UART clock source, Set DLAB=1
to access baud rate
//Register
//DLM:DLL=PCLK/(16*baud)= 30Mhz/(16*9600)= 195
LPC_UART0->DLL = 195; /* 9600 Baud
Rate @ 30.0 MHZ PCLK*/
LPC_UART0->DLM = 0; /* MSB = 0 */
LPC_UART0->LCR = 0x03; /* DLAB = 0*/
}

//Transmit a character
void UART0_Txmt(unsigned char Chr)
{
while((LPC_UART0->LSR & 0x20)==0);
//Bit5-THRE, Check THR empty or not
LPC_UART0->THR = Chr;
//Send the next character
}

//Receive a character
unsigned char UART0_Receive(void)
{
while((LPC_UART0->LSR & 0x01)==0);
//Bit0-RDR, Check receive data ready?
return(LPC_UART0->RBR);
//Read the data
}

//Transmit a string
void UART0_puts(unsigned char *string)
{
while(*string)
UART0_Txmt(*string++);
}

void delay_ms(long ms) // delay 1 ms per


count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

//Int to string (ascii)


void itoa(unsigned int val, unsigned char *str)
{
//Separate the single digit and add 0x30 (where the ascii '0'
starts
str[3] = val%10+'0';
//Get the remainder
val = val/10;
//Separate the single digit of remainder ie 10th digit of val
str[2] = val%10+'0';
//Get the remainder
val = val/10;
//Separate the single digit of remainder ie 100th digit of val
str[1] = val%10+'0';
//Get the remainder, its the 1000th digit
str[0] = val/10+'0';
//End the string with NULL character
str[4] = '\0';
}
Interfacing DAC:
Configure pin po.26 for DAC using 10 CON-PO-26
Enable DAC
Set the maximum current output as default (700MA)
Write the sample DAC values in DAC data register.
Connections:

HARDWARE PIN CONNECTIONS OUTPUT


OUT
Measure the waveform between P0.26 and
GND (JP4-DAC)
A square wave will come depends on the
DAC P0.26 P0.26 is already connected to JP4 written value
Place a Jumper @JP10 between middle
and P0.26 to hear the DAC in buzzer

Program DAC:
#include "LPC407x_8x_177x_8x.h"

void init_dac(void);
void Write_DAC(unsigned int dacval);
void delay_ms(long ms) ;

int main(void)
{
init_dac();
while(1)
{
Write_DAC(0x3FF);
delay_ms(500);
Write_DAC(0);
delay_ms(500);
}
}

void init_dac(void)
{

//1.Configure Pin P0.26 for DAC using IOCON_P0_26


//2.Enable DAC (bit 16)
LPC_IOCON->P0_26 = (2<<0) | (1<<16); /* Pin P0.26
used as DACDOUT */

//3.Set the Maximum current output as default (700uA)


LPC_DAC->CR = 0;

//4.Write the sample DAC values in DAC data register


void Write_DAC(unsigned int dacval)
{
LPC_DAC->CR = (dacval<<6);
}

void delay_ms(long ms) // delay 1 ms per


count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

Result
Thus the interfacing of ADC and DAC (in-built) with ARM processor has been verified and
observed the output successfully.
EXP NO:
Blinking of LEDs and LCD
DATE
Aim:
To verify the interrupt of LEDs and LCD in ARM development kit microprocessor board using
embedded C program

Apparatus Required:
PS-CORTEX-M4-TYRO-V4r2
Mini USB cable

Procedure:
For creating a project in keil
Open keil
Select project -> New project M vision project.
Create a project folder and name the project.
Select the processor and click ok ie, LPC 4088 in NXP (For our device)
Create a new source file by selecting file -> new.
Write the required source code.
Save the file with c extension.
Right click on source group and select “add files to group”.
Select the source code file/click add and then click close.
Navigate the folder “C\Keil\ARM\Startup\NXP\LPC407X-8X-177X-8X”and
copy the file”system-LPC-407X-8X-177X-8X.C”.
Paste it in your project directory.
Right click on source group once again and select add file to group.
Now add this “system LPC407X-8X-177X-8X.C.
Build the project (F7).
Right click “ target” on the project tag and select option for target.
On the target tag select the floating point hardware as not used .
Select output tag and put a check mark on “create hex file”
In the linker tag ,put a check mark on “use memory layout”…..and click ok.
Now rebuild the target and write your hex file into ARM CORTEX M4 use in
flash magic.
Procedure for Flash magic:
Click select
Expand ARM cortex from device database sources down and select your IC
(here NxP-> LPC4088)
Click ok
Put a check mark on ”Erase blocks used by hex file check box” Click browse
Navigate to the project folder, select the hex file to be loaded and click open.
Put a check mark on “verify after programming”. Click start this will start
programming the chip. Press RESET after programming.
Procedure For Flashing The Leds:
1. Power: In the PCONP register, set the PCGPIO bit
2. Configure pins P4.0 to P4.15 as GPIO pins i.e. IOCON_P4_0 to IOCON_P4_15.
3. Select LED pins P4.0 to P4.7 as output and SWITCH pins P4.8 to P4.15 as input
4. Read the Switch status and Display its value in LED
Hardware Connections:

HARDWARE PIN OUT CONNECTIONS OUTPUT

LED1 P4.0 SW5 P4.8


LED2 P4.1 SW6 P4.9
LED3 P4.2 SW7 P4.10
Turn ON and OFF the switches SW5-12,
LED4 P4.3 SW8 P4.11 Place a Jumper @JP3 The LED1-8 will be turned ON/OFF.
LED5 P4.4 SW9 P4.12 I.e. LED displays the Switch Status.
LED6 P4.5 SW10 P4.13
LED7 P4.6 SW11 P4.14
LED8 P4.7 SW12 P4.15

Program:
Blinking of LEDs
#include "LPC407x_8x_177x_8x.h"

void delay_ms(long ms);

int main(void)
{
//1. Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);

//2. Configure pins P4.0 to P4.15 as GPIO pins


LPC_IOCON->P4_0 = 0;
LPC_IOCON->P4_1 = 0;
LPC_IOCON->P4_2 = 0;
LPC_IOCON->P4_3 = 0;
LPC_IOCON->P4_4 = 0;
LPC_IOCON->P4_5 = 0;
LPC_IOCON->P4_6 = 0;
LPC_IOCON->P4_7 = 0;
LPC_IOCON->P4_8 = 0;
LPC_IOCON->P4_9 = 0;
LPC_IOCON->P4_10 = 0;
LPC_IOCON->P4_11 = 0;
LPC_IOCON->P4_12 = 0;
LPC_IOCON->P4_13 = 0;
LPC_IOCON->P4_14 = 0;
LPC_IOCON->P4_15 = 0;

//3. Configure the pins P4.0 to P4.7 as output


// SWITCH pins P4.8 to P4.15 as input
LPC_GPIO4->DIR= 0x00FF;
while(1)
{
//4. Read the Switch Status and display it in LEDs
LPC_GPIO4->PIN >>= 8;
delay_ms(50);
}
}

void delay_ms(long ms) // delay 1 ms per


count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

Procedure:
1. Power: In the PCONP register, set the PCGPIO bit
2. Configure all the LCD pins as GPIO using IOCON registers
3. Configure all the LCD pins as outputs
4. Initialize LCD by sending initialization commands
Command software routine:
5. Make RS pin low
6. Place the MSB 4bits of command on data lines and Pulse the ENABLE pin
7. Place the LSB 4bits of command on data lines and Pulse the ENABLE pin
Data software routine:
8. Make RS pin high
9. Place the MSB 4bits of data on data lines and Pulse the ENABLE pin
10. Place the LSB 4bits of data on data lines and Pulse the ENABLE pin
11. Send First line command using command software routine
12. Send 16 characters of data using data software routine
13. Send Second line command using command software routine
14. Send 16 characters of data using data software routine
Connections:
HARDWARE PIN OUT CONNECTIONS OUTPUT

CONTROL LINES
RS P0.4
RW GND
EN P0.5
DATA LINES Turn ON DIP Switch (SW29) The Strings “CORTEX DEV
D0 - Pins 2-LCD+ BOARD” and “LCD DEMO
D1 - PROGRAM" will be displayed
D2 - on LCD.
D3 -
D4 P4.28
D5 P4.29
D6 P4.30
D7 P4.31
Program: LCD

#include "LPC407x_8x_177x_8x.h"

#define RS_PORT (0)


#define RS_PIN (4)
#define RS_VAL (1 << RS_PIN)

#define EN_PORT (0)


#define EN_PIN (5)
#define EN_VAL (1 << EN_PIN)

#define DATA LPC_GPIO4->PIN

//data array
unsigned char Lcd_LINE1[]={"CORTEX DEV BOARD"},i=0;
unsigned char Lcd_LINE2[]={"LCD DEMO PROGRAM"};

void delay_ms(long ms);


void lcd_command(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_init(void);

int main(void)
{

//1. Set the PCGPIO bit


LPC_SC->PCONP |= (1<<15);

//2. Configure all the LCD pins as GPIO


// RS-P0.4, EN-P0.5, Datalines-P4.28 to P4.31
LPC_IOCON->P0_4 = 0;
LPC_IOCON->P0_5 = 0;
LPC_IOCON->P4_28 = 0;
LPC_IOCON->P4_29 = 0;
LPC_IOCON->P4_30 = 0;
LPC_IOCON->P4_31 = 0;

//3. Configure the pins P4.28 to P4.31 as output


// Configure the pins P0.4 and P0.5 as output
LPC_GPIO0->DIR |= 0x30;
LPC_GPIO4->DIR = (0xF << 28);

//4. Initialize LCD by sending Initialisation commands


lcd_init();

while (1)
{
//11. Send First line command
lcd_command(0x80);
//12. Send 16 characters from the line1 array
for(i=0;Lcd_LINE1[i]!='\0';i++)
{
lcd_data(Lcd_LINE1[i]);
delay_ms(50);
}

//13. Send Second line command


lcd_command(0xc0);
//14. Send 16 characters from the line2 array
for(i=0;Lcd_LINE2[i]!='\0';i++)
{
lcd_data(Lcd_LINE2[i]);
delay_ms(50);
}
delay_ms(1000);
//Clear the display and repeat
lcd_command(0x01);
}
}

void lcd_command(unsigned char cmd)


{
//5. Clear RS pin--Command mode
LPC_GPIO0->CLR |= RS_VAL;

//6. Place the MSB 4bits on data lines


DATA=cmd<<24;
//6. Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;

//7. Place the LSB 4bits on data lines


DATA=cmd<<28;
//7. Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}

void lcd_data(unsigned char data)


{
//8. Set RS pin--data mode
LPC_GPIO0->PIN |= RS_VAL;

//9. Place the MSB 4bits on data lines


DATA=data<<24;
//9. Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;

//10. Place the LSB 4bits on data lines


DATA=data<<28;
//10. Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}

void lcd_init(void)
{
delay_ms(100); //LCD powerup
time
lcd_command(0x33); //Wake up
lcd_command(0x32); //Wake up
lcd_command(0x28); //4bit mode
lcd_command(0x0C); //display on and
cursor off
lcd_command(0x06); //Entry mode and
shift
lcd_command(0x01); //Clear LCD
delay_ms(200); //Give more time
to settle
}

void delay_ms(long ms) // delay 1 ms per


count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

Result:
Thus the flashing of LEDs and LCD using ARM development kit board was observed by
using embedded C program successfully.
5 INTERFACING KEYBOARD AND STEPPER MOTOR

Aim:
To develop and verify the interfacing of keyboard and stepper motor with ARM development kit
and ARM microcontroller using embedded C program.

Apparatus Required:
PS CORTEX – M4- TYRO- V4r2
Mini VSB cable

Procedure:
For creating a project in keil
Open keil
Select project -> New project M vision project.
Create a project folder and name the project.
Select the processor and click ok ie, LPC 4088 in NXP (For our device)
Create a new source file by selecting file -> new.
Write the required source code.
Save the file with c extension.
Right click on source group and select “add files to group”.
Select the source code file/click add and then click close.
Navigate the folder “C\Keil\ARM\Startup\NXP\LPC407X-8X-177X-8X”and
copy the file”system-LPC-407X-8X-177X-8X.C”.
Paste it in your project directory.
Right click on source group once again and select add file to group.
Now add this “system LPC407X-8X-177X-8X.C.
Build the project (F7).
Right click “ target” on the project tag and select option for target.
On the target tag select the floating point hardware as not used .
Select output tag and put a check mark on “create hex file”
In the linker tag ,put a check mark on “use memory layout”…..and click ok.
Now rebuild the target and write your hex file into ARM CORTEX M4 use in
flash magic.
Hardware connection:
Turn on D/P switch sw29 pins 7 and 8.
Supply power to the board using sw1
Press and hold sw4 and press reset to enter into boot leader mode.

Procedure for Flash magic:


Click select Expand ARM cortex from device database sources down and select
your IC (here NxP-> LPC4088) Click ok Put a check mark on ”Erase blocks used
by hex file check box” Click browse
Navigate to the project folder, select the hex file to be loaded and clickopen.
Put a check mark on “verify after programming”.
Click start this will start programming the chip. Press RESET after programming.
Interfacing Procedure:
KEYBOARD:
1. Power: In the PCONP register, set the PCGPIO bit
2. Configure all the Keypad pins as GPIO using IOCON3_0 to IOCON3_7
3. Configure all the row pins as output and make it HIGH
4. Configure all the column pins as input and make it HIGH
5. Configure all the LCD pins as output and Initialize LCD
6. Make a row pin Zero and check all the four column lines one by one for zero
7. If any key is pressed, the corresponding column will get zero
8. Read the key value and display it in LCD
Connections:

HARDWARE PIN OUT CONNECTION OUTPUT

ROW1 P3.0
ROW2 P3.1
ROW3 P3.2
ROW4 P3.3 Turn ON DIP Switch (SW29) Press a Key (4x4 matrix
COL1 P3.4 Pins 2-LCD+ key- pad) and the number
will be displayed LCD
COL2 P3.5
COL3 P3.6
COL4 P3.7

Stepper Motor:
Power in the PCONP register, set the PCGP10 bit.
Configure all the LCD pins as GP10 using 10CON register.
Configure all the LCD pins as output.
Initialize LCD by sending initialization command.
COMMAND SOFTWARE ROUTINE:
Make RS pins low.
Place the MSB 4 bits of command on data line and pulse the enable pin.
Place the LSB 4 bits of command on data line and pulse the enable pin.
DATA SOFTWARE ROUTINE:
Make RS pins high.
Place the MSB 4 bits of command on data line and pulse the enable pin.
Place the LSB 4 bits of command on data line and pulse the enable pin.
Send the first line command using command software routine.
Send 16 characters of data and using command software routine.
Send 16 characters of data using data software routine.
Program:
Keyboard:
#include "LPC407x_8x_177x_8x.h"

#define RS_PORT (0)


#define RS_PIN (4)
#define RS_VAL (1 << RS_PIN)
#define EN_PORT (0)
#define EN_PIN (5)
#define EN_VAL (1 << EN_PIN)
#define DATA LPC_GPIO4->PIN
#define keyportc LPC_GPIO3->CLR
#define keyports LPC_GPIO3->SET

#define COL1 (LPC_GPIO3->PIN & 0x10)


#define COL2 (LPC_GPIO3->PIN & 0x20)
#define COL3 (LPC_GPIO3->PIN & 0x40)
#define COL4 (LPC_GPIO3->PIN & 0x80)

unsigned char k=0,key=0,i=0;


unsigned char Lcd_LINE1[]={"KEYPAD DEMO: "};
void delay_ms(long ms);
void lcd_command(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_init(void);
unsigned char get_key(void);
int main(void)
{
//1. Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);
//2. Configure all Keypad pins as GPIO
LPC_IOCON->P3_0 = 0x00;
LPC_IOCON->P3_1 = 0x10;
LPC_IOCON->P3_2 = 0x10;
LPC_IOCON->P3_3 = 0x10;
LPC_IOCON->P3_4 = 0x10;
LPC_IOCON->P3_5 = 0x10;
LPC_IOCON->P3_6 = 0x10;
LPC_IOCON->P3_7 = 0x10;

//3. Configure all the row pins as output and make it HIGH
// Configure all the column pins as input and make it

HIGH LPC_GPIO3->DIR = 0x0F;


LPC_GPIO3->PIN = 0x0F;

//4. Configure all the LCD pins as outputs


// RS-P0.4, EN-P0.5, Datalines-P4.28 to P4.31
LPC_IOCON->P0_4 = 0;
LPC_IOCON->P0_5 = 0;
LPC_IOCON->P4_28 = 0;
LPC_IOCON->P4_29 = 0;
LPC_IOCON->P4_30 = 0;
LPC_IOCON->P4_31 = 0;

//5. Configure the pins P4.28 to P4.31 as output


//Configure the pins P0.4 and P0.5 as output
LPC_GPIO0->DIR |= 0x30;
LPC_GPIO4->DIR = (0xF << 28);
//5. Initialize LCD
lcd_init();
//Send First line command
lcd_command(0x80);
//Send 16 characters from the line1 array
for(i=0;Lcd_LINE1[i]!='\0';i++)
{
lcd_data(Lcd_LINE1[i]);
delay_ms(50);
}
delay_ms(1000);
while (1)
{
if(get_key()!=0){
lcd_command(0xc0);
if(key<=10)lcd_data(key-1+'0');
else lcd_data(key-11+'A');
}
delay_ms(100);
}
}

void lcd_command(unsigned char cmd)


{
//Clear RS pin--Command mode
LPC_GPIO0->CLR |= RS_VAL;

//Place the MSB 4bits on data lines


DATA=cmd<<24;
//Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;

//Place the LSB 4bits on data lines


DATA=cmd<<28;
//Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}

void lcd_data(unsigned char data)


{
//Set RS pin--Command mode
LPC_GPIO0->PIN |= RS_VAL;

//Place the MSB 4bits on data lines


DATA=data<<24;
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
//Place the LSB 4bits on data lines
DATA=data<<28;
//Pulse the EN pin
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}

void lcd_init(void)
{
delay_ms(100); //LCD powerup
time lcd_command(0x33); //Wake up
lcd_command(0x32); //Wake up
lcd_command(0x28); //4bit mode
lcd_command(0x0C); //display on and

cursor off lcd_command(0x06); //Entry mode and


lcd_command(0x01); //Clear LCD
shift delay_ms(200); //Give more time

to settle
}
void delay_ms(long ms) // delay 1 ms per
count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

unsigned char get_key(void)


{
LPC_GPIO3->PIN=0x0F;
k=1;
for(i=0;i<4;i++){
keyportc |=(0x01<<i);
//Scan for a Key by sending '0' on ROWS
lcd_command(0xc0);
if(COL1==0){
//when a key pressed numbers 1--16 will be returned
key = k+0;
while(COL1==0)
; return key;
}
if(COL2==0
){
key = k+1;
while(COL2==0)
; return key;
}
if(COL3==0
){
key = k+2;
while(COL3==0)
; return key;
}
if(COL4==0
){
key = k+3;
while(COL4==0)
; return key;
}
k+=4;
keyports |=(0x01<<i);
}
return 0;
}

Program:
Stepper Motor:
Procedure:
1. Power: In the PCONP register, set the PCGPIO bit
2. Configure pins P3.23 to P3.26 as GPIO pins using IOCON registers IOCON_P3_23 to
IOCON_P3_26
3. Configure the pins P3.23 to P3.24 as output pins using their direction registers.
4. Send the stepper sequence via IO lines
Connections:
HARDWARE PIN CONNECTIONS OUTPUT
OUT

PHASE.1 P3.23 Connect a 5V adapter @J1 DC JACK.


Turn ON Slide switch SW1 (Power supply)
PHASE.2 P3.24 towards EXT (important)
Connect a Stepper Motor @J10 (6 wire) The stepper motor will start
Two red wires--VCC rotating
PHASE.3 P3.25
Turn ON DIP Switch (SW29) Pin1 (5V-
STP).
PHASE.4 P3.26

Program:
Stepper Motor:

#include "LPC407x_8x_177x_8x.h"

void delay_ms(long ms);

int main(void)
{
//1. Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);

//2. Configure pins P3.23 to P3.26 as GPIO pins


LPC_IOCON->P3_23 = 0x0;
LPC_IOCON->P3_24 = 0x0;
LPC_IOCON->P3_25 = 0x0;
LPC_IOCON->P3_26 = 0x0;

//3.Configure the pins P3.23 to P3.24 as output pins


LPC_GPIO3->DIR = (0x0F<<23);

while(1)
{
//4. Send the stepper sequence
//Stepper Squence 1001,1100,0110,0011
LPC_GPIO3->PIN=(0x09<<23);
delay_ms(5);
LPC_GPIO3->PIN=(0x0c<<23);
delay_ms(5);
LPC_GPIO3->PIN=(0x06<<23);
delay_ms(5);
LPC_GPIO3->PIN=(0x03<<23);
delay_ms(5);
}
}

void delay_ms(long ms) // delay 1 ms per count @ CCLK


120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}

Result:
Thus the interfacing of keyboard and Stepper Motor with ARM development
kit and microcontroller using embedded C program has been verified successfully.
EXP NO: 9 GARBAGE SEGREGATOR AND BIN LEVEL
DATE INDICATOR

AIM:
Mini Project of Garbage Segregator and Bin Level Indicator

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 Garbage Segregator and Bin Level Indicator 1

CONNECTION DIAGRAM:
PROGRAMME:

import numpy as np
import cv2
import RPi.GPIO as GPIO
import time
import pyttsx3
import I2C_LCD_Driver
import urllib.request

api_key = 'P47FDNAYU6MRM9WH'
#Garbage Segregator and Bin Level Indicator
mylcd = I2C_LCD_Driver.lcd()
mylcd.lcd_display_string(" Bin Level ", 1)
mylcd.lcd_display_string(" Indicator ", 2)
#GPIO Mode (BOARD / BCM)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#set GPIO Pins
GPIO_TRIGGER = 23
GPIO_ECHO = 24
#set GPIO direction (IN / OUT)
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)

#set GPIO Pins


GPIO_TRIGGER_2 = 22
GPIO_ECHO_2 = 27
#set GPIO direction (IN / OUT)
GPIO.setup(GPIO_TRIGGER_2, GPIO.OUT)
GPIO.setup(GPIO_ECHO_2, GPIO.IN)
detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video_capture =cv2.VideoCapture(0)
engine = pyttsx3.init()
engine.setProperty('rate', 140) #voice speed
def distance_1():
# set Trigger to HIGH
GPIO.output(GPIO_TRIGGER, True)
# set Trigger after 0.01ms to LOW
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
StartTime = time.time()
StopTime = time.time()
# save StartTime
while GPIO.input(GPIO_ECHO) == 0:
StartTime = time.time()

# save time of arrival


while GPIO.input(GPIO_ECHO) == 1:
StopTime = time.time()
# time difference between start and arrival
TimeElapsed = StopTime - StartTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance = (TimeElapsed * 34300) / 2
print (distance)
if distance > 20:
distance = 20
per = (distance / 2)*10
return per
def distance_2():
# set Trigger to HIGH
GPIO.output(GPIO_TRIGGER_2, True)
# set Trigger after 0.01ms to LOW
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER_2, False)
StartTime = time.time()
StopTime = time.time()
# save StartTime
while GPIO.input(GPIO_ECHO_2) == 0:
StartTime = time.time()
# save time of arrival
while GPIO.input(GPIO_ECHO_2) == 1:
StopTime = time.time()
# time difference between start and arrival
TimeElapsed = StopTime - StartTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance = (TimeElapsed * 34300) / 2
print (distance)
if distance > 20:
distance = 20
per = (distance / 2)*10
return per

engine.say('Welcome')
engine.runAndWait()
mylcd.lcd_clear()
mylcd.lcd_display_string("BIN LEVEl 1= 0 ", 1)
mylcd.lcd_display_string("BIN LEVEl 2= 0 ", 2)
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % api_key
while(True):
ret, img = video_capture.read()
#frame = cv2.resize(img,(0,0),fx=0.5, fy=0.5)
frame = cv2.resize(img,(400,350))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow('img',frame)
cv2.waitKey(1)
bin_1 = distance_1()
#bin_1 = input("bin_1=")
bin_2 = distance_2()
#bin_2 = input("bin_2=")
print ("Measured = "+ str(bin_1) +" "+ str(bin_2))
mylcd.lcd_clear()
if ((bin_1 == 100) and (bin_2 == 100)):
mylcd.lcd_display_string("Both bin full,Pls", 1)
mylcd.lcd_display_string("use anyother bin ", 2)
string = ("Both bin level is full, please use any other bin")
elif(bin_1 == 100):
mylcd.lcd_display_string("BIN LEVEl 1= full", 1)
mylcd.lcd_display_string("BIN LEVEl 2= "+str(int(bin_2)), 2)
string = ("first bin is full and" + "Second bin level is" + str(int(bin_2)))
elif(bin_2 == 100):
mylcd.lcd_display_string("BIN LEVEl 1= "+str(int(bin_1)), 1)
mylcd.lcd_display_string("BIN LEVEl 2= full", 2)
string = ("first bin level is" + str(int(bin_1)) + "and Second bin full")
else:
mylcd.lcd_display_string("BIN LEVEl 1= "+str(int(bin_1)), 1)
mylcd.lcd_display_string("BIN LEVEl 2= "+str(int(bin_2)), 2)
string = ("first bin level is" + str(int(bin_1)) + "and" + "Second bin level is" + str(int(bin_2)))
f = urllib.request.urlopen(baseURL+"&field1=%s&field2=%s" % (bin_1,bin_2))
print(f.read())
f.close()
engine.say(string)
engine.runAndWait()
time.sleep(5)
cv2.imshow('img',frame)
if(cv2.waitKey(1)==ord('q')):
break
video_capture.release()
cv2.destroyAllWindows()

Result:
Thus the mini project of Garbage Segregator and Bin Level Indicator has been
verified successfully.
EXP NO: 10 COLOUR BASED PRODUCT SORTING
DATE MACHINES

AIM:
Mini Project of Colour based Product Sorting Machines

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 Colour based Product Sorting Machines 1

CONNECTION DIAGRAM:
PROGRAMMES:

import cv2
import RPi.GPIO as GPIO
import time
import numpy as np
import I2C_LCD_Driver
import urllib.request

api_key = 'P47FDNAYU6MRM9WH'

#2 to 12.5
#Colour based Product Sorting
mylcd = I2C_LCD_Driver.lcd()
mylcd.lcd_display_string(" Coloue Based ", 1)
mylcd.lcd_display_string("Product Sorting ", 2)
servoPIN = 17
servoPIN_2 = 27

GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
GPIO.setup(servoPIN_2, GPIO.OUT)
webcam = cv2.VideoCapture(0)

start_position = 5.0
camera_stop = 6.6
end_position = 9.8
step_delay = 0.05
step_angle = 0.1

p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz


p.start(2.5) # Initialization
p_2 = GPIO.PWM(servoPIN_2, 50) # GPIO 17 for PWM with 50Hz
p_2.start(2.5) # Initialization
def get_colour():
string = "no_color"
_, image = webcam.read()
imageFrame = cv2.resize(image,(150,150))
hsvFrame = cv2.cvtColor(imageFrame, cv2.COLOR_BGR2HSV)
print(hsvFrame[50,45])
pink_lower = np.array([150, 180, 230], np.uint8)
pink_upper = np.array([170, 255, 255], np.uint8)
pink_mask = cv2.inRange(hsvFrame, pink_lower, pink_upper)

green_lower = np.array([25, 155, 145], np.uint8)


green_upper = np.array([102, 255, 215], np.uint8)
green_mask = cv2.inRange(hsvFrame, green_lower, green_upper)

kernel = np.ones((5, 5), "uint8")

pink_mask = cv2.dilate(pink_mask, kernel)


res_pink = cv2.bitwise_and(imageFrame, imageFrame, mask = pink_mask)

green_mask = cv2.dilate(green_mask, kernel)


res_green = cv2.bitwise_and(imageFrame, imageFrame, mask = green_mask)

contours, hierarchy = cv2.findContours(pink_mask, cv2.RETR_TREE,


cv2.CHAIN_APPROX_SIMPLE)
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
string = "pink"
x, y, w, h = cv2.boundingRect(contour)
imageFrame = cv2.rectangle(imageFrame, (x, y), (x + w, y + h), (0, 0, 255), 2)

contours, hierarchy = cv2.findContours(green_mask, cv2.RETR_TREE,


cv2.CHAIN_APPROX_SIMPLE)
for pic, contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
string = "green"
x, y, w, h = cv2.boundingRect(contour)
imageFrame = cv2.rectangle(imageFrame, (x, y), (x + w, y + h), (0, 255, 0), 2)
print(string)
cv2.imshow("Win_Color", imageFrame)
cv2.waitKey(100)
return string
object_coloue = 0
green = 0
pink = 0
other = 0
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % api_key
try:
while True:
mylcd.lcd_clear()
mylcd.lcd_display_string("green="+str(green)+" pink="+str(pink), 1)
mylcd.lcd_display_string("others="+str(other), 2)
for angle in np.arange(end_position,camera_stop,-step_angle):
angle = round(angle,3)
p.ChangeDutyCycle(angle)
time.sleep(step_delay)
time.sleep(2)
object_colour = get_colour()
if(object_colour == "green"):
green = green + 1
p_2.ChangeDutyCycle(2.2)
f = urllib.request.urlopen(baseURL+"&field1=%s" % (green))
#print(f.read())
f.close()
elif(object_colour == "pink"):
pink = pink + 1
p_2.ChangeDutyCycle(3.5)
f = urllib.request.urlopen(baseURL+"&field2=%s" % (pink))
#print(f.read())
f.close()
elif(object_colour == "no_color"):
other = other + 1
p_2.ChangeDutyCycle(4.2)
f = urllib.request.urlopen(baseURL+"&field3=%s" % (other))
#print(f.read())
f.close()
time.sleep(2)
for angle in np.arange(camera_stop,start_position,-step_angle):
angle = round(angle,3)
p.ChangeDutyCycle(angle)
time.sleep(step_delay)
time.sleep(2)
for angle in np.arange(start_position,end_position,step_angle):
angle = round(angle,3)
p.ChangeDutyCycle(angle)
time.sleep(step_delay)

except KeyboardInterrupt:
p.stop()
GPIO.cleanup()

webcam.release()
cv2.destroyAllWindows()
p.stop()
p_2.stop()
GPIO.cleanup()

Result:
Thus the mini project of Colour based Product Sorting Machines has been
verified successfully.
EXP NO: 11 IMAGE PROCESSING BASED FIRE DETECTION
DATE

AIM:
Mini Project of Image Processing based Fire Detection

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 Image Processing based Fire Detection 1

CONNECTION DIAGRAM:
PROGRAMMES:

import I2C_LCD_Driver
from time import *
import numpy as np
import cv2
mylcd = I2C_LCD_Driver.lcd()
mylcd.lcd_display_string(" Megatronics ", 1)
mylcd.lcd_display_string(" Fire Detecting ", 2)

fire_cascade = cv2.CascadeClassifier('cascade.xml')

cap = cv2.VideoCapture(0) #start video capturing


count = 0
sleep(2) # 2 sec delay
mylcd.lcd_clear()
mylcd.lcd_display_string("No Fire detect ", 1)
while cap.isOpened():
fire_check = 0
ret, img = cap.read() #capture a frame
# convert input image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
fire = fire_cascade.detectMultiScale(gray, 12, 5) #test for fire detection
for (x,y,w,h) in fire:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2) #highlight the area of image with fire
print( 'Fire is detected..!' + str(count))
fire_check = 1
count = count + 1
if fire_check == 1:
mylcd.lcd_display_string(" Fire detect ", 1)
else:
mylcd.lcd_display_string("No Fire detect ", 1)
cv2.imshow('img', img)
k = cv2.waitKey(100) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()

Result:
Thus the mini project of Image Processing based Fire Detection has been
verified successfully.
EXP NO: 12 VEHICLE NUMBER PLATE DETECTION
DATE

AIM:
Mini Project of Vehicle Number Plate Detection

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 Vehicle Number Plate Detection 1

CONNECTION DIAGRAM:

PROGRAMMES:

import cv2
import numpy as np

# read haarcascade for number plate detection


cascade = cv2.CascadeClassifier('haarcascade_russian_plate_number.xml')
cap = cv2.VideoCapture(0) #start video capturing
while cap.isOpened():
ret, img = cap.read()
# convert input image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Detect license number plates
plates = cascade.detectMultiScale(gray, 1.2, 5)
# loop over all plates
for (x,y,w,h) in plates:
# draw bounding rectangle around the license number plate
cv2.rectangle(img, (x,y), (x+w, y+h), (0,255,0), 2)
gray_plates = gray[y:y+h, x:x+w]
color_plates = img[y:y+h, x:x+w]
cv2.imshow('Number Plate', gray_plates)
print('Number of detected license plates:', len(plates))
cv2.imshow('Number Plate Image', img)
k = cv2.waitKey(100) & 0xff
if k == 27:
break

cap.release()
cv2.destroyAllWindows()

Result:
Thus the mini project of Vehicle Number Plate Detection has been verified
successfully.
EXP NO: 13 Smart Lock System
DATE

AIM:
Mini Project of Smart Lock System

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Hardware & Software Requirements Quantity

1 Smart Lock System 1

CONNECTION DIAGRAM:
PROGRAMMES:

#include"LiquidCrystal_I2C.h"

#define PR1 2
#define PR2 3
#define PR3 4
#define PR4 5
#define PC1 6
#define PC2 7
#define PC3 8
#define G_LED 10
#define B_LED 11
#define R_LED 12

#define Buzzer 13
#define relay 9
#define RR1 digitalRead(PR1)
#define RR2 digitalRead(PR2)
#define RR3 digitalRead(PR3)
#define RR4 digitalRead(PR4)

//LiquidCrystal_I2C lcd(0x3F,16,2);
LiquidCrystal_I2C lcd(0x27,16,2);

const byte ROWS = 4;


const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

uint8_t key;
uint8_t count;
uint8_t securitykey[4];
uint8_t get_key[4];
uint8_t Read_keypad()
{
uint8_t colum;
uint8_t result = '-';
for(colum = 0; colum <= 2; colum++)
{
switch(colum)
{
case 0:
digitalWrite(PC1, LOW);
digitalWrite(PC2, HIGH);
digitalWrite(PC3, HIGH);
break;
case 1:
digitalWrite(PC1, HIGH);
digitalWrite(PC2, LOW);
digitalWrite(PC3, HIGH);
break;
case 2:
digitalWrite(PC1, HIGH);
digitalWrite(PC2, HIGH);
digitalWrite(PC3, LOW);
break;
default:
colum = 0;
return result;
break;
}

if(RR1 == LOW)
{
Serial.print(colum);
Serial.println(" RR1");
result = keys[0][colum];
break;
}
else if(RR2 == LOW)
{
Serial.print(colum);
Serial.println(" RR2");
result = keys[1][colum];
break;
}
else if(RR3 == LOW)
{
Serial.print(colum);
Serial.println(" RR3");
result = keys[2][colum];
break;
}
else if(RR4 == LOW)
{
Serial.print(colum);
Serial.println(" RR4");
result = keys[3][colum];
break;
}
}
return result;
}
void new_key_disp(void)
{
lcd.setCursor(0,0);
lcd.print("New Security Key");
lcd.setCursor(0,1);
lcd.print("Type: ");
}
void get_key_disp(void)
{
lcd.setCursor(0,0);
lcd.print("Welcome to home ");
lcd.setCursor(0,1);
lcd.print("Key : ");
}
void get_securitykey(uint8_t *sec_key)
{
count = 0;
while(count < 4)
{
key = Read_keypad();
if(key != '-')
{
sec_key[count] = key;
lcd.setCursor(5+count,1);
lcd.print("*");
count++;
}
delay(1000);
}
}
uint8_t compareky(uint8_t* cmp1, uint8_t* comp2)
{
uint8_t i,ret = 1;
for(i=0;i<4;i++)
{
if(cmp1[i] != comp2[i])
{
ret =0;
break;
}
}
return ret;
}
void setup()
{
lcd.init();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Megatronics ");
lcd.setCursor(0,1);
lcd.print("Door Lock system");
lcd.backlight();
pinMode(PR1, INPUT_PULLUP);
pinMode(PR2, INPUT_PULLUP);
pinMode(PR3, INPUT_PULLUP);
pinMode(PR4, INPUT_PULLUP);
pinMode(PC1, OUTPUT);
pinMode(PC2, OUTPUT);
pinMode(PC3, OUTPUT);

pinMode(G_LED, OUTPUT);
pinMode(B_LED, OUTPUT);
pinMode(R_LED, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(relay, OUTPUT);
digitalWrite(G_LED, LOW);
digitalWrite(B_LED, HIGH);
digitalWrite(R_LED, LOW);
digitalWrite(relay, HIGH);
digitalWrite(Buzzer, HIGH);
Serial.begin(9600);
delay(2000);
new_key_disp();
get_securitykey(&securitykey[0]);
}
void loop()
{
uint8_t ret;
get_key_disp();
get_securitykey(&get_key[0]);
ret = compareky(&securitykey[0],&get_key[0]);
if(ret == 1)
{
lcd.setCursor(0,0);
lcd.print("Key matched ");
lcd.setCursor(0,1);
lcd.print("Door opened ");
digitalWrite(G_LED, HIGH);
digitalWrite(B_LED, LOW);
digitalWrite(R_LED, LOW);
digitalWrite(Buzzer, LOW);
digitalWrite(relay, LOW);
delay(1000);
digitalWrite(Buzzer, HIGH);
delay(4000);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Door closed ");
digitalWrite(G_LED, LOW);
digitalWrite(B_LED, HIGH);
digitalWrite(relay, HIGH);
delay(2000);
}else{
lcd.setCursor(0,0); lcd.print("Key
not matched "); lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(G_LED, LOW);
digitalWrite(B_LED, LOW);
digitalWrite(R_LED, HIGH);
digitalWrite(Buzzer, LOW);
while(1)
{
key = Read_keypad();
if(key == '#')
{
lcd.clear(); digitalWrite(G_LED,
LOW); digitalWrite(B_LED,
HIGH); digitalWrite(R_LED,
LOW); digitalWrite(Buzzer,
HIGH); delay(1000);
break;
}
}
}
delay(100);
}

Result:
Thus the mini project of Smart Lock System has been verified successfully.

You might also like