Microntroller & Its Interfacing(8051)
-
Upload
bedanshu-shekhar-mishra -
Category
Documents
-
view
243 -
download
0
Transcript of Microntroller & Its Interfacing(8051)
-
8/13/2019 Microntroller & Its Interfacing(8051)
1/19
~ 14 ~
MICROCONTROLLERS
Microcontrollers as the name suggests are small controllers. They are like single chip
computers that are often embedded into other systems to function as
processing/controlling unit. For example the remote control you are using probably has
microcontrollers inside that do decoding and other controlling functions. They are also
used in automobiles, washing machines, microwave ovens, toys ... etc, where automation
is needed.
Embedded system means the processor is embedded into the required application. An
embedded product uses a microprocessor or microcontroller to do one task only. In an
embedded system, there is only one application software that is typically burned into
ROM. Example: printer, keyboard, video game player .
Microprocessor - A single chip that contains the CPU or most of the computer
Microcontroller - A single chip used to control other devices
The microcontroller incorporates all the features that are found in microprocessor. The
microcontroller has built in ROM, RAM, Input Output ports, Serial Port, timers,
interrupts and clock circuit. A microcontroller is an entire computer manufactured on a
single chip. Microcontrollers are usually dedicated devices embedded within an
application. For example, microcontrollers are used as engine controllers in automobiles
and as exposure and focus controllers in cameras. In order to serve these applications,
they have a high concentration of on-chip facilities such as serial ports, parallel input
output ports, timers, counters, interrupt control, analog-to-digital converters, random
access memory, read only memory, etc. The I/O, memory, and on-chip peripherals of amicrocontroller are selected depending on the specifics of the target application. Since
microcontrollers are powerful digital processors, the degree of control and
programmability they provide significantly enhances the effectiveness of the application.
-
8/13/2019 Microntroller & Its Interfacing(8051)
2/19
-
8/13/2019 Microntroller & Its Interfacing(8051)
3/19
~ 16 ~
Microcontroller Vs Microprocessor:-
It is very clear from figure that in microprocessor we have to interface additional circuitry
for providing the function of memory and ports, for example we have to interface
external RAM for data storage, ROM for program storage, programmable peripheral
interface (PPI) 8255 for the Input Output ports, 8253 for timers, USART for serial port.
While in the microcontroller RAM, ROM, I/O ports, timers and serial communication
ports are in built. Because of this it is called as system onchip.
So in micro-controller there is no necessity of additional circuitry which is interfaced in
the microprocessor because memory and input output ports are inbuilt in the
microcontroller. Microcontroller gives the satisfactory performance for small
applications. But for large applications the memory requirement is limited because only
64 KB memory is available for program storage. So for large applications we prefer
microprocessor than microcontroller due to its high processing speed.
-
8/13/2019 Microntroller & Its Interfacing(8051)
4/19
~ 17 ~
Architecture of 8051:-
It is 8-bit microcontroller, means MC 8051 can Read, Write and Process 8 bit
data. This is mostly used microcontroller in the robotics, home appliances like
mp3 player, washing machines, electronic iron and industries. Mostly used blocks
in the architecture of 8051 are as follows:
a. 128 Byte RAM For Data Storage
MC 8051 has 128 byte Random Access memory for data storage. Random access
memory is non volatile memory. During execution for storing the data the RAM is used.
RAM consists of the register banks, stack for temporary data storage. It also consists of
some special function register (SFR) which are used for some specific purpose like timer,
input output ports etc. Normally microcontroller has 256 byte RAM in which 128 byte is
-
8/13/2019 Microntroller & Its Interfacing(8051)
5/19
~ 18 ~
used for user space which is normally Register banks and stack. But other 128 byte
RAM which consists of SFRs.
b. 4KB ROM In 8051, 4KB read only memory (ROM) is available for program storage. This is
used for permanent data storage. Or the data which is not changed during the
processing like the program or algorithm for specific applications.
This is volatile memory; the data saved in this memory does not disappear after
power failure.
We can interface up to 64KB ROM memory externally if the application is
large. These sizes are specified different by their companies.
Address Range of PC: Address range of PC means program counter (which
points the next instruction to be executing) can be moved between these
locations or we can save the program from this location to this location.
c. Difference between RAM and ROM
RAM is used for data storage while ROM is used for program storage.
Data of RAM can be changed during processing while data of ROM cant
be changed during processing.
a. We can take an example of calculator. If we want to perform addition of two
numbers then we type the two numbers in calculator, this is saved in the RAM, but
the Algorithms by which the calculation is performed is saved in the ROM. Data
which is given by us to calculator can be changed but the algorithm or program by
which calculation is performed cant be changed.d. Timers & Counters
Timer means which can give the delay of particular time between some events.
For example on or off the lights after every 2 sec. This delay can be provided
through some assembly program but in microcontroller two hardware pins are
-
8/13/2019 Microntroller & Its Interfacing(8051)
6/19
~ 19 ~
available for delay generation. These hardware pins can be also used for counting
some external events. How much times a number is repeated in the given table is
calculated by the counter.
In MC8051, two timer pins are available T0 and T1, by these timers we cangive the delay of particular time if we use these in timer mode.
We can count external pulses at these pins if we use these pins in counter
mode.
16 bits timers are available. Means we can generate delay between 0000H
to FFFFH.
TMOD, TCON registers are used for controlling timer operation.
-
8/13/2019 Microntroller & Its Interfacing(8051)
7/19
~ 20 ~
PIN DIAGRAM OF 8051
Power Supply pins
8051 c works with +5V DC source applied to Vcc and 0V to Gnd input pin. It
has an onchip crystal clock generator. As such it must be supported externally byconnecting a crystal across crystal input XTAL1, XTAL2. It has active hign reset input
pin. As such the controller is said to be reset upon application of active hign pulse.
-
8/13/2019 Microntroller & Its Interfacing(8051)
8/19
~ 21 ~
I/O port pins
A total number of 32 I/O pins are provided as port pins divided into 4 portsport 0, port
1, port 2 and port 3. All ports are both byte and bit addressable. All ports are
programmable. All the ports act as simple input/output ports. All the ports except port 1offer alternate functions. They are as follows.
Port 0 and Port 2: If input pin is grounded then port 0 acts as lower order
8bit address data bus where as port 2 acts as higher order 8 bit address bus.
Port 3: Each and every pin in this port offer some separate functionality
irrespective of level at input pin.
External Access Control pins
(External Access): If is connected to +5V then the
microcontroller fetches code from internal or inbuilt program memory. If it is cnneected
to 0V then the microcontroller fetches code from external program memory.
(Address Latch Enable): It is an active high output pin. It is used
for demultiplexing the address and data by connecting to the G pin of the 74LS373 chip.
-
8/13/2019 Microntroller & Its Interfacing(8051)
9/19
~ 22 ~
(Program Store Enable)This is an output pin. For opcode fetch operation,
microcontroller asserts output pin as low which can be used for selecting the
external program memory chip. This can also be used as ROM read control signal
1
to the inverting oscillator amplifier and input to the interanal clock operating
circuit.
put from the inverting oscillator amplifier.
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
which can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a
quartz crystal or ceramic resonator may be used. To drive the device from an external
clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in
Figure 2. There are no requirements on the duty cycle of the external clock signal, since
the input to the internal clocking circuitry is through a divide-by-two flip-flop, but
minimum and maximum voltage high and low time specifications must be observed.
-
8/13/2019 Microntroller & Its Interfacing(8051)
10/19
~ 23 ~
INTERFACING OF 8051
1) LED Interfacing(PORT as o/p):
Port as output: In this topic we study how we send the values on ports and
how we observe that value on ports. The microcontroller always loads the
binary equivalent of value on the ports. For example we send 0x0A. Here 0x
shows the value is in hexadecimal. The binary equivalent of 0x0A is
00001010. So if we send 0x0A the equivalent binary is observed on the port.
The LSB is observed on the LSB pins of port and MSB observed on the MSB
pins of port. Now how we observe the 0 and ones physically. There is
specific voltage level concerned with 0 and 1. These levels are TTL
compatible.
Logic Out put pin
0 Low (0 volt)
1 High(5v10ma according
to data sheet)
-
8/13/2019 Microntroller & Its Interfacing(8051)
11/19
~ 24 ~
So we can verify the loaded value by checking voltage level using multimeter or by
driving led from this voltage.
Example Program Of LED interfacing With 8051
WAP to interface 8 leds and glow them for some instance and then put it
off.
#include
Void delay();
Void main()
{
P1=0xff;
Delay(500);
P1=0x00;
}
Void delay(int itime)
{
Int i,j;
For(i=0;i
-
8/13/2019 Microntroller & Its Interfacing(8051)
12/19
~ 25 ~
2) LCD Interfacing
On most displays, the pins are numbered on the LCDs printed circuit board, but if
not, it is quit easy to locate pin1. Since the pin is connected to ground, it often has a
thicker PCB track connected to it, and it is generally connected to the metal work at
some point.
The function of each of the connections is shown in the table below:-
Pins 1 & 2 are the power supply lines, Vss & Vdd. The Vdd pin should be connected to
the positive supply & Vss to the 0V supply or ground.
supplies of 6V & 4.5V both work well, and even 3V is sufficient for some modules.
Consequently, these modules can be effectively and economically powered by
batteries.
Pin 3 is a control pin, Vee, which is used to alter the contrast of the display. Ideally,
these pin should be connected to a variable voltage supply. A preset potentiometer
connected between the power supply lines, with its wiper connected to the contrast pin
is suitable in many cases, but be aware that some modules may require a negative
potential; as low as 7V in some cases. For absolute simplicity, connecting this pin to 0V
will often suffice.
Pin 4 is register select (RS) line.
PIN NO. NAME FUNCTION
1 Vss Ground
2 Vdd +ve supply
3 Vee Contrast
4 RS Register select
5 R/W Read/Write
6 E Enable
7 D0 Data Bit 0
8 D1 Data Bit 1
9 D2 Data Bit 2
10 D3 Data Bit 3
11 D4 Data Bit 4
-
8/13/2019 Microntroller & Its Interfacing(8051)
13/19
~ 26 ~
12 D5 Data Bit 5
13 D6 Data Bit 6
14 D7 Data Bit 7
Three command control inputs. When this line is low, data bytes transferred to the
display are treated as commands, and data bytes read from the display indicate its
status. By setting the RS line high, character data can be transferred to and from the
module.
Pin 5 is (R/W) line. This line is pulled low in order to write commands or character
data to the module, or pulled high to read character data or status information from
its registers.
Pin 6 is Enable (E) line. This input is used to initiate the actual transfer of commands
or character data between the module and the data lines. When writing to the
display, data is transferred only on the high to low transition of this signal. However,
when reading from the display, data will become available shortly after the low to
high transition and remain available until the signal falls low again.
Pins 7 to 14 are the eight data bus lines (D0 to D7). Data can be transferred to and
from the display, either as a single 8-bit byte or as two 4-bit nibbles. In the latter
case, only the upper four data lines (D4 to D7) are used. This 4-bit mode is
beneficial when using a microcontroller, as fewer I/O lines are required.
-
8/13/2019 Microntroller & Its Interfacing(8051)
14/19
~ 27 ~
Example Program of LCD interfacing with 8051
WAP to Display ECE ROCKS On LCD
#include
#define lcdport P3
sbit rs=P2^0;
-
8/13/2019 Microntroller & Its Interfacing(8051)
15/19
~ 28 ~
sbit rw=P2^1;
sbit en=P2^2;
void cmd();
void dat();
void delay(int);
void main()
{
P3=0x00;
P2=0x00;
lcdport=0x38;
cmd();
lcdport=0x0e;
cmd();
lcdport=0x01;
cmd();
lcdport='E';
dat();
lcdport='C';
dat();
lcdport='E';
dat();
lcdport='R';
dat();
lcdport='O';
dat();
lcdport='c';
dat();
lcdport='k';
dat();
-
8/13/2019 Microntroller & Its Interfacing(8051)
16/19
~ 29 ~
lcdport='s';
dat();
}
void delay(int itime)
{
int i,j;
for(i=0;i
-
8/13/2019 Microntroller & Its Interfacing(8051)
17/19
~ 30 ~
3) SEVEN SEGMENT DISPLAY
7 segment LED display is very popular and it can display digits from 0 to 9 and quite a
few characters like A, b, C, ., H, E, e, F, n, o,t,u,y, etc. Knowledge about how to
interface a seven segment display to a micro controller is very essential in designing
embedded systems. A seven segment display consists of seven LEDs arranged in the
form of a squarish8slightly inclined to the right and a single LED as the dot character.
Different characters can be displayed by selectively glowing the required LED
segments. Seven segment displays are of two types,common cathode and comm on
anode.In common cathode type , the cathode of all LEDs are tied together to a single
terminal which is usually labeled as com and the anode of all LEDs are left alone as
individual pins labeled as a, b, c, d, e, f, g & h (or dot) . In common anode type, the
anode of all LEDs are tied together as a single terminal and cathodes are left alone as
individual pins. The pin out scheme and picture of a typical 7 segment LED display is
shown in the image below.
Digit drive pattern of a seven segment LED display is simply the different logic
combinations of its terminalsa to h in order to display different digits and characters.
The common digit drive patterns (0 to 9) of a seven segment display are shown in the
table below.
-
8/13/2019 Microntroller & Its Interfacing(8051)
18/19
~ 31 ~
Digit a b c d e f g
0 1 1 1 1 1 1 0
1 0 1 1 0 0 0 0
2 1 1 0 1 1 0 13 1 1 1 1 0 0 1
4 0 1 1 0 0 1 1
5 1 0 1 1 0 1 1
6 1 0 1 1 1 1 1
7 1 1 1 0 0 0 0
8 1 1 1 1 1 1 1
9 1 1 1 1 0 1 1
Sample Program for counting from 0 to 9 using 7 segment display
#include
void delay(int);
void main()
{
char i,arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0xfd,0x07,0x7f,0x6f};
for(i=0;i
-
8/13/2019 Microntroller & Its Interfacing(8051)
19/19
~ 32 ~