EET 2261 Unit 7 I/O Pins and Ports

Slides:



Advertisements
Similar presentations
Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 7 Indexed Addressing Mode Read Mazidi, Chapter 6. Homework #7 and Lab #7 due next week. Quiz next week.
Advertisements

Week10 Boolean Instructions on the Boolean Instructions  Boolean (or Bit) addressable capability is unique to the 8051  Enables efficient handling.
EET 2261 Unit 3 Assembly Language; Load, Store, & Move Instructions  Read Almy, Chapters 5 and 6.  Homework #3 and Lab #3 due next week.  Quiz next.
The 8051 Microcontroller and Embedded Systems
EET 252 Digital Systems II Professor Nick Reeder.
EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
Programmable Interval Timer
EET 2261 Unit 14 INCOMPLETE Analog-to-Digital Conversion (ADC) & Digital-to-Analog Conversion (DAC)  Read.  Homework #13 and Lab #13 due next week. 
TK2633 Introduction to Parallel Data Interfacing DR MASRI AYOB.
Input/Output (I/O) Ports and Interfacing
CHAPTER 4 I/O PORT PROGRAMMING. I/O Port Pins The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins All the ports upon RESET are configured as input,
Chapter 10 Flip-Flops and Registers Copyright ©2006 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. William Kleitz.
The 8085 Microprocessor Architecture
EET 2261 Unit 8 Seven-Segment Displays; S19 Records; System Clocks
ELEC 330 Digital Systems Engineering Dr. Ron Hayne
EET 2261 Unit 5 Tables; Decision Trees & Logic Instructions
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
68HC11 Polling and Interrupts
EET 2261 Unit 9 Interrupts  Read Almy, Chapters 17 – 19.  Homework #9 and Lab #9 due next week.  Quiz next week.
EET 2261 Unit 13 Controlling Stepper Motors and Servos  Read Almy, Chapter 21.  Lab #13 due next week.  Final Exam next week.
Programming the ATmega16
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
EET 2261 Unit 2 HCS12 Architecture
Railway Foundation Electronic, Electrical and Processor Engineering.
Chapter 17 Microprocessor Fundamentals William Kleitz Digital Electronics with VHDL, Quartus® II Version Copyright ©2006 by Pearson Education, Inc. Upper.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Chapter 4 Programmable Logic Devices: CPLDs with VHDL Design Copyright ©2006 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights.
1 EKT 225 MICROCONTROLLER I CHAPTER 3 I/O PORT PROGRAMMING.
Digital Fundamentals Floyd Chapter 1 Tenth Edition
Input/Output mechanisms
The 8051 Microcontroller and Embedded Systems
MICROPROCESSOR INPUT/OUTPUT
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals with PLD Programming.
Fall 2004EE 3563 Digital Systems Design EE3563 Chapter 8 Reading Assignments  8.1, ,   8.5.1, 8.5.2,  8.8  We will.
ENG241 Digital Design Week #8 Registers and Counters.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
IO Subsystem IV Ports and peripherals. IO Subsystem (1) All devices connected to the system buses, other than memory and CPU – Input and output ports.
Programmable Peripheral Interface Parallel port Interface 8255
Electronic Analog Computer Dr. Amin Danial Asham by.
Floyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd © 2008 Pearson Education Chapter 1.
Analog Capture- Port E. Digital to Analog and Analog to Digital Conversion D/A or DAC and A/D or ADC.
Introduction to Microprocessors - chapter3 1 Chapter 3 The 8085 Microprocessor Architecture.
Presented by Sadhish Prabhu
Teaching Digital Logic courses with Altera Technology
Chapter 3 Parallel Ports, Power Supply and the Clock Oscillator The aims of this chapter are to introduce: Why we need parallel input/output; How simple.
EET 2261 Unit 6 The Stack; Subroutines
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
EGR 2131 Unit 4 Combinational Circuits: Analysis & Design
EET 2261 Unit 3 Assembly Language; Load, Store, & Move Instructions
Fundamentals of Computer Engineering
Fri. Sept 29 Announcements
For further information
Homework Reading Machine Projects Labs
General Purpose I/O.
COMP2121: Microprocessors and Interfacing
Programmable Interval Timer
EET 2261 Unit 11 Controlling LCD and Keypad
ECET 330 Innovative Education--snaptutorial.com
Interfacing Memory Interfacing.
EET 2261 Unit 11 Controlling LCD and Keypad
EET 2261 Unit 9 Interrupts Read Almy, Chapters 17 – 19.
EET 2261 Unit 12 Controlling Stepper Motors and Servos
Digital Fundamentals Floyd Chapter 1 Tenth Edition
EET 2261 Unit 8 Seven-Segment Displays
EET 2261 Unit 6 The Stack; Subroutines
EGR 2131 Unit 12 Synchronous Sequential Circuits
Presentation transcript:

EET 2261 Unit 7 I/O Pins and Ports Read Almy, Chapters 12 – 15. Homework #7 and Lab #7 due next week. Quiz next week. Take Quiz 6.

General-Purpose Input/Output Ports A general-purpose I/O port is a group of pins (typically 8) that can be connected to generic digital input or output devices. Example of a generic digital input device: a switch that switches between 0 V and +5 V. Example of a generic digital output device: an LED. “Generic” means that these devices don’t have specialized synchronization or timing requirements, as some digital devices do.

Number and Names of Bits Input/Output Ports on the HCS12 Our HCS12 chip has ten general-purpose digital I/O ports: Port Number and Names of Bits Port A 8 bits: PA0 to PA7 Port B 8 bits: PB0 to PB7 Port E 8 bits: PE0 to PE7 (PE0 and PE1 are input only) Port H 8 bits: PH0 to PH7 Port J 4 bits: PJ0, PJ1, PJ6, PJ7 Port K 7 bits: PK0 to PK5, PK7 Port M 8 bits: PM0 to PM7 Port P 8 bits: PP0 to PP7 Port S 8 bits: PS0 to PS7 Port T 8 bits: PT0 to PT7

Multiplexed I/O Pins To keep the pin count to a reasonable number, most of the pins for the general-purpose I/O ports can also serve as inputs or outputs to specific modules on the HCS12. You must choose how you want to use the pins. Example: If you want to use the chip’s Enhanced Capture Timer module, then you can’t use Port T for general-purpose I/O. Note that the names on the Dragon12 board’s female header are abbreviated to show only one of the pin’s functions.

Multiplexed I/O Pins (Continued) To see which functions are shared by a single pin, see block diagram on page 6 of textbook or page 23 of Device User Guide. Also see pin diagram on page 52 of Device User Guide. Note that the names on the Dragon12 board’s female header are abbreviated to show only one of the pin’s functions.

Special-Function Registers The HCS12 has hundreds of special- function registers, some of which play a role in using the general-purpose I/O ports. Most of these registers are either: Data registers, which transfer data from place to place. Control registers, which control various aspects of the chip’s operation. Status registers, which hold status information about events that have occurred.

How to Access the Special-Function Registers In the HCS12’s memory map (page 26 of Device User Guide), addresses from $0000 to $03FF are assigned to the special- function registers. When you execute an LDAA or STAA instruction to one of these addresses, you’re not reading or writing to memory; instead, you’re reading or writing to a special- function register.

List of Special-Function Registers Pages 27-49 in the Device User Guide list all of the special-function registers and their addresses. Example: the special-function register named PORTA is assigned address $0000. So to copy data from Accumulator A to PORTA, you would use STAA $0000.

Special-Function Registers and the Ports Each I/O port has at least two special- function registers: A data register (such as PORTA or PORTB) that holds data traveling in or out through the port. A control register called a data-direction register (such as DDRA or DDRB) that controls whether the port’s pins are configured as inputs or as outputs.

Data Direction Registers Each bit in a DDR configures the corresponding pin of the port as an input (if the bit = 0) or as an output (if the bit = 1). Example: Suppose that on Port A we want to use pins 0 to 3 as input pins, and we want to use pins 4 to 7 as output pins. Then we must write the value %11110000 (or $F0) to DDRA: LDAA #$F0 ;0-3 in, 4-7 out STAA $0002 ;DDRA is at $0002

Example: Using Port A for Output Suppose we want to send %01011011 out on Port A. We must: Use DDRA to configure all of Port A’s pins as output pins. Send %01011011 to PORTA. This code will do the job: LDAA #$FF ;outputs STAA $0002 ;DDRA is at $0002 LDAA #$5B ;data to be sent STAA $0000 ;PORTA is at $0000

