Professional Documents
Culture Documents
Chapter 4 Io
Chapter 4 Io
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
Step 2:
SET bit 2 and bit 4 of TRIS register
CLEAR bit 6 and bit7 of TRIS register
to make these port serves as OUTPUT , we need to put 0’s bit in the register
TRISB = 0b00000000
TRY YOURSELF!!!
TRISB = 0b11011000