0% found this document useful (0 votes)
17 views4 pages

Chap4_port_programming

The document contains a series of AVR assembly language programs for various tasks including toggling bits on PORTB, PORTC, and PORTD, controlling LEDs, generating square waves, monitoring input pins, and managing a door alarm and switch status. Each program includes initialization of registers, delay subroutines, and specific logic to perform the desired operations. The programs demonstrate basic microcontroller functionality and I/O operations using AVR assembly language.

Uploaded by

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

Chap4_port_programming

The document contains a series of AVR assembly language programs for various tasks including toggling bits on PORTB, PORTC, and PORTD, controlling LEDs, generating square waves, monitoring input pins, and managing a door alarm and switch status. Each program includes initialization of registers, delay subroutines, and specific logic to perform the desired operations. The programs demonstrate basic microcontroller functionality and I/O operations using AVR assembly language.

Uploaded by

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

1 Write a test program for the AVR chip to toggle all the bits of PORTB,PORTC & PORTD every ¼

of a second .Assume a crystal frequency of 1MHz.

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 R20, 16
D0: LDI R21, 200
D1: LDI R22, 250
D2: NOP
NOP
DEC R22
BRNE D2
DEC R21
BRNE D1
DEC R20
BRNE D0
RET

2 An LED is connected to each pin of PortD.Write a program to turn on each LED from pin D0 to
pin D7.Call a delay subroutine before turning on the next LED.

LDI R16, HIGH(RAMEND)


OUT SPH, R16
LDI R16, LOW(RAMEND)
OUT SPL, R16

LDI R20, 0xFF


OUT DDRD, R20
SBI PORTD, 0
CALL DELAY
SBI PORTD, 1
CALL DELAY
SBI PORTD, 2
CALL DELAY
SBI PORTD, 3
CALL DELAY
SBI PORTD, 4
CALL DELAY
SBI PORTD, 5
CALL DELAY
SBI PORTD, 6
CALL DELAY
SBI PORTD, 7
CALL DELAY

L1: RJMP L1

DELAY:
LDI R20,32
DL1:LDI R21,200
DL2:LDI R22,250
DL3:
NOP
NOP
DEC R22
BRNE DL3

DEC R21
BRNE DL2

DEC R20
BRNE DL1
RET

3 Create a square wave of 50% duty cycle on bit0 of portC.

LDI R16, HIGH(RAMEND)


OUT SPH, R16
LDI R16, LOW(RAMEND)
OUT SPL, R16

SBI DDRC, 0
HERE:
SBI PORTC, 0
CALL DELAY
CBI PORTC, 0
CALL DELAY
RJMP HERE

DELAY:
LDI R20, 255
DL1:DEC R20
BRNE DL1
RET
4 Write a program to perform the following.
1) Keep monitoring the PB2 bit until it becomes HIGH.
2) When PB2 becomes high , write the value $45 to portC, and also send a HIGh to LOW
pulse to PD3.

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
5 Assume that bit PB3 is an input and represents the condition of a door alarm..If it goes LOW, it
means that the door is open. Monitor the bit continuously .Whenever it goes Low send a High
to Low pulse to Port C5 to turn on a buzzer.

CBI DDRB, 3
SBI DDRC, 5
HERE:
SBIC PINB, 3
RJMP HERE
SBI PORTC, 5
FINAL: RJMP FINAL

6 A switch is connected to pin PB0 and an LED to Pin PB7 .Write a program to get the status of
SW & send it to the LED.

CBI DDRB, 0
SBI DDRB, 4
AGAIN:
SBIC PINB, 0
RJMP OVER
CBI PORTB, 4
RJMP AGAIN
OVER:
SBI PORTB, 4
RJMP AGAIN
7 A switch is connected to pin PB0.Write a program to get the status of SW and save it in
location 0X200.
.EQU MYTEMP = 0x200

CBI DDRB, 0
AGAIN:
SBIC PINB, 0
RJMP OVER
LDI R16, 0
STS MYTEMP, R16
RJMP AGAIN
OVER:
LDI R16, 0x01
STS MYTEMP, R16
RJMP AGAIN

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy