[go: up one dir, main page]

0% found this document useful (0 votes)
348 views44 pages

8051 Peripheral Interfacing Guide

The document provides information about peripherals interfacing and coding in 8051 microcontrollers. It discusses various interfacing concepts and circuits including LED, LCD, 7-segment display, DC motor, buzzer, IR, and RS-232. For each topic, it describes the component, provides the interfacing circuit diagram and code, and simulates the circuit in Proteus. It also discusses concepts like serial communication, UART, USART, MAX232 voltage level converter, and DB9 connector used for RS-232 interfacing.

Uploaded by

malhiavtarsingh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
348 views44 pages

8051 Peripheral Interfacing Guide

The document provides information about peripherals interfacing and coding in 8051 microcontrollers. It discusses various interfacing concepts and circuits including LED, LCD, 7-segment display, DC motor, buzzer, IR, and RS-232. For each topic, it describes the component, provides the interfacing circuit diagram and code, and simulates the circuit in Proteus. It also discusses concepts like serial communication, UART, USART, MAX232 voltage level converter, and DB9 connector used for RS-232 interfacing.

Uploaded by

malhiavtarsingh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Peripheral Interfacing + Coding

Lets Learn How to do It in 8051 !!

Flow Chart for Designing an Embedded System


Step1

Logic Design

Step2

Interfacing

Step 3

Coding
Testing End Product

Step 4

Step5

What Interfacing Means?


The process of interconnecting two or more devices to each other in order to exchange data is called hardware interfacing Interfacing includes : The design of the interfacing circuit The type of medium used for data transfer (wired or wireless) The protocol on which the data transfer or communication is taking place (RS232, Bluetooth, TCP/IP)

LED Interfacing

About LED
Important Points:
LED has two leads: - Cathode - Anode. They are identified by the length of the lead. Cathode is of broader filament.

LED circuit concept


When a LED is connected to any circuit it usually takes 2 Volts (Red, Green) and a Blue or White LED takes 4 Volts. Since we have connected a 9 Volts battery we need a resistance to drop the voltage so that the LED wont burn out. Now in order to calculate the resistance between the LED & battery, we are going to use the Ohms Law: Consider the LED current is 10mA to 20mA we have: R = (Vs VL)/ I

LED circuit concept

LED interfacing circuit with 8051


Proteus Simulation

Coding

8051 Coding
// Program to blink a LED in Port 2.0 [1 bit operation] #include<reg51.h> void MSDelay(unsigned int a); sbit led = P2^0; void main() { while(1) { led=0; MSDelay(500); led=1; MSDelay(500); } } void MSDelay(unsigned int a) { unsigned int i, j; for(i=0; i<a; i++) for(j=0; j<1275; j++) {} } // Including header file // Defining Port 2.0 as Led port // Main function // infinite loop

// delay function

LCD Interfacing

About LCD
Pin no. Description

1
2 3 4

Ground
+5 Volts LCD contrast Instruction/Data input

5
6 7 to 14

Write/read signal
Enable signal D0 to D7 data bus lines

Basics of LCD
RS register select If RS=0, used to send commands such as clear display, cursor position etc. If RS=1, used to send data to the LCD. R/W read / write If R/W = 1, read from LCD If R/W = 0, write to LCD

E enable A 450 nano seconds high-to-low pulse is applied in order to send data.

LCD Address
For 16x2 LCD the address of the cursor positions are:

80 C0

81 C1

82 C2

83 C3

84 C4

85 C5

86 C6

to 8F to CF

All these addresses are in hexadecimal.

LCD Command Codes


HEX CODE COMMAND HEX CODE COMMAND

0x01
0x04 0x05 0x08

CLEAR LCD
SHIFT CURSOR LEFT SHIFT DISPLAY RIGHT DISPLAY OFF, CURSOR OFF

0x02
0x06 0x07 0x0A

RETURN HOME
SHIFT CURSOR RIGHT SHIFT DISPLAY LEFT DISPLAY OFF, CURSOR ON

0x0C
0x10 0x18 0x80 0x38

DISPLAY ON, CURSOR OFF


SHIFT CURSOR TO LEFT SHIFT DISPLAY TO LEFT FORCE CURSOR TO BEGINNING OF FIRST LINE 2 LINES & 5X7 MATRIX

0x0E
0x14 0x1C 0xC0

DISPLAY ON, CURSOR BLINKING


SHIFT CURSOR TO RIGHT SHIFT DISPLAY TO RIGHT FORCE CURSOR TO BEGINNING OF 2ND LINE

LCD Circuit diagram


Proteus Simulation

Coding

7 Segment Display Interfacing

About: Seven Segment Display

Connection: 7 Segment Display

Concept: 7 Segment Display


