SlideShare una empresa de Scribd logo
1 de 20
I/O PORTS
Prepared by:

Islam Samir
AGENDA




I/O ports and how to use them
Some exceptions with some ports.
Handling the bouncing problem.
AGENDA




I/O ports and how to use them
Some exceptions with some ports.
Handling the bouncing problem.
I/O PORTS


Every microcontroller must have means of communication to the
outside world.



The simplest way for communication is using general purpose I/O
ports.
I/O PORTS


Reading a port:

- Means reading the status (voltage level) present on the

-

pin.
Writing to a port:
Means writing to the port latches.

- You have to determine the direction of the I/O pin before
using it, this is done by changing the value of the TRIS
register.
I/O PORTS
Example on reading a port
If the voltages: 0.5v, 4v, 2v were present on three different pins.
If you read these pins, you’ll get the digital logic value
corresponds to each voltage level  0 1 0.
Considering the range of ‘0’ : 0v  2.5v
the range of ‘1’ : 2.5v  5v
I/O PORTS


The I/O pin direction is controlled by a register called TRIS.
PORT<x> is controlled by the register TRIS<x>.



If you write ‘1’ in a bit in TRIS<x> register, this means that the
corresponding bit in PORT<x> is input.



A ‘0’ means  output.
I/O PORTS
HOW?
 Setting a bit in the TRIS<x> register puts the
corresponding output driver in a high-impedance input
mode (O/P mode is off).


Clearing a bit in the TRISB register puts the contents of
the output latch on the selected pin(s). (O/P mode is on)



I/O ports are multiplexed with other peripherals, if these
peripherals were used you won’t use the pin as I/O pin.
I/O PORTS


Notes:

1)

If port pins are multiplexed with analog peripherals, you must select
the function of them to be analog input or digital I/O, you do so by
changing the value of ADCON1 register.

2)

For analog inputs, make the corresponding TRIS 1.
I/O PORTS
3)
-

-

Each of the PORTB pins has a weak internal pull-up resistors.
A single control bit can turn on all the pull-ups. This is performed by
clearing bit RBPU (OPTION_REG<7>).
The weak pull-up is automatically turned off when the port pin is
configured as an output.
I/O PORTS
4)

RA4 pin is "Open-Drain" type
output pin. This means it cannot
source current and it will be high
impedance when assigned logic '1'
to it.
- You cannot set this pin as an output
pin by only using 'TRISA=0x00'.
The solution is attaching a pull up
resistor (10K) to the RA4 pin in
order to use this pin as an output
pin.
SWITCHES


We use switches to give an order to the MCU to do
something by changing the voltage level applied on
an I/O pin (input).
SWITCHES

-

Bouncing problem:
The problem with using a mechanical switch is that switch
contacts "bounce“ when you close the switch.
SWITCHES
-

-

-

When the switch is closed, the two contacts actually separate
and reconnect, typically 10 to 100 times in about 100ms.
This bouncing would send multiple key press signals to the
MCU which is not what you want.

While 100 milliseconds is quite short for us as humans, it is
actually quite long for a digital circuit and the period between
spikes is often enough for the application to respond.
SWITCHES
Solution:
1-Using RC circuit:
- We use it as a LPF, as the ripples
happen very fast (high frequency).

2-By software:
- By reading the value of the pin more than one time in small
time intervals to make sure of the real value on the pin.
-

This done by testing the value, wait for some time (110 ms)
and test again if the value is the same, so it’s the true value.
LEDS


It’s the simplest way to indicate an
output.



We have to use a current limiting
resistor with it (typically 330Ω).
APPLICATION 1
-

Write a program outputs high on RC0, if RB0 is low using
switches and leds.
ASSIGNMENT
-

Write a code for a MCU that outputs these results on PORTC<5:7>
for the inputs entered on PORTB<3:5>.

 Write a function that handles the bouncing problem.
PORTB (input)

PORTC (output)

000

010

001

110

010

011

001

001

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
 
LPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLERLPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLER
 
MICROCONTROLLER 8051
MICROCONTROLLER 8051MICROCONTROLLER 8051
MICROCONTROLLER 8051
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentation
 
Switches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontrollerSwitches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontroller
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
TMS320C5x
TMS320C5xTMS320C5x
TMS320C5x
 
Microprocessor Fundamentals
Microprocessor FundamentalsMicroprocessor Fundamentals
Microprocessor Fundamentals
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLER
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Direct Memory Access
Direct Memory AccessDirect Memory Access
Direct Memory Access
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
 

Destacado

8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog worldIslam Samir
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIslam Samir
 

Destacado (7)

8051 ram org
8051 ram org8051 ram org
8051 ram org
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
Timers
TimersTimers
Timers
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
 
Interrupts
InterruptsInterrupts
Interrupts
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and Microcontrollers
 
USART
USARTUSART
USART
 

Similar a I/O Ports

An Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus InterfaceAn Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus InterfacePremier Farnell
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.pptnotagain0712
 
Pin configuration of 8085
Pin configuration of 8085Pin configuration of 8085
Pin configuration of 808582338476
 
An alarm system is to have 4 different devices, each with its sensor..pdf
An alarm system is to have 4 different devices, each with its sensor..pdfAn alarm system is to have 4 different devices, each with its sensor..pdf
An alarm system is to have 4 different devices, each with its sensor..pdfleventhalbrad49439
 
To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.Ankita Tiwari
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontrollerthokalpv
 
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]akmalKhan55
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING Radhika Talaviya
 
Introduction to arduino!
Introduction to arduino!Introduction to arduino!
Introduction to arduino!Makers of India
 
Automatic doorbell with object detection
Automatic doorbell with object detectionAutomatic doorbell with object detection
Automatic doorbell with object detectionAnurag Alaria
 
08 chapter03 06_status_bits_otl_otu_scan_logic_fa16
08 chapter03 06_status_bits_otl_otu_scan_logic_fa1608 chapter03 06_status_bits_otl_otu_scan_logic_fa16
08 chapter03 06_status_bits_otl_otu_scan_logic_fa16John Todora
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 

Similar a I/O Ports (20)

An Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus InterfaceAn Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus Interface
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt
 
Pin configuration of 8085
Pin configuration of 8085Pin configuration of 8085
Pin configuration of 8085
 
An alarm system is to have 4 different devices, each with its sensor..pdf
An alarm system is to have 4 different devices, each with its sensor..pdfAn alarm system is to have 4 different devices, each with its sensor..pdf
An alarm system is to have 4 different devices, each with its sensor..pdf
 
K 36 rev-l
K 36 rev-lK 36 rev-l
K 36 rev-l
 
To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
Pin 8085
Pin 8085Pin 8085
Pin 8085
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING
 
8051 book
8051 book8051 book
8051 book
 
embedded system
embedded system  embedded system
embedded system
 
Introduction to arduino!
Introduction to arduino!Introduction to arduino!
Introduction to arduino!
 
Automatic doorbell with object detection
Automatic doorbell with object detectionAutomatic doorbell with object detection
Automatic doorbell with object detection
 
INTELIGENT RAILWAY SYSTEM
INTELIGENT RAILWAY SYSTEMINTELIGENT RAILWAY SYSTEM
INTELIGENT RAILWAY SYSTEM
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
Logic Gates & Family.pdf
Logic Gates & Family.pdfLogic Gates & Family.pdf
Logic Gates & Family.pdf
 
08 chapter03 06_status_bits_otl_otu_scan_logic_fa16
08 chapter03 06_status_bits_otl_otu_scan_logic_fa1608 chapter03 06_status_bits_otl_otu_scan_logic_fa16
08 chapter03 06_status_bits_otl_otu_scan_logic_fa16
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 

Último

0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsApsara Of India
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 DelhiCall Girls in Delhi
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
Understanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key InsightsUnderstanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key Insightsseribangash
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdftbatkhuu1
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfOnline Income Engine
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetCreating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetDenis Gagné
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxAndy Lambert
 

