UNIT 3 THE 8051-REAL WORLD INTERFACING

Similar documents
8051 INTERFACING TO EXTERNAL MEMORY

CHAPTER 12 LCD AND KEYBOARD INTERFACING

Principle and Interface Techniques of Microcontroller

Interface DAC to a PC. Control Word of MC1480 DAC (or DAC 808) 8255 Design Example. Engineering 4862 Microprocessors

Chapter TEN. Memory and Memory Interfacing

Address connections Data connections Selection connections

RTC Interface 89C51 DS M. Krishna Kumar MAM/M7/LU17/V1/ Vcc VCC 5 SDA P1.0 6 SCL P KHz 3 BAT 3.

CHAPTER TWELVE - Memory Devices

Lecture Objectives. Introduction to Computing Chapter 0. Topics. Numbering Systems 04/09/2017

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

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

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

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

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


INTRO TO I/O INTERFACE

Allmost all systems contain two main types of memory :

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

Lecture-50 Intel 8255A: Programming and Operating Modes

ET2640. Unit 5:ADVANCED I/O TECHNIQUES Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458

Topics. Interfacing chips

Microprocessors/Microcontrollers

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

Microcontrollers. Principles and Applications. Ajit Pal +5 V 2K 8. 8 bit dip switch. P2 8 Reset switch Microcontroller AT89S52 100E +5 V. 2.

Microcontroller Systems. ELET 3232 Topic 11: General Memory Interfacing

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

MICROPROCESSORS & INTERFACING (A1423) C.Lokanath Reddy Assistant Professor.

CREATED BY M BILAL & Arslan Ahmad Shaad Visit:

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT IV I/O INTERFACING PART A (2 Marks)

Memory Expansion. Lecture Embedded Systems

8051 Interfacing and Applications Microcontroller

TOPIC 6 LATCH. FIGURE 1 INTERFACING OF ROM/EPROM TO µc 8051.

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Concept of Memory. The memory of computer is broadly categories into two categories:

Microcontroller and Embedded Systems:

Question Bank Microprocessor and Microcontroller

ECE 372 Microcontroller Design

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

9. PERIPHERAL CHIPS 9a

(Advanced) Computer Organization & Architechture. Prof. Dr. Hasan Hüseyin BALIK (5 th Week)

Microprocessor and Microcontroller question bank. 1 Distinguish between microprocessor and microcontroller.

ORG ; Week8. Memory and Memory Interfacing

EC 6504 MICROPROCESSOR AND MICROCONTROLLER

Summer 2003 Lecture 21 07/15/03

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

THE MICROCOMPUTER SYSTEM CHAPTER - 2

8051 Microcontroller

Read and Write Cycles

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

Introduction read-only memory random access memory

Computer Organization and Assembly Language (CS-506)


8254 is a programmable interval timer. Which is widely used in clock driven digital circuits. with out timer there will not be proper synchronization

Chapter 1: Basics of Microprocessor [08 M]


Memory & Simple I/O Interfacing

Developement of Multi Interface Board for Educational Trainer Kit

Chapter 19. Floppy Disk Controller Discussion. Floppy Disk Controller 127

output devices. connected to the controller. data communications link. relay systems. user program. MECH1500Quiz1ReviewVersion2 Name: Class: Date:

MICROPROCESSOR AND MICROCONTROLLER BASED SYSTEMS

Lab #2: Building the System

Chapter ELEVEN 8255 I/O PROGRAMMING

Reference Sheet for C112 Hardware

Description INPUT INTERFACING

COMP3221: Microprocessors and. and Embedded Systems. Overview. Lecture 23: Memory Systems (I)

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

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

A 3-SPEED STEPPER MOTOR

CPEG300 Embedded System Design. Lecture Interface with Peripheral Devices

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

EC6504 MICROPROCESSOR AND MICROCONTROLLER QUESTION BANK UNIT I - THE 8086 MICROPROCESSOR PART A

Contents. Main Memory Memory access time Memory cycle time. Types of Memory Unit RAM ROM

The Microcontroller Idea Book

Chapter 4 Main Memory

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

Unit 5 DOS INTERRPUTS

Microcontroller interfaces

UNIT - II PERIPHERAL INTERFACING WITH 8085

LCD AND KEYBOARD INTERFACING

Menu. word size # of words byte = 8 bits

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

Memory Overview. Overview - Memory Types 2/17/16. Curtis Nelson Walla Walla University

Answers to Chapter 2 Review Questions. 2. To convert controller signals into external signals that are used to control the machine or process

Three criteria in Choosing a Microcontroller

