Module I. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC.

Similar documents
e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

8051 Microcontrollers

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

MODULE-1. Short Answer Questions

8051 Microcontroller

8051 Microcontroller

8051 microcontrollers

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

1. Pin diagram of 8051 and ports

Microcontrollers. Fig. 1 gives a comparison of a microprocessor system and a microcontroller system.

Three criteria in Choosing a Microcontroller


UNIT IV MICROCONTROLLER

MICROCONTROLLER AND PLC LAB-436 SEMESTER-5

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

CS 320. Computer Architecture Core Architecture

UNIT MICROCONTROLLER AND ITS PROGRAMMING

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

ENE 334 Microprocessors

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Lecture 1. Course Overview and The 8051 Architecture

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

Question Bank Microprocessor and Microcontroller

Introduction To MCS-51

Engr. A. N. Aniedu Electronic and Computer Engineering Nnamdi Azikiwe University, Awka

CHAPTER 5 : Introduction to Intel 8085 Microprocessor Hardware BENG 2223 MICROPROCESSOR TECHNOLOGY

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

b. List different system buses of 8085 microprocessor and give function of each bus. (8) Answer:

8051 Overview and Instruction Set

Module Contents of the Module Hours COs

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

Moodle WILLINGDON COLLEGE SANGLI (B. SC.-II) Digital Electronics

EE6502- MICROPROCESSOR AND MICROCONTROLLER

Microcontrollers can be considered as self-contained systems with a processor, memory and I/O ports.

CPEG300 Embedded System Design. Lecture 3 Memory

ELEG3924 Microprocessor

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI

8051 MICROCONTROLLER

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip.

Embedded World Television, Radio, CD player, Washing Machine Microwave Oven Card readers, Palm devices

1 MALP ( ) Unit-1. (1) Draw and explain the internal architecture of 8085.

Department of Electronics and Instrumentation Engineering Question Bank

Microcomputer Architecture and Programming

THE 8051 MICROCONTROLLER Simple comparison: Pentium vs. 8051

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

8051 Microcontroller

UNIT 5. Microcontrollers. Syllabus

Microcontroller and Embedded Systems:

UNIT MICROCONTROLLER

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

MICROPROCESSOR MICROPROCESSOR. From the above description, we can draw the following block diagram to represent a microprocessor based system: Output

8051 Microcontroller memory Organization and its Applications

MCS-51 Serial Port A T 8 9 C 5 2 1

8/26/2010. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to Three Units of 8085

2. List the five interrupt pins available in INTR, TRAP, RST 7.5, RST 6.5, RST 5.5.

Microprocessor Architecture

12-Dec-11. Gursharan Singh Maninder Kaur. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to 8085


Principle and Interface Techniques of Microcontroller

Assembly Language programming (2)

Fig 1. Block diagram of a microcomputer

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

Control Unit: The control unit provides the necessary timing and control Microprocessor resembles a CPU exactly.

8051 MICROCONTROLLER

Fig 1. Block diagram of a microcomputer

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code:

Introducing The MCS 251 Microcontroller -- 8XC251SB


UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

C H A P T E R 1 INTRODUCTION

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Microcontroller and Applications

Chapter 9. Programming Framework

ET2640 Microprocessors

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

AVR Microcontrollers Architecture

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution


8051 Timers and Serial Port

ISSI. IS89C51 CMOS SINGLE CHIP 8-BIT MICROCONTROLLER with 4-Kbytes of FLASH ISSI IS89C51 NOVEMBER 1998 FEATURES GENERAL DESCRIPTION

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Microcontroller Intel [Instruction Set]

Basics of Microprocessor

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

Chapter 1: Basics of Microprocessor [08 M]

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following.

CPU CPU MEMORY MICRO CONTROLLER MICRO PROCESSER. Consists Memory, I/o ports. Memory, I/O Ports to be connected externally. MEMORY I/O PORTS I/O PORTS

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING YEAR : III SEM : VI

WINTER 14 EXAMINATION

History and Basic Processor Architecture

CHAPTER 1 MICROCOMPUTER SYSTEMS. 1.1 Introduction. 1.2 Microcontroller Evolution

