0% found this document useful (0 votes)
305 views33 pages

Unit 5 - A CASE STUDY - Using Pic Microcontroller

This document provides information on interfacing various components with a microcontroller including an LCD display, keyboard, stepper motor, AC appliances using a relay, and measuring external frequencies. It includes pin diagrams, programming examples, and explanations of how each component works and can be controlled using a microcontroller. The document contains detailed information on initializing and sending commands and data to a 16x2 LCD, scanning a keyboard matrix to detect key presses, continuously rotating a stepper motor in clockwise and counterclockwise directions, using a relay to switch high voltage loads on and off, and utilizing timers to measure external frequencies.

Uploaded by

Poonthalir
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)
305 views33 pages

Unit 5 - A CASE STUDY - Using Pic Microcontroller

This document provides information on interfacing various components with a microcontroller including an LCD display, keyboard, stepper motor, AC appliances using a relay, and measuring external frequencies. It includes pin diagrams, programming examples, and explanations of how each component works and can be controlled using a microcontroller. The document contains detailed information on initializing and sending commands and data to a 16x2 LCD, scanning a keyboard matrix to detect key presses, continuously rotating a stepper motor in clockwise and counterclockwise directions, using a relay to switch high voltage loads on and off, and utilizing timers to measure external frequencies.

Uploaded by

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

UNIT V

SYSTEM DESIGN – A CASE STUDY

1
LCD Interfacing
• A microcontroller is an inexpensive computer.
Its ability to store and run unique programs
makes it extremely versatile.
• LCD display is an inevitable part in almost all
embedded projects.
• 16×2 LCD module is a very common type of
LCD module that is used also in PIC based
embedded projects. It consists of 16 rows and
2 columns of 5×7 or 5×8 LCD dot matrices.

2
Pin diagram of LCD

3
Pin No: Name Function
1 VSS This pin must be connected to
the ground
2 VCC Positive supply voltage pin (5V
DC)
3 VEE Contrast adjustment
4 RS Register selection
5 R/W Read or write
6 E Enable
7 DB0 Data
8 DB1 Data
9 DB2 Data
10 DB3 Data
11 DB4 Data
12 DB5 Data
13 DB6 Data
14 DB7 Data
15 LED+ Back light LED+
16 LED- Back light LED- 4
Programming PIC for Interfacing 16X2 LCD:
• Interfacing LCD to PIC is not different from
interfacing to 8051.
• Only the pins, registers and architecture using for
interfacing will be different. When we look at the
program, functions like initialization, sending
data to the LCD will be almost same.
• In the PIC programming also for initializing the
LCD, the R/W pin should be low for writing the
data, Enable pins should be high and register
select pin (RS) should be high for writing the
data. For sending a command the RS should be
low, R/W pin should be low and enable pin should
be high.
5
Commands: There are some preset commands which will do a specific task in the LCD.
These commands are very important for displaying data in LCD. The list of commands given below:

COMMAND FUNCTION

0F For switching on LCD, blinking the cursor.

1 Clearing the screen

2 Return home.

4 Decrement cursor

6 Increment cursor

E Display on and also cursor on

80 Force cursor to beginning of the first line

C0 Force cursor to beginning of second line

38 Use two lines and 5x7 matrix

83 Cursor line 1 position 3

3C Activate second line

0C3 Jump to second line position 3

0C1 Jump to second line position1


6
• Initializing the LCD:
• lcdcmd(0x38);//Configure the LCD in 8-bit mode,2 line and 5×7
font
lcdcmd(0x0C);// Display On and Cursor Off
lcdcmd(0x01);// Clear display screen
lcdcmd(0x06);// Increment cursor
lcdcmd(0x80);// Set cursor position to 1st line,1st column
• Sending command to the LCD:
• rs=0; Register select pin is low.
• rw=0; Read/write Pin is also for writing the command to the LCD.
• en=1;enable pin is high.
• Sending data to the LCD:
• rs=1; Register select pin is high.
• rw=0; Read/write Pin is also for writing the command to the LCD.
• en=1; enable pin is high.
7
8
.

9
10
11
12
13
14
15
16
Keyboard Interfacing
• Keyboards are organized in a matrix of rows
and columns
• The CPU accesses both rows and columns
through ports.

17
• It is the function of the microcontroller to scan the
keyboard continuously to detect and identify the key
pressed.
• To detect a pressed key, the microcontroller grounds all
rows by providing 0 to the output latch, then it reads the
columns.
• If the data read from columns is D3 – D0 = 1111, no
key has been pressed and the process continues till key
press is detected.
• If one of the column bits has a zero, this means that a
key press has occurred. For example, if D3 – D0 =
1101, this means that a key in the D1 column has been
pressed.
• After detecting a key press, microcontroller will go
through the process of identifying the key.

18
• For example, identify the rows and columns of the
pressed keys for the following:
• (a) D3 – D0 = 1110 for the row, D3 – D0 = 1011 for the
column
• (b) D3 – D0 = 1101 for the row, D3 – D0 = 0111 for the
column
• The row and column can be used to identify the key.
• (a) The row belongs to D0 and the column belongs to
D2; therefore, key number 2 was pressed.
• (b) The row belongs to D1 and the column belongs to
D3; therefore, key number 7 was pressed.

19
Keyboard Programming in PIC

20
21
22
23
24
25
26
Stepper Motor Interfacing
• A motor in which the rotor is able to assume only discrete stationary
angular position is a stepper motor.
• The rotary motion occurs in a step-wise manner from one
equilibrium position to the next.
• Stepper Motors are used very wisely in position control systems like
printers, disk drives, process control machine tools, etc.
• The basic two-phase stepper motor consists of two pairs of stator
poles. Each of the four poles has its own winding.
• The excitation of any one winding generates a North Pole. A South
Pole gets induced at the diametrically opposite side.
• The rotor magnetic system has two end faces. It is a permanent
magnet with one face as South Pole and the other as North Pole.
• The Stepper Motor windings A1, A2, B1, B2 are cyclically excited
with a DC current to run the motor in clockwise direction. By
reversing the phase sequence as A1, B2, A2, B1, anticlockwise
stepping can be obtained.

27
Program to rotate the stepper motor continuously

28
Step Angle
• The number of steps required to complete one
full rotation depends on the step angle of the
stepper motor. The step angle can vary from
0.72 degrees to 15 degrees per step. Depending
on that 500 to 24 steps may be required to
complete one rotation.
• In position control applications the selection
on motor should be based on the minimum
degree of rotation that is required per step.

29
Interfacing AC Appliances
• By using relay switch we easily turn on or off
any high voltage device by microcontroller.
• Relay is an electrically operated switch that
works on electro-magnetism principle. The
three pin named NC, NO and COMMON - NC
stands for normally closed, NO for normally
open and common stands for common pin for
connecting NC or NO. P1 and P2 pin are for
providing control signal to relay.
• Now working principle of relay is very simple
when P1 and p2 get a certain amount of voltage
then coil between P1 and P2 get energized and
create a magnetic field around it. For this
magnetic field the metal switch liver which is
attach to the common pin is attracted towards
the NO pin and connection made between NO
and common pin. 30
Block diagram to turn on or off a LED
using PIC

A driver to energize
the relay with 10mA 31
Program to turn on and off the lamp by energizing
and de-energizing the rely for few ms

32
Measurement of Frequency
• Timers 0,1,2,3,4 can be used to measure external frequencies.

33

You might also like