Presentation is loading. Please wait.

Presentation is loading. Please wait.

1Week 10© Vocational Training Council, Hong Kong. Simple I/O Interfacing EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture.

Similar presentations


Presentation on theme: "1Week 10© Vocational Training Council, Hong Kong. Simple I/O Interfacing EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture."— Presentation transcript:

1 1Week 10© Vocational Training Council, Hong Kong. Simple I/O Interfacing EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 9

2 2Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Interface 8051 with the following Input/Output Devices Switches Solenoid and relays LEDs Seven Segment Display Dot matrix display In this Lecture ….

3 3Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Mechanical switches Electromagnetic relays Solid-state relays LEDs 7-segment Display Dot Matrix Display 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:

4 4Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 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) DPDT (double-pole-double-throw) Normally open (N.O.) contacts close when the switch is activated and normally close (N.C.) contacts OPEN when the switch is activated. Mechanical Switches N.O. SPST N.O. DPDT N.O. SPDT

5 5Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications

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

7 7Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Electromagnetic Relays 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 NC: NORMAL CLOSE NO: NORMAL OPEN

8 8Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Driving an Electromagnetic Relays 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 +5V Vs Figure 9.3 Driving circuit of an electromagnetic relay TTL

9 9Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Solid State Relays (SSR)/Switches Solid-state relays has no mechanical parts and made of semi- conductor 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 SSR + T1 T2 a.c. power supply Figure 9.4 Driving a solid state relay Input Control

10 10Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 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 TTL Figure

11 11Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Control of LEDs 8 LEDs are connected to Port 1 and linked to 5V supply The LEDs can directly be turned ON/OFF by the 8051 Under this connection, the LEDs will be OFF when port bit is at logic 1 ON when port bit is at logic 0 Figure = on 1 = off

12 12Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Example 9.1 : Control the 8 LEDs ON/OFF at the same time All LEDs ON All LEDs OFF

13 13Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Program Listing for Example 9.1 ORG0000H CLRA LOOP:MOVP1, A CPLA ACALLDELAY AJMPLOOP DELAY:MOVR6, #250 DL1:MOVR7, #200 DL2:DJNZR7, DL2 DJNZR6, DL1 RET END Start Set A = 00 Move the content of A to P1 Delay for 0.1s Invert the content of A Assume 12MHz clock, determine the delay time.

14 14Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications ORG0000H START:MOVR1, #07H MOVA, # B LEFT:MOVP1, A ACALLDELAY RLA DJNZR1, LEFT ; MOVR1, #07H MOVA, # B RIGHT:MOVP1, A ACALLDELAY RRA DJNZR1, RIGHT AJMPSTART ; DELAY:………. Example 9.2 : Glowing a LED in rotating sequence

15 15Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Example 9.3: Turning LEDs ON/OFF in a preset sequence by using a Look-up Table

16 16Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Program Listing of Example 9.3 ORG0000H START:MOVR0, #OK DATA+1 MOVDPTR, #DATA MOVR1, #00H LOOP:MOVA, R1 MOVP1, A ACALLDELAY INCR1 DJNZR0, LOOP AJMPSTART ; DELAY:MOVR5, #2 DL1:MOVR6, #250 DL2:MOVR7, #200 DL3:DJNZR7, DL3 DJNZR6, DL2 DJNZR5, DL1 RET ; DATA:DB B DB B DB B DB B DB B DB B DB B DB B ; DB B DB B DB B DB B DB B DB B DB B DB B ; DB B DB B DB B OK:DB B END

17 17Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Exercise: Write a 8051 program, using a look-up table, to light-up the LEDs in the sequence as shown below

18 18Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Simple I/O applications Figure 9.7

19 19Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 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. YELLOW=ON RED =OFF

20 20Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Flow Chart of Example 9.4 Start Initialization Set P3 as input port Read SW1 SW4 status SW1 closed? SW2 closed? SW3closed? SW4 closed? SW1 Handler Y SW2 Handler Y SW3 Handler Y SW4 Handler Y N N N

21 21Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Program Listing of Example 9.4 ORG0000H MOVR1, # B MOVR2, # B MOVR3, # B MOVR4, # B ; TEST:ORLP3, #0FFH JNBP3.7, CASE1 JNBP3.6, CASE2 JNBP3.5, CASE3 JNBP3.4, CASE4 AJMPTEST ; CASE1:MOVA, R1 MOVP1, A ACALLDELAY XRLA, # B MOVP1, A AJMPTEST ; CASE2MOVA, R2 MOVP1, A ACALLDELAY XRLA, # B MOVP1, A AJMPTEST ; CASE3MOVA, R3 MOVP1, A ACALLDELAY XRLA, # B MOV P1, A AJMPTEST ; CASE4MOVA, R4 MOVP1, A ACALL DELAY XRLA, # B MOV P1, A AJMPTEST ; DELAY:……….. END P1.x = 0, ON P1.x = 1. OFF