Sencer Yeralan and Helen Emery Gainesville, Florida January 2000

The Timers/Counters The Serial Interface The Interrupt System Reset P0.0-P0.7 P2.0-P2.7. Port 2 Drivers. Port 2 Latch

Microprocessors/Microcontrollers

Figure Programming model

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

SOLUTION MANUAL FOR THE 8051 MICROCONTROLLER 4TH EDITION BY MACKENZIE AND PHAN

Transcription:

MICROCONTROLLERS AND APPLICATIONS 1 Module 1 Module I Introduction to Microcontrollers: Comparison with Microprocessors Harvard and Von Neumann Architectures - 80C51 microcontroller features - internal block schematic pin descriptions, I/O ports. INTRODUCTION TO MICROCONTROLLERS 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-todigital converters, random access memory, read only memory, etc. The I/O, memory, and onchip peripherals of a microcontroller 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. The 8051 is the first microcontroller of the MCS-51 family introduced by Intel Corporation at the end of the 1970s. The 8051 family with its many enhanced members enjoys the largest market share, estimated to be about 40%, among the various microcontroller architectures. Microcontrollers Microcontroller (MC) may be called computer on chip since it has basic features of microprocessor with internal ROM, RAM, Parallel and serial ports within single chip. Or we can say microprocessor with memory and ports is called as microcontroller. This is widely used in washing machines, vcd player, microwave oven, robotics or in industries. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC. 8 bit microcontroller, means it can read, write and process 8 bit data. Ex. 8051 microcontroller. Basically 8 bit specifies the size of data bus. 8 bit microcontroller means 8 bit data can travel on the data bus or we can read, write process 8 bit data. COMPARISON WITH MICROPROCESSORS 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

MICROCONTROLLERS AND APPLICATIONS 2 Module 1 RAM, ROM, I/O ports, timers and serial communication ports are in built. Because of this it is called as system on chip. 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.

MICROCONTROLLERS AND APPLICATIONS 3 Module 1 Microprocessor Microcontroller CPU is stand-alone, RAM,ROM, I/O, timer are separate CPU, RAM, ROM, I/O and timer are all on a single chip. Designer can decide on the amount of ROM, RAM and I/O ports. fixed amount of on-chip ROM,RAM, I/O ports versatility for applications in which cost,power and space are critical. general-purpose single-purpose Harvard and Von Neumann Architectures There are two computer architectures, which are different in the way of accessing memories: von Neumann Architecture and Harvard Architecture. In von Neumann architecture, programs and data are stored in the same memory and managed by the same information-handling subsystem. In the Harvard architecture program and data are stored and handled by different subsystems. Harvard architecture uses physically separate memories for their instructions and data, requiring dedicated buses for each of them. Instructions and operands can therefore be fetched simultaneously. Eg:8051 & PIC Microcontrollers Today, the vast majority of computers are von Neumann architecture because of the efficiency of design, implementation, and operation of one memory system instead of two. Under certain conditions, a Harvard computer can be much faster than a von Neumann computer because data and program do not contend for the same information pathway, and storing the program in an immutable read-only memory can result in vast reliability improvements.

MICROCONTROLLERS AND APPLICATIONS 4 Module 1 Features of von Neumann Architecture :- 1. Instructions and Data are stored in the same memory. 2. Instructions and Data share one memory system. Features of Harvard Architecture :- 1. Physically separates storage and signal pathway for instructions and data. 2. Generally, the bit of Instructions is wider than Data. 3. For some computers, the Instruction memory is read-only. 4. In cases without caches, the Harvard Architecture is more efficient than von-neumann. Bus structures of the two are also different: Harvard architecture has separate data and instruction busses, allowing transfers simultaneously on both busses. Von Neumann architecture has only one bus which is used for both data transfers and instruction fetches, and therefore data transfers and instruction fetches must be scheduled they cannot be performed at the same time.

