0% found this document useful (0 votes)
27 views66 pages

MC Instruction Manual - 2023-24

The document is an instruction manual for a Microcontroller lab course at JSPM's Jayawantrao Sawant College of Engineering, detailing experiments and learning outcomes for students in the Electronics and Telecommunication Engineering department. It includes specific experiments such as interfacing LEDs and DACs with the 8051 microcontroller, along with objectives, procedures, and relevant software tools. The manual emphasizes practical skills in programming and interfacing various hardware components using embedded C and development environments like Microvision Keil 5.

Uploaded by

abhipawar041104
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)
27 views66 pages

MC Instruction Manual - 2023-24

The document is an instruction manual for a Microcontroller lab course at JSPM's Jayawantrao Sawant College of Engineering, detailing experiments and learning outcomes for students in the Electronics and Telecommunication Engineering department. It includes specific experiments such as interfacing LEDs and DACs with the 8051 microcontroller, along with objectives, procedures, and relevant software tools. The manual emphasizes practical skills in programming and interfacing various hardware components using embedded C and development environments like Microvision Keil 5.

Uploaded by

abhipawar041104
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/ 66

JSPM’s

Jayawantrao Sawant College Of Engineering


Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

MICROCONTROLLER

INSTRUCTION MANUAL

CLASS: TE E&TC
2019 PATTERN

Prepared by
V.P.Patil & T. A. Rajbhoj

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Experiment List
Experiment
CO
Learning Title of Experiment PO mapped
mapped
Outcomes
1. Demonstrate Parallel port interacting
of LEDS.
ELO-1: Students
2. Analyse & Demonstrate Waveform PO1, PO2,
will be able to
demonstrate Generation using DAC. PO3,PO4,PO5,
different 3. Describe & Demonstrate Interfacing CO304.2
PO8, PO9 &
interfacings of Stepper motor to 8051- software
using 8051 delay using Timer PO12
microcontroller.

1. Write & Demonstrate a program for


interfacing button, LED, relay &
buzzer.
2. Discuss & demonstrate the
ELO-2 Student Interfacing 16X2 LCD module.
CO304.4 PO1, PO2,
will be able to 3. Examine & demonstrate Generation
demonstrate of square wave using timer with CO304.5 PO3, PO4,
different
interrupt. CO304.6 PO5,PO8, PO9
interfacings
using PIC 4. Relate & demonstrate Interfacing & PO12.
Microcontroller. serial port with PC both side
communication.
5. Illustrate & demonstrate Generation
of PWM signal for DC Motor
control

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Experiment No. 1

Title: Parallel port interfacing of LEDS.

Problem Statement: Write a C program to Interface 8 bit LED Section to 8051 microcontrollers
for LED flashing.

CO 304.2: Interpret various Interfacings with 8051 microcontrollers.

ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.

OBJECTIVE:
1. To understand the PORTs of 8051 Microcontroller.
2. To interface common peripherals like LEDs.
3. To understand the use of Micro vision Keil 5.
4. To write a simple program in Embedded C.

PRE REQUSITE: 1 Principal Working of LED


2 C Programming language
3 Port structure.

S/W PACKAGES AND H/W USED:


Microvision Keil 5 & 8051 Development Board.

DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:


1. Microvision Keil 5

2. MCU 8051 IDE

3. Silicon Labs IDE

COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:


1. Microvision Keil 5

 Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.

 The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time


Kernels, Single-board Computers, and Emulators support all 8051 derivatives and

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

help you get your projects completed on schedule.

2. MCU 8051 IDE:

Integrated Development Environment for some microcontrollers based on 8051(e.g.


AT89S8253). Supported languages are Assembly and C. It has its own simulator, assembler,
editor and many other tools. See the project web site for more details and the newest
updates.

Features
 MCU Simulator

 Support for C language (with SDCC compiler)

 Macro assembler

 Advanced source code editor

 Hardware tools

 Disassembler

 Simulation of simple peripheral devices, like LED displays, etc.

3. Silicon Labs IDE:

The Silicon Labs Integrated Development Environment (IDE) is a complete, stand-alone


software program that includes a project manager, source editor, source-level debugger and
other utilities. The IDE interfaces to third party development toolchains to provide system
designers with a complete embedded software development environment. The IDE supports
the entire 8-bit microcontroller (MCU) portfolio.

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard , ISO 9001

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

THEORY:

Fig 1.1 Pin Diagram of 8051 Microcontroller

Light Emitting Diodes or LEDs are the mostly commonly used components in many
applications. These are the semiconductor light sources, commonly used LEDs will have a cut-
off voltage of 1.7V and current of 10mA. When an LED is applied with its required voltage and
current it glows with full intensity. The Light Emitting Diode is similar to the normal PN diode
but it emits energy in the form of light. The colour of light depends on the band gap of the
semiconductor.

The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins .All the ports upon RESET are
configured as input, ready to be use as input ports When the first 0 is written to a port, it
becomes an output. To reconfigure it as an input, a 1 must be sent to the port. To use any of
these ports as an input port, it must be programmed It can be used for input or output, each pin
must be connected externally to a 10K ohm pull-up resistor.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Fig 1.2 Structure of PORT 3


Procedure:
1) Open Micro Vision KEIL Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code & Create Hex file.
8) Make connections as per the interfacing diagram.
9) Open SST Easy App. Software.
10) Download the code & observe the required output on the development board.

ALGORITHM:

1. Start
2. Make port 0 as output port.
3. Send 0XFF to port 0.
4. Call delay routine.
5. Send 0X00 to port 0.
6. Call delay routine.
7. Stop

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

INTERFACING DIAGRAM:

Fig 1.3 Interfacing of LED using Microcontroller


CONCLUSION:

___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY AND APPLICATIONS.

 LEDs are widely used in many applications like in seven segments.


 They are used in dot matrix displays.
 They can be used for street lights.
 They are used as indicators.
 They can be used in traffic lights.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 They are used in emergency lights


 They can used to make electronic designs.

ORAL QUESTIONS:

1. What do you mean by LED interfacing?


2. In which port pins of LED can be interfaced?
3. What are the total number of interfacing pins in 8051?
4. Which 8051 ports has dual functions?
5. What is the function of using the resistor in series with LED port pin?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Experiment No. 2

TITLE: Interfacing DAC 0808 to 8051 microcontroller.


PROBLEM STATEMENT: Write a C program to interface DAC 0808 for generating square,
triangular & staircase waveforms.

CO 304.2: Interpret various Interfacings with 8051 microcontrollers.

ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.

OBJECTIVE:

1. To understand the DAC interfacing with 8051 Microcontroller.


2. To understand the use of Micro vision Keil 5.
4. To write a simple program in Embedded C for generating square, triangular & staircase
waveform.

PRE REQUSITE: 1 Principal Working of Digital to Analog Converter


2 C Programming language

S/W PACKAGES AND H/W USED:


Microvision Keil 5 & 8051 Development Board.

DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:


