Anda di halaman 1dari 24

Microcontroller

&
Interfacing of
Peripherals
Microcontroller & Microprocessor

Memory I/O Timer Serial I/O


CPU

I/O Memory Timer


External
External CPU
ADC Serial Memory
I/O
PWM WDT I/O
2
Microcontroller -

It is a highly integrated device which includes, on one chip,


all or most of the parts needed to perform an application
control function.
8 – Bit Microcontrollers
• Motorola’s 6811
•Intel’s 8051
•Zilog’s Z8
•Microchip Technology’s PIC 16X
Choosing a microcontroller-
•It must meet task at hand efficiently & cost effectively
Speed
Power Consumption
On chip Memory
No of I/O pins and Timers on chip
•Availability of development tools
•Availability of Microcontroller ICs
• Additional features available

5
Features of 8051 Architecture

• Optimized 8 bit CPU for control applications


•Extensive Boolean processing capabilities.
•8 bit and 16 bit registers.
• 4 K on chip program memory address space
•128 bytes of on chip data memory
•32 bi-directional and individually addressable I/O lines
• Two 16-bit timers/counters
•Full Duplex UART, programmable in 4 modes
•5 vector interrupts structure with priority levels
•On chip clock oscillator
Inside Microcontroller
Ex.INT Timer I/P

Timer/Counter
Interrupt RO RAM
M

CPU

Bus 4 I/O Serial


OSC
Contr Ports Port
ol

P0-P3
8051 Memory Model

FFF
7F FF
7
F

ROM
RA SFR
M

00
80 000
8
Byte Address
1F
Internal RAM Organization
Byte
BANK 3 Address Bit Address Byte Address
R0--R7 7F
2F 7F 78
18

17
BANK 2
R0--R7
10
0F
BANK 1
R0--R7
08

07
BANK 0
R0 -- R7 20 07
00 30
00
Working Registers Bit Addressable General purpose 9
SFR
A B IP IE TMOD TCON
E0 F0 A8
IP B8 89 88

TH0 TL0 TH1 TL1


8C 8A 8D 8B

SCON SBUF PCON PSW


* 98 99 87 D0

SP
81

DPTR
DPH DPL PC
83 82

Port 0 Port 1 Port Port 3


80 90 2 B0
A0 10
8051 Pin Assignments
A8---A15
Vcc AD0 AD1 AD2 AD3 AD4 AD5 AD6 Vp Prog
AD7 p
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23
22 21 ____
EA ALE PSEN
P0.0 -- P0.7 P2.0 ----2.7
P3.0 --P3.7

P1.0 - P1.7 RST


1 2 3 4 5 6 78 9 10 11 12 13 14 15 16 17 18
19 20
_____ ____
Vss
__ __
Port 1 Bit 0-7 RXD INT0 INT1 T0 T1
Reset WR RD XTAL1
TXD
XTAL2
Input - Output Pins, Ports

1. 8051 Interact with outside world with I/O ports


2. Each port has a D-type output latch for each pin.
3. Data on the latches is not same as that on the pins
4. Separate data paths are used to read the latch or pin
data
5.Different opcodes access the latch or pin states as
appropriate.
Voltages at ports are TTL Levels.
But currents are IIL=10 µA IoL = 1.6 mA IIH = 10 µA IOH = -60
µA
6.Normally ports are buffered when interfaced to
external device.
7.All ports can be used as input / output, To use port as
input , ‘1’ must be written to corresponding port.
PIN DESCRIPTION OF THE 8051

Pin no 1 to 8 : port 1 It can be used as i/o no external pull up


resistors are required.
Pin no 9 : Reset : I/P active high. Upon applying high pulse to
this pin for two machine cycles 8051 will reset and terminate
all activities
Pin no 10 - pin no 17 are duel functions It is used as Bi-
directional I/O port
PIN DESCRIPTION ….

Pin no 18 19 : this pins are provided to connecting a


crystal to form an oscillator
To use frequency source other than crys.osc.it is
connected XTAL1
with XTAL2 open
Maximum Crystal frequency is 16 MHz
PIN DESCRIPTION ….

Pin 20 : Ground pin


Pin 21 to 28 : Port 2 it is used as I/O port alternate use as
high order address bus when external memory is interfaced
to 8051
Pin 29 : PSEN : It is O/P pin it is connected to OE pin of ROM
Pin no. 30 : ALE / PROG : It is an O/P pin it is used for
demultiplex address and data bus it is I/P during flash
programming.
Pin 31 : EA/VPP : 8051 family members such as 8751 89c51
come with on chip ROM in such a cases EA pin is connected
to VCC.
VPP : It is connected to 12 V during flash programming.
Pin 32 to Pin 39 Port 0 : It is a I/O port it can be used as
bi-directional low order address and data bus for external
Interrupts
1- from Serial port when data transmission and reception
operation is executed.
2– from timers , when overflow occurs
2- from two input pins INT0, INT1
Each interrupt can be independently enabled and priority
will be given using IE and IP register.

16
Interrupt service routine starting
address

External 0 0003h
Timer/Counter 0 000Bh
External 1 0013h
Timer/Counter 1 001Bh
Serial port 0023h

17
Interfacing of Peripherals

18
Switch Interfacing

8051
4.7
4 s
.7kk
w
P0.0

19
l
Led Interfacing

8051
4.7
4
.7kk

Led
Px.x

20
Relay Interfacing

8051

Px.x

21
LCD
LCDInterfacing
Interfacing
LCD

+5
8051 P1.0 D v
Vcc
0
Vee
LCD
Vss

P1.7 D7 Rs R/W
E
P2.0
P
P2.1
2.0
P2.2

22
Embedded C Program for LED blinking
#include<reg51.h>
void main()
{
while(1) {
P1 = 0xFF;
delay();
P1 = 0x00;
delay();
}
}
Void delay(void)
{
unsigned char i;
for(i=0;i<1000;ii++);
}
23
24