You are on page 1of 76

Sri Krishna College of

Engineering Technology
(An Autonomous Institution)

(Approved by AICTE and Affiliated to Anna University, Chennai) (ACCREDITED BY NBA

&NAAC WITH “A” GRADE)

19ECI401
MICROPROCESSOR AND
MICROCONTROLLERS

Department of Electronics and


Communication Engineering

Submitted by

Name : karthikeyan M

Reg. No : 19EPCI014
SRI KRISHNA COLLEGE OF ENGINEERING AND TECHNOLOGY
COIMBATORE-641 008

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

19ECI401– MICROPROCESSOR AND MICRO CONTROLLERS


PRACTICAL RECORD

Name :KARTHIKEYAN M Reg. no:19EPCI014

Class :I M TECH A Branch:CSE

BONAFIDE CERTIFICATE

Certified bonafide record of work done by Mr.KARTHIKEYA M during the academic


year 2020-2021.

HOD Staff-In Charge

Submitted for the Autonomous Practical Examination held on …………..........

INTERNAL EXAMINER EXTERNAL EXAW


VISION OF THE DEPARTMENT- To be a center of excellence for technological education, training & research and
to produceWorld class Electronics and Communication Engineers to serve the nation and the to search

MISSION OF THE DEPARTMENT

To provide quality education in the fundamentals as well as the current trends in the field of

Electronics and Communication Engineering, to continuously update the various facilities in

the department to facilitate R&D and consulting activities and to disseminate knowledge by

organizing seminars, Faculty Development Programs and Workshops.

PROGRAMME EDUCATIONAL OBJECTIVES

PEO- I Excel in professional career to provide engineering solution by demonstrating


Technical competence in electronics and communication engineering.

PEO- II Identify, analyze and formulate problems to offer appropriate design solutions that
are technically superior, economically feasible, environmentally compatible and
Socially acceptable.

PEO- III Achieve progress in professional and research career through communication
Skills, team work and knowledge up-gradation through continuous education.

PROGRAMME OUTCOMES

PO- a Apply the knowledge of the physical sciences, mathematics, computing, Electronics
and Communication Engineering fundamentals for modeling and solving complex
engineering problems.

PO- b Design and Conduct scientific and engineering experiments, as well as to


analyze, evaluate and Interpret generated data pertaining to engineering
activities.

PO- c Design and evaluate complex systems for specific purpose in Electronics and
Communication Engineering, with due considerations for economic, environmental,
social, political, ethical, health and safety considerations

PO- d Identify complex Electronics and Communication Engineering problems, formulate,


analyze, design and provide solution for them.

PO- e Apply appropriate techniques, skills, and modern tools for the design and analysis
of engineering systems.

PO- f Attain broad education to provide engineering solution by taking environment and
sustainability into consideration
PO- g Understand the contemporary technical, professional issues and provide engineering
solution for societal problems

PO- h Develop consciousness of professional, ethical, legal, security, social issues and
Responsibilities

PO- i Function effectively as individuals and in teams which may involve people from
diverse background to accomplish a common goal

PO- j Communicate effectively both in written and oral form to address activities with
engineering community and society

PO- k Engage in lifelong learning through higher studies/additional qualifications to adapt


technical changes

PO- l Apply engineering and management fundamentals to manage the projects in time
with due consideration for finance

TABLE OF CONTENTS
Ex .No Date Exp.Name Page no Marks Staff Sign
1. 09/01/2021 8086 ARITHMETIC 9
OPERATIONS
2. 23/01/2021 8051 17
ARITHMETIC
OPERATORS
3. 28/01/2021 LARGEST 36
AND SMALLEST
IN AN ARRAY
4. 12/02/2021 Interfacing 8051 with 42
ADC
5. 27/02/2021 Interfacing 8051 with 47
Stepper motor
6. 06/03/2021 PROGRAMMABLE 56
PERIPHERAL
INTERFACE TO 8051
MICROCONTROLLER
7. 13/03/2021 INTERFACING LED 60
USING ARM WITH
KEIL C
8. 20/03/2021 DATA 64
TRANSCEIVER IN
ARM USING UART
9. 27/03/2021 PROGRAMMING 67
USING ARDUNIO –
LED FADING
10. 27/03/2021 TRAFFIC LIGHT 71
CONTROLLER
USING ARDUNIO
11. 27/03/2021 INTERFACING 75
GAS SENSOR
WITH ARDUINO

