Question
Please help me fix my code so it does the following. Atmel assembly only for 324p Write assembly code so that when switch on PB0
Please help me fix my code so it does the following. Atmel assembly only for 324p
Write assembly code so that when switch on PB0 is on the LEDs sequentially light up starting at PA0 through PA7. In the same code when switch on PD1 is on the LEDs sequentially light up starting at PA7 through PA0.
In both cases use a subroutine for a 1 second DELAY between sequentially turning on the LEDs
.equ CLEAR = 0// Equates variable 'CLEAR' to value '0'
.equ ALL_OUTPUT = 0xFF// Equates variable 'ALL_OUTPUT' to value '0xFF'
.def TEMP = r16// Defines variable 'TEMP' for register 'r16'
// SETUP
ldi TEMP, ALL_OUTPUT// Loads '0xFF' into 'r16'
out DDRB, TEMP// Outputs value from 'r16' into 'DDRB'
// STACK POINTER INITIALIZATION
ldi TEMP, low(RAMEND)// Loads low-byte end of SRAM location
out SPL, TEMP// Outputs value from 'r16' into stack pointer's low-byte
ldi TEMP, high(RAMEND)// Loads high-byte end of SRAM location
out SPH, TEMP// Outputs value from 'r16' into stack pointer's high-byte
ldi TEMP, CLEAR// Loads '0' into 'r16'
MAIN:// Label for main function
LDI R20, 0xFF
OUT DDRB, R20;make PORTB an output port
SBI PORTB,0;set bit PD0
CALL DELAY;DELAY before next one
CBI PORTB,0;clear bit PD0
SBI PORTB,1;turn on PD1
CALL DELAY;DELAY before next one
CBI PORTB,1;clear bit PD1
SBI PORTB,2;turn on PD2
CALL DELAY
CBI PORTB,2;clear bit PD2
SBI PORTB,3
CALL DELAY
CBI PORTB,3;clear bit PD3
SBI PORTB,4
CALL DELAY
CBI PORTB,4;clear bit PD4
SBI PORTB,5
CALL DELAY
CBI PORTB,5;clear bit PD1
SBI PORTB,6
CALL DELAY
CBI PORTB,6;clear bit PD1
SBI PORTB,7
CALL DELAY
CBI PORTB,7;clear bit PD7
DELAY:// Label for DELAY function
.equ COUNT = 9999// Each unit represents 0.5us for 8MHz clock
.equ PRESCALER = 200// Multiplies the counter
ldi r23, PRESCALER// r23 off time count
L1:
ldi r24, COUNT%256// r24 off time count
ldi r25, COUNT/256// r25 off time count
L2:
subi r24, 1// Decrement off time count
sbci r25, 0// Upper byte
brne L2// Loop until zero
dec r23// Decrement number of repeats
brne L1// Loop until zero
ret// Finish DELAY and return
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started