www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
AVR I/O PORT Programming
AVR I/O PORT Programming
Chapter 5
Chapter 5
The AVR microcontroller
and embedded
systems
using assembly and c
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
I/O Port Programming in AVR
I/O Port Programming in AVR
• In the AVR family, there are many ports for I/O operations, depending on which family
member you choose.
• Atmega32 40-pin chip. A total of 32 pins are set aside for four ports PORTA, PORTB,
PORTC, and PORTD.
• The rest of the pins are designated as VCC, GND, XTAL1, XTAL2, RESET, AREF,
AGND, and AVCC.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• I/O port pins and their functions
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• DDRx register role in outputting data:
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• DDR register role in inputting data:
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• PIN register role in inputting data:
• PORT register role in inputting data
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• The following code gets the data present at the pins of port C and send it to port B
indefinitely after adding the value 5 to it.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• If we want to make the pull up resistors of Port C active, we must put 1s into the Port C
register.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• Port A
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• Port B
• Same as port A
• Dual role of Ports A and B
• The AVR multiplexes an analog to digital converter through Port A to save I/O pins.
The alternate functions of the pins for Port A are shown in Table.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• Port C and Port D
• Same as Port A and B
• Dual role of Ports C and D
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
I/O Bit Manipulation Programming
I/O Bit Manipulation Programming
• I/O ports and bit addressability:
• Some times we need to access only 1 0r 2 bits of the port instead of the entire 8 bits.
• A powerful feature of AVR I/O ports is their capability to access individual bits of the
port without altering the rest of the bits in that port.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• SBI (set bit in I/O register)
• SBI ioReg, bit_num
• Where ioReg can be the lower 32 I/O registers (addresses 0 to 31) and bit_num is the
desired bit number from 0 to 7.
• SBI PORTB, 5
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• CBI (Clear bit in I/O register)
• CBI ioReg, bit_number
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
• Checking an input pin
• To make decisions based on the status of a given bit in the file register, we use the
SBIC (Skip if bit in I/O register Cleared) and SBIS (Skip if Bit in I/O register Set)
instructions.
• SBIS (Skip if Bit in I/O register Set)
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
www. MicroDigital Ed. com
BIHEuniversity
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Questions and Answers
Questions and Answers
END

AVR_ Microcontroller_Muhammad Ali_Mazidi_AVR_Lecture5_Fall2023

  • 1.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. AVR I/O PORT Programming AVR I/O PORT Programming Chapter 5 Chapter 5 The AVR microcontroller and embedded systems using assembly and c
  • 2.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. I/O Port Programming in AVR I/O Port Programming in AVR • In the AVR family, there are many ports for I/O operations, depending on which family member you choose. • Atmega32 40-pin chip. A total of 32 pins are set aside for four ports PORTA, PORTB, PORTC, and PORTD. • The rest of the pins are designated as VCC, GND, XTAL1, XTAL2, RESET, AREF, AGND, and AVCC.
  • 3.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • I/O port pins and their functions
  • 4.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 5.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • DDRx register role in outputting data:
  • 6.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • DDR register role in inputting data:
  • 7.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • PIN register role in inputting data: • PORT register role in inputting data
  • 8.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • The following code gets the data present at the pins of port C and send it to port B indefinitely after adding the value 5 to it.
  • 9.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • If we want to make the pull up resistors of Port C active, we must put 1s into the Port C register.
  • 10.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 11.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • Port A
  • 12.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 13.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • Port B • Same as port A • Dual role of Ports A and B • The AVR multiplexes an analog to digital converter through Port A to save I/O pins. The alternate functions of the pins for Port A are shown in Table.
  • 14.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • Port C and Port D • Same as Port A and B • Dual role of Ports C and D
  • 15.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 16.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. I/O Bit Manipulation Programming I/O Bit Manipulation Programming • I/O ports and bit addressability: • Some times we need to access only 1 0r 2 bits of the port instead of the entire 8 bits. • A powerful feature of AVR I/O ports is their capability to access individual bits of the port without altering the rest of the bits in that port.
  • 17.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • SBI (set bit in I/O register) • SBI ioReg, bit_num • Where ioReg can be the lower 32 I/O registers (addresses 0 to 31) and bit_num is the desired bit number from 0 to 7. • SBI PORTB, 5
  • 18.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • CBI (Clear bit in I/O register) • CBI ioReg, bit_number
  • 19.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 20.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 21.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 22.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 23.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. • Checking an input pin • To make decisions based on the status of a given bit in the file register, we use the SBIC (Skip if bit in I/O register Cleared) and SBIS (Skip if Bit in I/O register Set) instructions. • SBIS (Skip if Bit in I/O register Set)
  • 24.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 25.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 26.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 27.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 28.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 29.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 30.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 31.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 32.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved.
  • 33.
    www. MicroDigital Ed.com BIHEuniversity AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ 07458. • All Rights Reserved. Questions and Answers Questions and Answers END