Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
8051 microcontroller and it’s interface
-
Upload
abhishek-choksi -
Category
Engineering
-
view
221 -
download
2
Transcript of 8051 microcontroller and it’s interface
Gandhinagar Institute Of Technology
Subject – Microprocessor & Microcontroller Interfacing (2150907)
Branch – Electrical
Topic – 8051 microcontroller and It’s Interface
Name Enrollment No.
Abhishek Chokshi 140120109005
Himal Desai 140120109008
Harsh Dedakia 140120109012
Guided By – Prof. Supraja Ma’am
Why do we need to learn Microprocessors/controllers?
• The microprocessor is the core of computer systems.• Nowadays many communication, digital
entertainment, portable devices, are controlled by them.
• A designer should know what types of components he needs, ways to reduce production costs and product reliable.
Three criteria in Choosing a Microcontroller
• meeting the computing needs of the task efficiently and cost effectively– speed, the amount of ROM and RAM, the number of I/O ports
and timers, size, packaging, power consumption– easy to upgrade– cost per unit– Noise of environment
• availability of software development tools– assemblers, debuggers, C compilers, emulator, simulator,
technical support
• wide availability and reliable sources of the microcontrollers
Block Diagram
CPU
InterruptControl
OSC BusControl
4kROM
Timer 1Timer 2
Serial
128 bytes RAM
4 I/O Ports
TXD RXD
External Interrupts
P0 P2 P1 P3Addr/Data
8051 Internal Block Diagram8051 Internal Block Diagram
8051 Basic Component• 4K bytes internal ROM• 128 bytes internal RAM• Four 8-bit I/O ports (P0 - P3).• Two 16-bit timers/counters• One serial interface
RAM
I/O Port Timer
Serial COM Port
Microcontroller
CPUA single chip
ROM
1
23
45
6
7
8
9
10
11
1213
14
15
16
17
18
1920
40
3938
3736
35
34
33
32
31
30
2928
27
26
25
24
23
2221
P1.0
P1.1P1.2
P1.3P1.4
P1.5
P1.6
P1.7
RST(RXD)P3.0
(TXD)P3.1
(T0)P3.4
(T1)P3.5
XTAL2
XTAL1GND
(INT0)P3.2
(INT1)P3.3
(RD)P3.7
(WR)P3.6
Vcc
P0.0(AD0)P0.1(AD1)
P0.2(AD2)P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPPALE/PROG
PSENP2.7(A15)
P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)
P2.1(A9)
P2.0(A8)
8051(8031)(8751)(8951)
Port 0( pins 32-39)
• When connecting an 8051 to an external memory, the 8051 uses ports to send addresses and read instructions.
– 16-bit address: P0 provides both address A0-A7, P2 provides address A8-A15.
– Also, P0 provides data lines D0-D7.
• When P0 is used for address/data multiplexing, it is connected to the 74LS373 to latch the address.
I/O Port Programming
Pins of 8051
Port 2 (pins 21 through 28)
• Port 2 occupies a total of 8 pins.
• It can be used as input or output.
• Port 2 does not need any pull-up resistors since it already has pull-up resistors internally.
• Upon reset, port 2 is configured as an input port.
Port 1 is denoted by P1.P1.0 ~ P1.7P1 as an output port (i.e., write CPU data to the external pin)P1 as an input port (i.e., read pin data into CPU bus)
Port 1 ( pins 1-8 )
Port 3 ( pins 10-17 )
• Although port 3 is configured as an output port upon reset, this is not the way it is most commonly used.
• Port 3 has the additional function of providing signals.
– Serial communications signal : RxD, TxD
– External interrupt : /INT0, /INT1
– Timer/counter : T0, T1
– External memory accesses : /WR, /RD
• Vcc ( pin 40 ):– Vcc provides supply voltage to the chip.
– The voltage source is +5V.
• GND ( pin 20 ): ground
• XTAL1 and XTAL2 ( pins 19,18 ):– These 2 pins provide external clock.
• RST ( pin 9 ): reset
– It is an input pin and is active high ( normally low ) .
• Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost.
• /EA ( pin 31 ): external access
– The /EA pin is connected to GND to indicate the code is stored externally.
– For 8051, /EA pin is connected to Vcc.
– “/” means active low.
• /PSEN ( pin 29 ): program store enable
– This is an output pin and is connected to the OE pin of the ROM
• ALE ( pin 30 ): address latch enable
– It is an output pin and is active high.
– 8051 port 0 provides both address and data.
– The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch.
• I/O port pins
– The four ports P0, P1, P2, and P3.
– Each port uses 8 pins.
– All I/O pins are bi-directional.
• They are both 16 bit registers.• Each is to hold the address of a byte in memory• PC contains the address of the next instruction to be
executed.• DPTR is made up of two 8 bit register DPH and DPL;• DPTR contains the address of internal & external code and
data that has to be accessed.
Program Counter & Data Pointer
A and B CPU registers
• Totally 34 general purpose registers or working registers.• Two of these A and B hold results of many instructions,
particularly math and logical operations of 8051 cpu.• The other 32 are in four banks,B0 – B3 of eight registers each.• A(accumulator) is used for
addition,subtraction,mul,div,boolean bit manipulation and for data transfers.
• But B register can only be used for mul and div operations.
Stack Pointer
• The register used to access the stack is called SP (stack pointer) register.
• The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH. When 8051 powered up, the SP register contains value 07.
7FH
30H
2FH
20H1FH
17H10H
0FH
07H
08H
18H
00HRegister Bank 0
)Stack) Register Bank 1
Register Bank 2
Register Bank 3
Bit-Addressable RAM
Scratch pad RAM
PSW (program status word) register
Instruction Timing
• One “machine cycle” = 6 states (S1 - S6)• One state = 2 clock cycles– One “machine cycle” = 12 clock cycles
• Instructions take 1 - 4 cycles– e.g. 1 cycle instructions: ADD, MOV, SETB, NOP– e.g. 2 cycle instructions: JMP, JZ– 4 cycle instructions: MUL, DIV
• RAM memory space allocation in the 8051
7FH
30H
2FH
20H
1FH
17H
10H
0FH
07H
08H
18H
00HRegister Bank 0
)Stack) Register Bank 1
Register Bank 2
Register Bank 3
Bit-Addressable RAM
Scratch pad RAM
Memory Organization
Address Multiplexing for External Memory
Accessing external code memory
Accessing External Data Memory
Interface to 1K RAM
Timers/Counters
• A timer is a counter that is increased with every time an instruction is executed e.g. 8051 with 12MHz increases a counter every 1.000 µs
• General 8051 has 3 timer:– 2 16-bit timer– 1 16-bit timer with extra-
functionality (introduced with the 8052)
Timer/Counter Mode Control Register TMOD
Timer/Counter Control Register TCON
Uses of Timers & Counters
- Interval Timing- Periodic event timing- Time base for measurements- Event Counting-Baud Rate Generation
8051 Timers
- 2 timers (Timer 0 and Timer 1)- 16-bit timers (65,535) max- Flag is set when the timer overflows-Timers can be based on internal clock (OSC/6) or from external source (counter mode).TMOD - Timer/Counter mode registerTCON - Timer/Counter control register
TMOD Register:
• Gate : When set, timer only runs while INT(0,1) is high.
• C/T : Counter/Timer select bit.
• M1 : Mode bit 1.• M0 : Mode bit 0.
TCON Register:
• TF1: Timer 1 overflow flag. TR1: Timer 1 run control bit.• TF0: Timer 0 overflag. TR0: Timer 0 run control bit.• IE1: External interrupt 1 edge flag. IT1: External interrupt 1 type flag.• IE0: External interrupt 0 edge flag. IT0: External interrupt 0 type flag.
• TF: Overflow flag
– Set by hardware on Timer/Counter overflow
– Cleared by hardware when processor vectors to interrupt routine
• TR: Run control bit
– Set/Cleared by software to turn Timer/Counter on/off
• IE: Interrupt Edge flag
– Set by hardware when external interrupt edge detected
– Cleared when interrupt processed
• IT: Interrupt Type control bit
– Set/Cleared by software to specify falling edge/low level triggered external interrupts
Timer Modes
Mode 0: 13-Bit Timer
- Lower byte (TL0/TL1) + 5 bits of upper bytes (TH0/TH1).- Backward compatible to the 8048- Not generally used
Mode 1: 16-bit
- All 16 bits of the timer (TH0/TL0, TH1,TL1) are used.- Maximum count is 65,536-At 12Mhz, maximum interval is 65536 microseconds or 65.536 milliseconds- TF0 must be reset after each overflow- THx / TLx must be manually reloaded after each overflow.
Mode 2: 8-bit Auto Reload
- Only the lower byte (TLx) is used for counting.- Upper byte (THx) holds the value to reload into TLx after an overflow.- TFx must be manually cleared.- Maximum count is 256- Maximum interval is 256 Microseconds or .256 milliseconds
Mode 3- Split Timer
- Splits Timer 0 into two 8-bit timers- TL0 sets TF0- TH0 sets TF1- Timer 1 is available for other 3 modes, but the TF1 is not available.
Advantages of Microcontroller based System
• As the peripherals are integrated into a single chip, the overall system cost is very less
• The product is of small size compared to micro processor based system
• The system design now requires very little efforts
• As the peripherals are integrated with a microprocessor the system is more reliable
• Though microcontroller may have on chip ROM,RAM and I/O ports, addition ROM, RAM I/O ports may be interfaced externally if required
• On chip ROM provide a software security
Disadvantages of microprocessor
• The overall system cost is high
• A large sized PCB is required for assembling all the components
• Overall product design requires more time
• Physical size of the product is big
• A discrete components are used, the system is not reliable
Edsim51 Simulator diagram
References• www.wikipedia.org• https://iitg.vlab.co.in/• https://coep.vlab.co.in/• https://www.youtube.com/watch?v=95uGOJ1Ud2c&list=PLJGA4olwzpA-rvcdWULcRuMn2495g0n8j• Techmax Publication