0% found this document useful (0 votes)
44 views17 pages

Chapter 4 Io

This document discusses input/output ports for microcontrollers. It describes the ports on the PIC16F877A microcontroller including Port A (6 bits), Port B (8 bits), Port C (8 bits), Port D (8 bits), and Port E (3 bits). It explains that the TRIS, PORT, and LAT registers are used to configure the ports as inputs or outputs and to read from and write to the port pins. The value placed in the TRIS register determines whether each pin acts as an input (1) or output (0). Examples are given to configure ports and pins as either inputs or outputs using the TRIS register.

Uploaded by

Amzar Shukri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views17 pages

Chapter 4 Io

This document discusses input/output ports for microcontrollers. It describes the ports on the PIC16F877A microcontroller including Port A (6 bits), Port B (8 bits), Port C (8 bits), Port D (8 bits), and Port E (3 bits). It explains that the TRIS, PORT, and LAT registers are used to configure the ports as inputs or outputs and to read from and write to the port pins. The value placed in the TRIS register determines whether each pin acts as an input (1) or output (0). Examples are given to configure ports and pins as either inputs or outputs using the TRIS register.

Uploaded by

Amzar Shukri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DJM50122 EMDEDDED SYSTEM APPLICATION

CHAPTER 4
INPUT OUTPUT PORTS
PROGRAMMING
Prepared:
Norhaniza Azreen Bt Mohamed Mokhtar
Criteria for choosing a
microcontroller
● The amount of RAM and ROM.
● Power consumption. Especially for
battery powered.
YOUR LOGO
● The number of I/O pins and timers on
chip.
PORT A
• PORT A is 6 bit wide and bi-
directional
• Its corresponding data direction
register is TRIS A
• If TRIS A port pin is set to 1,
corresponding port A pin will act as
an input and vice versa.
• PORT A is used for analog input
PORT B
• Port B is 8 bit and bi –directional.
• Its corresponding data direction
register is TRIS B
• If TRIS B port pin is set to 1,
corresponding port B pin will act
as an input pin and vice versa
• Port B is used for data
transmission.
PORT C
• Port C is 8 bit wide and bi –directional
• Its corresponding data direction
register is TRIS c
• If TRIS C Port pin is set to 1,
corresponding port C pin will act as an
input pin and vice versa.
• Port C is used for control registers
( serial communication, I2C functions,
serial data transfer )
PORT D
● Port D is 8 bit wide and bi-
directional
● Its corresponding data direction
register is TRIS D
● If TRIS D port pin is set to 1,
corresponding port D pin will act as
an input pin and vice versa
● Port D is used as data port
PORT E
• Port E is 3 bit wide. They are for
read, write and chip select
operation.
• Each pin is individually
configurable as inputs and outputs
• Port E is generally used for
controlling purposes.
CODE PIC INSTRUCTION FOR I/O
HANDLING
To use of i/o port as input or output port,
it must be programme

1.TRISx (8 bit)
2.PORTx (8 bit)
3.LATx (8 bit)
TRIS
● TRIS x is register used for choosing if a PORTx pin should be an input
or an output Where x is the name of the port either of A,B,C,D,E.
● Every port has its own TRIS x register
 TRIS A
 TRIS B
 TRIS C
 TRIS D
 TRIS E
● Data direction (TRIS ) register needs to be set before the I/O operation
1 to make a port an input
0 to make a port an output
● After a RESET all port pin are defined as inputs
PORT

● PORT x is the register of the physical pin you see on


your PIC

● Every PORT x pin has its corresponding TRIS x bit. If


you want PORTx bit 6 as an output , TRISx bit 6
should be 0.
LATCH

• The latch register reads and modifies the write operation on


of I/O pin and stored the output data that is to be passed on
to the external hardware
• A write to the LATx register has the same effect as a write to
the PORTx register
TRIS REGISTER ROLE IN INPUTTING AND
OUTPUTTING DATA

• By clearing some bit of the TRIS register ( bit =0 ), the


corresponding port pin is configuration as OUTPUT.
• Similarly, by setting some bit of the TRIS register ( bit=1), the
corresponding port pin is configured as input

This rule is easy to remember


0 = Output , 1= Input
Determine the value of TRIS register for
the following circuit.
SOLUTION

Step 1: analyze i/o pin


INPUT : Pin 2 and pin 4 of I/O port
OUTPUT : Pin 6 and pin 7 of I/O port

Step 2:
SET bit 2 and bit 4 of TRIS register
CLEAR bit 6 and bit7 of TRIS register

The value of TRIS register in binary is 00110101


If the external circuit is connected to port D,
we will write TRISD = 0b00110101
EXAMPLE
Write C statement to make PORT B of PIC16F877A become
output.

to make these port serves as OUTPUT , we need to put 0’s bit in the register

TRISB = 0b00000000
TRY YOURSELF!!!
TRISB = 0b11011000

You might also like