SRI KRISHNA COLLEGE OF ENGINEERING AND TECHNOLOGY


KUNIAMUTHUR, COIMBATORE – 641008

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
RUBRIC ASSESSMENT
Name of the Laboratory:19ECI401- MICROPROCESSORS AND MICROCONTROLERS

Criteria Excellent Good Average Below


Average
Objective, Algorithm, (18 - 20 marks) (14 - 16 (10 – 13 (0 - 9
marks)
Description with marks) marks)
sample
Data Clear listing of Clear listing Clear listing of Unclear
of
(20 marks) objective with objective objective with objective
with and
suitable relevant incomplete steps
explanation, able explanation explanation
to give step by able to and steps &
step explain
procedure with the various unable to give
sample data and steps sample data
involved
expected output almost
correctly
Coding (27 - 30 marks) (21 - 26 (15 – 20 (0-14
(30 marks) marks) marks) marks)
Able to Able to Implementatio Unable to
n
declare/define declare/ of logic to a declare /
define
variables the variables certain extent define the
correctly and correctly and with basic variables
and
feed the codes feed the knowledge of not able to
codes
following the following the syntax write the
logic involved logic to some code
perfectly with extend with correctly
proper syntax syntax and following
and structure structure proper
syntax
Compilation/ (27 - 30 marks) (21 - 26 (15 – 20 (0-14
Assembling
and Debugging marks) marks) marks)
(30 marks) Able to clear all Cleared most Cleared most Compilation
syntactical, of the of the is not
logical errors syntactical, syntactical successful
and logical errors error and and unable
compiled to
and compiled compilation is clear errors
successfully.
with few not successful
warnings
Generalization, (9 - 10 marks) (7 - 8 marks) (5 – 6 marks) (0 – 4
marks)
Execution and Result Satisfies all test Satisfies Partial result Unable to
(10 marks) case set, minimal test generate
accurate
result coinciding case set, result
with manual accurate
result
calculation
Documentation (9 - 10 marks) (7 - 8 marks) (5 – 6 marks) (0 – 4
marks)
(10 marks) Well presented Presented the Not presented Improperly
the content in content and in an presented
organized the
detail. Fully still scope for manner content
complied with improvement
the requirement

SRI KRISHNA COLLEGE OF ENGINEERING AND


TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 01
Title of Experiment 8086 ARITHMETIC OPERATIONS
Date of Experiment 09/01/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Equipments required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:
To perform addition,subtraction,multiplication,division of two 16-
bit data and store the result in memory using 8086 microprocessor
OUPUT(8Bit_Addition):
OUTPUT(8Bit_Subtraction):
OUTPUT(Addition+Subtraction 8Bit):
OUTPUT(8Bit_Multiplication):
OUTPUT(8Bit_Division):
OUTPUT(16Bit_Addition):
OUTPUT(16Bit_Subtraction):
OUTPUT(Largest Number):
OUTPUT(Smallest Number):
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 4
Title of Experiment Interfacing 8051 with ADC

Date of Experiment 20/02/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Equipments required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:
To Interface 8051 with ADC.

Interfacing 8051 with ADC


AIM :
To write a assemble language program to Interface 8051 with ADC
ALGORITHM :

Steps for converting the analogue input  and reading the output from ADC0804.

1. Make CS=0 and send a low to high pulse to WR pin to start the conversion.
2. Now keep checking the INTR pin.  INTR will be 1 if conversion is not finished and INTR
will be 0 if conversion is finished.
3. If conversion is not finished (INTR=1) , poll until it is finished.
4. If conversion is finished (INTR=0), go to the next step.
5. Make CS=0 and send a high to low pulse to RD pin to read the data from the ADC.
THEORY:
i.)Interfacing ADC to 8051

ADC (Analog to digital converter) forms a very essential part in many embedded projects and this
article is about interfacing an ADC to 8051 embedded controller. ADC 0804 is the ADC used here
and before going through the interfacing  procedure, we must neatly understand how the ADC
0804 works.