1. Internal Architecture of 8085 Microprocessor

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

MICROCONTROLLER BASED SMART FAN SYSTEM

I2C-AO112DIx I2C-Bus 4-20mA Analog Output Boards Din-Rail supports

This set of Microprocessor Multiple Choice Questions & Answers (MCQs) focuses on PIO 8255 (Programmable Input Output Port).

Input/Output Ports and Interfacing

Vidyalankar T.E. Sem. V [EXTC] Microprocessors and Microcontrollers I Prelim Question Paper Solution V SS (GND)

PAS 9737/AI-SMT ENGINEERING SPECIFICATION

Basics of Microprocessor

commodore semiconductor group NMOS 950 Rittenhouse Rd., Norristown, PA Tel.: 215/ TWX: 510/ (MEMORY, I/O, TIMER ARRAY)

CS 320 February 2, 2018 Ch 5 Memory

Bachelor of Engineering in Computer and Electronic Engineering

1. What is Microprocessor? Give the power supply & clock frequency of 8085?

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Summer 2003 Lecture 18 07/09/03

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

Transcription:

UNIT 3 THE 8051-REAL WORLD INTERFACING

8031/51 INTERFACING TO EXTERNAL MEMORY The number of bits that a semiconductor memory chip can store is called chip capacity It can be in units of Kbits (kilobits), Mbits (megabits), and so on This must be distinguished from the storage capacity of computer systems While the memory capacity of a memory IC chip is always given bits, the memory capacity of a computer system is given in bytes 16M memory chip 16 megabits A computer comes with 16M memory 16 megabytes Memory chips are organized into a number of locations within the IC Each location can hold 1 bit, 4 bits, 8 bits, or even 16 bits, depending on how it is designed internally The number of locations within a memory IC depends on the address pins The number of bits that each location can hold is always equal to the number of data pins To summarize A memory chip contain 2x location, where x is the number of address pins Each location contains y bits, where y is the number of data pins on the chip The entire chip will contain 2x y bits One of the most important characteristics of a memory chip is the speed at which its data can be accessed To access the data, the address is presented to the address pins, the READ pin is activated, and after a certain amount of time has elapsed, the data shows up at the data pins The shorter this elapsed time, the better, and consequently, the more expensive the memory chip The speed of the memory chip is commonly referred to as its access time 2

ROM is a type of memory that does not lose its contents when the power is turned off ROM is also called nonvolatile memory There are different types of read-only memory PROM EPROM EEPROM Flash EPROM Mask ROM The CPU provides the address of the data desired, but it is the job of the decoding circuitry to locate the selected memory block Memory chips have one or more pins called CS (chip select), which must be activated for the memory s contents to be accessed Sometimes the chip select is also referred to as chip enable (CE) In connecting a memory chip to the CPU, note the following points The data bus of the CPU is connected directly to the data pins of the memory chip Control signals RD (read) and WR (memory write) from the CPU are connected to the OE (output enable) and WE (write enable) pins of the memory chip In the case of the address buses, while the lower bits of the address from the CPU go directly to the memory chip address pins, the upper ones are used to activate the CS pin of the memory chip Normally memories are divided into blocks and the output of the decoder selects a given memory block Using simple logic gates Using the 74LS138 Using programmable logics The simplest way of decoding circuitry is the use of NAND or other gates The fact that the output of a NAND gate is active low, and that the CS pin is also active low makes them a perfect match 3

This is one of the most widely used address decoders The 3 inputs A, B, and C generate 8 activelow outputs Y0 Y7 Each Y output is connected to CS of a memory chip, allowing control of 8 memory blocks by a single 74LS138 In the 74LS138, where A, B, and C select which output is activated, there are three additional inputs, G2A, G2B, and G1 G2A and G2B are both active low, and G1 is active high If any one of the inputs G1, G2A, or G2B is not connected to an address signal, they must be activated permanently either by Vcc or ground, depending on the activation level 4