Example: Using Port A for Input Suppose we want to read in a byte from Port A. We must: Use DDRA to configure all of Port A’s pins as input pins. (May not be needed, since by default ports are configured as inputs.) Load an accumulator from PORTA. This code will do the job: LDAA #$00 ;inputs STAA $0002 ;DDRA is at $0002 LDAA $0000 ;load from PORTA Warn not to confuse Port A and Port B with Accumulator A and Accumulator B.

Using Labels for the Addresses Programs are easier to read and maintain if we use EQU directives to define labels for commonly used numbers. Example: Instead of this: LDAA #$00 STAA $0002 LDAA $0000 We can do this: PORTA EQU $0000 DDRA EQU $0002 LDAA #$00 STAA DDRA LDAA PORTA Remind that labels must start in the first column.

Using Labels for the Addresses Including the other lines that we use in all our programs, here’s a complete program to read in a byte from Port A: ABSENTRY Entry ORG $2000 PORTA EQU $0000 DDRA EQU $0002 Entry: LDAA #$00 STAA DDRA LDAA PORTA BRA * END Have them enter and assemble it. See what happens if you get rid of the EQU directives.

Include Files When you create a project, CodeWarrior automatically creates two files named derivative.inc and mc9s12dg256.inc. (The second file’s name depends on the device you select in the New Project Wizard.) These are called include files, which is why the names end in .inc.

What’s in These Include Files? These files contain EQU directives that define thousands of commonly used labels such as PORTA, DDRA, and so on. You should not edit these files.

How to Use These Include Files The following assembler directive tells CodeWarrior to add everything from those two include files into your program. INCLUDE 'derivative.inc' This will save you from having to type your own EQU directives for PORTA, DDRA, and all of the other special-function registers.

Earlier Example, But this Time Using the Include Files Now we can use PORTA and DDRA in our program without typing EQU statements that define those labels. INCLUDE 'derivative.inc' ABSENTRY Entry ORG $2000 Entry: LDAA #$00 STAA DDRA LDAA PORTA BRA * END Have them enter it, assemble it, and start debugger. Note that Source window in debugger now contains more than 8000 lines! How many of those lines are HCS12 instructions?

Name of Data Direction Register Names of the Port Registers and Bits CAUTION! Note variations: Port Name of Data Register Name of Data Direction Register Names of Bits Port A PORTA DDRA PA0 to PA7 Port B PORTB DDRB PB0 to PB7 Port E PORTE DDRE PE0 to PE7 Port H PTH DDRH PH0 to PH7 Port J PTJ DDRJ PJ0, PJ1, PJ6, PJ7 Port K PORTK DDRK PK0 to PK5, PK7 Port M PTM DDRM PM0 to PM7 Port P PTP DDRP PP0 to PP7 Port S PTS DDRS PS0 to PS7 Port T PTT DDRT PT0 to PT7

Switches on the Dragon12 Trainer On our trainer board, Port H is wired to eight DIP switches. If we want to use these switches, we must configure Port H for input. (See Schematic Diagram 4.) We’ll use these switches and LEDs to get the hang of programming I/O.

LEDs on the Dragon12 Trainer On our trainer board, Port B is wired to eight LEDs. If we want to use these LEDs, we must configure Port B for output. We must also configure PJ1 as an output and set it equal to 0. (See p. 24 of Dragon12 manual and Schematic Diagram 4.) We’ll use these switches and LEDs to get the hang of programming I/O.

Speaker on the Dragon12 Trainer On our trainer board, bit 5 of Port T is wired to a speaker (buzzer). See p. 28 of Dragon12 manual and Schematic Diagram 1. To make a noise on the speaker, you must configure bit PT5 for output, and then cause this output pin to alternate rapidly between HIGH and LOW. The pitch of the sound depends on how quickly you alternate it.

Review: BCLR and BSET We’ve used BCLR and BSET to manipulate single bits in memory. We can also use BCLR and BSET to manipulate single bits of an output port. (Recall that I/O ports “look” just like memory locations to the HCS12’s CPU.)

Using BSET with an I/O Port: Example Example: Suppose we want to set bit 3 of Port E. Here’s how to do it: BSET $0008, %00001000 Better yet, use a label instead of a number for the address: BSET PORTE, %00001000

