This preview shows page 1. Sign up to view the full content.
Unformatted text preview: I/O Ports ECET 209 – Lecture 2
Introduction to Microcontrollers Overview
• Basic Microcontrollers
• Input / Output Operations ECET 209 Purdue University 2 I/O ECET 209 Purdue University 3 Input / Output
• Microcontrollers are used to control devices
• Need the ability to:
– monitor or read inputs like switches or sensors
– control devices like actuators or motors ECET 209 Purdue University 4 I/O Ports
• Allows the micro to see the “World” and to
modify or change the “World” ECET 209 Purdue University 5 Quiz ECET 209 Purdue University 6 ECET 209 Purdue University 7 Port Configuration
• The Atmel AVR Family of
microcontrollers requires that the ports
be configured for either input or output. ECET 209 Purdue University 8 Port Configuration
• The microcontroller has a data direction
register for each port that controls the
direction (input or output) of the desired
port. ECET 209 Purdue University 9 ECET 209 Purdue University 10 Simplified IO Port Diagram
PULLUP DATA BUS Q D CLK 2 3
Write DDRn 1 6 Q CLR 5 RESET
Read DDRn 5 Q D CLK 2 3
Write PORTn 1 6 Q CLR PORT PIN RESET
Read PORTn Register Read PORTn PIN ECET 209 Purdue University 11 Port Registers ECET 209 Purdue University 12 Data Direction Registers
• Port's Data Direction is the DDRn
– Controls whether or not it is an input or an
– Setting (writing a one) to a bit in the DDRn
configures the pin as an Output
– Clearing (writing a zero) to a bit in the DDRn
configures the pin as an Input
ECET 209 Purdue University 13 How is this Accomplished?
– We are going to use C as a Tool. ECET 209 Purdue University 14 Port Registers 1 ECET 209 1 1 Purdue University 1 1 1 1 1 15 C to Configure Ports
• PORTC as an Output (write 1’s to DDRC) DDRC = 0xFF; ECET 209 // configure PORTC as Output Purdue University 16 C to Configure Ports
• PORTA as an Input (write 0’s to DDRA) DDRA = 0x00; ECET 209 // configure PORTA for Input Purdue University 17 Internal Pull-up Resistors
• To Float or not to Float
– Largely depends on the design
– For this class, We will use the Pull-up Option ECET 209 Purdue University 18 Configuring Pull-ups ON ECET 209 Purdue University 19 Configuration
• The PORTn register controls if the Pull-up
is activated or not.
– Writing a one to the PORTn register will
activate the internal pull-up resistor.
– Writing a zero to the PORTn register will
deactivate or turn off the internal pull-up
ECET 209 Purdue University 20 The C Code
• PORTA configured as an input with the
internal pull-up resistors on.
DDRA = 0x00; // configure PORTA for Input PORTA = 0xFF; // turn on the pull-up resistors ECET 209 Purdue University 21 Any Questions about Configuring
Ports ? ECET 209 Purdue University 22 Reading and Controlling Ports
• Now we are ready to actually use the ports.
• When using the port as an input, we read
from the input PINS.
• When using the port as an output, we write
to the output PORT register. ECET 209 Purdue University 23 The C Code
• Reading and writing to and from Ports PORTC = PINA; ECET 209 // echo value on PortA to PortC Purdue University 24 Block Diagrams PORTB PORTD ECET 209 PORTA PORTC Purdue University 25 ECET 209 Purdue University 26 Picking the Right Micro
• The AVR 8-Bit RISC family has ~35
– # of I/O pins range from 6 to 54
Flash from 1K to 128K
Supply voltage from 1.8V to 5.5V
Frequency range from 1 to 20 MHz
… ECET 209 Purdue University 27 Picking the Right Micro
• The right microcontroller can make or break
• Influence the development time
• Influence the budget
• Influence your Senior Design Grade!!
ECET 209 Purdue University 28 Questions? ECET 209 Purdue University 29 ...
View Full Document
- Fall '08