Microprocessor Lab3
Microprocessor Lab3
Microprocessor Lab3
Code:
.ORG 0x00
start:
LDI R20, 0x01
OUT DDRB, R20 ;set the output pins
off:
LDI R22, 0x00 ;load 0 to R22
OUT PORTB, R22 ;output it to portB
RJMP start ;repeat program
Hardware:
Code
.ORG 0x00
LDI R20, 200
LDI R21, 100
LDI R22, 0x01 ;constant that will xor output after every cycle
ldi R16, 0x00 ;will store our output
OUT DDRB, R22 ;for controlling one output LED
DELAY:
NOP
NOP
NOP
DEC R20 ;decrement the first counter and jump to the second
Brne loop2
rjmp end
end:
EOR R16, R22 ;XOR the output
OUT PORTB, R16 ;to output value from xor to the output
LDI R20, 200
LDI R21, 100
RJMP DELAY
4.3 Subroutines and Stack
4.3.1 Task C
The following program stores seven characters in memory. Write a subroutine named
CHECK PALINDROME that return 1 in R16 if this seven letter word is a palindrome
else return 0 in R16. Utilize the property of AVR stack in your function.
Replace these seven characters with "ROTATOR" and then with "JUMPOFF" to check
Code
.ORG 0x00
LDI R16, 'R'
STS 0x200, R16
LDI R16, 'A'
STS 0x201, R16
LDI R16, 'C'
STS 0x202, R16
LDI R16, 'E'
STS 0x203, R16
LDI R16, 'C'
STS 0x204, R16
LDI R16, 'A'
STS 0x205, R16
LDI R16, 'R'
STS 0x206, R16
CALL CheckPalindrome
rjmp Here
Here:
RJMP Here
.ORG 0x50
CheckPalindrome:
LDI R16, 0
LDI R20, 0
LDS R17, 0x200
LDS R18, 0x206
CP R17,R18
BRNE END
LDS R17, 0x201
LDS R18, 0x205
BRNE END
LDS R17, 0x202
LDS R18, 0x204
BRNE END
LDI R16, 1
RJMP Here
Ret
END:
RJMP Here
For Racecar
For Rotator
For JUMPOFF