Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

I/O Ports


Published on

Published in: Business
  • Be the first to comment

I/O Ports

  1. 1. I/O PORTS Prepared by: Islam Samir
  2. 2. AGENDA    I/O ports and how to use them Some exceptions with some ports. Handling the bouncing problem.
  3. 3. AGENDA    I/O ports and how to use them Some exceptions with some ports. Handling the bouncing problem.
  4. 4. 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.
  5. 5. 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.
  6. 6. 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
  7. 7. 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.
  8. 8. 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.
  9. 9. 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.
  10. 10. 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.
  11. 11. 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.
  12. 12. 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).
  13. 13. SWITCHES  - Bouncing problem: The problem with using a mechanical switch is that switch contacts "bounce“ when you close the switch.
  14. 14. 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.
  15. 15. 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.
  16. 16. LEDS  It’s the simplest way to indicate an output.  We have to use a current limiting resistor with it (typically 330Ω).
  17. 17. APPLICATION 1 - Write a program outputs high on RC0, if RB0 is low using switches and leds.
  18. 18. 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