0% found this document useful (0 votes)
4 views5 pages

Experiment 7 Microcontroller

The document outlines an experiment involving the study of I/O port operations and timing delays using the ATmega32 microcontroller. It includes assembly language programs for toggling ports, generating delays, and monitoring inputs, with specific outputs for LEDs connected to the ports. Each section describes the program, expected register states, and the resulting LED behavior based on the operations performed.

Uploaded by

rathodkushal037
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)
4 views5 pages

Experiment 7 Microcontroller

The document outlines an experiment involving the study of I/O port operations and timing delays using the ATmega32 microcontroller. It includes assembly language programs for toggling ports, generating delays, and monitoring inputs, with specific outputs for LEDs connected to the ports. Each section describes the program, expected register states, and the resulting LED behavior based on the operations performed.

Uploaded by

rathodkushal037
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

Experiment – 7

Study of I/O Port Operations and Timing Delays in ATmega32

Aim

To study I/O port operations, timing delays, port toggling, and input monitoring using
ATmega32 assembly language programs.

(a) Toggle all bits of PORTB, PORTC and PORTD every 1/4 second

Program

.include "[Link]"
.org 0x0000
rjmp MAIN

MAIN:
ldi r16, HIGH(RAMEND)
out SPH, r16
ldi r16, LOW(RAMEND)
out SPL, r16

ldi r16, 0xFF


out DDRB, r16
out DDRC, r16
out DDRD, r16

ldi r16, 0x55

L3:
out PORTB, r16
out PORTC, r16
out PORTD, r16
call QDELAY
com r16
rjmp L3

QDELAY:
ldi r21,200
D1: ldi r22,250
D2: nop
dec r22
brne D2
dec r21
brne D1
ret

Registers & I/O after execution

• DDRB = FFH
• DDRC = FFH
• DDRD = FFH
• PORTB, PORTC, PORTD toggle between 55H and AAH

Output

LEDs connected to PORTB, PORTC and PORTD toggle every ¼ second.

(b) Toggle all bits of PORTB continuously using 55H and AAH

Program

.include "[Link]"
.org 0x0000
rjmp MAIN

MAIN:
ldi r16, HIGH(RAMEND)
out SPH, r16
ldi r16, LOW(RAMEND)
out SPL, r16

BACK:
ldi r16,0x55
out PORTB,r16
call DELAY

ldi r16,0xAA
out PORTB,r16
call DELAY

rjmp BACK

DELAY:
ldi r20,0xFF
AGAIN:
nop
nop
dec r20
brne AGAIN
ret

Registers & I/O after execution

• PORTB alternates between 55H and AAH

Output

LEDs connected to PORTB display alternating ON/OFF pattern continuously.

(c) Toggle PORTB every 1 second

Program

.include "[Link]"
.org 0x0000
rjmp MAIN

MAIN:
ldi r16, HIGH(RAMEND)
out SPH, r16
ldi r16, LOW(RAMEND)
out SPL, r16

ldi r16,0xFF
out DDRB,r16

BACK:
ldi r16,0x55
com r16
out PORTB,r16
call DELAY_1S
rjmp BACK

DELAY_1S:
ldi r20,32
L1: ldi r21,200
L2: ldi r22,250
L3: nop
nop
dec r22
brne L3
dec r21
brne L2
dec r20
brne L1
ret

Registers & I/O after execution

• PORTB toggles between 00H and FFH every second.

Output

LEDs connected to PORTB toggle once every second.

(d) Monitor PB2 and generate output on PORTC and PD3

Program

.include "[Link]"
.org 0x0000
rjmp MAIN

MAIN:
cbi DDRB,2

ldi r16,0xFF
out DDRC,r16

sbi DDRD,3

AGAIN:
sbis PINB,2
rjmp AGAIN

ldi r16,0x45
out PORTC,r16

sbi PORTD,3
cbi PORTD,3

HERE:
rjmp HERE

Registers & I/O after execution

• PB2 acts as input


• PORTC outputs 45H
• PD3 generates a HIGH-to-LOW pulse

Output

When PB2 becomes HIGH,


• Value 45H is sent to PORTC
• PD3 generates a pulse

You might also like