a/0 b/1

f/5

g/6

e/4

c/2

h/7

d/3

Truth Table: 7 Segment Display


OUTPUT 0 1 2 3 4 5 6 h 1 1 1 1 1 1 1 g 1 1 0 0 0 0 0 f 0 1 1 1 0 0 0 e 0 1 0 1 1 1 0 d 0 1 0 0 1 0 0 c 0 0 1 0 0 0 0 b 0 0 0 0 0 1 1 a 0 1 0 0 1 0 0 HEX CODE C0 F9 A4 B0 99 92 82

7 8 9

1 1 1

1 0 0

1 0 0

1 0 1

1 0 0

0 0 0

0 0 0

0 0 0

F8 80 90

Truth Table: 7 Segment Display


#include<reg51.h> void MSDelay(unsigned int); void main() { P2 = 0xFE; //select digit 1 while (1) { P3 = 0xC0; MSDelay(100); P3 = 0xF9; P3 = 0xB0; MSDelay(100); P3 = 0x99; P3 = 0x82; MSDelay(100); P3 = 0xF8; P3 = 0x90; MSDelay(100); } } void MSDelay(unsigned int itime) { unsigned int i, j; for(i=0; i<itime; i++) for(j=0; j<1275; j++); }

MSDelay(100); MSDelay(100); MSDelay(100);

P3 = 0xA4; MSDelay(100); P3 = 0x92; MSDelay(100); P3 = 0x80; MSDelay(100);

DC Motor Interfacing

About: DC Motor
A DC motor is an electric motor that works on Direct current.

Video: DC Motor, What is it?

DC Motor Control: H-BRIDGE CONTROLLER


Making an H-Bridge using Switch

Proteus Simulation

DC Motor Control: H-BRIDGE CONTROLLER


Using H-BRIDGE IC (L293D) L293D is a Dual H-Bridge IC, It can drive 2 DC Motor

I/P 1 0

I/P 2 0

Rotation No Rotation

1
0 1

0
1 1

Forward
Reverse Break

DC Motor Control: Circuit Diagram

Coding Proteus Simulation

Buzzer Interfacing

About: Buzzer
Buzzer is used to give alert or to alarm about some conditions.

Buzzer: Circuit Diagram

Coding Proteus Simulation

IR Interfacing [IR Communication]

About : IR Transmitter & Reciever


PHOTODIODE OR PHOTOTRANSISTOR (RECIEVER) IR LED (TRANSMITTER)

Concept
Silicon photodiodes are semiconductor devices responsive to highenergy particles and photons. Photodiodes operate by absorption of photons or charged particles and generate a flow of current in an external circuit, proportional to the incident power. Photodiodes can be used to detect the presence or absence of minute quantities of light and can be calibrated for extremely accurate measurements.

LM 358 : Comparator IC

Internally frequency compensated for unity gain Large DC voltage gain : 100dB Wide power supply range : 3V~32V(or1.5V~16V) Input common-mode voltage range includes ground Large output voltage swing : 0V DC to VCC-1.5V DC Power drain suitable for battery operation

Variable Resistance

Working of IR Sensor

Coding
#include<reg51.h> sbit sensor = P3^0; sbit led = P2^1; void main() { sensor = 1; led = 0; while(1) { if(sensor == 1) led = 1; else led = 0; } }

RS 232 Interfacing [Serial COM]

Serial Communication
In serial communication the whole data unit, say a byte is transmitted one bit at a time

In serial transmission only one wire is used for data transfer. Its logic level changes according to bit being transmitted (0 or 1). But a serial communication need some way of synchronization.

Can you make out what data is coming?

Serial Communication | Contd..


If we add another line called the clock line to synchronize you then it will become very easy. You need to note down the value of data line only when you see the "clock line" high. Lets understand this with help of an animation. A Serial Line.(HIGH=RED & LOW=WHITE)

What is RS 232 Communication


In RS232 there are two data lines RX and TX. TX is the wire in which data is sent out to other device. RX is the line in which other device put the data it need to sent to the device.

Difference between UART & USART


In UART the "clock" line helps you in "synchronizing" the incoming data. In this way many serial busses like SPI and I2C works. But USART is different from UART [Universal Asynchronous Receiver Transmitter. ] there is no clock line. In USART a start bit and stop bits are used to synchronize the incoming data.

About MAX 232


If The serial port in the computer works on 15V to +15V but the microcontroller works on +5V & 0V. So in order to communicate with the microcontroller one has to use a voltage level convertor.

In order to do this MAX232 manufactured by Maxim is used.

About DB9 Connector


q

Circuit: RS 232 Communication + ISP


n

8051

P3.1 Pin 11 P3.0 Pin 10

Coding Proteus Simulation

You might also like