1. Microvision Keil 5

2. MCU 8051 IDE

3. Silicon Labs IDE

COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:


1. Microvision Keil 5

 Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.

 The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time


Kernels, Single-board Computers, and Emulators support all 8051 derivatives and
help you get your projects completed on schedule.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

2. MCU 8051 IDE:

Integrated Development Environment for some microcontrollers based on 8051(e.g.


AT89S8253). Supported languages are Assembly and C. It has its own simulator, assembler,
editor and many other tools. See the project web site for more details and the newest
updates.

Features
 MCU Simulator

 Support for C language (with SDCC compiler)

 Macro assembler

 Advanced source code editor

 Hardware tools

 Disassembler

 Simulation of simple peripheral devices, like LED displays, etc.

3. Silicon Labs IDE:

The Silicon Labs Integrated Development Environment (IDE) is a complete, stand-alone


software program that includes a project manager, source editor, source-level debugger and
other utilities. The IDE interfaces to third party development toolchains to provide system
designers with a complete embedded software development environment. The IDE supports
the entire 8-bit microcontroller (MCU) portfolio.

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard

THEORY:
Digital-to-analog (DAC) converter:
The digital to analog converter (DAC) is a widely used to convert digital pulses to analog
signals. There two methods of creating DAC: 1. binary weighted, 2. R/2R ladder. The vast
majority of integrated circuit DACs use the R/2R method since it can achieve a much higher
degree of precision. The first criterion judging a DAC is its resolution, which is a n function of

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

the number of binary inputs. The common ones are 8, 10 and 12 bits. The number of data bit
inputs decides the resolution of the DAC since the number of analog output levels is equal to
2n,
where n is the number of data bit inputs. Therefore, an 8-bit input DAC such as the DAC0808
provides 256 discrete voltage (or current) levels of output. Similarly, the 12-bit DAC provides
4096 discrete voltage levels.
DAC 0808
In the DAC 0808, the digital inputs are converted to current (I out), and by connecting a
register to the I out pin, we convert the result to voltage. The total current provided by the I out
pin is a function of the binary numbers at then D0 – D7 inputs of the DAC0808 and the
reference current (I out), and is as follows:

Where D0 is the LSB, D7 is the MSB for the inputs, and I ref is the input current that must be
applied to pin 14. The Iref current is generally set to 2.0 mA. Figure shows the generation of
current reference (setting Iref = 2mA) by using the standard 5-V power supply and 1K and
1.5Kohm
standard resistors. Now assuming that Iref = 2mA, if all the inputs to the DACare high, the

maximum output current is 1.99mA.

Fig 2.1 Converting I out to voltage in DAC080

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Ideally we connect the output pin Iout to a resistor, convert this current to voltage, and monitor
the output on scope. In real life, however this can cause inaccuracy since the input resistance of
the load where it is connected will also affect the output voltage. For this reason, the Iref current
output is isolated by connecting it to an op-amp such as 741 with Rf = 5K ohms for the feedback
resistor.

INTERFACING DAIGRAM:

Fig 2.2 Interfacing of DAC using Microcontroller

Procedure:
1) Open Micro Vision KEIL Software.
2) Create New Project.
3) Select the Microcontroller.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code.
7) Create Hex file.
8) Build the project & observe output on port & logic analyzer.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

FLOWCHART:

Fig 2.3 Flowchart for DAC interfacing for square wave generation
CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 DACs are commonly used in music players to convert digital data streams into analog audio
signals.
 They are also used in televisions and mobile phones to convert digital video data into analog
video signals.
 These two applications use DACs at opposite ends of the frequency/resolution trade-off.
 A modem requires DAC to convert data to analog signals, which can be carried by a telephone
wire.
 Another example of a DAC device is a video adapter.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows
the Interfacing of Stepper motor
using 8051.
https://www.youtube.com/watch?v=B3r
cigTuDv8

ORAL QUESTIONS:

1. What is the necessity of interfacing DAC with microcontroller?

2. What are the different types of DAC ?

3. What is DAC interfacing?

4. Explain the working of DAC?

5. What are the application of DAC?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 3

TITLE : Interfacing of stepper motor to 8051 microcontroller.

PROBLEM STATEMENT:

Interface Stepper motor to 8051 Microcontroller. Write a program in to rotate the motor through
clockwise & anticlockwise direction.

CO 304.2: Interpret various Interfacings with 8051 microcontrollers.

ELO-1: Students will be able to demonstrate different interfacings using 8051 microcontroller.

OBJECTIVE:

1. To understand the stepper motor interfacing with 8051 Microcontroller.


2. To write a simple program in Embedded C for generating clockwise & anticlockwise
rotation of motor.

PRE REQUSITE: 1 Principal Working of a Stepper Motor


2 C Programming language

S/W PACKAGES AND H/W USED:


Microvision Keil 5 & 8051 Development Board.

DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:


1. Microvision Keil 5

2. MCU 8051 IDE

3. Silicon Labs IDE

COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:


1. Microvision Keil 5

 Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the
student just learning about embedded software development.

 The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time


Kernels, Single-board Computers, and Emulators support all 8051 derivatives and

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

help you get your projects completed on schedule.

2. MCU 8051 IDE:

Integrated Development Environment for some microcontrollers based on 8051(e.g.


AT89S8253). Supported languages are Assembly and C. It has its own simulator, assembler,
editor and many other tools. See the project web site for more details and the newest
updates.

Features
 MCU Simulator

 Support for C language (with SDCC compiler)

 Macro assembler

 Advanced source code editor

 Hardware tools

 Disassembler

 Simulation of simple peripheral devices, like LED displays, etc.

3. Silicon Labs IDE:

The Silicon Labs Integrated Development Environment (IDE) is a complete, stand-alone


software program that includes a project manager, source editor, source-level debugger and
other utilities. The IDE interfaces to third party development toolchains to provide system
designers with a complete embedded software development environment. The IDE supports
the entire 8-bit microcontroller (MCU) portfolio.

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard ISO 13373-9

THEORY:
A stepper motor is a widely used device that translates electrical pulses into mechanical
movement. In applications such as disk drives, dot matrix printers, and robotics, the stepper
motor is used for position control. Stepper motors commonly have a permanent magnet rotor
(also called the shaft) surrounded by a stator. There are also steppers called variable reluctance

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

stepper motors that do not have a PM rotor. The most common stepper motors have four stator
windings that are paired with a center-tapped common as shown in Figure 8.2. This type of
stepper motor is commonly referred to as a four-phase or uni-polar stepper motor. The center
tap allows a change of current direction in each of two coils when a winding is grounded,

there by resulting in a polarity change of the stator.

Fig 3.1 Rotor Alignment

Fig 3.2 Stator windings configuration

While a conventional motor shaft runs freely, the stepper motor shaft moves in a fixed
repeatable increment, which allows one to move it to a precise position. This repeatable fixed
movement is possible as a result of basic magnetic theory where poles of the same polarity repel
and opposite poles attract. The direction of the rotation is dictated by the stator poles. The stator
poles are determined by the current sent through the wire coils. As the direction of the current
is changed, the polarity is also changed causing the reverse motion of the rotor. The stepper

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

motor discussed here has a total of 6 leads: 4 leads representing the four stator windings and 2
commons for the center-tapped leads. As the sequence of power is applied to each stator winding,
the rotor will rotate.There are several widely used sequences where each has a different degree of
precision. Table No. 3.1 shows a 2-phase, 4-step stepping sequence.

Table No 3.1 Normal 4-step Sequence

It must be noted that although we can start with any of the sequences in Table 8.1, once we start
we must continue in the proper order. For example, if we start with step 3 (0110), we must
continue in the sequence of steps 4, 1, 2, etc.

STEP ANGLE:
How much movement is associated with a single step? This depends on the internal
construction of the motor, in particular the number of teeth on the stator and the rotor. The step
angle is the minimum degree of rotation associated with a single step. Various motors have
different step angles. Table shows some step angles for various motors. In table 8.4, notice the
term steps per revolution. This is the total number of steps needed to rotate one complete
rotation or 360 degrees (e. g., 180 steps * 2 degrees =360).
It must be noted that perhaps contrary to one’s initial impression, a stepper motor does not
need more terminal leads for the stator to achieve smaller steps. All the stepper motors
discussed in this section have 4 leads for the stator winding and 2 COM wires for the center tap.
Although some manufacturers set aside only one lead for the common signal instead of two,
they always have 4 leads for the stators. Next we discuss some associated terminology in order
to understand the stepper motor further.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Table No 3.2 Stepper motor step angles

Formula:

Procedure:

1) Open Micro Vision KEIL Software.


2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code & Create Hex file.
8) Make connections as per the interfacing diagram.
9) Open SST Easy App. Software.
10) Download the code & observe the required output on the development board.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

ALGORITHM:

1. Start
2. Make port 0 as output port.
3. Send 0XFF to port 0.
4. Call delay routine.
5. Send 0X00 to port 0.
6. Call delay routine.
7. Stop

INTERFACING DIAGRAM:

Fig 3.3 Interfacing of stepper motor to 8051


CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 3D printing equipment.
 Textile machines.
 Printing presses.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Gaming machines.
 Medical imaging machinery.
 Small robotics.
 CNC milling machines.
 Welding equipment.

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows
the Interfacing of Stepper motor
using 8051.
https://www.electronicshub.org/stepper-
motor-control-using-8051-
microcontroller/

ORAL QUESTIONS:

1. What are the kinds of Interface available in stepper motor?

2. Which IC is used to interface stepper motor to 8051?

3. How many windings are there in a stepper motor?

4. What are the advantages of a stepper motor?

5. How can we control the speed of a stepper motor?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 4
TITLE : Interfacing Push buttons, LEDs, Relay & Buzzer to PIC Microcontroller
PROBLEM STATEMENT:
Interface Push buttons, LEDs, Relay and Buzzer to PIC Microcontroller. Write a
program in Embedded C to interact with peripherals as follows.
a. LED’s start chasing from left to right and turn ON Relay, buzzer whenever
pushbutton 1 is pressed.
b. LED’s start chasing from right to left and turn OFF Relay, buzzer whenever

pushbutton 2 is pressed.

CO 304.4: Demonstrate various interfacings using PIC microcontroller.

ELO-2 Students will be able to demonstrate different interfacings using microcontroller.


OBJECTIVE:
1. To understand the PORT Structure of PIC Microcontroller.
2. To study the SFRs to control the PORT Pins.
3. To interface common peripherals like pushbuttons, LEDs, relay.
4. To understand the use of MPLAB IDE and C18 Compiler.

5. To write a simple program in Embedded C.

PRE REQUSITE: 1 Principal Working of LED, Buzzer and switch

2 C Programming language

3 Assembly language
S/W PACKAGES AND H/W USED:

MPLAB IDE, C18 Compiler, PICKIT 2 Development Board


DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:


1 MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
 Create and edit source code using the built-in editor
 Assemble, compile and link source code.
 Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
 Make timing measurements with the simulator or emulator.
 View variables in Watch windows.
 Program firmware into devices with device programmers

2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROM

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard ISO,ISO 9001-2015


THEORY
Depending on the device selected, there are up to five general purpose I/O ports available on
PIC18F Microcontroller devices. Some pins of the I/O ports are multiplexed with an alternate
function from the peripheral features on the device. In general, when a peripheral is enabled,
that pin may not be used as a general purpose I/O pin.
Each port has three registers for its operation and figure 1.1 and figure 1.2 shows the functioning
of each registers: TRIS register (Data Direction register): To select PORT pin as input or output.
All port pins are input by default. Whenever a bit in the TRISx register is a 0, the corresponding
bit in PORTx is an output. If the bit in TRISx is a 1, the corr esponding bit in PORTx is an
input.PORT register (reads the levels on the pins of the device) LAT register (output latch): The
data latch (LAT register) is useful for read-modify write operations on the value that the I/O pins
are driving.

Fig 4.1 TRISX Register

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Generic I/O Port structure:


All the ports of PIC18 are bidirectional and identical. They all have the
following four components in their structure as shown in figure 1.3.
3. DATA LATCH
4. OUTPUT DRIVER
5. INPUT BUFFER
6. TRIS LATCH

The PIC18 Ports have both the latch and buffer. Therefore, when reading the ports there are two
possibilities:
4. Reading the input pin
5. Reading the latch

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

PORTA, TRISA and LATA Registers


• PORTA is an 8-bit wide, bidirectional port.
• The RA4 pin is multiplexed with the Timer0 module clock input to become the RA4/T0CKI
pin.
• The RA6 pin is multiplexed with the main oscillator pin; it is enabled as an oscillator or I/O
pin by the selection of the main oscillator in Configuration Register.
1. PORTA, TRISA and LATA Registers
• PORTA is an 8-bit wide, bidirectional port.
• The RA4 pin is multiplexed with the Timer0 module clock input to become the RA4/T0CKI
pin.
• The RA6 pin is multiplexed with the main oscillator pin; it is enabled as an oscillator or I/O
pin by the selection of the main oscillator in Configuration Register. Several PORTA pins are
multiplexed with analog inputs, the analog VREF+ and VREF- inputs and the comparator
voltage reference output.
• The operation of pins RA5 and RA3:RA0 as A/D converter inputs is selected by
clearing/setting the control bits in the ADCON1 register.
• On a Power-on Reset, RA5 and RA3:RA0 are configured as analog inputs and read as ‘0’. RA4
is configured as a digital input.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

3. PORTB, TRISB and LATB Registers


a. PORTB is an 8-bit wide, bidirectional port.
b. Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on all
the pull-ups. This is performed by clearing bit RBPU (INTCON2 register). The
weak pull-up is automatically turned off when the port pin is configured as an
output. The pull-ups are disabled on a Power-on Reset.
c. Four of the PORTB pins (RB7:RB4) have an interrupt on change feature. Only pins
configured as inputs can cause this interrupt to occur (i.e., any
d. RB7:RB4 pin configured as an output is excluded from the interrupt on change
comparison). The input pins (of RB7:RB4) are compared with the old value latched
on the last read of PORTB. The “mismatch” outputs of RB7:RB4 are ORed together
to generate the RB Port Change Interrupt with Flag bit RBIF (INTCON register).
e. On a Power-on Reset, RB4:RB0 are configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as digital inputs. By programming the
configuration bit, PBADEN, RB4:RB0 will alternatively be configured as digital
inputs on POR.
Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.

ALGORITHM

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Define the lrbit and rlbit
7. Define relay as RC1
8. Initialize buzzer and relay to 0
9. If not lrbit then set the buzzer and relay to 1 and shift the PORTD to left by 1, If PORTD
value is 0x00 then make the MSB bit equal to 1
10. If not rlbit then set the buzzer and relay to 0 and shift the PORTD to right by 1, If PORTD
value is 0x80 then make the LSB bit equal to 1
11. Stop
INTERFACING DIAGRAM:

Fig 4.2 Interfacing Buzzer and LED

CONCLUSION:

___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 PIC microcontroller can be used in different applications such as audio accessories,
peripherals, and video games, etc.
 Light sensing & controlling devices.

 Temperature sensing and controlling devices.

 Fire detection & safety devices.

 Industrial instrumentation devices.

 Process control devices.

 Industrial instrumentation devices.

 Process control devices.

 Home Applications (TVs, VCR, Video Games, Camcorder, Music Instruments, Home
Security Systems, Garage Door Openers, etc.)

 Communication Systems (Mobile Phones, Intercoms, Answering Machines, Paging


Devices, etc.)

 Office (Fax Machines, Printers, Copiers, Laser Printers, etc.)

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows the
Interfacing of LED BUZZER and relay
.
https://www.youtube.com/watch?v=1c
75RScEapE

ORAL QUESTIONS:
1] What is mean by common anode and common cathode connection of LED’s? Explain with
the diagram.
2] Explain the working of Relay.
3] Explain working of a Switch.
4] What is features of PIC microcontroller?
5] Differentiate between PIC and 8051.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 5
TITLE : Interfacing of LCD to Pic Microcontroller.
PROBLEM STATEMENT: Interface LCD to PIC Microcontroller. Write a program in
Assembly Language to display a message on LCD.

CO 304.4: Demonstrate various interfacings using PIC microcontroller.

ELO-2 Students will be able to demonstrate different interfacings using microcontroller.


OBJECTIVE:
1. TO Draw the complete interfacing diagram of LCD
2. Write a program to interface LCD to PIC & observe the output.

PRE REQUSITE: 1 Principal working of an LCD

2 C Programming language

3 Assembly language
S/W PACKAGES AND H/W USED:

MPLAB IDE, C18 Compiler, Explore PIC Development Board


DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
4. MPLAB IDE
5. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
 Create and edit source code using the built-in editor
 Assemble, compile and link source code.
 Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Make timing measurements with the simulator or emulator.


 View variables in Watch windows.
 Program firmware into devices with device programmer.

PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
4. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
5. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
6. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard ISO,ISO 9001-2015

THEORY:

Fig 5.1 LCD

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

In LCD 16×2, the term LCD stands for Liquid Crystal Display that uses a plane panel
display technology, used in screens of computer monitors & TVs, smartphones, tablets, mobile
devices, etc. Both the displays like LCD & CRTs look the same but their operation is different.
Instead of electrons diffraction at a glass display, a liquid crystal display has a backlight that
provides light to each pixel that is arranged in a rectangular network. Every pixel includes a
blue, red, green sub-pixel that can be switched ON/OFF. Once all these pixels are deactivated,
then it will appear black and when all the sub-pixels are activated then it will appear white. By
changing the levels of each light, different color combinations are achievable. This article
discusses an overview of LCD 16X2 & its working with applications.

What is LCD 16X2?

An electronic device that is used to display data and the message is known as LCD 16×2. As the
name suggests, it includes 16 Columns & 2 Rows so it can display 32 characters (16×2=32) in
total & every character will be made with 5×8 (40) Pixel Dots. So the total pixels within this LCD
can be calculated as 32 x 40 otherwise 1280 pixels.

Specifications of LCD 16X2

The specifications of LCD 16X2 are discussed below.

 The operating voltage of this display ranges from 4.7V to 5.3V


 The display bezel is 72 x 25mm
 The operating current is 1mA without a backlight
 PCB size of the module is 80L x 36W x 10H mm
 HD47780 controller
 LED color for backlight is green or blue
 Number of columns – 16
 Number of rows – 2
 Number of LCD pins – 16
 Characters – 32
 It works in 4-bit and 8-bit modes

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Pixel box of each character is 5×8 pixel


 Font size of character is 0.125Width x 0.200height

Working Principle

The basic working principle of LCD is passing the light from layer to layer through modules.
These modules will vibrate & line up their position on 90o that permits the polarized sheet to
allow the light to pass through it. These molecules are accountable for viewing the data on every
pixel. Every pixel utilizes the method of absorbing light to illustrate the digit. To display the
value, the position of molecules must be changed to the angle of light. So this light deflection
will make the human eye notice the data that will be the ingredient wherever the light gets
absorbed. Here, this data will supply to the molecules & will be there till they get changed At
present, LCDs are used frequently in CD/DVD players, digital watches, computers, etc. In
screen industries, LCDs have replaced the CRTs (Cathode Ray Tubes) because these displays
use more power as compared to LCD, heavier & larger.

The displays of LCDs are thinner as compared to CRTs. As compared to LED screens, LCD has
less power consumption because it functions on the fundamental principle of blocking light
instead of dissipating.

Registers of LCD

The registers used in LCD are two types like data register & command register. The register can
be changed by using the RS pinout. If we set ‘0’ then it is command register and if it is ‘1’ then
it is data register.

Command Register

The main function of the command register is to save instructions illustrated on LCD. That
assists in data clearing & changes the cursor location & controls the display.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Data Register

The data register is used to save the date to exhibit on the LCD. Once we transmit data to LCD,
then it shifts to the data register to process the data. If we fix the register value at one that the
data register will start working.

Pin configuration of LCD:

Fig 5.2 LCD PIN configuration

 Pin1 (Ground): This pin connects the ground terminal.


 Pin2 (+5 Volt): This pin provides a +5V supply to the LCD
 Pin3 (VE): This pin selects the contrast of the LCD.
 Pin4 (Register Select): This pin is used to connect a data pin of an MCU & gets either 1 or
0. Here, data mode = 0 and command mode =1.
 Pin5 (Read & Write): This pin is used to read/write data.
 Pin6 (Enable): This enables the pin must be high to perform the Read/Write procedure.
