0% found this document useful (0 votes)
41 views19 pages

Input/Output Ports and Interfacing: Digital Systems Engineering

The document discusses input/output ports and interfacing with peripherals for microcontroller systems. It covers basic I/O concepts including input and output devices. It describes how devices are interfaced to a microprocessor unit using I/O ports and addresses. Specific examples are provided for interfacing LEDs, seven-segment displays, switches, and an LCD to the ports of a PIC18F microcontroller. Addressing schemes and software instructions for reading input and writing output are also outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views19 pages

Input/Output Ports and Interfacing: Digital Systems Engineering

The document discusses input/output ports and interfacing with peripherals for microcontroller systems. It covers basic I/O concepts including input and output devices. It describes how devices are interfaced to a microprocessor unit using I/O ports and addresses. Specific examples are provided for interfacing LEDs, seven-segment displays, switches, and an LCD to the ports of a PIC18F microcontroller. Addressing schemes and software instructions for reading input and writing output are also outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Input/Output Ports and Interfacing

Digital Systems Engineering

Images Courtesy of Ramesh Gaonkar and Delmar Learning


Basic I/O Concepts
 Peripherals such as LEDs and keypads 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 display, LCD, and printer
 Devices are interfaced to an MPU using I/O ports

330_09 2
I/O Interfacing

330_09 3
Interfacing and Addressing
 I/O ports
 Buffers and latches on the MCU chip
 Assigned binary addresses by decoding the address bus
 Generally bidirectional
 Internal data direction registers
 To read 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
 Reads data using the data bus
 To write binary data to an output peripheral
 MPU places the address of an output port on the address bus
 Places data on data bus
 Asserts the WR signal to enable the output port

330_09 4
PIC18F452/4520 I/O Ports
 MCU includes five I/O ports
 PORTA, PORTB, PORTC, PORTD, PORTE
 Ports are multiplexed
 Can be set up to perform various functions
 Each I/O port is associated with several SFRs
 PORT
 Functions as a latch or a buffer
 TRIS
 Data direction register
 Logic 0 sets up the pin as an output
 Logic 1 sets up the pin as an input
 LAT
 Output latch similar to PORT

330_09 5
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 6
PIC18F452/4520 I/O Ports
 PORTB

330_09 7
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 8
Interfacing Output Peripherals
 Commonly used output peripherals in embedded systems
 LEDs

 Seven-Segment Displays

 LCDs

 Two ways of connecting LEDs to I/O ports


 Common Cathode

 LED cathodes are grounded


 Logic 1 from the I/O port turns on the LEDs
 Current is supplied by the I/O port called current sourcing
 Common Anode
 LED anodes are connected to the power supply
 Logic 0 from the I/O port turns on the LEDs
 Current is received by the chip called current sinking

330_09 9
Interfacing Output Peripherals

Common Cathode Common Anode


330_09 10
Seven-Segment Display
 Seven-segment Displays
 Used to display BCD digits
 0 thru 9
 A group of 7 LEDs physically
mounted in the shape of the
number eight
 Plus a decimal point
 Each LED is called a segment
 ‘a’ through ‘g’
 Two types
 Common anode
 Common cathode

330_09 11
Seven-Segment Display
 Common Anode
 All anodes are connected together to a power supply
 Cathodes are connected to data lines
 Logic 0 turns on a segment
 Example: To display the digit 1
 All segments except b and c should be off
 11111001 = F9H
Common Anode

330_09 12
Seven-Segment Display
 Common Cathode
 All cathodes are connected together to ground
 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
 00000110 = 06H

330_09 13
Example 9.4
 Interfacing Seven-Segment Display to PORTB
 Common Anode
 Table Look-Up

330_09 14
Illustrative Program
 Problem Statement
 Interface two common-anode seven-segment
displays to PORTD and PORTC of the PIC18F
 Write instructions to implement an up-counter,
counting from 00 to 59
 Display the count on the two seven-segment
displays

330_09 15
Interfacing Input Peripherals
 Commonly used input peripherals
 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
 The other side is grounded
 The logic level changes when the position is switched
 Push-button key
 Same as the DIP switch except that contact is momentary

330_09 16
Interfacing Dip Switches

330_09 17
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
MOVWF PORTC ;Display on PORTC
330_09 18
Interfacing LCD
 Software
 To write into the LCD
 Send the initial instructions to set up the LCD
 4-bit or 8-bit mode
 Continue to check DB7 until it goes low
 Write instructions to IR to set up LCD parameters
 Number of display lines and cursor status
 Write data to display a message

330_09 19

You might also like