Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Overview
Introduction Block Diagram and Pin Description of the 8051 Timers Registers Interrupts
CPU
I/O Port
General-purpose microprocessor
CPU for Computers No RAM, ROM, I/O on CPU chip itself
4K bytes ROM 128 bytes RAM Four 8-bit I/O ports Two 16-bit timers 64K external code memory space 64K data memory space
The 8051 is a 40 pin device, and out of these 40 pins, 32 are used for I/O.
24 of these are dual purpose, i.e. they can operate as I/O or a control line or as part of address or data bus.
Vccpin 40 Vcc provides supply voltage to the chip. The voltage source is +5V. GNDpin 20ground XTAL1 and XTAL2pins 19,18 The time taken by an instruction to be executed is given by
T = (C*12d)/crystal frequency
ALEpin 30address 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
PORTS OF 8051
8051 has 4 Ports. Port 0, Port1, Port2 , Port3 Port 0 is a dual purpose port, it is located from pin 32 to pin 39 (8 pins). The pins serve as inputs, outputs, or, when used together, as a bidirectional low order address and data bus for external memory. When a pin is used as an input, a 1 must be written to the corresponding port 0 latch by the program. When used as an output, a 0 must be written.
Ports.
Port 1 is a dedicated I/O port from pin 1 to pin 8.Upon reset it is configured as outport. It is generally used for interfacing to external device thus if you need to connect to switches or LEDs, you could make use of these 8 pins.
Like port 0, port 2 is a dual-purpose port.(Pins 21 through 28) It can be used for general I/O or as the high byte of the address bus for designs with external code memory.
Ports contd
Port 3 is also dual purpose but designers generally avoid using this port unnecessarily for I/O because the pins have alternate functions which are related to special features of the 8051. Indiscriminate use of these pins may interfere with the normal operation of the 8051. However, for a programmer, it is the same to program P0, P1, P2 and P3. All the ports upon RESET are configured as output. To use any of the ports as an input port,it must be set(Programmed)
Alternate functions of P3
PSW REGISTER
CONTROL registers
Timers
Serial ports
Interrupt system
Timers /Counters
Timer/Counter 0 Timer/Counter 1
2.
An event counter.
Timer
Set the initial value of registers Start the timer and then the 8051 counts up. Input from internal system clock (machine cycle) When the registers equal to 0 and the 8051 sets a bit to denote time out
8051
P2 P1
TH0 TL0
Set Timer 0
to LCD
Counter
Show the number of events on registers External input from T0 input pin (P3.4) for Counter 0 External input from T1 input pin (P3.5) for Counter 1 External input from Tx input pin. We use Tx to denote T0 or T1. 8051
TH0
P1
TL0
to LCD
P3.4 a switch T0
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
Tcon contd
TR0 for Timer/counter 0; TR1 for Timer/counter 1. TR is set by programmer to turn timer/counter on/off. TR=0 : off (stop) TR=1 : on (start)
TF0 for timer/counter 0; TF1 for timer/counter 1. TF is like a carry. Originally, TF=0. When TH-TL roll over to 0000 from FFFFH, the TF is set to 1. TF=0 : not reach TF=1: reach
TMOD Register
(MSB) GATE C/T M1 Timer 1
(LSB) M0
Both Timer 0 &Timer 1 use the same Mode register TMOD. It is an-8-bit register .The lower 4-bits are meant for Timer 0 &the upper 4-bits are meant for Timer 1 It is not bit addressable. It is used similar to any other register of 8051 .
TMod contd.
C/T : Timer or counter selected cleared for timer operation (input from internal system clock). Set for counter operation (input from Tx input pin). M1,M0 : Used for mode selection.Because the Timers of 8051 can be set in 4different modes. M1 0 0 1 M0 0 0 or 1) 1 1 Mode 0 Operation 13-bit timer mode 8-bit THx + 5-bit TLx (x= 16-bit timer mode 8-bit auto reload 8-bit THx + 8-bit TLx 8-bit auto reload
0 2 timer/counter;
THx holds a value which is to be reloaded into TLx each time it overflows. 1 1 3 Split timer mode
TMod contd
Timer Mode-0
Setting timer x mode bits to 00 in the TMOD register results in using the THX register as a 8bit counter and TLX as a 5-bit register (lower bits). The upper 3-bits of TLX are indeterminate and should be ignored. The timer overflow flag in TCON is set whenever THX goes from FFh to 00h.
Timer Mode-2
(Auto-reload feature) TLX is used as a 8-bit counter only. THX is used to hold a value that is loaded into TLX every time TLX overflows from FFh to 00h. The time flag is also set when TLX overflows. The mode shows auto reload feature where TLX will be initialized to the content of THX after TLX overflows.
Timer Mode-3
Timer 1 in Mode-3 simply holds its count. The effect is the same as setting TR1=0. Timer 0 in Mode 3 establishes TL0 and TH0 as two sperate counters. Timer-1 can still be used in Mode-0,1 and 2 but no interrupt will be generated by Timer-1 while Timer-0 is in Mode-3.
8051 Interrupts
An interrupt is an external or internal event that disturbs the microcontroller to inform it that a device needs its service. A Microcontroller can serve various devices. The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler.
THANK YOU