This pin is connected to the data pin of the microcontroller to be held high constantly.
 Pin7 (Data Pin): The data pins are from 0-7 which are connected through the
microcontroller for data transmission. The LCD module can also work on the 4-bit mode
through working on pins 1, 2, 3 & other pins are free.
 Pin8 – Data Pin 1

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Pin9 – Data Pin 2


 Pin10 – Data Pin 3
 Pin11 – Data Pin 4
 Pin12 – Data Pin 5
 Pin13 – Data Pin 6
 Pin14 – Data Pin 7
 Pin15 (LED Positive): This is a +Ve terminal of the backlight LED of the display & it is
connected to +5V to activate the LED backlight.
 Pin16 (LED Negative): This is a -Ve terminal of a backlight LED of the display & it is
connected to the GND terminal to activate the LED backlight.

Procedure:
1. Open MPLAB IDE Software.
2. Create New Project by selecting the suitable device.
3. Write code in Editor Window and save file.
4. Add the file to target.
5. Compile the code .
6. Make connections as per the interfacing diagram.
7. Download the code & observe the required output on the development board.

Program:

INTERFACING DIAGRAM:

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Fig 5.3 Interfacing of LCD with PIC microcontroller

CONCLUSION:

___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 The LCDs are commonly used in all the digital wrist watches for displaying time.

 The LCD (liquid crystal display) is used in aircraft cockpit displays.

 It is used for displaying images used in digital cameras.

 It is used in instruments panel where all the lab instruments uses LCD screens for display.

 It is used as a display screen in calculators.

 The television is main applications of LCD.

 Mostly the computer monitor is made up of LCDs.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 The LCDs are used in mobile screens.

 It is also used in video players.

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows
the Interfacing of LCD using PIC.

https://www.youtube.com/watch?v=u2V
PLtELzZ4

ORAL QUESTIONS:

1. How many Data Pins are there in LCD?

2. How an LCD is controlled?

3. What material is used in LCD?

4. What is the role of RS pin and Enable pin in LCD?

5. What are the applications of LCD.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 6
TITLE : Generation of Square wave using timer with interrupt.
PROBLEM STATEMENT:
Write a program to generate a square wave of 10 Hz on the port pin RB0 (pin no. 33). Use

Timer 0 interrupt for ON period and OFF period delay.

CO 304.4: Demonstrate various interfacings using PIC microcontroller.

ELO-2 Students will be able to demonstrate different interfacings using microcontroller.


OBJECTIVE :
a. To understand the basic concepts of Timer and Counter
b. To study in detail Timer0 of PIC Microcontroller
c. To Study interrupt structure of PIC Microcontroller

d. To use timer interrupt and its related SFR.

PRE REQUSITE: 1 Principal Working of LED, Buzzer

2 C Programming language

3 Assembly language
S/W PACKAGES AND H/W USED:

MPLAB IDE, C18 Compiler, Explore PIC Development Board


DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
1 MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
 Create and edit source code using the built-in editor

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Assemble, compile and link source code.


 Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
 Make timing measurements with the simulator or emulator.
 View variables in Watch windows.
 Program firmware into devices with device programmers

2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
7. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
8. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
9. Supports most common programmers, ICD2 debugger and several types of bootloaders.

It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.

ISO STANDARD : ISO/IEC 10861 , 1118.1-1990 - IEEE Standard ISO,ISO 9001-2015

THEORY

1. Timer
The microcontroller oscillator uses quartz crystal for its operation. Even though it is not the
simplest solution, there are many reasons to use it. The frequency of such oscillator is precisely
defined and very stable, so that pulses it generates are always of the same width, which makes
them ideal for time measurement. Such oscillators are also used in quartz watches.
1.1 How does the timer operate?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

In practice, pulses generated by the quartz oscillator are once per each machine cycle, directly
or via a prescaler, brought to the circuit which increments the number stored in the timer
register. If one instruction (one machine cycle) lasts for four quartz oscillator periods then this
number will be incremented a million times per second (each microsecond) by embedding
quartz with the frequency of 4MHz. It is easy to measure short time intervals, up to 256
microseconds, in the way described above because it is the largest number that one register can
store. This restriction may be easily overcome in several ways such as by using a slower
oscillator, registers with more bits, prescaler or interrupts. The first two solutions have some
weaknesses so it is more recommended to use prescaler or interrupt.

1.2 Using a prescaler in timer operation


A prescaler is an electronic device used to reduce frequency by a predetermined factor. In
order to generate one pulse on its output, it is necessary to bring 1, 2 , 4 or more pulses on its
input. Most microcontrollers have one or more prescaler built in and their division rate may be
changed from within the program. The prescaler is used when it is necessary to measure longer
periods of time. If one prescaler is shared by timer and watchdog timer, it cannot be used by
both of them simultaneously.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

1.3 Using interrupt in timer operation


If the timer register consists of 8 bits, the largest number it can store is 255. As for 16-bit
registers it is the number 65535. If this number is exceeded, the timer will be automatically reset
and counting will start at zero again. This condition is called an overflow. If enabled from within
the program, the overflow can cause an interrupt, which gives completely new possibilities. For
example, the state of registers used for counting seconds, minutes or days can be changed in an
interrupt routine. The whole process (except for interrupt routine) is automatically performed
behind the scenes, which enables the main circuits of the microcontroller to operate normally.
This figure 1.3 illustrates the use of an interrupt in timer operation. Delays of arbitrary duration,
having almost no influence on the main program execution, can be easily obtained by assigning
the prescaler to the timer.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

2. Counters
If the timer receives pulses from the microcontroller input pin, then it turns into a counter.
Obviously, it is the same electronic circuit able to operate in two different modes. The only
difference is that in this case pulses to be counted come over the microcontroller input pin and
their duration (width) is mostly undefined. This is why they cannot be used for time
measurement, but for other purposes such as counting products on an assembly line, number

of axis rotation, passengers etc. (depending on sensor in use).


3. Timers / Counters in PIC Microcontroller
There are 3 - 5 timers on board in PIC microcontroller. These timers can also be used as counters
when external pulses are applied. The timers are programmable, and sometimes share with
other peripheral devices. These are named as TMR0, TMR1, TMR2, TMR3 and TMR4. There are
few other timers, not to be discussed here like Watchdog Timer and Brown-
Out timers. These timers are useful in measuring the time delays in various events as well as
counting and timing external events.

4. Timer0 Module in PIC Microcontroller


The Timer0 module incorporates the following features:

a. Software selectable operation as a timer or counter in both 8-bit or 16-bit modes


b. Readable and writable registers
c. Dedicated 8-bit, software programmable prescaler
d. Selectable clock source (internal or external)
e. Edge select for external clock

f. Interrupt on overflow

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

The T0CON register (Register 11-1) controls all aspects of the module’s operation, including the
prescale selection. It is both readable and writable. A simplified block diagram of the Timer0
module in 8-bit mode is shown in Figure 1.1. Figure 1.2 shows a simplified block diagram of the
Timer0 module in 16-bit mode.

4.1 Timer0 Operation


Timer0 can operate as either a timer or a counter; the mode is selected by clearing the T0CS bit
(T0CON<5>). In Timer mode, the module increments on every clock by default unless a
different prescaler value is selected. If the TMR0 register is written to, the increment is inhibited
for the following two instruction cycles. The user can work around this by writing an adjusted
value to the TMR0 register.
The Counter mode is selected by setting the T0CS bit (= 1). In Counter mode, Timer0 increments
either on every rising or falling edge of pin RA4/T0CKI. The incrementing edge is
determined by the Timer0 Source Edge Select bit, T0SE (T0CON<4>); clearing this bit selects
the rising edge. An external clock source can be used to drive Timer0; however, it must meet

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

certain requirements to ensure that the external clock can be synchronized with the internal
phase clock (TOSC). There is a delay between synchronization and the onset of incrementing

the timer/counter.
4.2 Prescaler
An 8-bit counter is available as a prescaler for the Timer0 module. The prescaler is not directly
readable or writable; its value is set by the PSA and T0PS2:T0PS0 bits (T0CON<3:0>) which
determine the prescaler assignment and prescale ratio. Clearing the PSA bit assigns the
prescaler to the Timer0 module. When it is assigned, prescale values from 1:2 through 1:256,
in power-of-2 increments are selectable. When assigned to the Timer0 module, all instructions
writing to the TMR0 register clear the prescaler count
4.3 Timer0 Interrupt
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h in 8-bit
mode, or from FFFFh to 0000h in 16-bit mode. This overflow sets the TMR0IF flag bit.
The interrupt can be masked by clearing the TMR0IE bit (INTCON<5>). Before reenabling the
interrupt, the TMR0IF bit must be cleared in software by the Interrupt Service Routine. Since
Timer0 is shut down in Sleep mode, the TMR0 interrupt cannot awaken the processor from
Sleep.

4.4 Timer0 Register Map:

4.4. Register (SFR) Description


1.1.4 TMR0L : Used 8-bit and 16bit mode. The register holds the current count value which
is updated by clock source. User must write initial value.
1.1.5 TMR0H : Used only in 16-bit mode. The register holds the higher byte current count

value which is updated by clock source.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

T0CON: Timer0 Control Register

Bit

NOTE: All bits are applicable to this exercise


INTCON: Interrupt Control Register

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Calculations:

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.

Algorithm:
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Define the timer isr function
7. Configure the RB0 as output
8. Set the Initial value for RB0
9. Clear Timer0 overflow flag
10. Start the Timer0
11. Continue Program execution until the timer overflow interrupt is generated
12. load timer value to generate delay 50ms
13. Stop

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Interfacing Diagram

Fig 6.1 Generation of square wave using Timer


Conclusion:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 Square-wave Waveforms are used extensively in electronic and micro electronic circuits
for
 clock and timing control signals as they are symmetrical waveforms of equal and square
duration representing each half of a cycle and nearly all digital logic circuits use square
wave waveforms on their input and output gates.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 DACs are commonly used in music players to convert digital data streams into analog
audio signals.
 They are also used in televisions and mobile phones to convert digital video data into
analog video signals

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows
the generation of square wave using
timer interrupt.

https://www.youtube.com/watch?v=6IhI
WbMGMIU

ORAL QUESTIONS:

1. How many interrupts are present in PIC microcontroller?

2. Which PORT in PIC will support for external interrupt?

3. What is the execution speed of instructions in PIC specially while operating at maximum
value of clock rate?

4. What are the standard waveforms that can be generated using the DAC component?

5. How does a DAC work in a microcontroller?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 7
TITLE : Serial Communication between PC and PIC Microcontroller.
PROBLEM STATEMENT:
Write a program in Embedded C to transfer the message and receive serially at
9600 baud, 8 bit data, 1 stop bit.
OBJECTIVE :
a. To study the RS232 standard for serial communication
b. To Study the on-chip USART of PIC Microcontroller
c. To calculate the desired baud rate.
d. To interface MAX232 with PIC Microcontroller for serial communication.
S/W PACKAGES AND H/W USED:
MPLAB IDE, C18 Compiler, Explore PIC Development Board
DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
 Create and edit source code using the built-in editor
 Assemble, compile and link source code.
 Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
 Make timing measurements with the simulator or emulator.
 View variables in Watch windows.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 Program firmware into devices with device programmers

PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.

THEORY

1. Serial Communication:
The microcontroller is parallel device that transfers eight bits of data simultaneously over eight
data lines to parallel I/O devices. However, in many situations, parallel data transfer is
impractical. For example, parallel data transfer over a long is very expensive. Hence, a serial
communication is widely used in long distance communication. In serial data communication,
8-bit data is converted to serial bits using a parallel in serial out shift register and then it is
transmitted over a single data line. The data byte is always transmitted with least significant bit
first.Serial ports are a type of computer interface for serial communication that complies with
the RS-232 standard. They are 9-pin connectors that relay information, incoming or outgoing,
one byte at a time. Each byte is broken up into a series of eight bits, hence the term serial port.
Serial ports are controlled by a special chip call a UART
(Universal Asynchronous Receiver Transmitter).

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

1.1 Communication links:


Serial communication is classified into three types of communication.
1. Simplex communication link: In simplex transmission, the line is dedicated for transmission.
The transmitter sends and the receiver receives the data.
2. Half duplex communication link: In half duplex, the communication link can be used for
either transmission or reception. Data is transmitted in only one direction at a time.Full duplex
communication link: If the data is transmitted in both ways at the same time, it is a full duplex
i.e. transmission and reception can proceed simultaneously. This communication link requires
two wires for data, one for transmission and one for reception
1.2 Types of Serial communication:
Serial data communication uses two types of communication:-
Synchronous serial data communication: In this transmitter and receiver are synchronized. It
uses a common clack to synchronize the receiver and the transmitter. First the synch character
is sent and then the data is transmitted. This format is generally used for high speed
transmission. In Synchronous serial data communication a block of data is transmitted at a time.
Asynchronous Serial data transmission: In this, different clock sources are used for transmitter
and receiver. In this mode, data is transmitted with start and stop bits. A transmission begins
with start bit, followed by data and then stop bit. For error checking purpose parity bit is
included just prior to stop bit. In Asynchronous serial data communication a single byte is
transmitted at a time.
1.3 Baud rate:
The rate at which the bits are transmitted is called baud or transfer rate. The baud rate is the
reciprocal of the time to send one bit. In asynchronous transmission, baud rate is not equal to
number of bits per second. This is because; each byte is preceded by a start bit and followed by
parity and stop bit. For example, in synchronous transmission, if data is transmitted with 9600
baud, it means that 9600 bits are transmitted in one second. For bit transmission time = 1
second/ 9600 = 0.104 ms.
2. RS-232 standards:
To allow compatibility among data communication equipment made by various
manufactures, an interfacing standard called Rs232 was set by the Electronics

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Industries Association (EIA) in 1960. In 1963 it was modified and called RS232A.
RS232B and RS232C were issued in 1965 and 1969, respectively. Today Rs232is the
most widely used serial I/O interfacing standard. This standard is used in PCs and
numerous equipments. However, since the standard was set long before the advent of
logic family, its input and output voltage levels are not TTL compatible. In RS232, a logic
one (1) is represented by -3 to -25V and referred as MARK while logic zero (0) is
represented by +3 to +25V and referred as SPACE. For this reason to connect any RS232
to a microcontroller system we must use voltage converters such as MAX232 to convert
the TTL logic level to RS232 voltage levels and vice-versa. MAX232 IC chips are
commonly referred as line drivers.
3.3.1 Transmit Status & Control Register

3.3.2 Receive Status & Control Register

3.3.3 Baud rate control register

Baud Rate Generator (BRG)


The BRG is a dedicated 8-bit, or 16-bit, generator that supports both the Asynchronous and
Synchronous modes of the EUSART. By default, the BRG operates in 8-bit mode. Setting the
BRG16 bit (BAUDCON<3>) selects 16-bit mode. The SPBRGH:SPBRG register pair controls the
period of a free-running timer. In Asynchronous mode, bits BRGH (TXSTA<2>) and BRG16
(BAUDCON<3>) also control the baud rate. In Synchronous mode, BRGH is ignored. Given the
desired baud rate and FOSC, the nearest integer value for the SPBRGH:SPBRG registers can be
calculated using the formulas in Table 1.1. From this, the error in baud rate can be determined.
It may be advantageous to use the high baud rate (BRGH = 1), or the 16-bit BRG to reduce the
baud rate error, or achieve a slow baud rate for a fast oscillator frequency.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Writing a new value to the SPBRGH:SPBRG registers causes the BRG timer to be reset (or
cleared). This ensures the BRG does not wait for a timer overflow before outputting the new
baud rate.
CALCULATIONS
For Fosc = 20MHz, Baud rate = 9600
SPBRGH:SPBRG = [Fosc/4(Baud rate)]-1
= [20x106/(4x9600)] – 1
= [519]10 = [0207]16
% Error = (Calculated baud rate - Desired Baud Rate)/Desired Baud Rate
= (Fosc / [4(SPBRGH:SPBRG+1)] – 9600)/Desired Baud Rate
= ([20x106/[4x(520+1)]] – 9600)/Desired Baud Rate
= (9615 – 9600)/9600
% Error = 0.16 %
Therefore to reduce error we have selected SPBRGH = 0x02 and SPBRG = 0x08
Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.
Algorithm:
Transmission
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Configure RXD line as input

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

7. Configure TXD line as output


8. Wait till transmit buffer is not empty
9. Transmit the data after that
10. Stop
Reception
1. Start
2. Select the Oscillator to HS
3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Configure RXD line as input
7. Configure TXD line as output
8. Wait util data from PC is received
9. Read the received data after that
10. Stop
Interfacing Diagram :

Fig 7.1 Interfacing PIC with UART

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 Serial communication (also called RS232 communication) enables a microcontroller to
be connected to another microcontroller or to a PC using a serial cable.
 Some microcontrollers have built-in hardware called universal synchronous–
asynchronous receiver–Transmitter (UART) to implement a serial communication
interface.

Its pleasure to bring to your attention Please Scan the QR-Code.


on the following link which shows the
Serial communication using PIC
MICROCONTROLLER
https://www.youtube.com/watch?v=QW
EMqz6Ph7k

ORAL QUESTIONS:

1. Why baud rate is used in serial communication?

2. What are the types of serial communication?

3. Which mode of serial communication is fastest?

4. What is the formula for Baud Rate?

5. What is Synchronous and Asynchronous serial communication

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

EXPERIMENT NO 8
TITLE: Generation of PWM Signal for DC motor control.
PROBLEM STATEMENT:
Interface DC Motor to PIC microcontroller. Write a program in Embedded C to
control the speed of DC motor using on-chip PWM Module of PIC Microcontroller.
OBJECTIVE :
a. To understand the working of PWM.
b. To study the on-chip CCP Module (PWM section) of PIC
Microcontroller.
c. To interface DC motor, via Driver IC L293D, to PIC Microcontroller
d. Apply the PWM signal to control the speed of DC Motor.
S/W PACKAGES AND H/W USED:
MPLAB IDE, C18 Compiler, Explore PIC Development Board, DC Motor, CRO
DIFFERENT SOFTWARE TOOLS AVAILABLE IN USE CURRENTLY:
1. MPLAB IDE
2. PickLAB
COMPARE AND CONTRAST EXISTING SOFTWARE OR HARDWARE TOOLS:
1 MPLAB IDE
MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of
free software components for fast application development and super-charged debugging.
MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip
and third party software and hardware development tools. Moving between tools is a snap, and
upgrading from the free software simulator to hardware debug and programming tools is done
in a flash because MPLAB IDE has the same user interface for all tools.
Features:
 Create and edit source code using the built-in editor
 Assemble, compile and link source code.
 Debug the executable logic by watching program flow with the built-in simulator or in
real time with in-circuit emulators or in-circuit debuggers.
 Make timing measurements with the simulator or emulator.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

 View variables in Watch windows.


 Program firmware into devices with device programmer

2 PickLAB IDE:
Piklab is an open source integrated development environment (IDE) for applications devised
on Microchip PIC and digital signal processor IC (dsPIC) microcontroller (MCU) that can be
compiled only with Qt on Linux and Windows. Qt, being a cross platform framework, allows
Piklab to develop non-graphical user interface (non-GUI) programs. Based on general public
licence version 2 (GNU GPL v2), Piklab is a complete development environment, providing
access to different toolchains.
Features:
1. Provides tools for the complete development process that includes editing and
compilation of the source, programming the device and debugging.
2. Integrates with several types of compilers, assembler toolchains and gpsim simulators.
3. Supports most common programmers, ICD2 debugger and several types of bootloaders.
It also supports some direct programmers for most of the devices with PIC18F MCUs
and PIC24C EEPROMs.