ii.) ADC 0804:


ADC0804 is an 8 bit successive approximation analogue to digital converter from National
semiconductors. The features of ADC0804 are  differential analogue voltage inputs, 0-5V input
voltage range, no zero adjustment, built in clock generator, reference voltage can be externally
adjusted to convert smaller analogue voltage span to 8 bit resolution etc. The pin out diagram of
ADC0804 is shown in the figure below.

iii.) Interfacing 8051 with ADC:


The figure above shows the schematic for interfacing ADC0804 to 8051. The circuit initiates the
ADC to convert a given analogue input , then accepts the corresponding digital data and displays it
on the LED array connected at P0. For example, if the analogue input voltage Vin is 5V then all
LEDs will glow indicating 11111111 in binary which is the equivalent of 255 in decimal.
AT89s51 is the microcontroller used here. Data out pins (D0 to D7) of the ADC0804 are
connected to the port pins P1.0 to P1.7 respectively. LEDs D1 to D8 are connected to the port pins
P0.0 to P0.7 respectively. Resistors R1 to R8 are current limiting resistors. In simple words P1 of
the microcontroller is the input port and P0 is the output port.
Control signals for the ADC (INTR, WR, RD and CS) are available at port pins P3.4 to P3.7
respectively. Resistor R9 and capacitor C1 are associated with the internal clock circuitry of the
ADC. Preset resistor R10 forms a voltage divider which can be used to apply a particular input
analogue voltage to the ADC. Push button S1, resistor R11 and capacitor C4 forms a debouncing
reset mechanism. Crystal X1 and capacitors C2,C3 are associated with the clock circuitry of the
microcontroller.

Program : Interfacing ADC to 8051

ORG 00H
MOV P1,#81h // initiates P1 as the input port
MAIN: CLR P3.7 // makes CS=0
SETB P3.6 // makes RD high
CLR P3.5 // makes WR low
SETB P3.5 // low to high pulse to WR for starting conversion
WAIT: JB P3.4,WAIT // polls until INTR=0
CLR P3.7 // ensures CS=0
CLR P3.6 // high to low pulse to RD for reading the data from ADC
MOV A,P1 // moves the digital data to accumulator
CPL A // complements the digital data (*see the notes)
MOV P0,A // outputs the data to P0 for the LEDs
SJMP MAIN // jumps back to the MAIN program
END

Program:

Proteus design:
RESULT:

Thus assemble language program to Interface 8051 with ADC was executed in proteus

software.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 5
Title of Experiment Interfacing 8051 with Stepper motor

Date of Experiment 27/02/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Equipments required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:
To Interface 8051 with Stepper motor.

Interfacing 8051 with Stepper Motor


AIM :
To write a assemble language program to Interface 8051 with Stepper motor
Algorithm :
Programming steps for delay function
1. Load Tmod register value i.e. TMOD = 0x01 for Timer0 mode1 (16-bit timer mode).

2. Load calculated THx value i.e. here TH0 = 0xFC.

3. Load calculated TLx value i.e. here TL0 = 0x18.

4. Start the timer by setting a TRx bit. i.e. here TR0 = 1.

5. Poll TFx flag till it does not get set.

6. Stop the timer by clearing TRx bit. i.e. here TR0 = 0.

7. Clear timer flag TFx bit i.e. here TF0 = 0.

8. Repeat from step 1 to 7 for the delay again.

Step by step connections


Step 1: If you’re using Proteus or and other simulation software or even hardware, select the
AT89C51 or AT89S51 microcontroller or any other compatible variant. (The AT89C51 is an 8-bit
microcontroller from the Atmel family which works with the 8051 architecture.)
Step 2: Connect a 12 MHz oscillator between pin 18 and 19.
Step 3: Connect two capacitors of 22pF, with one terminal on either side of the oscillator and the
other terminal to ground, as shown below.
Step 4: Set Pin 31, i.e., EA pin to HIGH by connecting it to the +5V DC source.
Step 5: Now, to make the RESET circuit, connect Pin 9 (RST) to +5V through a capacitor of 10µF
and connect the same pin to +0V (GND) through a 10kΩ resistor or a potentiometer.
Step 6: Connect the 4 pins of Port 2 to the input side of ULN2003a IC as follows,
P2.0 to 1B
P2.1 to 2B
P2.2 to 3B
P2.3 to 4B
Step 7: Connect the outputs of the ULN2003a to the 4 wires of the stepper motor as shown in the
circuit diagram below. Note: Please note that while connecting the pins 1C, 2C, 3C, and 4C to the
wires of the stepper, try all the possible connections. If the motor starts oscillating instead of
rotating, then carefully look for the 4 coil wires and 2 common wires.
Step 8: Connect the two common wires of the stepper motor and Pin 9 of the IC to a 12V DC
supply.
THEORY:
What is a stepper motor?

● A motor, in general, is a device that converts electrical energy into mechanical en-
ergy.
● As the name suggests, a stepper motor is a device that does the same task as above
but, in steps.
● It is a brushless, synchronous electric motor that can divide a complete rotation into
a number of steps. Stepper motors generally have a permanent magnet shaft (rotor),
and it is surrounded by a stator.
● The best feature of this type of motor is that the motor’s angular position can be ac-
curately controlled without any feedback mechanism, as long as the motor is not
oversized. (From a designer’s point of view the sizing of the motor is essential, if
the stepper motor is undersized then it will not be able to withstand load and if it is
oversized then it becomes too expensive for its purpose.).
● Therefore, it works in a simple accurate open-loop system, where the output is dir-
ectly dependent on the input.
● A stepper motor rotates at small angles to complete 360 degrees rotation, these
small angles are called steps, hence the name Stepper Motor. Typically, a stepper
motor consists of 200 steps.

Type of Stepper Motor


Stepper motors are broadly divided into two types

1. Unipolar stepper motor


2. Bipolar stepper motor

Unipolar stepper motor


The unipolar stepper motor has five or six wires out of which four wires are joined to one of the
ends of each of the four stator coils. The connections at the center of the coils are joined together
and are connected to the 12V supply. They are called unipolar steppers because power always
comes in on this one pole.
Bipolar stepper motor
The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers,
bipolar steppers have no common center connection. They have two independent sets of coils
instead.

Working of a stepper motor


A stepper motor works on the principle of magnetic attraction and repulsion. The coils of stators
are placed on electromagnets which are energized and de-energized by the pulses of the
microcontroller which creates magnetic north and south on the stator poles. The rotor is mounted
on a permanent magnet having a permanent N and S marked.

The sequence in which the coils are excited to form the poles causes the rotor to attract one pair of
stator pole and repel the other causing motion in the shaft and the load connected to it. The
sequence on which the coils are energized is discussed in detail in the next section of this article.
 

Interfacing stepper motor to 8051 Microcontroller

We are using Port 2 of 8051 microcontroller to generate high and low pulses and using a current
amplifier IC i.e. ULN2003a to amplify the current to drive the stepper motor using the pulse of the
microcontroller. On the basis of the way the coils are energized, a Unipolar Stepper motor can be
classified into three categories:

Wave Drive Mode

Full Drive Mode

Half Drive Mode

Wave drive mode

In this mode only one coil is energized at a time, all the four coils are energized one after the other
in a sequence. In terms of power consumption, this mode is a power saver, but the torque
produced is less compared to the full drive mode. In the following table, A-B-C-D refers to the
stator coils, that are to be energized sequentially in the manner and ‘1’s and ‘0’s refers to ‘HIGH‘
and ‘LOW’ states.

Steps A B C D HEX

1 1 0 0 0 0x08

2 0 1 0 0 0x04

3 0 0 1 0 0x02

4 0 0 0 1 0x01
ULN2003A driver:
A Stepper motor consumes a current of 0.1 – 1 A during step rotation with the load. An AT89c51
produces a maximum current of 0.045A through the ports. Therefore, the pulses sent from Port 2
are not sufficient to run a stepper motor. Hence, we cannot directly interface stepper motors with
microcontrollers like AT89C51 microcontroller.
There are two solutions to this problem:

1. To use a motor driver like L239D


2. Or, to use a current amplification IC like ULN2003A, here we choose the latter.

8051- Timer
8051 has two timers Timer0 (T0) and Timer1 (T1), both are 16-bit wide. Since 8051 has 8-bit
architecture, each of these is accessed by two separate 8-bit registers as shown in the figure below.
These registers are used to load timer count.