Review: BRCLR and BRSET We’ve used BRCLR and BRSET to branch based on bits in memory. We can also use BRCLR and BRSET to branch based on bits of an input port.

Using BRSET with an I/O Port: Example Example: Suppose we want to branch if bit 3 of Port E is a 1 (in other words, if bit 3 of Port E is set). Here’s how to do it: BRSET $0008, %00001000, GoHere Better yet, use a label instead of a number for the address: BRSET PORTE, %00001000, GoHere

Some Electrical Considerations Unused input pins must not be allowed to float. An output pin’s current consumption is roughly proportional to the rate (frequency) at which the pin’s values changes. Example: If an output pin is being used to make an LED blink on and off, a blink rate of 10 times per second consumes roughly twice as much current as a rate of 5 times per second. See Chapter 13 for more detail on this and the next several slides.

Connecting a Mechanical Switch Two important considerations when connecting a mechanical switch to an input pin: The pin must never be allowed to float. A common way to achieve this is to use the HCS12’s internal pull-up resistors. The switch may need to be debounced, either in hardware or in your program.

Pull-Up Resistors A pull-up resistor is a resistor with one end connected to a HIGH voltage level and the other end connected to a point in a digital circuit. The resistor’s purpose is to pull up the voltage at that point to a HIGH level when it would otherwise be in a float condition (not HIGH or LOW).

Pull-Up Resistor (Continued) Good explanation at http://www.seattlerobotics.org/encoder/mar97/basics.html

Pull-Up Resistors on the Dragon12 Board’s DIP Switches The Dragon12’s eight DIP switches are connected to pull-up resistors (and pull-down resistors) on the board. See Schematic Diagram 4.

Pull-Up Resistors on the Red Trainer’s Data Switches The red trainer’s eight data switches are also connected to pull-up resistors. (Schematic diagram from trainer’s user manual.)

Internal Pull-Up Resistors on the HCS12 The HCS12, like many microcontrollers, has an internal pull-up resistor on each I/O pin. These pull-up resistors are disabled by default, but the programmer can enable them. Very handy for when you’re connecting an HCS12 input pin to a switch that’s not already connected to a pull-up resistor. Next slide shows the hardware associated with a single pin on Port A.

Hardware Associated with a Single I/O Pin on Port A See page 143 of text. This figure applies to Ports A, B, E, and K. The other ports are more complicated. See figure on page 141 of text.

Activating the Internal Pull-Up Resistors: Ports A, B, E, K How do we activate the HCS12’s internal pull-up resistors? By using bits in special function registers. For Ports A, B, E, and K, use the PUCR register. See page 24 of the MEBI Block User Guide.

Activating the Internal Pull-Up Resistors: Ports H, J, M, P, S, T For these ports, use the PERx and PPSx registers. See page 37 of the Port Integration Module Block User Guide.

Review: Connecting a Mechanical Switch Two important considerations when connecting a mechanical switch to an input pin: The pin must never be allowed to float. A common way to achieve this is to use the HCS12’s internal pull-up resistors. The switch may need to be debounced, either in hardware or in your program.

Contact Bounce Although it’s not obvious to us in everyday life, most mechanical switches suffer from contact bounce. When you flip the switch lever, the contacts inside the switch repeatedly bounce open and closed for a short time ( 50 ms). This can lead to problems in digital circuits, as shown in the following figures from your Digital Electronics textbook.

Figure 11.37 Switch used as a clock input to a toggle flip-flop.

Figure 11.38 Waveform at point Cp for Figure 11–37 assuming Q starts HIGH.

Ways to Solve Contact Bounce There are several standard ways to debounce a switch. In hardware, we can use a latch or flip-flop, or an RC circuit with a Schmitt-trigger gate. See Section 114 of your Digital Electronics textbook (by Kleitz) for details. As noted on page 136 of our textbook, debouncing can also be done in your program by checking the input at well-spaced time intervals.

No Debounce Circuit on the Dragon12 Board’s DIP Switches The Dragon12 does not include any hardware to debounce the DIP switches.

Debounce Circuit on Our Red Trainer’s Pulse Switches The red trainer includes internal hardware to debounce the pulse switches.

No Debounce Circuit on Red Trainer’s Data Switches The trainer does not include any internal hardware to debounce the data switches.

Some Timing Considerations Un