Chapter 3 Io

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

DJM50122 EMDEDDED SYSTEM APPLICATION

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.
● The number of I/O pins and timers on YOUR LOGO
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