Timer Mode Control (TMOD): 

TMOD is an 8-bit register used for selecting timer or counter and mode of timers. Lower 4-bits are
used for control operation of timer 0 or counter0, and remaining 4-bits are used for control
operation of timer1 or counter1.This register is present in SFR register, the address for SFR
register is 89th.

Timer Control (TCON): 

TCON is an 8-bit control register and contains a timer and interrupt flags.
Programming steps for delay function

1. Load Tmod register value i.e. TMOD = 0x01 for Timer0 mode1 (16-bit timer mode).
2. Load calculated THx value i.e. here TH0 = 0xFC.
3. Load calculated TLx value i.e. here TL0 = 0x74.
4. Start the timer by setting a TRx bit. i.e. here TR0 = 1.
5. Poll TFx flag till it does not get set.
6. Stop the timer by clearing TRx bit. i.e. here TR0 = 0.
7. Clear timer flag TFx bit i.e. here TF0 = 0.
8. Repeat from step 1 to 7 for the delay again.

Delay Function to Generate 1 ms Delay

In order to generate a delay of 1ms, the calculations using above steps are as follows. 

1. NNNN = 1ms/1.085μs ≈ 922.


2. MMMM = 65536-922 = 64614
3. 64614 in Hexadecimal = FC66h
4. Load TH with 0xFC and TL with 0x66

Program - 8051 with Stepper motor

org 00H

LOOP:Mov TMOD,#01h

Mov P2,#08h

ACALL DELAY

Mov P2,#04H

ACALL DELAY

Mov P2,#02H
ACALL DELAY

Mov P2,#01H

ACALL DELAY

SJMP LOOP

DELAY:

MOV r0,#200

Back: MOV TH0,#0FCH

Mov TL0,#18H

SETB TR0

Wait:JNB TF0,wait

Clr TR0

Clr TF0

DJNZ R0,Back

Ret

end
PROGRAM:

PROTEAUS DESING:

RESULT:

Thus assemble language program to Interface 8051 with Stepper motor was simulated in Keil and

output was visualized in proteus software.


SRI KRISHNA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)

KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 06
Title of Experiment PROGRAMMABLE PERIPHERAL INTERFACE TO 8051 MICROCONTROLLER

Date of Experiment 06/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective & Software required 10
Source code 30
Compilation and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:

SOFTWARE REQUIRED:
PROGRAMMABLE PERIPHERAL INTERFACE TO 8051 MICROCONTROLLER

Aim:
To interface an LED through 8255 Programmable Peripheral Interface with 8051 through assembly language

Theory:

The number of I/O pins of Intel 8051 microcontroller is limited to 32 only. In some special design cases these many
I/O pins might not be sufficient for the system designer. For applications that require the pulses from many pins of
the 8051, it is always recommended to use 8255 PPI to avoid data loss and damage to the microcontroller.

The 8255 is a widely used, programmable, parallel I/O device. It can be programmed to transfer data under various
conditions, from simple I/O to interrupt I/O.  
Features
• Three 8‐bit IO ports PA, PB, PC  
• PA can be set for Modes 0, 1, 2. PB for 0, 1 and PC for mode 0 and for BSR. Modes 1 and 2 are interrupt driven.  
• PC has two 4‐bit ports: PC upper (PCU) and PC lower (PCL), each can be set independently for Input or Output.
Each PC bit can be set/reset individually in BSR mode.  
• PA and PCU are Group A (GA) and PB and PCL are Group B (GB)  
• Address/data bus must be externally demultiplexed.  

8255 can be operated in two modes BSR (Bit Set Reset) mode or  
i. I/O mode
ii. BSR mode Bit set/reset, applicable to PC only. One bit is S/R at a time.  

Algorithm:

1) Start the program.


2) Initialize the Timer 1.
3) Store the values in accumulator.
4) The timer is initialized and started.
5) Monitor the timer overflow and clear the contents.
6) LED is connected through the 8255 interface.
7) Stop the program.

