0% found this document useful (0 votes)
1 views

IO programming

Unit-5 covers I/O programming with a focus on digital input and output circuitry, including functions like pinMode(), digitalWrite(), delay(), and digitalRead(). It explains the Arduino Uno pin definitions and how to interface microcontrollers with external devices. The document also details the operation and configuration of digital pins, including considerations for using pull-up resistors.

Uploaded by

Aksh Vashist
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

IO programming

Unit-5 covers I/O programming with a focus on digital input and output circuitry, including functions like pinMode(), digitalWrite(), delay(), and digitalRead(). It explains the Arduino Uno pin definitions and how to interface microcontrollers with external devices. The document also details the operation and configuration of digital pins, including considerations for using pull-up resistors.

Uploaded by

Aksh Vashist
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit-5

I/O Programming
• Digital Output Circuitry
• Digital Input Circuitry
• pinMode ()
• Arduino Uno Pin Definitions
• digitalWrite ()
• delay ()
• digitalRead()
• Analog Input Circuitry
• analogRead()

Digital Output Circuitry

• Fully appreciate the software interface to microcontrollers and to gain insight into how to
interface controllers to external devices, it is useful to examine the underlying circuitry.
• In this chapter we shall investigate the basic digital output circuitry.
• Anything that can be controlled with a simple logical yes/no, true/false input can be a target.
• Although controllers usually have limited output current and voltage capability, they can
control devices such as power transistors which can in turn control more demanding loads.
• A simplified diagram of the General Purpose Input-Output (GPIO) circuitry

• The circuit represents a single bit.

• An IO port consists of eight bits, typically.

• Therefore this circuitry would be replicated seven more times to accommodate a single
byte-wide port, of which there may be several.

• Also, in order to reduce the external pin count of the IC, pins may be multiplexed with other
functions.

• The multiplexers are not shown in this schematic.

• Pxn, at the far left of the schematic, represents the physical output pin.

• The data bus shown along the right edge is the source for data being written to the physical
pin and also the destination for data being read from the pin.

Arduino Uno Pin Definitions


First have to think in terms of an Arduino pin number instead of a port bit number. Below is a table
of Arduino Uno pin designations versus ATmega 328P port and pin naming. when originally we wrote
pinMode( 8, OUTPUT );

The function decoded Arduino pin 8 as being bit 0 of port B (i.e., PORTB). It also determined that the
corresponding DDR is DDRB. The bit 0 mask is 0x01 and it was ORed with the contents of DDRB, thus
selecting the direction for that bit as output mode.

digitalWrite( )

Write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. If the pin is
configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal 20K pullup
resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup resistor is
enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely cause. The
remedy is to set the pin to an output with the pinMode() function.

Note: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED
and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k
pull-up resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and
series resistor pull the voltage level down, meaning it always returns LOW. a digital input, use an
external pull down register.

Syntax

•digitalWrite(pin, value)

Parameters

pin: the pin number

value: HIGH or LOW

• Returns none

delay( )

• Pauses the program for the amount of time (in miliseconds) specified as parameter.

(There are 1000 milliseconds in a second.)

Syntax

delay( ms )

Parameters

•ms: the number of milliseconds


to pause (unsigned long)

• Returns nothing

digitalRead ()

Reads the value from a specified digital pin, either HIGH or LOW.

Syntax

digitalRead( pin )

Parameters

• pin: the number of the digital

pin you want to read (int )

• Returns • HIGH or LOW

You might also like