EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 9 Simple I/O Interfacing

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

Assembly Language programming (2)

Microcontroller Intel [Instruction Set]

8051 I/O and Class 6 EE4380 Spring 03. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

8051 Microcontroller

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

INTERFACING 16 2 LCD WITH 8051

8051 Overview and Instruction Set

Digital Blocks Semiconductor IP

Assembly Language programming (3)

CHAPTER 1.0: INTRODUCTION TO AUTOMATION SYSTEM

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

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

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

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

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Programming of 8085 microprocessor and 8051 micro controller Study material

Application Brief D-005

FACULTY OF ENGINEERING LAB SHEET

SN8F5000 Family Instruction Set

Embedded Controller Programming

If I wanted to connect an LED and little light bulb and have them switch on and off with one switch, my schematic would look like the one below.

Module Contents of the Module Hours COs

MICROCONTROLLER BASED WATER LEVEL CONTROL SYSTEM

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING


Applications of 8051 Microcontrollers

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

CPEG300 Embedded System Design. Lecture Interface with Peripheral Devices

Experiment# 8: Photo-Interrupter Control

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

TUTORIAL Assembly Language programming (2)

8051 Interfacing and Applications Microcontroller

C51 Family. Architectural Overview of the C51 Family. Summary

Report Title: Digital Voltmeter using 89C51

~: Simple Programs in 8051 assembly language :~

Exercise 2. Switches EXERCISE OBJECTIVE DISCUSSION OUTLINE DISCUSSION. Introduction to switches. Switch types

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

Principle and Interface Techniques of Microcontroller

Memory & Simple I/O Interfacing

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

UNIT 9: RELAYS WHAT IS A RELAY (PRINCIPLE OF OPERATION)?

Microcontroller and Embedded Systems:

1. Pin diagram of 8051 and ports

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

Introduction To MCS-51

Highlights. FP51 (FPGA based 1T 8051 core)

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Principle and Interface Techniques of Microcontroller

Question Bank Microprocessor and Microcontroller

8051 Microcontroller Assembly Programming


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

Lab-Report Microprocessors

Q. Classify the instruction set of 8051 and list out the instructions in each type.

ELEG3923 Microprocessor Ch.9 Timer Programming

Microcontroller. Instruction set of 8051

ET2640 Microprocessors

Chapter 3. Bit Addressable Area. By DeccanRobots

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

8051 Programming using Assembly

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

DR bit RISC Microcontroller. Instructions set details ver 3.10

LCD AND KEYBOARD INTERFACING

8051 Microcontrollers

MICROPROCESSOR LABORATORY MANUAL

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

JUMP, LOOP AND CALL INSTRUCTIONS

Chapter Family Microcontrollers Instruction Set

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

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

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

What are output transducers An output transducer will convert electrical signals passed to it by the process into another form of energy.

Product Manual Dual Relay Board

1. LCD (Liquid Crystal Display)interface

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

DEV-1 HamStack Development Board

Application Brief D-002

Instruction Set Of 8051

Experiment #2 PLC Input Output Wiring Methods. OBJECTIVES After successfully completing this laboratory, you should be able to:

Application Note. Interfacing the X9241 XDCPs to 8051 Microcontrollers AN20. by Applications Staff, June 2000

;~~~~~~~~~~~~ ;P4-6-1.ASM ~ ;~~~~~~~~~~~~ SYMBOLS RS REG P2.0 EN REG P2.1 PICK REG P3.0 RELAY0 REG P3.1 RELAY1 REG P3.6 RELAY2 REG P3.

ELEG3923 Microprocessor Ch.4 I/O Ports

Dodatak. Skup instrukcija

8051 Microcontroller Logical Operations. Prepared by : A. B. Modi Target Audience : 5 th Semester Students

CONTENTS. 1.0 Introduction Description of the Circuit Installation Connection of Power Supply 4

Assembly Language programming (1)

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

Interrupt Programming: Interrupts vs. Polling Method:

Module 12: Elementary Input/Output

CPEG300 Embedded System Design. Lecture 8 Timer

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

CPEG300 Embedded System Design. Lecture 6 Interrupt System

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

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

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

Lecture (02) PIC16F84 (I)

Transcription:

Department of Electrical Engineering Lecture 9 Simple I/O Interfacing Week 10 1

In this Lecture. Interface 8051 with the following Input/Output Devices Switches Solenoid and relays LEDs Seven Segment Display Dot matrix display 2

