V
V
VARSAVA2021-01-20 17:06:57
Atmel AVR
VARSAVA, 2021-01-20 17:06:57

I don’t understand what is the error in the Assembler code for Atmega 16?

6008375fb1d4c313122994.png
Here is the diagram. By default, one light is on (let's say the top one). When you press the button, the second one should light up and the second one should go out.
Start:
in r16 pinc
sbrs r16, 2
out ddra, r16
ldi port A, r17 0b00000010 cpi
r17, 1
breq zxc
rjmp start
zxc:
ldi r17, 255
out ddra, r17
ldi r18, 0b0b00000101
out porta, r18
rjmp
wrote this code , I understand that it is not correct, but I do not understand what the error is. (thanks in advance for helping a newbie).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evgeniy_lm, 2021-01-20
@evgeniy_lm

Error in everything.
1. There are no light bulbs
on the diagram 2. Suppose there are LEDs on the diagram (this is not indicated, but again about light bulbs), then it was necessary to indicate where they are connected.
3. The actual algorithm of operation:
a) set the pins of the ports for input for the button, for output for the LED
b) in a cycle (or better on a timer) we check the button press: if it is pressed and the press flag is reset, we invert the LED state variable and issue it to the port, raise the flag pressing (so that there is no cyclic switching while holding the button); if it is not pressed, reset the flag
. when the button is guaranteed to be held for some time (usually 0.1s)
If you need a ready-made code, write to the mail, we will agree

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question