Último (20)

0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Understanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key InsightsUnderstanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key Insights
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdf
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdf
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetCreating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 

I/O Ports

  • 2. AGENDA    I/O ports and how to use them Some exceptions with some ports. Handling the bouncing problem.
  • 3. AGENDA    I/O ports and how to use them Some exceptions with some ports. Handling the bouncing problem.
  • 4.
  • 5. I/O PORTS  Every microcontroller must have means of communication to the outside world.  The simplest way for communication is using general purpose I/O ports.
  • 6. I/O PORTS  Reading a port: - Means reading the status (voltage level) present on the  - pin. Writing to a port: Means writing to the port latches. - You have to determine the direction of the I/O pin before using it, this is done by changing the value of the TRIS register.
  • 7. I/O PORTS Example on reading a port If the voltages: 0.5v, 4v, 2v were present on three different pins. If you read these pins, you’ll get the digital logic value corresponds to each voltage level  0 1 0. Considering the range of ‘0’ : 0v  2.5v the range of ‘1’ : 2.5v  5v
  • 8. I/O PORTS  The I/O pin direction is controlled by a register called TRIS. PORT<x> is controlled by the register TRIS<x>.  If you write ‘1’ in a bit in TRIS<x> register, this means that the corresponding bit in PORT<x> is input.  A ‘0’ means  output.
  • 9. I/O PORTS HOW?  Setting a bit in the TRIS<x> register puts the corresponding output driver in a high-impedance input mode (O/P mode is off).  Clearing a bit in the TRISB register puts the contents of the output latch on the selected pin(s). (O/P mode is on)  I/O ports are multiplexed with other peripherals, if these peripherals were used you won’t use the pin as I/O pin.
  • 10.
  • 11. I/O PORTS  Notes: 1) If port pins are multiplexed with analog peripherals, you must select the function of them to be analog input or digital I/O, you do so by changing the value of ADCON1 register. 2) For analog inputs, make the corresponding TRIS 1.
  • 12. I/O PORTS 3) - - Each of the PORTB pins has a weak internal pull-up resistors. A single control bit can turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin is configured as an output.
  • 13. I/O PORTS 4) RA4 pin is "Open-Drain" type output pin. This means it cannot source current and it will be high impedance when assigned logic '1' to it. - You cannot set this pin as an output pin by only using 'TRISA=0x00'. The solution is attaching a pull up resistor (10K) to the RA4 pin in order to use this pin as an output pin.
  • 14. SWITCHES  We use switches to give an order to the MCU to do something by changing the voltage level applied on an I/O pin (input).
  • 15. SWITCHES  - Bouncing problem: The problem with using a mechanical switch is that switch contacts "bounce“ when you close the switch.
  • 16. SWITCHES - - - When the switch is closed, the two contacts actually separate and reconnect, typically 10 to 100 times in about 100ms. This bouncing would send multiple key press signals to the MCU which is not what you want. While 100 milliseconds is quite short for us as humans, it is actually quite long for a digital circuit and the period between spikes is often enough for the application to respond.
  • 17. SWITCHES Solution: 1-Using RC circuit: - We use it as a LPF, as the ripples happen very fast (high frequency). 2-By software: - By reading the value of the pin more than one time in small time intervals to make sure of the real value on the pin. - This done by testing the value, wait for some time (110 ms) and test again if the value is the same, so it’s the true value.
  • 18. LEDS  It’s the simplest way to indicate an output.  We have to use a current limiting resistor with it (typically 330Ω).
  • 19. APPLICATION 1 - Write a program outputs high on RC0, if RB0 is low using switches and leds.
  • 20. ASSIGNMENT - Write a code for a MCU that outputs these results on PORTC<5:7> for the inputs entered on PORTB<3:5>.  Write a function that handles the bouncing problem. PORTB (input) PORTC (output) 000 010 001 110 010 011 001 001