1. Use 4 LEDs as the group1 and the other 4 LEDs as the group2. Make sure each L
ID: 3668336 • Letter: 1
Question
1. Use 4 LEDs as the group1 and the other 4 LEDs as the group2. Make sure each LED interface to one pin on Arduino board (ATMEGA 328P). Use 2 switches to control LEDs. When switch1 is pressed, 4 LEDs in group1 will blink simultaneously 3 times. When switch2 is pressed, the 4 LEDs in group2 will blink simultaneously 3 times. You can use either assembly LANGUAGE or AVR Cprogramming
2. Connect 4 LEDs to port b and one switch to port d. When the switch is pressed show the knight rider. The time interval between each stage is around 2 seconds. You can use either assembly LANGUAGE or AVR Cprogramming.
Explanation / Answer
1)
org 00H
;MAIN PROGRAM
toggle: MOV P1, #01H ;move 00000001 to PORT1
CALL delay ;execute delay
MOV A,P1 ;move PORT1 value to accumulator
CPL A ;complement PORT1 value
MOV P1, A ;move 1111110 to PORT1
CALL delay ;execeute delay
sjmp toggle
;DELAY SUB-ROUTINE
delay: MOV R5, #10 ;load register R5 with 10
third: MOV R6, #200 ;load register R6 with 200
second: MOV R4, #200 ;load register R4 with 200
DJNZ R4, $ ;decrement R4 till it is 0
DJNZ R6, second ;decrement R6 till it is 0
DJNZ R5, third ;decrement R5 till it is 0
ret ;return to main program
END
2)
led1 bit P 2.0
ORG 0000h
loop:
clr led1
//TURN ON THE LED
call delay
setb led1
//TURN OFF THE LED
call delay
ajmp loop
delay:
mov r6,#201
l0_delay:
mov r7,#216
l1_delay:
mov r4,#10
djnz r4,$
djnz r5,l3_delay
djnz r6,l2_delay
ret
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.