Chap4_port_programming
Chap4_port_programming
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.
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
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