I-O Port Programming in AVR
I-O Port Programming in AVR
1. 32
2. In the ATmega32, there are three pins assigned to Vcc (power supply) and
three pins assigned to GND (ground).
- PA0: Pin 40
- PA1: Pin 39
- PA2: Pin 38
- PA3: Pin 37
- PA4: Pin 36
- PA5: Pin 35
- PA6: Pin 34
- PA7: Pin 33
These pins can be used for various I/O functions as configured in the
microcontroller.
- PB0: Pin 16
- PB1: Pin 15
- PB2: Pin 14
- PB3: Pin 13
- PB4: Pin 12
- PB5: Pin 11
- PB6: Pin 10
- PB7: Pin 9
- PC0: Pin 23
- PC1: Pin 22
- PC2: Pin 21
- PC3: Pin 20
- PC4: Pin 19
- PC5: Pin 18
- PC6: Pin 17
These pins can be used for various I/O functions as configured in the
microcontroller.
- PD0: Pin 2
- PD1: Pin 3
- PD2: Pin 4
- PD3: Pin 5
- PD4: Pin 6
- PD5: Pin 7
- PD6: Pin 8
- PD7: Pin 9
These pins can be configured for various I/O functions, including external
interrupts.
8. Input
- Configuration:
- Function: It controls the output level of the pins configured as outputs and
influences the behavior of pins configured as inputs (when using pull-up
resistors).
- Behavior:
- If a bit is set to `1`, the corresponding output pin is driven high (logic level
‘1’).
- If a bit is set to `0`, the corresponding output pin is driven low (logic level
‘0’).
- For input pins, setting the bit in `PORTx` enables the internal pull-up
resistor for that pin, keeping it at a high level unless driven low externally.
Summary
Set Output Levels: Use `PORTx` to drive output pins high or low, or to
enable pull-ups for input pins.
Int main(void) {
While (1) {
Return 0;
While (1) {
Return 0;
Address: 0x3A
Address: 0x37
Address: 0x34
14.
a) #include <avr/io.h>
#include <util/delay.h>
Int main(void) {
While (1) {
Return 0;
b) #include <avr/io.h>
#include <util/delay.h>
Int main(void) {
While (1) {
: “=r” (PORTB)
: “0” (PORTB)
);
Asm volatile (
: “=r” (PORTC)
: “0” (PORTC)
);
Return 0;