Module 6 Interfacing With 8051
Module 6 Interfacing With 8051
16×2 Liquid Crystal Display which will display the 32 characters at a time in two rows (16
characters in one row). Each character in the display is of size 5×7 pixel matrix.
PIN
NAME FUNCTION
NO
1 VSS Ground pin
2 VCC Power supply pin of 5V
3 VEE Used for adjusting the contrast commonly attached to the potentiometer.
RS is the register select pin used to write display data to the LCD (characters), this pin has to be
4 RS high when writing the data to the LCD. During the initializing sequence and other commands this
pin should low.
Reading and writing data to the LCD for reading the data R/W pin should be high (R/W=1) to
5 R/W
write the data to LCD R/W pin should be low (R/W=0)
Enable pin is for starting or enabling the module. A high to low pulse of about 450ns pulse is
6 E
given to this pin.
7 DB0
8 DB1
9 DB2
10 DB3
DB0-DB7 Data pins for giving data(normal data like numbers characters or command data) which
11 DB4
is meant to be displayed
12 DB5
13 DB6
14 DB7
15 LED+ Back light of the LCD which should be connected to Vcc
16 LED- Back light of LCD which should be connected to ground.
Follow these simple steps for displaying a character or data
E=1; enable pin should be high
RS=1; Register select should be high
R/W=0; Read/Write pin should be low.
To send a command to the LCD just follows these steps:
E=1; enable pin should be high
RS=0; Register select should be low
R/W=0; Read/Write pin should be low.
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
Programming LCD to 8051
STEP1: Initialization of LCD.
STEP2: Sending commands to LCD.
STEP3: Writing the data to LCD.
Initializing LCD
To initialize LCD to the 8051 the following instruction and commands are to be
embed in to the functions
0x38 is used for 8-bit data initialization.
0xoC for making LCD display on and cursor off.
0X01 for clearing the display of the LCD.
0x80 for positioning the cursor at first line .
Sending Commands to the LCD
E=1; enable pin should be high
RS=0; Register select should be low for sending commands
Placing the data on the data registers
R/W=0; Read/Write pin should be low for writing the data.
Writing the Data to the LCD
E=1; enable pin should be high
RS=1; Register select should be high for writing data
Placing the data on the data registers
R/W=0; Read/Write pin should be low for writing the data.
The data pins of the LCD are connected to PORT0 (first, the PORT0 pins must be pulled-HIGH
with the help of a 1KΩ Resistor Pack). RS and E are connected to PORT2 pins P2.0 and P2.1.
A 10KΩ Potentiometer is used to adjust the contrast of the LCD.
INTERFACING STEPPER MOTOR WITH 8051
To interfacing 8051 with DC motor requires a motor driver. There are various types
of driver ICs among which L293D is typically used for interfacing DC motor with
8051. L293 is an IC with 16 pins
This L293 IC is having ratings of 600mA per channel and DC supply voltage in
the range of 4.5V to 36V. These ICs can be protected from inductive spikes by
connecting higher speed clamp diodes internally. This 16 pin L293D IC can be
used for controlling the direction of two DC motors. The IC L293D works based
on the H-bridge concept. The voltage can be made to flow in either direction
using this circuit (H-bridge) such that by changing the voltage direction the motor
direction can be changed.
The keypad is used as an input device to read the key pressed by the user and to
process it.
4x4 keypad consists of 4 rows and 4 columns. Switches are placed between the
rows and columns. A keypress establishes a connection between the corresponding
row and column between which the switch is placed.
To read the keypress, we need to configure the rows as outputs and columns as
inputs.
Columns are read after applying signals to the rows in order to determine whether or
not a key is pressed and if pressed, which key is pressed.
Bouncing is the tendency of any two metal contacts in an electronic device to
generate multiple signals as the contacts close or open; debouncing is any kind of
hardware device or software that ensures that only a single signal will be acted upon
for a single opening or closing of a contact.
PIR Motion Sensor Interface with 8051
PIR sensor detects infrared heat radiations. It can be used to detect the
presence of living objects that emit infrared heat radiation.
The PIR sensor is split into two slots. The two slots are connected to a
differential amplifier.
Whenever a stationary object is in front of the sensor, the two slots receive
the same amount of radiation and the output is zero.
Whenever a moving object is in front of the sensor, one of the slots receives
more radiation than the other slot. This makes the output swing high or low.
This change in output voltage as a result of the detection of motion.
Ultrasonic Module HC-SR04 works on the principle of SONAR and RADAR system.
•The HC-SR04 module has an ultrasonic transmitter, receiver, and control circuit on a
single board.
•The module has only 4 pins, Vcc, Gnd, Trig, and Echo.
•When a pulse of 10µsec or more is given to the Trig pin, 8 pulses of 40 kHz are
generated. After this, the Echo pin is made high by the control circuit in the module.
•The echo pin remains high till it gets the echo signal of the transmitted pulses back.
•The time for which the echo pin remains high, i.e. the width of the Echo pin gives the
time taken for generated ultrasonic sound to travel towards the object and return.
•Using this time and the speed of sound in air, we can find the distance of the object
using a simple formula for distance using speed and time.
Steps of Programming
1.8051 microcontroller needs to transmit at least 10 us trigger pulse to the HC-SR04 Trig Pin.
2.After getting a trigger pulse, HC-SR04 automatically sends eight 40 kHz sound waves and waits for rising edge output at the
Echo pin.
3.When the rising edge capture occurs at the Echo pin which is connected to the input of 8051, start Timer of 8051 and again
wait for the falling edge on the Echo pin.
4.As soon as the falling edge is captured at the Echo pin, the microcontroller reads the count of the Timer. This time count is
used to calculate the distance to an object.
Calculation (distance in cm)
Where,
Sound Velocity = 34300 (in cm per second)
Here, the oscillator frequency of AT89S52 (8051) is 11.0592 MHz then the timer frequency of 8051 will be 921.6 kHz. So,
the time required to execute 1 instruction is 1.085 us.
So, the timer gets incremented after 1.085 us time elapse.
e.g.