Introduction The 8051 microcontroller is commonly used for real-world applications, e.g. display control, lighting control, machine control, etc. Various input and output devices are connected to the I/O ports of the microcontroller to deal with different applications. We will introduce some common I/O devices for simple application in this lecture. They are: Mechanical switches Electromagnetic relays Solid-state relays LEDs 7-segment Display Dot Matrix Display 3

Mechanical Switches Mechanical switches are common input devices One or more pairs of contacts that can be open or close. Typical switch designations are: SPST (single-pole-single-throw) SPDT (single-pole-double-throw) N.O. SPST N.O. DPST DPDT (double-pole-double-throw) N.O. DPST Normally open (N.O.) contacts close when the switch is activated and normally close (N.C.) contacts close when the switch is activated. 4

Connect mechanical switches to 8051 Reset EA V CC XTAL1 XTAL2 8051 V SS P3.7 P3.6 P3.5 P3.4 SW opens, input to 8051 is HIGH (1) SW closes, input to 8051 is LOW (0) +5V Figure 9.1 SW1 SW2 SW3 SW4 ORG 0000H : JNB P3.7, CASE1 JNB P3.6, CASE2 JNB P3.5, CASE3 JNB P3.4, CASE4 : CASE1: : Check the : status of SW1 : CASE2: : : CASE3: : : CASE4: : : 5

Electromagnetic Relays EEE3410 Microcontroller Applications Electromagnetic relay consists of two parts - solenoid and relay contacts Solenoid is a coil of wire used to produce a magnetic field to move a steel actuator where points of contacts are located. The actuator is used to close/open the contact points, such construction is called a relay. Figure 9.2 construction of a Electromagnetic relay 6

Driving an Electromagnetic Relays EEE3410 Microcontroller Applications Figure 9.3 show a typical driving circuit of an electromagnetic relay. The transistor will act as a switch to allow current passing through the solenoid. The diode placed across the coil terminal is to protect the transistor damaged from spike voltage during ON/OFF. The external circuit connected to relay terminals will be turned ON/OFF by the TTL. Contact closed if TTL = High Contact opened if TTL = Low TTL +5V Vs Figure 9.3 Driving circuit of an electromagnetic relay 7

Solid State Relays/Switches Solid-state relays has no mechanical parts and made of semiconductor materials It combines the isolation, driving, and contact closure functions into a single package It is commonly use to control ac loads Relay closed if input = High Relay opened if input = Low Input Control + SSR T1 T2 a.c. power supply Figure 9.4 Driving a solid state relay 8

Light-Emitting Diode (LED) Light-emitting diodes (LEDs) can be turned on when a current passes through it. Figure 9.5 Shows a typical TTL circuit driving a LED The 330Ω resistor is used to limit the amount of current to pass through the LED to prevent it burning off. The TTL output is LOW, the LED will ON The TTL output is HIGH, the LED will OFF +5V 330Ω TTL Figure 9.5 9

Control of LEDs +5V EA V CC Reset P1.7 P1.6 8 LEDs are connected to Port 1 and linked to 5V supply 8051 P1.5 P1.4 The LEDs can directly be turned ON/OFF by the 8051 XTAL1 XTAL2 V SS P1.3 P1.2 P1.1 P1.0 Figure 9.6 Under this connection, the LEDs will be OFF when port bit is at logic 1 ON when port bit is at logic 0 10

Example 9.1 : Control the 8 LEDs ON/OFF at the same time All LEDs ON All LEDs OFF 11

Program Listing for Example 9.1 Start Set A = 00 Move the content of A to P1 Delay for 0.1s Invert the content of A ORG 0000H CLR A LOOP: MOV P1, A CPL A ACALL DELAY AJMP LOOP DELAY: MOV R6, #250 DL1: MOV R7, #200 DL2: DJNZ R7, DL2 DJNZ R6, DL1 RET END Assume 12MHz clock, determine the delay time. 12

Example 9.2 : Glowing a LED in rotating sequence ORG 0000H START: MOV R1, #07H MOV A, #11111110B LEFT: MOV P1, A ACALL DELAY RL A DJNZ R1, LEFT ; MOV R1, #07H MOV A, #01111111B RIGHT: MOV P1, A ACALL DELAY RR A DJNZ R1, RIGHT AJMP START ; DELAY:. 13

