Input/Output Ports and Interfacing

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

1 ECE 372 – Microcontroller Design Parallel IO Ports - Outputs Parallel IO Ports E.g. Port T, Port AD Used to interface with many devices Switches LEDs.
PROGRAMMABLE PERIPHERAL INTERFACE -8255
Programmable Interval Timer
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati.
Programmable Keyboard/ Display Interface: 8279
kashanu.ac.ir Microprocessors 6-1 I/O Devices Switches, LED, LCD Lec note 6.
TK2633 Introduction to Parallel Data Interfacing DR MASRI AYOB.
Input/Output (I/O) Ports and Interfacing
Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Microprocessor and Microcontroller Fundamentals
Microprocessor and Microcontroller
Counter Circuits and VHDL State Machines
P Address bus Data bus Read-Only Memory (ROM) Read-Write Memory (RAM)
OTHER COMBINATIONAL LOGIC CIRCUITS WEEK 7 AND WEEK 8 (LECTURE 2 OF 3)
Microcontroller Architecture— PIC18F Family
Digital I/O Connecting to the Outside World
EEE305 Microcontroller Systems Lecture 5B: Simple I/O Embedded C using PIC microcontrollers Teaching resources on on
Embedded Systems Design 1 Lecture Set B Interfacing the MCS-51 to: –7 and 16 segment displays –a Multiplexed 7-Segment Display –a Keypad –an LCD.
ASPPRATECH.
Lecture – 7 Basic input and output
Microcontroller Architecture PIC18F Family
INPUT-OUTPUT ORGANIZATION
Khaled A. Al-Utaibi  Intel Peripheral Controller Chips  Basic Description of the 8255  Pin Configuration of the 8255  Block Diagram.
Dr. Rabie A. Ramadan Al-Azhar University Lecture 6
The 8253 Programmable Interval Timer
Basic I/O Interface A Course in Microprocessor
I/O devices Peripheral devices (also called I/O devices) are pieces of equipment that exchange data with a CPU Examples: switches, LED, CRT, printers,
Programming and Problem Solving ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
COMP3221: Microprocessors and Embedded Systems Lecture 18: Computer Buses and Parallel Input/Output (II) Lecturer: Hui.
8086/8088 Hardware Specifications Power supply:  +5V with tolerance of ±10%;  360mA. Input characteristics:  Logic 0 – 0.8V maximum, ±10μA maximum;
Application Programs ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
10/24/2015 Amrita Vishwa Vidyapeetham 1 Key Board & LED Interfacing.
8279 KEYBOARD AND DISPLAY INTERFACING
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Programmable Peripheral Interface Parallel port Interface 8255
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
Counter Circuits and VHDL State Machines
Module 11 Adapted By and Prepared James Tan © 2001.
PPI-8255.
8279 KEYBOARD AND DISPLAY INTERFACING
Programmable Interrupt Controller (PIC)
Magnitude Comparator Dr. Ahmed Telba.
Parallel I/O. Introduction This section focuses on performing parallel input and output operations on the 68HC11 3 operation types – Simple, blind data.
EE365 - Microprocessors period 26 10/23/00 D. R. Schertz # Parallel Ports.
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
Alpha/Numeric Keypad Functions using AVR Preliminary Design Review Luke R. Morgan ECE /17/2008.
 The Programmable Interrupt Controller (PlC) functions as an overall manager in an Interrupt-Driven system. It accepts requests from the peripheral equipment,
Chapter Microcontroller
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
I/O Devices Switches, LED, LCD
ECE 447: Lecture 12 Keypads ECE 447: Lecture 10. ECE 447: Matrix Keypad.
KEYBOARD/DISPLAY CONTROLLER - INTEL Features of 8279 The important features of 8279 are, Simultaneous keyboard and display operations. Scanned keyboard.
LED AND KEYBOARD INTERFACING PREPARED BY :- PREPARED BY :- RAVAL AKASH ( ) RAVAL AKASH ( ) PATEL HARDIK ( ) PATEL HARDIK.
MICROPROCESSOR AMARTYA ROY-72 ANGSHUMAN CHATTERJEE-80 ASHISH LOHIA-70 MOLOY CHAKRABORTY-60.
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Microprocessor and Microcontroller Fundamentals
Microprocessor and Microcontroller Fundamentals
LCD AND KEYBOARD INTERFACING
Input/Output Ports and Interfacing
IPCOWALA INSTITUTE OF ENGINEERING & TECHNOLOGY-DHARMAJ
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Keyboard/Display Controller INTEL 8279
Interfacing Memory Interfacing.
LCD and Keyboard Sepehr Naimi
8279 – Programmable Keyboard/Display Interface
LCD AND KEYBOARD INTERFACING
The Programmable Peripheral Interface (8255A)
Presentation transcript:

Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning ELEC 330

