Major Electronic Peripherals Interfacing to Microcontroller 8051 - LEKULE

Breaking

25 Aug 2016

Major Electronic Peripherals Interfacing to Microcontroller 8051

Interfacing is one of the important concepts in microcontroller 8051 because the microcontroller is a CPU that can perform some operation on a data and gives the output. However to perform the operation we need an input device to enter the data and in turn output device displays the results of the operation. Here we are using keyboard and LCD display as input and output devices along with the microcontroller.
Microcontroller 8051 Peripheral devices
Microcontroller 8051 Peripheral devices

Interfacing is the process of connecting devices together so that they can exchange the information and that proves to be easier to write the programs. There are different type of input and output devices as for our requirement such as LEDs, LCDs, 7segment, keypad, motors and other devices.
Here is given some important modules interfaced with microcontroller 8051.

1. LED Interfacing to Microcontroller:

Description:
LEDs are most commonly used in many applications for indicating the output. They find huge range of applications as indicators during test to check the validity of results at different stages. They are very cheap and easily available in a variety of shape, color and size.

Light Emitting Diode
Light Emitting Diode


The principle of operation of LEDs is very easy. A simple LEDs also servers as a basic display devices, it On and OFF state express meaning full information about a device. The common available LEDs have a 1.7v voltage drop that means when we apply above 1.7V, the diode conducts. The diode needs 10mA current to glow with full intensity. 

The following circuit describes “how to glow the LEDs”.

LEDs can be interfaced to the microcontroller in either common anode or common cathode configuration. Here the LEDs are connected in common anode configuration because the common cathode configuration consumes more power.

Circuit Diagram
LED Interfacing to Microcontroller
LED Interfacing to Microcontroller.