Other widely used decoders are programmable logic chips such as PAL and GAL chips One disadvantage of these chips is that one must have access to a PAL/GAL software and burner, whereas the 74LS138 needs neither of these The advantage of these chips is that they are much more versatile since they can be programmed for any combination of address ranges The 8031 chip is a ROMless version of the 8051 It is exactly like any member of the 8051 family as far as executing the instructions and features are concerned, but it has no on-chip ROM To make the 8031 execute 8051 code, it must be connected to external ROM memory containing the program code 8031 is ideal for many systems where the on-chip ROM of 8051 is not sufficient, since it allows the program size to be as large as 64K bytes For 8751/89C51/DS5000- based system, we connected the EA pin to Vcc to indicate that the program code is stored in the microcontroller s on-chip ROM To indicate that the program code is stored in external ROM, this pin must be connected to GND Since the PC (program counter) of the 8031/51 is 16-bit, it is capable of accessing up to 64K bytes of program code In the 8031/51, port 0 and port 2 provide the 16-bit address to access external memory P0 provides the lower 8 bit address A0 A7, and P2 provides the upper 8 bit address A8 A15 P0 is also used to provide the 8-bit data bus D0 D7 P0.0 P0.7 are used for both the addressand data paths address/data multiplexing ALE (address latch enable) pin is an output pin for 8031/51 ALE = 0, P0 is used for data path ALE = 1, P0 is used for address path 74LS373 D Latch To extract the address from the P0 pins we connect P0 to a 74LS373 and use the ALE pin to latch the address Normally ALE = 0, and P0 is used as a data bus, sending data out or bringing data in Whenever the 8031/51 wants to use P0 as an address bus, it puts the addresses A0 A7 on the P0 pins and activates ALE = 1 5

PSEN (program store enable) signal is an output signal for the 8031/51 microcontroller and must be connected to the OE pin of a ROM containing the program code It is important to emphasize the role of EA and PSEN when connecting the 8031/51 to external ROM When the EA pin is connected to GND, the 8031/51 fetches opcode from external ROM by using PSEN The connection of the PSEN pin to the OE pin of ROM In systems based on the 8751/89C51/ DS5000 where EA is connected to Vcc, these chips do not activate the PSEN pin This indicates that the on-chip ROM contains program code Connection to External Program ROM 6

7

Show the design of an 8031-based system with 8K bytes of program ROM and 8K bytes of data ROM. 8

speed control of a stepper motor The requirement is to use a microcontroller to drive a stepper motor in both forward and reverse directions of shaft rotation and to implement a two-speed (fast and slow) arrangement. Switches are to be used to produce the two speeds and effect a reversal of shaft rotation. A possible arrangement is shown in the block diagram, which uses a P89C664 microcontroller. 9

Generally a stepper motor has four sets of coils. One end of each coil may be connected together and then connected to DCsu pply. The remaining four ends may be driven through transistors either separately or in integrated circuit form. A four-bit code sequence continuously applied to the drive circuit from the microcontroller port causes the motor shaft to rotate in angular steps. Cheap (e.g. 12) stepper motors have step angles of 7.5 degrees whereas more expensive (e.g. 45) motors have step angles of 1.8 degrees. Step resolution and turning force (i.e. torque) may be improved by using a step-down gearbox. The stepping code sequence may be obtained from the motor manufacturer or distributor. The program in this example uses a common fourstep sequence of A 9 5 6 that, if sent continuously, would cause the motor shaft to rotate. Figure 7.8 shows the driving signals from the port pins. Sending the code in reverse 6 5 9 A causes the motor shaft rotation to reverse. The rotation speed depends on the delay each step is held for. Details of a suitable drive circuit are shown in Figure 7.9. The transistors (TR) must be chosen to easily handle the coil current. If the value of coil current is not given by the motor supplier then it is possible to measure the coil resistance with a multimeter (a typical value would be 15 ohms). Dividing Vcc by the coil resistance gives a good estimate of the coil current; double this value and select a transistor that has this current as its maximum-rated value. In this way the transistors will not run hot. The value of resistor R is chosen to control the input current of the transistor. The transistor current ratio is given in component catalogues as hfe, which is device forward current gain in commonemitter mode. In this circuit hfe is basically the coil current divided by the input current to the transistor. Thus the transistor input current is: input current=(coil current)=hfe The 74LS04 logic gate comprises eight inverter buffer circuits. Using two in series will restore the voltage level at the input to resistor R to the same value as the output from the relevant port pin. The voltage from the 74LS04 logic gate to turn on the transistor is 5 V. The voltage input to the transistor on the other side of the resistor is approximately 0.7 V; so the voltage difference across the resistor R is (5 _ 0:7)V ¼ 4:3V 10