THEORY:
1. PWM Technique:
Depending upon the device selected there are 1 – 4 CCP (Capture/Compare/PWM) modules
in PIC microcontroller. Each module contains a 16- bit register, which can operate as a 16-bit
Capture register, a 16-bit Compare register or a PWM Master/Slave Duty Cycle register.
Each Capture/Compare/PWM module is associated with a control register (generically,
CCPxCON) and a data register (CCPRx). The data register, in turn, is comprised of two 8-bit
registers: CCPRxL (low byte) and CCPRxH (high byte). All registers are both readable and
writable.The CCP modules utilize Timers 1, 2 or 3, depending on the mode selected.Timer1 and
Timer3 are available to modules in Capture or Compare modes, while Timer2 is available for
modules in PWM mode.The pin assignment for CCP2 (Capture input, Compare and PWM
output) can change, based on device configuration. The CCP2MX Configuration bit determines
which pin CCP2 is multiplexed to. By default, it is assigned to RC1 (CCP2MX = 1). If the

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Configuration bit is cleared, CCP2 is multiplexed with RB3. Changing the pin assignment of
CCP2 does not automatically change any requirements for configuring the port pin. Users must
always verify that the appropriate TRIS register is configured correctly for
CCP2 operation, regardless of where it is located.
Capture Mode Applications
Event arrival time recording
Period measurement
Pulse-width measurement
Interrupt generation
Event counting
Time reference
Duty cycle measurement
PWM Mode of CCP Module
In Pulse-Width Modulation (PWM) mode, the CCPx pin produces up to a 10-bit resolution
PWM output. Since the CCP2 pin is multiplexed with a PORTB or PORTC data latch, the
appropriate TRIS bit must be cleared to make the CCP2 pin an output. A PWM output has a
time base (period) and a time that the output stays high (duty cycle). The frequency of the PWM
is the inverse of the period (1/period). The simplified block diagram of the CCP1 configured to
generate PWM is shown in Figure 9.1, with example waveforms in Figure 9. 2. The block
diagram for CCP2 is similar to CCP1. It can be seen that Figure 9.1 contains CCPR1L, Timer 2,
comparator and the PR2 register working together. Although not shown, Timer 2 is still driven
from the on-chip oscillator, through its own prescaler. The comparator output drives an R–S
flip-flop. When the value in PR2 equals Timer 2, then the comparator clears the timer and sets
the flip-flop, whose output goes high. This is seen in Figure 9.2. This action sets the PWM
period.

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Figure 8.1 : PWM Block Diagram

PWM Mode Register Description


Standard CPPx Control Register (CCPxCON – CCP1CON/CCP2CON)

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Timer 2 Control Register

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

Timer 2 Module
The Timer2 module timer incorporates the following features:
• 8-bit timer and period registers (TMR2 and PR2, respectively)
• Readable and writable (both registers)
• Software programmable prescaler (1:1, 1:4 and 1:16)
• Software programmable Postscaler (1:1 through 1:16)
• Interrupt on TMR2 to PR2 match
• Optional use as the shift clock for the MSSP module
The module is controlled through the T2CON register which enables or disables the timer and
configures the prescaler and Postscaler. Timer2 can be shut off by clearing control bit, TMR2ON
(T2CON<2>), to minimize power consumption. A simplified block diagram of the module is
shown in Figure.

Figure 8.2 : Simplified Block Diagram of Timer2 Module

Timer2 Operation
In normal operation, TMR2 is incremented from 00h on each clock (FOSC/4). A 2-bit
counter/prescaler on the clock input gives direct input, divide-by-4 and divide-by-16 prescale
options. These are selected by the prescaler control bits, T2CKPS1:T2CKPS0 (T2CON<1:0>). The
value of TMR2 is compared to that of the period register, PR2, on each clock cycle. When the
two values match, the comparator generates a match signal as the timer output. This signal also
resets the value of TMR2 to 00h on the next cycle and drives the output counter/ Postscaler.
The TMR2 and PR2 registers are both directly readable and writable. The TMR2

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

register is cleared on any device Reset, while the PR2 register initializes at FFh. TMR2 is not
cleared when T2CON is written. Both the prescaler and postscaler counters are cleared on the
following events:
1 a write to the TMR2 register
2 a write to the T2CON register
3 any device Reset (Power-on Reset, MCLR Reset, WDT Reset or Brown-out)
Timer2 Interrupt
Timer2 also can generate an optional device interrupt. The Timer2 output signal (TMR2 to PR2
match) provides the input for the 4-bit output counter/postscaler. This counter generates the
TMR2 match interrupt flag which is latched in TMR2IF (PIR1<1>). The interrupt is enabled by
setting the TMR2 Match Interrupt Enable bit,TMR2IE (PIE1<1>). A range of 16 postscale options
(from 1:1 through 1:16 inclusive) can be selected with the postscaler control bits,
T2OUTPS3:T2OUTPS0 (T2CON<6:3>)
Calculation
Desired PWM Frequency = 4 KHz

Quadruple half H Drivers (L293D)


The L293D is quadruple high-current half-H drivers. The L293D is designed to provide
bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V. The device is
designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping motors, as
well as other high-current/high-voltage loads in positive supply applications. All inputs are
TTL compatible. Each output is a complete totem-pole drive circuit, with a Darlington transistor
sink and a pseudo-Darlington source Drivers are enabled in pairs, with drivers 1 and 2 enabled

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

by 1,2EN and drivers 3 and 4 enabled by 3,4EN as shown in pin diagram and function table.
When an enable input is high, the associated drivers are enabled, and their outputs are active
and in phase with their inputs. When the enable input is low, those drivers are disabled, and
their outputs are off and in the high-impedance state. With the proper data inputs, each pair of
drivers forms a full-H (or bridge) reversible drive suitable for solenoid or motor applications.

Figure 8.3 L293 D Driver IC


Procedure:
1) Open MPLAB IDE Software.
2) Create New Project by selecting the suitable device.
4) Write code in Editor Window and save file.
5) Add the file to target.
6) Compile the code .
8) Make connections as per the interfacing diagram.
9) Download the code & observe the required output on the development board.
ALGORITHM:
1. Start

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

2. Select the Oscillator to HS


3. Disable Watchdog timer
4. Disable Low Voltage Programming
5. Disable PORTB Analog inputs
6. Set PORTC, RC2 as output (CCP1)
7. Set PWM Frequency 2KHz
8. Configure CCP1CON as PWM mode.
9. Start timer 2 with prescaler 1:16
10. Turn ON the Motor
11. Set Duty Cycle 80% and OSCILLATOR FREQUENCY 20MHz.
12. Stop

Interfacing diagram

Figure 8.4 Interfacing of PIC with DC motor

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB


JSPM’s
Jayawantrao Sawant College Of Engineering
Sr. No. 58, Handewadi Road, Hadapsar, Pune, Maharashtra 411028
Department of Electronics and Telecommunication Engineering

CONCLUSION:
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

RELEVANCE TO THE INDUSTRY and APPLICATIONS:


 Cranes.
 Air compressor.
 Lifts.
 Elevators.
 Winching system.
 Electric traction.
 Hair drier.
 Vacuum cleaner and in speed regulation application.

Its pleasure to bring to your attention on Please Scan the QR-Code.


the following link which shows the
Interfacing of DC motor using PIC.
https://www.youtube.com/watch?v=Ck8cCj
DXNQA

ORAL QUESTIONS:
a. What are the types of DC motor?
b. Explain the principal of operation of DC motor?
c. Which DC motor is preferred for constant speed?
d. What is PWM DC control?
e. Why PWM is used to control motors?

TE [Electronics and Telecommunication] Subject: MICROCONTROLLERs LAB

You might also like