Example 9.3: Turning LEDs ON/OFF in a preset sequence by using a Look-up Table 14

Program Listing of Example 9.3 ORG 0000H START: MOV R0, #OK DATA+1 MOV DPTR, #DATA MOV R1, #00H LOOP: MOV A, R1 MOVC A, @A+DPTR MOV P1, A ACALL DELAY INC R1 DJNZ R0, LOOP AJMP START ; DELAY: MOV R5, #2 DL1: MOV R6, #250 DL2: MOV R7, #200 DL3: DJNZ R7, DL3 DJNZ R6, DL2 DJNZ R5, DL1 RET ; DATA: DB 01111110B DB 00111100B DB 00011000B DB 00000000B DB 00011000B DB 00111100B DB 01111110B DB 11111111B ; DB 01111110B DB 00111100B DB 00011000B DB 00000000B DB 00011000B DB 00111100B DB 01111110B DB 11111111B ; DB 00000000B DB 11111111B DB 00000000B OK: DB 11111111B END 15

Exercise: Write a 8051 program, using a look-up table, to light-up the LEDs in the sequence as shown below 16

Simple I/O applications +5V EA V CC Reset XTAL1 8051 P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 Figure 9.7 XTAL2 P3.7 P3.6 P3.5 P3.4 SW1 SW2 SW3 SW4 V SS 17

Example 9.4: Refer to the 8051 circuit in figure 9.5, write a 8051 program to light-up the LEDs in the pattern as shown below when the respect switch is closed. When SW1 Closed When SW2 Closed When SW3 Closed When SW4 Closed Priority: SW1 SW2 SW3 SW4 18

Flow Chart of Example 9.4 2 Start SW1 closed? Y SW1 Handler 1 Initialization 2 N SW2 closed? Y SW2 Handler Set P3 as input port N SW3closed? Y SW3 Handler Read SW1 SW4 status N SW4 closed? Y SW4 Handler 1 19

Program Listing of Example 9.4 ORG 0000H MOV R1, #00000000B MOV R2, #01010101B MOV R3, #00001111B MOV R4, #11110000B ; TEST: ORL P3, #0FFH JNB P3.7, CASE1 JNB P3.6, CASE2 JNB P3.5, CASE3 JNB P3.4, CASE4 AJMP TEST ; CASE1: MOV A, R1 MOV P1, A ACALL DELAY XRL A, #11111111B MOV P1, A AJMP TEST ; CASE2 MOV A, R2 MOV P1, A ACALL DELAY XRL A, #10101010B MOV P1, A AJMP TEST ; CASE3 MOV A, R3 MOV P1, A ACALL DELAY XRL A, #11110000B MOV P1, A AJMP TEST ; CASE4 MOV A, R4 MOV P1, A ACALL DELAY XRL A, #00001111B MOV P1, A AJMP TEST ; DELAY:.. END 20

7-Segment LED Numeric Display A single-character display panel Contains 7 LED segments arranged as an 8 Two configurations: common-anode and common-cathode a f e g d b c Dp Segment Pattern 21

7-Segment LED Numeric Display Common-anode configuration Common a b c d e f g Dp Common-cathode configuration Common a b c d e f g Dp 22

7-Segment LED Numeric Display Segment displays are driven by connecting each segment to a port bit, or they can be driven by decoder/driver IC Output Port bit 7 6 5 4 3 2 1 0 Display segment Dp g f e d c b a Normally the LED should be connected to the power via resistors to protect them from burning When using common-cathode configuration, a segment will be lit only if the lead of the segment connected with a High voltage and the common cathode lead with Low voltage 23

7-Segment LED Numeric Display EEE3410 Microcontroller Applications XTAL1 XTAL2 8051 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 Vcc a b a c d f b g e f e c g Dp d Dp.. Figure 9.8 Use R3 as counter, write a 8051 assembly language program using look-up table method, to display the value in R3 to a 7-segment display 24

Program Listing ORG 0000H MOV R3, #00H LOOP: MOV DPTR, #TABLE MOV A, R3 MOVC A, @A+DPTR ; ; Display numbers on 7-segment display MOV P1, A ACALL DELAY ; ; Increase R3 by 1 and loop back MOV A, R3 ADD A, #1 DA A ANL A, #0FH MOV R3, A AJMP LOOP ; DELAY:.. TABLE: DB 11000000B ; 0 DB 11111001B ; 1 DB 10100100B ; 2 DB 10110000B ; 3 DB 10011001B ; 4 DB 10010010B ; 5 DB 10000010B ; 6 DB 11111000B ; 7 DB 10000000B ; 8 DB 10010000B ; 9 ; END 25