MICROCONTROLLERS AND APPLICATIONS 5 Module 1 80C51 microcontroller The Intel 8051 is a Harvard architecture, single chip microcontroller (µc) which was developed by Intel in 1980 for use in embedded systems. This is mostly used microcontroller in the robotics, home appliances like mp3 player, washing machines, electronic iron and industries. Intel's official designation for the 8051 family of µcs is MCS 51.Many vendors such as Atmel, Philips, and Texas Instruments produce MCS-51 family microcontroller chips. The 8051 is an 8-bit microcontroller with 8 bit data bus and 16-bit address bus. The 16 bit address bus can address a 64K ( 2 16 ) byte code memory space and a separate 64K byte of data memory space. The 8051 has 4K on-chip read only code memory and 128 bytes of internal Random Access Memory (RAM). Intel's original 8051 family was developed using NMOS technology, but later versions, identified by a letter "C" in their name, e.g. 80C51, used CMOS technology and were less power-hungry than their NMOS predecessors - this made them eminently more suitable for battery-powered devices. Features of 8051 microcontroller are given as follows. 8-bit CPU 16-bit Program Counter 8-bit Processor Status Word (PSW) 8-bit Stack Pointer Internal RAM of 128bytes Special Function Registers (SFRs) of 128 bytes 32 I/O pins arranged as four 8-bit ports (P0 - P3) Two 16-bit timer/counters : T0 and T1 Two external and three internal vectored interrupts One full duplex serial I/O

MICROCONTROLLERS AND APPLICATIONS 6 Module 1 Internal Schematic of 80C51 microcontroller Mostly used blocks in the architecture of 8051 are as follows: 128 Byte RAM for Data Storage Fig: 8051 architecture 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 used for user space which is normally Register banks and stack. But other 128 byte RAM which consists of SFRs. Now what is the meaning of 128 byte RAM. What are address range which is provided for data storage. We will discuss here. We know that 128 byte = 2 7 byte

MICROCONTROLLERS AND APPLICATIONS 7 Module 1 Since 2 7 bytes so last 7 bits can be changed so total locations are from 00H to 7F H. This procedure of calculating the memory address is called as memory mapping. We can save data on memory locations from 00H to 7FH. Means total 128 byte space from 00H to 7FH is provided for data storage. 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. The address range can be calculated in the same way just like the RAM which is discussed in previous section. 4KB = 2 2. 2 10 B (since 1KB = 2 10 B = 2 12 Byte Address range of PC is 0000H to 0FFFH means total 4KB locations are available from 0000H to 0FFFH. At which we can save the program. Timers and 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

MICROCONTROLLERS AND APPLICATIONS 8 Module 1 program but in microcontroller two hardware pins are 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 can give 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. Two special function registers are available. If we want to load T0 with 16 bit data then we can load separate lower 8 bit in TL0 and higher 8 bit in TH0. In the same way for T1. TMOD, TCON registers are used for controlling timer operation. Serial Port There are two pins available for serial communication TXD and RXD. Normally TXD is used for transmitting serial data which is in SBUF register, RXD is used for receiving the serial data. SCON register is used for controlling the operation. Input Output Ports There are four input output ports available P0, P1, P2, P3. Each port is 8 bit wide and has special function register P0, P1, P2, P3 which are bit addressable means each bit can be set or reset by the Bit instructions (SETB for high, CLR for low) independently. The data at any port which is transmitting or receiving is in these registers. The port 0 can perform dual works. It is also used as Lower order address bus (A0 to A7) multiplexed with 8 bit data bus P0.0 to P0.7 is AD0 to AD7 respectively the address bus and data bus is demultiplexed by the ALE signal and latch which is further discussed in details.

MICROCONTROLLERS AND APPLICATIONS 9 Module 1 Port 2 can be used as I/O port as well as higher order address bus A8 to A15. Port 3 also have dual functions it can be worked as I/O as well as each pin of P3 has specific function. P3.0 RXD Serial I / P for Asynchronous communication/serial O / P for synchronous communication. P3.1 TXD Serial data transmit. P3.2 INT0 External Interrupt 0. P3.3 INT1 External Interrupt 1. P3.4 T0 Clock input for counter 0. P3.5 T1 Clock input for counter 1. P3.6 WR Signal for writing to external memory. P3.7 RD Signal for reading from external memory. When external memory is interfaced with 8051 then P0 and P2 can t be worked as I/O port they works as address bus and data bus, otherwise they can be accessed as I/O ports. Oscillator It is used for providing the clock to MC8051 which decides the speed or baud rate of MC. We use crystal which frequency vary from 4MHz to 30 MHz, normally we use 11.0592 MHz frequency. Interrupts Interrupts are defined as requests because they can be refused (masked) if they are not used, that is when an interrupt is acknowledged. A special set of events or routines are followed to handle the interrupts. These special routines are known as interrupt handler or interrupt service routines (ISR). These are located at a special location in memory. INT0 and INT1 are the pins for external interrupts.

MICROCONTROLLERS AND APPLICATIONS 10 Module 1 ALU Arithmetic Logical Unit This unit is used for the arithmetic calculations. A-Accumulator This register is used for arithmetic operations. This is also bit addressable and 8 bit register. B-Register This register is used in only two instructions MUL AB and DIV AB. This is also bit addressable and 8 bit register.

MICROCONTROLLERS AND APPLICATIONS 11 Module 1 PC-Program Counter Points to the address of next instruction to be executed from ROM. It is 16 bit register means the 8051 can access program address from 0000H to FFFFH. A total of 64KB of code. Initially PC has 0000H. ORG instruction is used to initialize the PC ORG 0000H means PC initialize by 0000H. PC is incremented after each instruction. ROM Memory Map in 8051 4KB, 8KB, 16KB, 32KB, 64KB on chip ROM is available. Max ROM space is 64 KB because 16 bit address line is available in 8051. Starting address for ROM is 0000H (because PC which points the ROM is 16 bit wide). 8051 Flag Bits and PSW Register Used to indicate the Arithmetic condition of ACC. Flag register in 8051 is called as program status word (PSW). This special function register PSW is also bit addressable and 8 bit wide means each bit can be set or reset independently. There are four flags in 8051 P Parity flag PSW 0.0 1 odd number of 1 in ACC 0 even number of 1 in ACC OV(PSW 0.2) overflow flag this is used to detect error in signed arithmetic operation. This is similar to carry flag but difference is only that carry flag is used for unsigned operation.

MICROCONTROLLERS AND APPLICATIONS 12 Module 1 Eg: for selecting Bank 1, we use following commands SETB PSW0.3 (means RS0=1) CLR PSW0.4 (means RS1=0). Initially by default always Bank 0 is selected. F0 user definable bit AC Auxiliary carry flag when carry is generated from D3 to D4, it is set to 1, it is used in BCD arithmetic. CY carry flag Affected after 8 bit addition and subtraction. It is used to detect error in unsigned arithmetic opr. We can also use it as single bit storage. SETB C for cy = 1 CLR C for cy = 0 Structure of RAM or 8051 Register Bank and Stack 128 byte RAM is available in 8051 128 byte = 2 7 B.Therefore address range of RAM is 00H to 7FH. In MC8051, 128 byte visible or user accessible RAM is available which is shown in figure. Extra 128B RAM which is not user accessible. 80H to FFH used for storage of SFR (special function register). Four Register Banks There are four register banks, in each register bank there are eight 8 bit register available from R0 to R7 By default Bank 0 is selected. Locations 20H to 2FH is bit addressable RAM means each bit from 00H to FFH in this we can set or reset CF rather than changing whole byte. Locations 30H to 7FH is used as scratch pad means we can use this space for data reading and writing or for data storage.

MICROCONTROLLERS AND APPLICATIONS 13 Module 1 Stack in 8051 RAM locations from 08H to 1FH can be used as stack. Stack is used to store the data temporarily. Stack is last in first out (LIFO) Stack pointer (SP) 8bit register to indicate current RAM address available for stack or it points the top of stack. Initially by default at 07H because first location of stack is 08H. After each PUSH instruction the SP is incremented by one while in MP after PUSH instruction SP is decremented. After each POP instruction the SP is decremented. DPTR Data Pointer in 8051 16 bit register, it is divided into two parts DPH and DPL. DPH for Higher order 8 bits, DPL for lower order 8 bits. DPTR, DPH, DPL these all are SFRs in 8051. Special Function Register RAM scratch pad, there is extra 128 byte RAM which is used to store the SFRs. Following figure shows special function bit address, all access to the four I/O ports CPU register, interrupt control register, timer/counter, UART, power control are performed through registers between 80H and FFH.

MICROCONTROLLERS AND APPLICATIONS 14 Module 1 Pin Descriptions of 80C51 Description of each pin is discussed here: VCC 5V supply VSS GND XTAL2/XTALI are for oscillator input Port 0 32 to 39 AD0/AD7 and P0.0 to P0.7 Port 1 1 to 8 P1.0 to P1.7 Port 2 21 to 28 P2.0 to P2.7 and A 8 to A15 Port 3 10 to 17 P3.0 to P3.7 P 3.0 RXD Serial data input SBUF P 3.1 TXD Serial data output SBUF P 3.2 INT0 External interrupt 0 TCON 0.1 P 3.3 INT1 External interrupt 1 TCON 0.3 P 3.4 T0 External timer 0 input TMOD

MICROCONTROLLERS AND APPLICATIONS 15 Module 1 P 3.5 T1 External timer 1 input TMOD P 3.6 WR External memory write cycle Active LOW P 3.7 RD External memory read cycle Active LOW RST for Restarting 8051 ALE Address latch enable 1 Address on AD 0 to AD 7 0 Data on AD 0 to AD 7 PSEN Program store enable

MICROCONTROLLERS AND APPLICATIONS 16 Module 1 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most registers. In other words, the positive voltage on this pin resets the microcontroller. By applying logic zero to this pin, the program starts execution from the beginning. Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides, all of them have alternative functions: Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication output. Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication clock output. Pin 12: INT0 Interrupt 0 input. Pin 13: INT1 Interrupt 1 input. Pin 14: T0 Counter 0 clock input. Pin 15: T1 Counter 1 clock input. Pin 16: WR Write to external (additional) RAM. Pin 17: RD Read from external RAM. Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz up to over 50 Hz. Pin 20: GND Ground.

MICROCONTROLLERS AND APPLICATIONS 17 Module 1 Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs. Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every time the microcontroller reads a byte from memory. Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both data and address transmission. Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. It means that even there is a program written to the microcontroller, it will not be executed. Instead, the program written to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal then external (if exists). Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0). Pin 40: VCC +5V power supply.

MICROCONTROLLERS AND APPLICATIONS 18 Module 1 I/O Ports There are four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as output, ready to be used as output ports. To use any of these ports as an input port, it must be programmed. Port 0: Port 0 occupies a total of 8 pins (pins 32-39).It can be used for input or output. To use the pins of port 0 as both input and output ports, each pin must be connected externally to a 10K ohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.Open drain is a term used for MOS chips in the same way that open collector is used for TTL chips. With external pull-up resistors connected upon reset, port 0 is configured as an output port. For example, the following code will continuously send out to port 0 the alternating values 55H and AAH. MOV A,#55H BACK: MOV P0,A ACALL DELAY CPL A SJMP BACK Port 0 as Input : With resistors connected to port 0, in order to make it an input, the port must be programmed by writing 1 to all the bits. In the following code, port 0 is configured first as an input port by writing 1 s to it, and then data is received from the port and sent to P1. MOV A,#0FFH ; A = FF hex MOV P0,A ; make P0 an input port BACK: MOV A,P0 ;get data from P0 MOV P1,A ;send it to port 1 SJMP BACK

MICROCONTROLLERS AND APPLICATIONS 19 Module 1 Dual role of port 0: Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. When connecting an 8051/31 to an external memory, port 0 provides both address and data. The 8051 multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but when ALE =1 it has address and data with the help of a 74LS373 latch. Port 1: Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or output. In contrast to port 0, this port does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, Port 1 is configured as an output port. For example, the following code will continuously send out to port1 the alternating values 55h & AAh. MOV A,#55H ; A = 55 hex BACK: MOV P1,A ;send it to Port 1 ACALL DELAY ;call delay routine CPL A ;make A=0 SJMP BACK Port 1 as input: To make port1 an input port, it must programmed as such by writing 1 to all its bits. In the following code port1 is configured first as an input port by writing 1 s to it, then data is received from the port and saved in R7,R6 & R5. MOV A,#0FFH ;A=FF HEX MOV P1,A ;make P1 an input port by writing all 1 s to it MOV A,P1 ;get data from P1 MOV R7,A ;save it in register R7 ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV R6,A ;save it in register R6 ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV R5,A ;save it in register R5 Port 2 : Port 2 occupies a total of 8 pins (pins 21-28). It can be used as input or output. Just like P1, P2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset,port 2 is configured as an output port. For example, the following code will send out continuously to port 2 the alternating values 55h and AAH. That is all the bits of port 2 toggle continuously. MOV A,#55H ; A = 55 hex BACK: MOV P2,A ;send it to Port 2 ACALL DELAY ;call delay routine CPL A ;make A=0 SJMP BACK