Program:
mov dptr,#8003h
mov a,#80h
movx @dptr,a
mov dptr, #8000h
mov a, #01h
loop1: movx @dptr,a
acall delay
delay: mov tmod, #10h
loop2: mov th1,#08h
mov tl1,#0fdh
setb tr1
loop3:jnb tf1,loop3
clr tf1
clr tr1
cpl a
sjmp loop1
ret
end
Sample Output:

U1
19 39
XTAL1 P0.0/AD0
38
P0.1/AD1
37
P0.2/AD2
18 36
XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
9 32
RST P0.7/AD7 U2 8255A
21 34 4
80C51 P2.0/A8
22 33
D0 PA0
3
P2.1/A9 D1 PA1
P2.2/A10
23 32
D2 PA2
2 D1
29 24 31 1 LED-BLUE
PSEN P2.3/A11 D3 PA3
30 25 30 40
ALE P2.4/A12 D4 PA4
31 26 29 39
EA P2.5/A13 D5 PA5
27 28 38
P2.6/A14 D6 PA6
28 27 37
P2.7/A15 D7 PA7
1 10 5 18
P1.0 P3.0/RXD RD PB0
2 11 36 19
P1.1 P3.1/TXD WR PB1
3 12 9 20
P1.2 P3.2/INT0 A0 PB2
4 13 8 21
P1.3 P3.3/INT1 A1 PB3
5 14 35 22
P1.4 P3.4/T0 RESET PB4
6 15 23
P1.5 P3.5/T1 PB5
7 16 6 24
P1.6 P3.6/WR CS PB6
8 17 25
P1.7 P3.7/RD PB7
80C51 14
PC0
15
PC1
16
PC2
17
PC3
13
PC4
12
PC5
11
PC6
10
PC7

8255A

Result:
Thus the LED is connected through interfacing a 8255 PPI with 8051 and rotated through
assembly language programming.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 07
Title of Experiment INTERFACING LED USING ARM WITH KEIL C
Date of Experiment 13/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Equipments required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100
OBJECTIVE
To write an embedded C program for interfacing LED and to verify the output in the ARM
kit.
SYSTEM AND SOFTWARE TOOLS REQUIRED
● ARM Evaluation Kit
● ARM Development tools
● LED
● Keil C software

THEORY
NXP’s ARM7 (LPC2148), ARM Primer Kit is proposed to smooth the progress of developing
and debugging of various designs encompassing of High speed 32-bit Microcontrollers.

LED (LIGHT EMITTING DIODES)


Light Emitting Diodes (LED) is the most commonly used components, usually for
displaying pins digital states. Typical uses of LEDs include alarm devices, timers and
confirmation of user input such as a mouse click or keystroke.

INTERFACING LED
Fig. shows how to interface the LED to microcontroller. As you can see the Anode is
connected through a resistor to GND & the Cathode is connected to the Microcontroller pin. So
when the Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.
ALGORITHMS

Step 1: Start the program


Step 2: Enable Input and Output Ports
Step 3: Initialize timer
Step 4: Place the data for the LED in the data bus
Step 5: Call delay
Step 6: Rotate the data for the LEDs to switch on next LED
Step 7: Use infinite loops for the continuous blinking of LEDs
Step 8: Stop the program

PROGRAM:

#include <LPC21xx.H> /* LPC21xx definitions */

void wait (void) { /* wait function */


int d;

for (d = 0; d < 1000000; d++); /* only to delay for LED flashes */


}

int main (void) {


unsigned int i; /* LED var */

IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */

while (1) { /* Loop forever */


for (i = 1<<16; i < 1<<23; i <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */
IOSET1 = i; /* Turn on LED */
wait (); /* call wait function */
IOCLR1 = i; /* Turn off LED */
}
for (i = 1<<23; i > 1<<16; i >>=1 ) { /* Blink LED 7,6,5,4,3,2,1 */
IOSET1 = i; /* Turn on LED */
wait (); /* call wait function */
IOCLR1 = i; /* Turn off LED */
}}}
RESULT
Thus an embedded C program for interfacing LED is written and the output is verified in
the ARM kit
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 08
Title of Experiment DATA TRANSCEIVER IN ARM USING UART
Date of Experiment 20/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Equipments required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100
DATA TRANSCEIVER IN ARM USING UART