Basic Concepts I/O devices (or peripherals) such as LEDs and keyboards are essential components of microcontroller-based systems Input devices Provide digital information to an MPU Examples: switch, keyboard, scanner, and digital camera Output devices Receive digital information from an MPU Examples: LED, seven-segment LED, LCD, and printer I/O devices are interfaced (connected) to an MPU using I/O ports 330_09

I/O Interfacing 330_09

Interfacing and Addressing I/O ports Buffers and latches on the MCU chip Assigned binary addresses by decoding the address bus Generally bidirectional meaning they can be set up either as input ports (buffers) or output ports (latches) through internal data direction registers To read (receive) binary data from an input peripheral MPU places the address of an input port on the address bus, enables the input port by asserting the RD signal, and reads data using the data bus To write (send) binary data to an output peripheral MPU places the address of an output port on the address bus, places data on data bus, and asserts the WR signal to enable the output port 330_09

PIC18F452/4520 I/O Ports MCU includes five I/O ports PORTA, PORTB, PORTC, PORTD, PORTE Ports are multiplexed meaning they can be set up by writing instructions to perform various functions Each I/O port is associated with the special functions registers (SFRs) to setup various functions PORT: This register functions as a latch or a buffer determined by the logic levels written into the associated TRIS register. TRIS: This is a data direction register. Writing logic 0 to a pin sets up the pin as an output pin, and logic 1 sets up the pin as an input pin. LAT: This is an output latch similar to PORT. 330_09

PIC18F452/4520 I/O Ports PORTA: Example of Multiple Fns Digital I/O: RA6-RA0 Analog Input: AN0-AN4 V REF+ : A/D Reference Plus V V REF- : A/D Reference Minus V TOCK1: Timer0 Ext. Clock SS: SPI Slave Select Input LVDIN: Low V Detect Input 330_09

PIC18F452/4520 I/O Ports PORTB 330_09

I/O Example Write instructions to set up pins RB7-RB4 of PORTB as inputs and pins RB3-RB0 as outputs Opcode Operands Comments MOVLW 0xF0 ;Load B’11110000’ into WREG MOVWF TRISB ;Set PORTB TRIS Reg 330_09 ELEC 330

Interfacing Output Peripherals Commonly used output peripherals in embedded systems LEDs Seven-Segment Displays LCDs Two ways of connecting LEDs to I/O ports: LED cathodes are grounded and logic 1 from the I/O port turns on the LEDs. The current is supplied by the I/O port called current sourcing. LED anodes are connected to the power supply and logic 0 from the I/O port turns on the LEDs. The current is received by the chip called current sinking. 330_09

Interfacing Output Peripherals Common Cathode Common Anode 330_09

Seven-Segment Display Seven-segment LEDs Often used to display BCD numbers (1 through 9) A group of eight LEDs physically mounted in the shape of the number eight plus a decimal point Each LED is called a segment and labeled as ‘a’ through ‘g’ Two types Common anode Common cathode 330_09

Seven-Segment Display In a common anode seven-segment LED All anodes are connected together to a power supply and cathodes are connected to data lines Logic 0 turns on a segment. Example: To display digit 1, all segments except b and c should be off. Byte 11111001 = F9H will display digit 1. Common Anode 330_09

Seven-Segment Display In a common cathode seven-segment LED All cathodes are connected together to ground and the anodes are connected to data lines Logic 1 turns on a segment. Example: To display digit 1, all segments except b and c should be off. Byte 00000110 = 06H will display digit 1. 330_09

Example 9.4 Interfacing Seven-Segment LEDs to PORTB Common Anode Table Look-Up 330_09

Illustrative Program Problem Statement Interface two common-anode seven-segment LEDs to PORTD and PORTC of the PIC18F microcontroller Write instructions to design an up-counter counting from 00 to 59 at the interval of 100ms Display the count as two seven-segment LEDs 330_09 ELEC 330

Interfacing Input Peripherals Commonly used input peripherals in embedded systems are: DIP switches, push-button keys, keyboards, and A/D converters. DIP switch: One side of the switch is tied high (to a power supply through a resistor called a pull-up resistor), and the other side is grounded. The logic level changes when the position is switched. Push-button key: The connection is the same as in the DIP switch except that contact is momentary. 330_09

Interfacing Dip Switches 330_09

Reading from an I/O Port Read input switches on PORTB (RB7-RB4) RB0 set HI (1) Switches Open = LOW (0) Switches Closed = HIGH (1) Display on PORTC Opcode Operands Comments MOVLW 0xF0 ;Load B’11110000’ into WREG MOVWF TRISB ;Set PORTB TRIS Reg CLRF TRISC ;Set PORTC as Output BSF PORTB,0 ;Set RB0 High MOVF PORTB,W ;Read PORTB PORTC ;Display on PORTC 330_09

Internal Pull-Up Resistor Turning off the internal FET provides a pull-up resistor Bit7 (RBPU) in the INTCON2 register enables or disables the pull-up resistor Instruction to Enable Pull Up Resistors: BCF INTCON2,7 330_09

