Name: …………………………… Student ID: ………………… Name: …………………………… Student ID: …………………

Laboratory 01 MCS-51 I/O Port 1. Objective 1. Learn to program MCS-51 (NXP’s P89V51RD2) using EX-51 Plus experimental board. 2. Learn to access I/O port of MCS-51 using assembly language

Fig. 1 Schematic of the EX-51 Plus ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

2

2. Background Knowledge EX-51 Plus is an experimental board designed based on P89V51RD2. It includes several external Input/output devices such as a LED array, a 7-segment display, a matrix switch, a buzzer, a relay, an ADC, switches, etc. Its schematic is shown in Fig.1. In this lab we will write assembly programs to control the LED array, receive input from the switches, and drive 7-segment display. Therefore it will be very helpful to review the operation of those devices.

2.1 Driving LED from logic gate LED is often used as a status of the I/O port. This experiment shows how to make direct connection of LEDs to the output of the logic. The LED is a semiconductor diode, and behaves electrically as one. It will conduct current in one direction, called the forward direction, but not the other. What makes it so useful is that when it is connected so that it conducts; it emits photons from its semiconductor junction. The LED has the voltage/current characteristic shown in Fig. 2a. A small forward voltage will cause very little current to flow. As the voltage increases there comes a point where the current suddenly starts flowing rather rapidly. For most LEDs this voltage is in the range shown, typically around 1.8 V.

(a) LED V-I characteristic

(b) Gate output sourcing current

(c) Gate output sinking current

Fig. 2 LED and its connections to the logic gate output ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

3

Fig. 2 (b) and (c) show circuits used to make direct connections of LEDs to the output of logic gates. There are three important points to be observed 1) The connection of Fig. 2 (b) makes the LED lights when the gate is at logic high. 2) The connection of Fig. 15(c) makes the LED lights when the logic gate is at logic zero 3) A current-limiting resistor needs to be connected in series with the LED, to control how much current flow.

Fig. 3 LED and its terminal marking