AIM:
To transmit and receive a single character data using UART module in ARM
SOFTWARE REQUIRED
i. ARM Evaluation kit
ii. Keil software

THEORY:
The simplest way to communicate between a computer and a microcontroller is through UART
i.e. Universal Asynchronous Receiver Transmitter. It is a type of Serial Communication Protocol
and it uses only two wires for transferring the data. UART Protocol uses only two wires (or pins
in a device like microcontroller) to transmit the data. In that, one is for transmitting the data and
the pin is called TX pin in the device. The other pin is used to receive the data and is called RX
pin.

As UART is a serial communication, the data is transmitted in a series of packets. Usually, a


packet consists of 4 parts: a start bit, the actual data, a parity bit and stop bits. The LPC214x series
of MCUs have two UART blocks called UART0 and UART1. Each UART block is associated
with two pins, one for transmission and the other for receiving. In UART0 block, the TXD0
(Transmit) and RXD0 (Receive) pins in the device are P0.0 and P0.1 respectively. In case of
UART1, the TXD1 and RXD1 pins are P0.8 and P0.9 respectively.

Both the UART modules are identical, except the UART1 block has an additional full modem
interface. This includes all the pins for RS232 compatibility like flow control pins (CTS, RTS)
etc. Both the UART blocks have 16 byte Receive and Transmit FIFO structures to hold the
transmit and receive data. In order to control the data access and assembly, the UART blocks have
two registers each. For the transmitter operation, the TX has two special registers called Transmit
Holding Register (THR) and Transmit Shift Register (TSR). In order to transmit the data, it is first
sent to THR and then moved to TSR. For the receiver operation, the RX has two special registers
called Receiver Buffer Register (RBR) and Receive Shift Register (RSR). When the data is
received, it is first stored in the RSR and then moved to RBR.

PROGRAM:
#include <lpc214x.h>
int main()
{
PINSEL0 |= 0x05;
U0LCR = 0x83; // line control
U0DLL = 97; //
U0LCR = 0x3; // not
while(1)
{
while(!(U0LSR&0x20));
U0THR='A';
}
}

RESULT:

The transmiting and receiving the single character data using UART module in ARM has

successfully completed.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)

KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 09
Title of Experiment PROGRAMMING USING ARDUNIO –
LED FADING

Date of Experiment 27/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective & Software required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:

EQUIPMENTS REQUIRED:

SOFTWARE REQUIRED
PROGRAMMING USING ARDUNIO – LED FADING

AIM:

To write a program using Ardunio and with the use of analog output (Pulse Width Modulation
(PWM)) to fade an LED.

HARDWARE REQUIRED
1) Arduino or Genuino board
2) LED
3) 220 ohm resistor
4) hook-up wires
5) breadboard

CIRCUIT
PWM is a technique for getting an analog-like behavior from a digital output by switching it off and on very
fast and with different ratio between on and off time. An LED connected to digital output pin 9 through a 220 ohm
resistor.

CODE
intledPin = 9; // LED connected to digital pin 9

void setup() {
// nothing happens in setup
}

void loop() {
// fade in from min to max in increments of 5 points:
for (intfadeValue = 0 ; fadeValue<= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:


for (intfadeValue = 255 ; fadeValue>= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
Program – Tinker CAD:

/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.

The analogWrite() function uses PWM, so if you


want to change the pin you're using, be sure to
use another PWM capable pin. On most Arduino,
the PWM pins are identified with a "~" sign,
like ~3, ~5, ~6, ~9, ~10 and ~11.
*/

int brightness = 0;

void setup()
{
pinMode(9, OUTPUT);
}

void loop()
{
for (brightness = 0; brightness <= 255; brightness += 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}
for (brightness = 255; brightness >= 0; brightness -= 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}
}
RESULT

The PROGRAMMING USING ARDUNIO – LED FADING has been successfully


executed and completed.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)

KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 10
Title of Experiment TRAFFIC LIGHT CONTROLLER USING AR-
DUNIO

Date of Experiment 27/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Software required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:

SOFTWARE REQUIRED:
TRAFFIC LIGHT CONTROLLER USING ARDUNIO

AIM
To write a program using Ardunio to control the traffic light.
APPARATUS REQUIRED:

i. Red, yellow and green LEDs.


ii. A breadboard.
iii. 6 x 220 Ohm resistors.
iv. Connecting wires.
v. 1 x pushbutton switch.
vi. 1 x 10k Ohm resistor

CIRCUIT

That was easy. Now for the difficult part -– the actual logic of a traffic light. Create a sepa-
rate function for changing the lights (you’ll see why later).

When you first begin programming, the code itself is very rudimentary – it’s figuring out the minute logic
details that presents the biggest problem. The key to being a good programmer is to be able to look at any process, and
break it down into its fundamental steps.
CODE

void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}

void loop(){
changeLights();
delay(15000);
}

voidchangeLights(){
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);

// turn off yellow, then turn red on for 5 seconds


digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);

