Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Take the attached file q5.asm as a template which have already provided the delay code code from previous assignment: .equ A = 13 .equ C
Take the attached file q5.asm as a template which have already provided the delay code
code from previous assignment:
.equ A = 13
.equ C = 17
.equ SEED = 19
.cseg
.org 0
ldi r16, SEED
ldi r17, A
mul r16, r17
mov r16, r0
ldi r17, C
add r16, r17
andi r16, 0b00111111
done:
rjmp done
q5 template below:
.def ZERO = r20 .def ONE = r21 .cseg .org 0 ldi ZERO, 0 ldi ONE, 1 ;necessary initialization repeat: ; generate a random number in range 0~63 and store it in R16 ; illuminate LEDs according to value in R16 ; delay 1s clr r19 clr r18 loop1: ldi r20, 20 loop2: nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop inc r20 cpi r20, 0 brne loop2 add r18, ONE adc r19, ZERO cpi r19, 250 brne loop1 ;another round rjmp repeatIn ATmega2560, each I/O port has three associated registers, the data direction rister (DDRx), ouipui register (POR), and inpui rister (PINx) orx ample, the registers for Port B are named as DDRB, PORTB and PINB (Check lab materials for more details). Continue with your code for Question 5 in Assignment 1, write a program to re- peat illuminating LEDs randomly (according to the random number generated) with an interval as approximately 1 second. For example, if the random number generated is 55, or Ob00110111 in binary, then the LEDs to be illuminated are indexed as 1, 2, 3, 5 and 6. Hints: (1) use sbrc or sbrs to test each bit (0-5th) (2) 0th, 1st bits control value in PORTB (3) 2-5th bits control value in PORTL (4) 6th, 7th bits always 0 Example: Suppose the random value is Ob00101101. The code logic is like: R16: 0 010 11 0 1 PORTL: 10001010 PORTB: 00000010 In ATmega2560, each I/O port has three associated registers, the data direction rister (DDRx), ouipui register (POR), and inpui rister (PINx) orx ample, the registers for Port B are named as DDRB, PORTB and PINB (Check lab materials for more details). Continue with your code for Question 5 in Assignment 1, write a program to re- peat illuminating LEDs randomly (according to the random number generated) with an interval as approximately 1 second. For example, if the random number generated is 55, or Ob00110111 in binary, then the LEDs to be illuminated are indexed as 1, 2, 3, 5 and 6. Hints: (1) use sbrc or sbrs to test each bit (0-5th) (2) 0th, 1st bits control value in PORTB (3) 2-5th bits control value in PORTL (4) 6th, 7th bits always 0 Example: Suppose the random value is Ob00101101. The code logic is like: R16: 0 010 11 0 1 PORTL: 10001010 PORTB: 00000010
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