2.2 7-segment display The 7-segment display consists of seven LEDs (hence its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is called a segment because when illuminated the segment forms part of a numerical digit to be displayed. An additional 8th LED allows the indication of a decimal point, (DP) when two or more 7-segment displays are connected to-gether to display numbers greater than ten. Each one of the seven LEDs in the display is given a positional segment with one of its connection pins being brought straight out of the rectangular plastic package. These individ-ually LED pins are labeled from a through to g representing each individual LED. The other LED pins are connected together and wired to form a common pin. The displays common pin is generally used to identify which type of 7-segment display it is. As each LED has two connecting pins, one called the “Anode” and the other called the “Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode (CC) and Common Anode(CA).

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

4

Fig.4 A common cathode 7-segment display and a common anode 7-segment display 1. The Common Cathode (CC) – All the cathode connections of the LED segments are joined together to logic “0” or ground. The individual segments are illuminated by applica-tion of a “HIGH”, or logic “1” signal via a current limiting resistor to forward bias the individ-ual Anode terminals (a-g). 2. The Common Anode (CA) – All the anode connections of the LED segments are joined together to logic “1”. The individual segments are illuminated by applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the Cathode of the particular segment (a-g). In general, common anode displays are more popular as many logic circuits can sink more current than they can source. Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased. For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Then the various digits from 0 through 9 can be displayed using a 7-segment display as shown. Driving a 7-segment Display In this example, the segments of a common cathode display are illuminated using the switches. If switch “a” is closed, current will flow through the “a” segment of the LED to the current limiting resistor connected to pin a and to 0 volts, making the circuit. Then only segment a will be illuminated. So a LOW condition (switch to ground) is required to activate the LED segments on this common anode display.

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

5

Fig 5. Binary codes for control switches and its corresponding numbers When need to display more than one digit, switches and digit selector signals are required. As shown in Fig. 6 and Fig.7 for the common anode and the common cathode respectively. From Fig.6 each segment on each display is wired together, and connected back to a microcontroller pin configured as digital output. The common anode of each digit is then connected to its own switch using BJT PNP Transistor (such as A1015). When a select digit signal is LOW, it turns on the switch to connect that digit to its Vsupply. Thus, it enable that digit to display. The timing diagram shown then applies. The segment drives are configured for Digit 1, and that digit’s drive transistor is activated, illuminating the digit. A moment later the segment drives are configured for Digit 2, and that digit’s drive transistor is activated. This continues endlessly with each digit in turn. If it is done rapidly enough, then the human eye perceives all digits as being continuously illuminated; a useful rate is for each digit to be illuminated in turn for around 5 ms. Vsupply

Select Digits

R4

E B

A1015 C

B

E A1015 C

R3

Drive Segments

R3

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports Data to segments

6 Digit 1

Digit 2

Digit 1

Digit 2

Select Digit 1

Select Digit 2

Fig. 6 Schematics and timing diagram for 2 digit display using the common anode For the common cathode, the schematic and its timing diagram is shown in Fig.7. The differences are BJT PNP Transistors (such as C1815) is used instead and the logics to drive the segments and select the digits are opposite to those of the common anode. R3

Drive Segments

R3

R4 Select Digits

C B

C1815

C B

E

E

Data to segments

Digit 1

Digit 2

C1815

Digit 1

Digit 2

Select Digit 1

Select Digit 2

Fig. 7 Schematics and timing diagram for 2 digit display using the common cathode

2.3 Matrix Switch (Keypad) Matrix switch is an arrangement of multiple switches into two-dimensional array. Typically, each push button switch is connected to each input port. Thus, for m input switches, m input ports are ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

7

required. However, if m switches are arranged in 2-D array as n columns x o rows where m = n x o, it will require only n + o input ports. This clearly reduces number of input port required since n + o is always less than m. In this arrangement such as a 4x4 matrix as shown in Fig.8, each push button is placed at each intersection between rows and columns. When closed, it will connect only one row and column together. That row and column will have the same logic state. Therefore it is easily to identify whether which switch is pressed by detecting the column and row input that have the same logic state.

Col0 Col1 Col2 Col3 Row0 Row1 Row2 Row3

Fig.8. 4x4 keypad

2.4 Program Flash Magic Flash Magic is a utility to program (i.e. download) the Intel’s hex code to the internal flash memory of the MCU. It supports several MCU families. Please read the user guide for more detail. Steps for programming 1. Connect board EX-51 to USB port of your computer using a serial-to-USB adapter (FTDI). Turn off EX-51’s power switch. 2. Start Flash Magic

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

8

3. Disable DTR control: Options > Advanced Options > Hardware Config >

Uncheck Use DRT to control RST 4. Set up for download Step 1 Setup Communication: Select Device: 89V51RD2

COM Port:(depend on your computer)

Step 2 Check Erase all Flash Step 3 Browse hex file to be downloaded Step 4 Check Verify after programming Step 5 Click Start. When a Reset Device window pops up, turn on EX-51’s power switch. Wait until it finishes programming and verifying. Then press the reset switch on EX-51 to start your program.

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

9

3. Experiment 3.1 Driving a LED array 3.11 Set up a circuit as shown in Fig.9 3.12 Test the circuit using an assembly file 101.asm. 3.13 Modify file 101.asm to perform the following:  Make a pair of LEDs flashing simultaneously; begin from the outer pair (LED1 and LED8) and precede to the center pair (LED4 and LED5) then reverse its direction.

Fig.9 3.2 Polling input from switches to control a LED array In this experiment we will use a polling technique to monitor two push button switches connected at P3.2 and P3.3. Practically, a single push on a mechanical switch can actually create a multiple connecting (on) and disconnecting (off) alternatively between its contacts for a moment. This is known as switch bouncing. Switch bouncing can result in a wrong input data if it is read immediately. One way to avoid this pitfall is to wait until the switch reaches a stable state before read it. This can be accomplished by reading the input from the switch for a second time after a certain amount of delay to ensure that the input is already stable. Note that an alternate function of P3.2 and P3.3 is Interrupt input. In this program, however after the system reset, the interrupt is disable therefore both pins function as a general I/O port. ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

10

Fig.10 3.2.1 Set up a circuit according to schematic shown in Fig.10 3.2.2 Test the circuit using an assembly file 202.asm. What happen when press S1 one time………………………………………………………………………………………… What happen when press S2 one time………………………………………………………………………………………… What happen when press and hold S1………………………………………………………………………………………… What happen when press and hold S2………………………………………………………………………………………… 3.2.3 Remove a part of the program that prevents an error from switch bouncing. Test the circuit again as in 3.2.2. Compare both results. Can you draw any conclusion? …………………………………………………………………………………………………………………………………………………………… …………………………………………………………………………………………………………………………………………………………… 3.2.3 Write a program to performs as follows When start the program all LEDs are turned off.  Each time that S1 is pressed a LED is turned on beginning from LED8, then LED7 and so on.  Each time that S2 is pressed a LED is turned on beginning from LED1, then LED2 and so on. Whenever all LED are turned on  Each time that S1 is pressed a LED is turned off beginning from LED8, then LED7 and so on.  Each time that S2 is pressed a LED is turned off beginning from LED1, then LED2 and so on.

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

11

3.3 Drive a single digit 7-segment display

Fig.11 3.3.1 Set up a circuit as shown in Fig.11 3.3.2 Test the circuit using an assembly file 301.asm. In file 301.asm, observe how to use directive EQU to define a constant for each 7-segment number without storing them in EEPROM, and how to select between digit1 (DSP1) and digit2 (DSP2). 3.3.3 Modify file 301.asm to perform as follows After pressing S1, it continues to display only the odd number and after pressing S2, it continues to display only even number.

3.4 Stop Watch (Double-digit display) 3.4.1 Set up a circuit as shown in Fig.11 3.4.2 Test the circuit using an assembly file 302.asm The program works similar to a stopwatch. After it is reset, both DSPs display “00”. S2 is the START/STOP switch. When press S2 it starts counting, press again it will stop. S1 is the CLEAR switch. Press S1 to clear counter to be “00”. In file 302.am, observe how to use DB to reserve memory spaces for each 7-segment number. How to use indexed addressing to read each 7-segment number. 3.4.3 Modify the program to make it as a count down counter. After resetting, both DSPs display “FF”. When press S2 it start to count down, press again it will stop counting. S1 is the SET switch. ECG 330 Microprocessors and Interfacing Laboratory

MUIC

Laboratory 01: MCS-51 I/0 Ports

12

Press S1 will set counter to be “FF”. When the counter counts down and reaches “00” by itself, it then flashes “00” two times before stop counting.

4. References 1. User’s Guide EX-51: MCS-51 Experimental Board P89V51RD2, Innovative Experiment, 2011 2. Rob Toulson and Tim Wilmshurst, Fast and Effective Embedded Systems Design, Elsevier, 2012 3. Wikipedia (for some pictures)

5. Appendix Schematic for peripheral ICs

74HC573 D-Latch with Tri-state Output

The 74HC541 is an octal noninverting buffer/line driver with 3-state outputs. The device features two output enables (OE1 and OE2). A HIGH on OEn causes the outputs to assume a high impedance OFF-state. Inputs include clamp diodes that enable the use of current limiting resistors to interface inputs to voltages in excess of VCC. Maximum output current is ± 35 mA

ECG 330 Microprocessors and Interfacing Laboratory

MUIC

The Common Cathode

An additional 8th LED allows the indication of a decimal point, (DP) when two or more 7-segment displays are ... Depending upon the decimal digit to be displayed, the particular set of. LEDs is forward biased. For instance, to display the .... 3.4 Stop Watch (Double-digit display). 3.4.1 Set up a circuit as shown in Fig.11.

2MB Sizes 0 Downloads 134 Views

Recommend Documents

Cathode Ray Tube Notes.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Cathode Ray ...

Plasmonic cathode research at UCLA - shortv2.pdf
E. Threkheld, UCLA. • H. Padmore, A. Polyakov, LBNL. • F. Hannon, JLAB. • Funding agencies: DOE STTR, Radiabeam Technologies, NSF. Page 2 of 15 ...

Cathode Ray Tubes and the Millikan Oil Drop Experiment Notes Blank ...
Download. Connect more apps... Try one of the apps below to open or edit this item. Cathode Ray Tubes and the Millikan Oil Drop Experiment Notes Blank.pdf.

The Common Link
In light of the 125th Anniversary Celebration for our Diocese, I thought this would be a perfect time to revisit the history of Catholic Education here in Mitchell, as well as the history of our Foundation. I tend to assume (which we all know what ha

The Value of a Common Foundation 1.1
for software development, and its deployment in higher education. .... but make the loop far easier to close by making its elements more visible and transparent.

The Value of a Common Foundation 1.1
for software development, and its deployment in higher education. If you feel that you are familiar with open source software and its benefits, both in a general ...

The Value of a Common Foundation 1.1
source in education initiatives, Jasig and The Sakai Foundation, chartered the Jasig-‐Sakai Joint ... mainstream of the information technology landscape.

Treatment of the Common Cold
Feb 15, 2007 - Sutter AI, Lemiengre M, Campbell H, Mackinnon HF. Antihistamines for the common ... at: http://www.aafp.org/afp/ otcmonograph/index.html. 12.

Treatment of the Common Cold
Feb 15, 2007 - University of Pittsburgh Medical Center, Pittsburgh, Pennsylvania ..... Data regarding prophylactic use of vitamin C are more varied. Thirty trials ... Philadelphia, Pa., and completed a pediatrics residency at Children's. Hospital ...

man-91\common-the-rapper.pdf
LIST EBOOK RELATED TO COMMON THE RAPPER PDF. 1. PDF Ebook : Pal ... 6. PDF Ebook : Common Flu. 7. PDF Ebook : Common Law Llb Notes. 8. PDF Ebook : Common As 400 Commands. 9. PDF Ebook : Common Lcd Tv Problems. 10. PDF Ebook ... PDF Ebook : Most Commo

PDF CUPS: Common UNIX Printing System: Common ...
CUPS: Common UNIX Printing System is first on the scene with CUPS ... author's picking apart of IPP transactions and the CUPS API for programmers writing ...

Greatest Common Factor/Greatest Common Factor
Mr Mohit Paul, Mr Kunal Bahri and Ms Astha Nigam ... Greatest Common Factor/Greatest Common Factor - (20 Multiple Choices Questions) Quiz Assignment.pdf.

Common Cause.pdf
another raid by the Income Tax Department on the very. next day. The raid by the C.B.I. reportedly led to. recovery of incriminating documents and unaccounted.

Emailing- Common Phrases - UsingEnglish.com
I look forward to your quick reply. I look forward to hearing from you soon./ I expect to hear from you soon./ I am waiting for your reply./ Please get back to me as soon as you can./ Please reply asap. Thank you (in advance)./ Thank you for your coo

Common Sense
at first, when their number was small, their habitations near, and the public ... state of a king shuts him from the world, yet the business of a king requires him to know ... of a machine are put in motion by one, it only remains to know which power