The resistor value is given by: R ¼ ðvoltage across the resistorþ/input current R ¼ ð4:3 _ hfeþ=ðcoil currentþ A logic 1 (5 V) from the microcontroller port pin is applied through the two inverter gates of the 74LS04 to the resistor R. This sets up 0.7V to the transistor base that causes the transistor to behave as an electronic switch, turning the device on and allowing current to flow through the coil. The logic gates act as a buffer ensuring that the microcontroller port pin is not current loaded. The diodes D reduce the large induced voltages caused when the current is suddenly switched on or off. TIMER VALUES FOR ROTATION SPEED Consider a 7.5 degree stepper motor having a step sequence of A 9 5 6. Assume it is desired to make the shaft rotate at 60 revolutions per minute or one revolution every second. 360/7:5 ¼ 48 steps in a revolution and the program action will basically be step-delay; so this means 48 delays¼one revolution. 48 delays ¼ 1 s 1 delay ¼ ð1=48þ s ¼ 20:833 ms 11

8031/51 INTERFACING WITH THE 8255 (a) Find the I/O port addresses assigned to ports A, B, C, and the control register. (b) Program the 8255 for ports A, B, and C to be output ports. (c) Write a program to send 55H and AAH to all ports continuously. Solution (a) The base address for the 8255 is as follows: (b) The control byte (word) for all ports as output is 80H as seen in 12

Example 15-1. For Figure above. 13

(a) Find the I/O port addresses assigned to ports A, B, C, and the control register. (b) Find the control byte for PA = in, PB = out, PC = out. (c) Write a program to get data from PA and send it to both B and C. Solution: (a) Assuming all the unused bits are 0s, the base port address for 8255 is 1000H. Therefore we have: 1000H PA 1001H PB 1002H PC 1003H Control register (b) The control word is 10010000, or 90H. LCD AND KEYBOARD INTERFACING LCD is finding widespread use replacing LEDs The declining prices of LCD The ability to display numbers, characters,and graphics Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD Ease of programming for characters and graphics 14

15

16

Keyboards are organized in a matrix of rows and columns The CPU accesses both rows and columns through ports Therefore, with two 8-bit ports, an 8 x 8 matrix of keys can be connected to a microprocessor When a key is pressed, a row and a column make a contact Otherwise, there is no connection between rows and columns In IBM PC keyboards, a single microcontroller takes care of hardware and software interfacing A 4x4 matrix connected to two ports The rows are connected to an output port and the columns are connected to an input port It is the function of the microcontroller to scan the keyboard continuously to detect and identify the key pressed To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch, then it reads the columns If the data read from columns is D3 D0 = 1111, no key has been pressed and the process continues till key press is detected If one of the column bits has a zero, this means that a key press has occurred For example, if D3 D0 = 1101, this means that a key in the D1 column has been pressed After detecting a key press, microcontroller Starting with the top row, the microcontroller grounds it by providing a low to row D0 only 17

It reads the columns, if the data read is all 1s, no key in that row is activated and the process is moved to the next row It grounds the next row, reads the columns, and checks for any zero This process continues until the row is identified After identification of the row in which the key has been pressed Find out which column the pressed key belongs to Program 12-4 for detection and identification of key activation goes through the following stages: 1. To make sure that the preceding key has been released, 0s are output to all rows at once, and the columns are read and checked repeatedly until all the columns are high When all columns are found to be high, the program waits for a short amount of time before it goes to the next stage of waiting for a key to be pressed To see if any key is pressed, the columns are scanned over and over in an infinite loop until one of them has a 0 on it Remember that the output latches connected to rows still have their initial zeros (provided in stage 1), making them grounded 18

After the key press detection, it waits 20 ms for the bounce and then scans the columns again (a) it ensures that the first key press detection was not an erroneous one due a spike noise (b) the key press. If after the 20-ms delay the key is still pressed, it goes back into the loop to detect a real key press To detect which row key press belongs to, it grounds one row at a time, reading the columns each time If it finds that all columns are high, this means that the key press cannot belong to that row Therefore, it grounds the next row and continues until it finds the row the key press belongs to Upon finding the row that the key press belongs to, it sets up the starting address for the look-up table holding the scan codes (or ASCII) for that row 4. To identify the key press, it rotates the column bits, one bit at a time, into the carry flag and checks to see if it is low Upon finding the zero, it pulls out the ASCII code for that key from the look-up table otherwise, it increments the pointer to point to the next Element of the look-up table 19

20

21

INTERFACING ADC ADCs (analog-to-digital converters) are among the most widely used devices for data acquisition A physical quantity, like temperature, pressure, humidity, and velocity, etc., is converted to electrical (voltage, current) signals using a device called a transducer, or sensor We need an analog-to-digital converter to translate the analog signals to digital numbers, so microcontroller can read them ADC804 IC is an analog-to-digital converter It works with +5 volts and has a resolution of 8 bits Conversion time is another major factor in judging an ADC Conversion time is defined as the time it takes the ADC to convert the analog input to a digital (binary) number In ADC804 conversion time varies depending on the clocking signals applied to CLK R and CLK IN pins, but it cannot be faster than 110 µs CLK IN and CLK R CLK IN is an input pin connected to an external clock source To use the internal clock generator (also called self-clocking), CLK IN and CLK R pins are connected to a capacitor and a resistor, and the clock frequency is determined by Typical values are R = 10K ohms and C = 150 pf 22

