Parallel Ports

15
Dr. Iyad Jafar Parallel Ports

description

Parallel Ports. Dr. Iyad Jafar. Outline. Why Do We Need Parallel Ports? Hardware Realization of Parallel Ports Interfacing to Parallel Ports The PIC 16F84A Parallel Ports . Why Do We Need Parallel Ports?. - PowerPoint PPT Presentation

Transcript of Parallel Ports

Page 1: Parallel Ports

Dr. Iyad Jafar

Parallel Ports

Page 2: Parallel Ports

Outline

Why Do We Need Parallel Ports?Hardware Realization of Parallel PortsInterfacing to Parallel PortsThe PIC 16F84A Parallel Ports

2

Page 3: Parallel Ports

Why Do We Need Parallel Ports?

Almost any microcontroller needs to transfer digital data from/to external devices and for different purposesDirect user interface – switches, LEDs, keypads, displays

Input measurement - from sensors, possibly through ADC

Output control information – control motors and actuators

Bulk data transfer – to other systems/subsystems

Transfer could be serial or parallel !3

Page 4: Parallel Ports

Hardware Realization of Parallel PortsOutput Parallel Port

4

Page 5: Parallel Ports

Hardware Realization of Parallel PortsInput Parallel Port

5

Page 6: Parallel Ports

Hardware Realization of Parallel PortsBidirectional Parallel Port

6

Page 7: Parallel Ports

The PIC 16F84 Parallel PortsPORT B

8-bit general-purpose bidirectional digital portPin RB0 is multiplexed with the external interrupt INT and has Schmitt trigger interface Data from/to this port is stored in PORTB register (0x06)Pins can be configured for input or output by setting or clearing corresponding bits in the TRISB register (0x86)Pins RB4 – RB7 have a useful ‘interrupt on change’ facility

7

Page 8: Parallel Ports

The PIC 16F84 Parallel PortsPORT B

8

Configurable pull-up resistors using RBPU bit in the

OPTION register

Latches input data whenever the port is

read

Multiplexed input

Page 9: Parallel Ports

The PIC 16F84 Parallel PortsPORT B

9

Lathes data on port read

Holds previous latched data

Compares previous and present port

input values

Clearing the RBIF bit ?

Page 10: Parallel Ports

The PIC 16F84 Parallel PortsPORT A

5-bit general-purpose bidirectional digital portPin RA4 is multiplexed and can be used as the clock for the TIMER 0 module Data from/to this port is stored in PORTA register (0x05)Pins can be configured for input or output by setting or clearing corresponding bits in the TRISA register (0x85)

10

Page 11: Parallel Ports

The PIC 16F84 Parallel PortsPORT A

11

Page 12: Parallel Ports

The PIC 16F84 Parallel PortsExample – configuring port B such that pins 0 to 2 are inputs, pins 3 to 4 outputs, and pins 5 to 7 are inputs

bcf STATUS, RP0; select bank0clrf PORTB ; clear port B latchesbsf STATUS , RP0 ; select bank1movlw 0xE7movwf TRISB ; PORTB<7:5> input, ; PORTB<4:3> output; PORTB<2:0> input

12

Page 13: Parallel Ports

Example on Using I/O PortsExample – on external interrupt (rising edge ON RB0), start flashing a LED connected to RB1 every 1 ms. If another interrupt occurs, stop flashing, and so on …

assume 4MHz clock.Requirements: 1)Configure RB0 as input and RB1 as output 2)Enable external interrupt (INTE) and global interrupts (GIE)3)Write a 1 ms delay routine 4)Keep track of the current status of flashing (on/off)

13

Page 14: Parallel Ports

Example on Using I/O Ports#include P16F84A.INCFLASH EQU 0X20 ; STORE THE STATE OF FLASHINGCOUNT EQU 0X21 ; COUNTER FOR DELAY LOOP

ORG 0X0000GOTO START ORG 0X0004GOTO ISR

; ---------------------------------- MAIN PROGRAM -----------------------------------------------START CLRF FLASH ; CLEAR FLASHING STATUS

BSF STATUS,RP0 ; SELECT BANK 1MOVLW B'00000001' ; CONFIGURE RB0 AS INPUT AND RB1 AS OUPUTMOVWF TRISBBSF OPTION_REG, INTEDG ; SELECT RISING EDGE FOR EXTERNAL INTERRUPT BSF INTCON , INTE ; ENABLE EXTERNAL INTERRUPT BSF INTCON , GIE ; ENABLE GLOBAL INTERRUPTBCF STATUS,RP0 ; SELECT BANK 0CLRF PORTB ; CLEAR PORTB

WAIT BTFSS FLASH , 0 ; IF BIT 0 OF FLASH IS CLEAR THEN NO FLASHING GOTO WAIT ; WAIT UNTIL BIT 0 IS SET MOVLW B'00000010' XORWF PORTB , 1 ; COMPLEMENT RB1 TO FLASHCALL DEL_1MSGOTO WAIT

14

Page 15: Parallel Ports

Example on Using I/O Ports; ---------------- DELAY ROUTINE ------------------------DEL_1MS NOP

MOVLW D'142'MOVWF COUNT

LOOP NOPNOPNOPNOPDECFSZ COUNT , 1 GOTO LOOPRETURN ; DELAY = (2+1+1+1+(4+1+2)*141+(4+2+2)*4/4MHz

= 1ms

; --------------- INTERRUPT SERVICE ROUTINE ---------------ISR XORWF FLASH , 1 ; COMPLEMENT THE STATUS

BCF INTCON , INTF ; CLEAR THE INTF FLAG RETFIE

END

15