Dot-matrix LED Display Consists of a number of LED arranged in the form of a matrix e.g. 35 LED in a 5 columns x 7 rows matrix, or 64 LED in a 8 x 8 matrix a b c d e f g To display a digit/character, use the method of scanning 1 2 3 4 5 i.e. scan a column at a time. If the scanning is fast enough, it appears that the digit/character is displayed (due to illusion of our eyes) 26

Dot-matrix LED Display Internal circuitry of a 5 x 7 dot matrix display is shown on the right Voltage should be supplied to terminals C and 1 to light up the LED indicated in this picture a b c d e f g 1 2 3 4 5 27

Dot-matrix LED Display EA Reset 8051 XTAL1 XTAL2 Vcc V SS P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P1.0 P1.1 P1.2 P1.3 P1.4 1 2 3 4 5 a b c d e f g 28

Dot-matrix LED Display EEE3410 Microcontroller Applications Example: Displaying the character E on the dot-matrix. a b c d e fg a b c d e fg a b c d e fg a b c d e fg 1 2 3 4 5 isplaying the character E on the 5x7dot-matrix. 1 2 3 4 5 1 2 3 4 5 Step 1: signals on pins pins 12356 10000 pins gfedcba 1111111 Step 2: signals on pins pins 12356 01000 pins gfedcba 1001001 1 2 3 4 5 Step 3: signals on pins pins 12356 00100 pins gfedcba 1001001 a b c d e fg a b c d e fg Step 4: signals on pins pins 12356 00010 pins gfedcba 1001001 1 2 3 4 5 1 2 3 4 5 29

Code Words and Displays of 0 to 4 00111110B 01010001B 01001001B 01000101B 00111110B 00000000B 01000010B 01111111B 01000000B 00000000B 01000110B 01100001B 01010001B 01001001B 01000110B 00100001B 01000001B 01001001B 01001101B 00110011B 00011000B 00010100B 00010010B 01111111B 00010000B 30

Code Words and Displays of 5 to 9 00100111B 01000101B 01000101B 01000101B 00111001B 00111100B 01001010B 01001001B 01001001B 00110000B 00000001B 01111110B 01111001B 00000101B 00000011B 00110110B 01001001B 01001001B 01001001B 00110110B 00000110B 01001001B 01001001B 00101001B 00011110B 31

Program Listing character display on 5x7 Dot-matrix display (1/2) ORG 0000H START: MOV DPTR, #TABLE ; point to the starting add of 1 st char MOV R3, #10 ; display 10 characters LOOP: MOV R2, #100 ; scan 100 times for each character SCAN: ACALL SACN1 ; 10ms x 100 = 1000ms DJNZ R2, SCAN INC DPTR ; increase DPTR by 5 to INC DPTR ; point to the starting address of INC DPTR ; the next character INC DPTR INC DPTR DJNZ R3, LOOP ; loop back to display 10 char AJMP START ; ====================== ; == Scan Subroutine == ; ====================== SCAN1 MOV R1, #00H ; R1 points to the starting add of a char MOV R5, #11111110B ; start from the leftmost column MOV R4, #05 ; there are 5 columns LOOP1 MOV A, R1 ; get the code at add R1+DPTR MOVC A, @A+DPTR MOV P3, A ; send the code to the dot-matrix display MOV P1, R5 ; turn-on a particular transistor 32

Program Listing character display on 5x7 Dot-matrix display (2/2) MOV R6, #5 ; delay for 2ms DL1: MOV R7, #200 DL2: DJNZ R7, DL2 DJNZ R6, DL1 ORL P1, #11111111B ; turn-off display MOV A, R5 ; RL A ; move to next column MOV R5, A ; totally there are 5 columns INC R1 ; DJNZ R4, LOOP1 ; RET ; return the main program ; ============================ ; == Character Table == ; ============================ TABLE: DB 00111110B ; codes for 0 DB 01010001B DB 01001001B DB 01000101B DB 00111110B DB 00000000B ; code for 1 : ; codes for 2 to 9 : ; END 33

Department of Electrical Engineering END of Lecture 9 Simple I/O Interfacing Week 10 1