Interfacing Push-Button Keys Electrical connection of a push-button key is same as that of a DIP switch except that the connection is temporary when the key is pressed When a key is pressed (or released), mechanical metal contact bounces momentarily and can be read as multiple inputs The reading of one contact as multiple inputs can be eliminated by a key-debounce technique, using either hardware or software 330_09

Key Debounce Techniques Hardware technique Two NAND gates connected as an S-R latch The output of the latch is a pulse without a bounce Software technique Wait for 10 to 20 ms after detection of a switch closure If the reading is still the same it is accepted 330_09

Interfacing a Matrix Keypad Problem statement Interface a 4 x 4 Hex keypad to PORTB Write a program to recognize a key pressed and encode the key in its binary value Display binary code on PORTC 330_09

Interfacing a Matrix Keypad Hardware (PIC18 Simulator) 4 x 4 matrix keypad organized in the row and column format Four columns are connected to the lower half of PORTB (RB0-RB3) Four rows are connected to upper half of PORTB (RB4-RB7) When a key is pressed, it makes a contact with the corresponding row and column 330_09

Interfacing a Matrix Keypad PIC18 Simulator Keypad Matrix 1 4 7 A 2 5 8 3 6 9 B C D E F 330_09

Interfacing a Matrix Keypad Software To recognize and encode the key pressed, the program should: Set all the columns High by sending ones. Check for any key pressed (non-zero). Set one column High at a time and check all the rows in that column. Once a key is identified, it is encoded based on its position in the column. 330_09

Interfacing Seven Segment LEDs Time Multiplex Scanning Technique Problem statement Interface four common cathode seven-segment LEDs to PORTB and PORTC for display using the time multiplex scanning technique. Write instructions to display a four-digit number stored in data registers. 330_09

Time Multiplex Scanning Hardware Eight data lines of PORTB are connected to the anodes of eight segments (a-g) of each LED Each cathode is connected to PORTC (RC0-RC3) through a transistor Transistors (and LEDs) can be turned on by sending logic 1 to the base of a transistor Each LED is turned on and off in a sequence to display a digit 330_09

Time Multiplex Scanning 330_09

Time Multiplex Scanning Software To turn on four LEDs in a sequence for a continuous display: Codes of the numbers to be displayed are stored in data registers in a sequence. The program gets the codes from the data registers by using the pointer (FSR) and sends them out to the LED segments through PORTB. One LED at a time is turned on by sending logic 1 to the corresponding transistor connected to PORTC. After an appropriate delay, the first LED is turned off and the next LED is turned on. Turning LEDs on/off is repeated in a sequence. 330_09

Interfacing LCD Problem statement Interface a 2-line x 20 character LCD module with the built-in HD44780 controller to I/O ports of the PIC18 microcontroller. Explain the control signals necessary to read from and write to the LCD. Write a program to display ASCII characters. 330_09

Interfacing LCD Hardware 20 x 2-line LCD displays (two lines with 20 characters per line) LCD has a display Data RAM (registers) that stores data in 8-bit character code. Each register in Data RAM has its own address that corresponds to its position on the line. The address range for Line 1 is 00 to 13H and Line 2 is 40H to 53H. 330_09

Interfacing LCD 330_09

Interfacing LCD Driver HD44780 8-bit data bus (RD7-RD0) Three control signals: RS – Register Select (RA3) R/W – Read/Write (RA2) E – Enable (RA1) Three power connections Power, ground, and the variable register to control the brightness 330_09

Interfacing LCD Can be interfaced either in the 8-bit mode or the 4-bit mode In the 8-bit mode, all eight data lines are connected for data transfer In the 4-bit mode, only four data lines (DB7-DB4 or DB3-DB0) are connected and two transfers per character (or instruction) are needed Driver has two 8-bit internal registers Instruction Register (IR) to write instructions (Table 9-3) to set up LCD Data Register (DR) to write data (ASCII characters) 330_09

Interfacing LCD LCD Operation When the MPU writes an instruction to IR or data to DR, the controller: Sets the data line DB7 high as a flag indicating that the controller is busy completing the operation Sets the data line DB7 low after the completion of the operation The MPU should always check whether DB7 is low before sending an instruction or a data byte After the power up, DB7 cannot be checked for the first two initialization instructions. 330_09

Interfacing LCD Writing to or Reading from LCD (Table 9-4) The MPU: Asserts RS low to select IR Asserts RS high to select DR Reads from LCD by asserting the R/W signal high Writes into LCD by asserting the R/W signal low Asserts the E signal high and then low (toggles) to latch a data byte or an instruction 330_09

Interfacing LCD Timing diagram: writing to LCD 330_09

Interfacing LCD Software To write into the LCD, the program should: Send the initial instructions (commands) before it can check DB7 to set up the LCD in the 4-bit or the 8-bit mode. Check DB7 and continue to check until it goes low. Write instructions to IR to set up the LCD parameters such as the number of display lines and cursor status. Write data to display a message. 330_09