0% found this document useful (0 votes)
12 views13 pages

Lecture - 05 - ATmega32 Pinout and Digital IO

Uploaded by

Mustaq Mujahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views13 pages

Lecture - 05 - ATmega32 Pinout and Digital IO

Uploaded by

Mustaq Mujahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

EEE/ECE 365

Microprocessor

Lecture #5
ATmega32 Pinout and Digital I/O

Md Rakibul Hasan, Lecturer, Dept. of EEE


BRAC University
Slide Courtesy of Imtiaz Ahmed, Lecturer, Dept. of EEE, BRAC University
13 June 2022
ATmega32 Pinout & Descriptions
❑ There are 4 ports that provide parallel I/O interfaces
to outside world: Port A, Port B, Port C, and Port D.
❑ Each port has 8 bi-directional digital I/O lines.
❑ Even though bidirectional, at any time the I/O lines
can either be Input or Output.
❑ The directions of each I/O lines must be configured
(input or output) before they are used.

2
ATmega32 Pinout & Descriptions

13 June 2022
3
13 June 2022
Role of DDRx Register in Outputting Data
• Each of the Ports A-D in ATmega32 can be used for Input or Output.
• An I/O register called DDRx is used solely for the purpose of making
a given port input or output port.
• For example, to make a port an output, we write 1 to the DDRx
register.
• In other words, to output data to all of the pins of Port B, we must
first put 0b11111111 (0xFF) into DDRB register to make all the pins
output.

4
13 June 2022
How data is sent to the output port?
• Once you set the direction of a port as output, the data that you
want to send to the output, you have to write that data into PORTx
register.
• If DDRC=0xFF and then PORTC=0x3B, the data at the output will also
be 0x3B.
• That is -
0 0 1 1 1 0 1 1
PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0

5
Example-1

13 June 2022
Problem Statement
a) Eight LEDs are connected to eight pins of Port C.
b) At first, only MSB LED will glow and others will remain OFF.
c) After 0.5 sec, its adjacent LED will glow and others will be OFF.
d) In this way, the shifting of the glowing LED will move up to LSB LED.
e) The same movement will continue for ever.

6
Interfacing Circuit

13 June 2022
7
7
The Code (Ex-1)

13 June 2022
// LED shifting.c while (1)
{
#include <mega32.h> PORTC=0x80;
#include <delay.h> delay_ms(500);
for (shift=0;shift<7;shift++)
void main(void) {
{ PORTC=PORTC>>1;
char shift; delay_ms(500);
DDRC=0xFF; }
}
}

8
Example-2

13 June 2022
Problem Statement:
In the previous example (example-1),

At every 3 number of complete cycle of shifting, all LED will glow and
remain glowing for 2 sec.

Then, the shifting will start again (from MSB to LSB).

The whole process described will be repeated forever.

9
The Modified Code (Ex-2)

13 June 2022
#include <mega32.h>
#include <delay.h> for (count=0;count<3;count++)
{
void main(void) PORTC=0x80;
{ delay_ms(500);
char shift,count; for (shift=0;shift<7;shift++)
DDRC=0xFF; {
while (1) PORTC=PORTC>>1;
{ delay_ms(500);
}
}
PORTC =0xFF;
delay_ms(2000);
}
}
10
Example-3

13 June 2022
Problem Statement:
In the previous example (example-2),

One glowing LED will shift in the right direction three times, and then all
LED will glow and remain glowing for 2 sec.

After that, shifting will be in the left direction next three time.

Then, all LED will glow and remain glowing for 2 sec.

These two kinds of shifting will be repeated for ever.

11
13 June 2022
The Modified Code (Ex-3)
#include <mega32.h> while (1)
#include <delay.h> { for (count=0;count<3;count++)
for (count=0;count<3;count++) {
void main(void) { PORTC =0x01;
{ PORTC=0x80; delay_ms(500);
char shift,count; delay_ms(500); for (shift=0;shift<7;shift++)
DDRC=0xFF; for (shift=0;shift<7;shift++) {
{ PORTC=PORTC<<1;
PORTC=PORTC>>1; delay_ms(500);
delay_ms(500); }
} }
} PORTC =0xFF;
PORTC =0xFF; delay_ms(2000);
delay_ms(2000); }
}
12
13 June 2022
13
Thanks

You might also like