22 22Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications A single-character display panel Contains 7 LED segments arranged as an 8 Two configurations: common-anode and common-cathode 7-Segment LED Numeric Display a b c d e f g Segment Pattern Dp

23 23Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Common-anode configuration Common-cathode configuration 7-Segment LED Numeric Display a b cd e fg Dp Common a b cd e fgDp Common Pull-high Pull-low

24 24Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Segment displays are driven by connecting each segment to a port bit, or they can be driven by decoder/driver IC 7-Segment LED Numeric Display Output Port bit Display segmentDpgfedcba 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

25 25Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 7-Segment LED Numeric Display 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 8051 b c d e f g a XTAL1 XTAL2 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 Figure 9.8 Vcc a b c d e f g Dp.

26 26Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Program Listing ORG0000H MOVR3, #00H LOOP:MOVDPTR, #TABLE MOVA, R3 ; ; Display numbers on 7-segment display MOVP2, A ACALLDELAY ; ; Increase R3 by 1 and loop back MOVA, R3 ADDA, #1 DAA ANLA, #0FH MOVR3, A AJMPLOOP ; DELAY:………….. TABLE:DB B; 0 DB B; 1 DB B; 2 DB B; 3 DB B; 4 DB B; 5 DB B; 6 DB B; 7 DB B; 8 DB B; 9 ; 0=ON, 1=OFF END Display 0,1,2,,,,8,9,0,1,2,3…. Output port, P Display segment Dpgfedcba 7-segment BCD addition

27 27Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 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 To display a digit/character, use the method of scanning c d e f g a b 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) Dot-matrix LED Display

28 28Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications 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 Dot-matrix LED Display c d e f g a b 12345

29 29Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P Reset XTAL1 XTAL2 V SS EA Vcc P1.0 P1.1 P1.2 P1.3 P1.4 c d e f g a b Dot-matrix LED Display Drive Column P1 Method On column Off On column Off On column Off On column Off On column Off Repeat 100 times

30 30Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Example: Displaying the character E on the dot-matrix. Dot-matrix LED Display b c d e f g a Displaying the characterE on the 5x7dot-matrix. Step 1: signals on pins pins – pins gfedcba – Step 2: signals on pins pins – pins gfedcba – Step 3: signals on pins pins – pins gfedcba – Step 4: signals on pins pins – pins gfedcba – b c d e f g a b c d e f g a b c d e f g a b c d e f g a b c d e f g a

31 31Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Code Words and Displays of 0 to B B B B B B B B B B B B B B B B B B B B B B B B B

32 32Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Code Words and Displays of 5 to B B B B B B B B B B B B B B B B B B B B

33 33Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications Program Listing – character display on 5x7 Dot-matrix display (1/2) ORG0000H START:MOVDPTR, #TABLE; point to the starting add of 1 st char MOVR3, #10; display 10 characters: 0,1,2,3,,,,,9,0,1,…. LOOP:MOVR2, #100; scan 100 times for each character SCAN:ACALLSCAN1; 10ms x 100 = 1000ms DJNZR2, SCAN INCDPTR; increase DPTR by 5 to INCDPTR; point to the starting address of INCDPTR; the next character INCDPTR DJNZR3, LOOP; loop back to display 10 char AJMPSTART ; ====================== ; == Scan Subroutine == ; ====================== SCAN1:MOVR1, #00H; R1 points to the starting add of a char MOVR5, # B; start from the leftmost column MOVR4, #05; there are 5 columns, R4 as a counter ! LOOP1:MOVA, R1; get the code at add R1+DPTR MOVP3, A; send the code to the dot-matrix display (ROW) MOVP1, R5; turn-on a particular transistor (COLUMN)

34 34Week 9© Vocational Training Council, Hong Kong. EEE3410 Microcontroller Applications MOVR6, #5; delay for 2ms delay routine DL1:MOVR7, #200 ; delay routine DL2:DJNZR7, DL2 ; delay routine DJNZR6, DL1 ; delay routine ORLP1, # B; turn-off display ANL P1,# B ; turn-off display MOVA, R5; RLA; move to next column MOVR5, A; totally there are 5 columns INCR1; NEXT COLUMN DATA DJNZR4, LOOP1; RET; return the main program ; ============================ ; == Character Table == ; ============================ TABLE:DB B; codes for 0 DB B DB B DB B DB B DB B; code for 1 :; codes for 2 to 9 :; END Program Listing – character display on 5x7 Dot-matrix display (2/2)

35 1Week 10© Vocational Training Council, Hong Kong. Simple I/O Interfacing EEE3410 Microcontroller Applications Department of Electrical Engineering END of Lecture 9


Download ppt "1Week 10© Vocational Training Council, Hong Kong. Simple I/O Interfacing EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture."

Similar presentations


Ads by Google