We get f = 606 khz and the conversion time is 110 µs Vref/2 It is used for the reference voltage If this pin is open (not connected), the analog input voltage is in the range of 0 to 5 volts (the same as the Vcc pin) If the analog input range needs to be 0 to 4 volts, Vref/2 is connected to 2 volts D0-D7 The digital data output pins These are tri-state buffered The converted data is accessed only when CS = 0 and RD is forced low To calculate the output voltage, use the following formula Dout = digital data output (in decimal), Vin = analog voltage, and step size (resolution) is the smallest change Analog ground and digital ground Analog ground is connected to the ground of the analog Vin Digital ground is connected to the ground of the Vcc pin To isolate the analog Vin signal from transient voltages caused by digital switching of the output D0 D7 This contributes to the accuracy of the digital data output The following steps must be followed for data conversion by the ADC804 chip Make CS = 0 and send a low-to-high pulse to pin WR to start conversion Keep monitoring the INTR pin If INTR is low, the conversion is finished If the INTR is high, keep polling until it goes low 23

After the INTR has become low, we make CS = 0 and send a high-to-low pulse to the RD pin to get the data out of the ADC804 24

the following is a program for the ADC connected to 8255 as show in fig 15-11 25

A unique feature 8255 of port C The bits can be controlled individually low any of the PC0 to PC7, see figure. BSR mode allows one to set to high or INTERFACING ADC THROUGH 8255 26

INTERFACING thermistor A thermistor responds to temperature change by changing resistance, but its response is not linear The complexity associated with writing software for such nonlinear devices has led many manufacturers to market the linear temperature sensor The sensors of the LM34/LM35 series are precision integrated-circuit temperature sensors whose output voltage is linearly proportional to the Fahrenheit/Celsius temperature The LM34/LM35 requires no external calibration since it is inherently calibrated It outputs 10 mv for each degree of Fahrenheit/Celsius temperature Signal conditioning is a widely used term in the world of data acquisition It is the conversion of the signals (voltage, current, charge, capacitance, and resistance) produced by transducers to voltage, which is sent to the input of an Ato- D converter Signal conditioning can be a current-tovoltage conversion or a signal amplification The thermistor changes resistance with temperature, while the change of resistance must be translated into voltage in order to be of any use to an ADC 27

Example: Look at the case of connecting an LM35 to an ADC804. Since the ADC804 has 8-bit resolution with a maximum of 256 steps and the LM35 (or LM34) produces 10 mv for every degree of temperature change, we can condition Vin of the ADC804 to produce a Vout of 2560 mv full-scale output. Therefore, in order to produce the fullscale Vout of 2.56 V for the ADC804, We need to set Vref/2 = 1.28. This makes Vout of the ADC804 correspond directly to the temperature as monitored by the LM35. 28

SELF CHECK What is the maximum size of memory that can be connected with 8051? What would be the statues of EA pin when a external memory is connected? Can a 10 bit ADC be connected with 8051 through 8255? How will you vary the Speed of the STEPPER MOTOR? What is a LINEAR THERMISTOR? 29

QUESTIONS: 1. Draw the Block diagram and explain the operations of 8255 communication interface. 2. Draw the Diagram of ADC and explain the functions of each pin 3. Sketch and explain the interface of PPI 8255 to the 8051. 4.Interface 4 7 segment LEDs to display as a BCD counter 8. Sketch and explain the interface of ADC to the 8051 microcontroller 9. Interface 8x8 key pad with 8051 10. Discuss in detail stepper motor interfacing with 8051. 11.Discuss in detail the interfacing of relay and optocouplers with 8051. 12.Write a 8051 assembly language program to interface a stepper motor and make to rotate in clockwise for 5 times continuously. Find the time required to execute the program. Mention the machine cycles. 13.Write a 8051 assembly language program to interface a 8255 in mode 0. Read the status of the switch from PORT A. Complement it and Blink the corresponding LEDs of PORT B.Find the time required to execute the program. Mention the machine cycles and T-States. 14.Discuss in detail the interfacing of thermistor with 8051. 15.Discuss in detail the interfacing of DAC with 8051. 30