Source code:
#include
void main()
{
unsigned int i;
while(1)
{
P0=0x00;
for(i=0;i<30000 br="" i=""> P0=0xff;
for(i=0;i<30000 br="" i=""> }
}

2. 7-Segment Display interfacing circuit

Description:
A Seven segment display is the most basic electronic display. It consists of eight LEDs which are associated in a sequence manner so as to display digits from 0 to 9 when proper combinations of LEDs are switched on. A 7-segment display uses seven LEDs to display digits from 0 to 9 and the 8th LED is used for dot. A typical seven segment looks likes as shown in figure below.
7-Segment Display
7-Segment Display

The 7-segment displays are used in a number of systems to display the numeric information. They can display one digit at a time. Thus the number of segments used depends on the number of digits to display. Here the digits 0 to 9 are displayed continuously at a predefined time delay.

The 7-segment displays are available in two configurations which are common anode and common cathode. Here common anode configuration is used because output current of the microcontroller is not sufficient enough to drive the LEDs. The 7-segment display works on negative logic, we have to provide logic 0 to the corresponding pin to make on LED glow.

7-Segment Display Configurations
7-Segment Display Configurations

The following table shows the hex values used to display the different digits.
7-Segment Display Table
7-Segment Display Table

Circuit Diagram
7-Segment Display interfacing
7-Segment Display interfacing

Source Code:
#include
sbit a= P3^0;
void main()
{
unsigned char n[10]= {0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0xE00,0x10};
unsigned int i,j;
a=1;
while(1)
{
for(i=0;i<10 br="" i=""> {
P2=n[i];
for(j=0;j<60000 br="" j=""> }
}
}

3. LCD Interfacing to Microcontroller

LCD stands for liquid crystal display which can display the characters per line. Here 16 by 2 LCD display can display 16 characters per line and there are 2 lines. In this LCD each character is displayed in 5*7 pixel matrix.
LCD Display
LCD Display

LCD is very important device which is used for almost all automated devices such as washing machines, an autonomous robot, power control systems and other devices. This is achieved by displaying their status on small display modules like 7-seven segment displays, multi segment LEDs etc. The reasons being, LCDs are reasonably priced, easily programmable and they have a no limitations of displaying special characters.

It consists of two registers such as command/instruction register and data register.
The command/instruction register stores the command instructions given to the LCD. A command is an instruction which is given to the LCD that perform a set of predefined tasks like initializing, clearing the screen, setting the cursor posing, controlling display etc.
The data register stores the data to be displayed on LCD. The data is an ASCII value of the characters to be displayed on the LCD.

Operation of LCD is controlled by two commands. When RS=0, R/W=1 it reads the data and when RS=1, R/W=0, it writes (print) the data.


LCD uses following command codes:
LCD Display Commands
LCD Display Commands


Circuit Diagram:
LCD Interfacing to Microcontroller
LCD Interfacing to Microcontroller

Source code:
#include
#define kam P0
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
void lcd_initi();
void lcd_dat(unsigned char );
void lcd_cmd (unsigned char );
void delay(unsigned int );
void display(unsigned char *s, unsigned char r);
void main()
{
lcd_initi();
lcd_cmd(0x80);
delay(100);
display(“EDGEFX TECHLNGS”, 15);
lcd_cmd(0xc0);
display(“KITS & SOLTIONS”,15);
while(1);
}
void display(unsigned char *s, unsigned char r)
{
unsigned int w;
for(w=0;w {
lcd_dat(s[w]);
}
}
void lcd_initi()
{
lcd_cmd(0x01);
delay(100);
lcd_cmd(0x38);
delay(100);
lcd_cmd(0x06);
delay(100);
lcd_cmd(0x0c);
delay(100);
}
void lcd_dat(unsigned char dat)
{
kam = dat;
rs=1;
rw=0;
en=1;
delay(100);
en=0;
}
void lcd_cmd(unsigned char cmd)
{
kam=cmd;
rs=0;
rw=0;
en=1;
delay(100);
en=0;
}
void delay( unsigned int n)
{
unsigned int a;
for(a=0;a }

4. Stepper motor interfacing circuit

Types of Stepper Motors-1
Unipolar Stepper Motor


A stepper motor is one of the most commonly used motor for precise angular movement. The advantage of using a stepper motor is that the angular position of the motor can be controlled without any feedback mechanism. The stepper motors are widely used in industrial and commercial applications. They are also commonly used as in drive systems such as robots, washing machines etc.
Types of Stepper Motors-2
Bipolar Stepper Motor


Stepper motors can be unipolar or bipolar and here we are using unipolar stepper motor. The unipolar stepper motor consists of six wires out of which four are connected to coil of the motor and two are common wires. Each common wire is connected to a voltage source and remaining wires are connected to the microcontroller.


Circuit Diagram:
Stepper motor interfacing circuit
Stepper motor interfacing circuit


Source code:
#include
sbit a=P3^0;
sbit b=P3^1;
sbit c=P3^2;
sbit d=P3^3;
void delay();
void main()
{
while(1)
{
a=0;
b=1;
c=1;
d=1;
delay();
a=1;
b=0;
c=1;
d=1;
delay();
a=1;
b=1;
c=0;
d=1;
delay();
a=1;
b=1;
c=1;
d=0;
}
}
void delay()
{
unsigned char i,j,k;
for(i=0;i<6 br="" i=""> for(j=0;j<255 br="" j=""> for(k=0;k<255 k="" p="">
}

5. Matrix keypad interfacing to 8051

Description:
Matrix Keypad
Matrix Keypad

Keypad is a widely used input device with lot of applications such as telephone, computer, ATM, electronic lock etc. A keypad is used to take input from the user for further processing. Here a 4 by 3 matrix keypad consisting of switches arranged in rows and columns is interfaced to the microcontroller. A 16 by 2 LCD is also interfaced for displaying the output.

The interfacing concept of keypad is very simple. Every number of keypad is assigned two unique parameters that are row and column (R, C). Hence every time a key is pressed the number is identifying by detecting the row and column numbers of keypad.
Keypad Internal Diagram
Keypad Internal Diagram

Initially all the rows are set to zero (‘0’) by the controller and columns are scanned to check if any key is pressed. In case of no key is pressed the output of all columns will be high (‘1’).


Circuit Diagram
Matrix keypad interfacing to 8051
Matrix keypad interfacing to 8051


Source Code:
#include
#define kam P0
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit c1=P1^4;
sbit c2=P1^5;
sbit c3=P1^6;
sbit r1=P1^0;
sbit r2=P1^1;
sbit r3=P1^2;
sbit r4=P1^3;
void lcd_initi();
void lcd_dat(unsigned char );
void lcd_cmd (unsigned char );
void delay(unsigned int );
void display(unsigned char *s, unsigned char r);
void main()
{
lcd_initi();
lcd_cmd(0x80);
delay(100);
display(“0987654321”, 10);
while(1);
}
void display(unsigned char *s, unsigned char r)
{
unsigned int w;
for(w=0;w {
lcd_dat(s[w]);
}
}
void lcd_initi()
{
lcd_cmd(0x01);
delay(100);
lcd_cmd(0x38);
delay(100);
lcd_cmd(0x06);
delay(100);
lcd_cmd(0x0c);
delay(100);
}
void lcd_dat(unsigned char dat)
{
kam = dat;
rs=1;
rw=0;
en=1;
delay(100);
en=0;
}
void lcd_cmd(unsigned char cmd)
{
kam=cmd;
rs=0;
rw=0;
en=1;
delay(100);
en=0;
}
void delay( unsigned int n)
{
unsigned int a;
for(a=0;a }
}


We hope we have been able to provide ample knowledge about the basic yet important interfacing circuits of microcontroller 8051. These are the most basic circuits required in any embedded system application and we hope we have provided you with a good revision.


A further query or feedback related to this topic is welcome to be mentioned in the comment section below.

No comments: