Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parallel Input/Output

Similar presentations


Presentation on theme: "Parallel Input/Output"— Presentation transcript:

1 Parallel Input/Output

2 The basic 8051 microcontroller has four 8-bit ports, P0, P1, P2 and P3.

3 Port Address P0 80H P1 90H P2 A0H P3 B0H

4 Pinout All pins on all the ports (32 pins) can be used as either inputs or outputs

5 Initialization of port pins
Output ports (Does NOT need to be initialized) To use a port pin as an output requires no initialization. You simply write to the port. For example, SETB P1.5 sends a logic 1 to P1 bit 5; MOV P0, A sends the data in the accumulator to P0. Input ports (Needs to be initialized) To initialize a port pin as an input we must first write a logic 1 to that pin. SETB P3.2 sets P3 pin 2 as an input; MOV P2, #0FFH initializes each pin of P2 as an input.

6 A comment on initialization is important
It is important when initialising a port pin on the 8051 to write a comment stating this, otherwise it is difficult to know whether data is being sent out to the port pin, or the port pin is being initialised for input. For example, the code should be written something like: MOV P2, #0FFH ; initialising P2, all pins, as inputs

7 Why must a logic 1 be written to the port pin to make it an input pin?

8 Writing to a port

9 Read from a port

10 Read from a port

11 Typical programming for input/output ports
; Used as output ports: don’t have to be initialized SETB P ; set pin 5 of port 3 MOV P1, #4AH ; sending data 4AH to port 1 MOV P2, A ; send whatever data is in the accumulator to port 2 ; Used as input ports: must be initialized SETB P ; initialize pin 0 of port 1 as an input pin MOV P2, #FFH ; initialize pins of port 2 as inputs MOV C, P ; Read state on pin 0 of port 1 to the carry MOV R3, P ; Read datum on port 2 into R3

12

13

14

15


Download ppt "Parallel Input/Output"

Similar presentations


Ads by Google