MICROCONTROLLERS AND APPLICATIONS 20 Module 1 Port 2 as input : To make port 2 an input, it must programmed as such by writing 1 to all its bits. In the following code, port 2 is configured first as an input port by writing 1 s to it. Then data is received from that port and is sent to P1 continuously. MOV A,#0FFH MOV P2,A BACK: MOV A,P2 MOV P1,A SJMP BACK ;A=FF hex ;make P2 an input port by writing all 1 s to it ;get data from P2 ;send it to Port1 ;keep doing that Dual role of port 2 : In systems based on the 8751, 8951, and DS5000, P2 is used as simple I/O. However, in 8031-based systems, port 2 must be used along with P0 to provide the 16-bit address for the external memory. As shown in pin configuration 8051, port 2 is also designed as A8-A15, indicating the dual function. Since an 8031 is capable of accessing 64K bytes of external memory, it needs a path for the 16 bits of the address. While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 of the address. In other words, when 8031 is connected to external memory, P2 is used for the upper 8 bits of the 16 bit address, and it cannot be used for I/O. Port 3 : Port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is configured as an output port upon reset. Port 3 has the additional function of providing some extremely important signals such as interrupts. This information applies both 8051 and 8031 chips.

MICROCONTROLLERS AND APPLICATIONS 21 Module 1 Functions of port 3 P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Bits P3.2 and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for timers 0 and 1. Finally P3.6 and P3.7 are used to provide the WR and RD signals of external memories connected in 8031 based systems. Read-modify-write feature : The ports in the 8051 can be accessed by the read-modify-write technique. This feature saves many lines of code by combining in a single instruction all three action of (1) reading the port, (2) modifying it, and (3) writing to the port. The following code first places 01010101 (binary) into port 1. Next, the instruction XLR P1,#0FFH performs an XOR logic operation on P1 with 1111 1111 (binary), and then writes the result back into P1. MOV P1,#55H ;P1=01010101 AGAIN: XLR P1,#0FFH ;EX-OR P1 with 1111 1111 ACALL DELAY SJMP AGAIN Single bit addressability of ports: There are times that we need to access only 1 or 2 bits of the port instead of the entire 8 bits. A powerful feature of 8051 I/O ports is their capability to access individual bits of the port without altering the rest of the bits in that port. For example, the following code toggles the bit p1.2 continuously. BACK: CPL P1.2 ACALL DELAY SJMP BACK ;complement p1.2 only Notice that P1.2 is the third bit of P1, since the first bit is P1.0, the second bit is P1.1, and so on. Notices in example of those unused portions of port1 are undisturbed. Table bellow shows the bits of 8051 I/O ports. This single bit addressability of I/O ports is one of the features of the 8051 microcontroller.

MICROCONTROLLERS AND APPLICATIONS 22 Module 1 REVIEW QUESTIONS 1. What is Microcontroller? 2. Differentiate between microprocessor and microcontroller. 3. List the features of 8051 microcontroller. 4. What are the advantages and disadvantages of using Harvard architecture in 8051? 5. Draw and explain the block diagram of 8051. 6. Explain the functional pin diagram of 8051 Microcontroller. 7. Name the five interrupt sources of 8051?. 8. What is the use of flags in 8051 microcontroller? 9. What is meant by interrupt? 10. Write a short note on Oscillator clock in 8051 microcontroller. 11. What are the I/O ports used in 8051 controller? 12. List and explain all SFRs ESSAY QUESTIONS 1. Describe the architecture of 8051 with neat diagram. 2. Explain the I/O port structure of 8051. 3. Explain the functional pin diagram of 8051 Microcontroller.