// red and yellow on for 2 seconds (red is already on though)


digitalWrite(yellow, HIGH);
delay(2000);

// turn off red and yellow, then turn on green


digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);
}
Program – Tinker CAD:

void setup()
{

pinMode(13, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(6000);
digitalWrite(13, LOW);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
delay(3000);
digitalWrite(2, LOW);
}

RESULT:

The TRAFFIC LIGHT CONTROLLER USING ARDUNIO has been stuied and
executed successfully
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)

KUNIAMUTHUR, COIMBATORE 641008

Experiment No. 11
Title of Experiment INTERFACING GAS SENSOR WITH AR-
DUINO
Date of Experiment 27/03/2021

Evaluation by Faculty Member


Criteria Maximum Marks Marks scored by student
Objective& Software required 10
Source code 30
Compiling and Debugging 30
Result 20
Documentation 10
Total Marks 100

EXPERIMENT OBJECTIVE:

SOFTWARE REQUIRES:
INTERFACING GAS SENSOR WITH ARDUINO

AIM
To write a program to Interfacing Gas sensor with Arduino .

APPARATUS REQUIRED:

i. Arduino or Genuino Board


ii. Arduino Ethernet Shield

THEORY:

Gas sensor is one which comes handy in applications where we have to detect the variation in the concentration of
toxic gases in order to maintain the system safe and avoid/caution any unexpected threats. There are various gas
sensors to detect gases like oxygen, Carbon Dioxide, Nitrogen, methane etc. They can also be commonly found in
devices that are used to detect the leakage of the harmful gases, monitor the air quality in industries and offices etc.
A gas sensor is a device which detects the presence or concentration of gases in the atmosphere. Based on the
concentration of the gas the sensor produces a corresponding potential difference by changing the resistance of the
material inside the sensor, which can be measured as output voltage. Based on this voltage value the type and
concentration of the gas can be estimated.

SCHEMATIC:
CODE

constintgaspin=A0; //Gas sensor output pin to Arduino Analog A0 pin


void setup(){
Serial.begin(9600); //Initialize serial port-9600 bps
}
void loop(){
Serial.println(analogRead(gaspin));
delay(1000); // print value every 1 sec
}

Program -Tinker CAD:

/*
### Detector de gás ###
# Verde = Seguro #
# Amarelo = Alerta #
# Laranja = Perigo #
# Vermelho = Área Contaminada #
*/

int const PINO_SGAS = A1;


int LED_VERDE = 7;
int LED_AMARELO = 6;
int LED_VERMELHO1 = 5;
int LED_VERMELHO2 = 4;
void setup(){
pinMode(LED_VERDE, OUTPUT);
pinMode(LED_AMARELO, OUTPUT);
pinMode(LED_VERMELHO1, OUTPUT);
pinMode(LED_VERMELHO2, OUTPUT);
Serial.begin(9600);
}

void loop(){
int valor = analogRead(PINO_SGAS);
valor = map(valor, 300, 750, 0, 100);
digitalWrite(LED_VERDE, HIGH);
digitalWrite(LED_AMARELO, valor >= 30 ? HIGH : LOW);
digitalWrite(LED_VERMELHO1, valor >= 50 ? HIGH : LOW);
digitalWrite(LED_VERMELHO2, valor >= 80 ? HIGH : LOW);

delay(250);
}
RESULT:

The INTERFACING GAS SENSOR WITH ARDUINO has been studied and
executed successfully.

You might also like