0
#define __SFR_OFFSET 0
#include <avr/io.h>

.global main 

main: 
ldi R16, 0xFD          ; Set PD1–PD6 as outputs, PD0 as input
out DDRD, R16

ldi R16, 0x01          ; Enable pull-up resistor on PD0
out PORTD, R16

ldi R16, 0b00000111    ; Set PB0 and PB1 and PB2 as outputs
out DDRB, R16


wait_button:
    sbis PIND, 0        ; Skip if bit in PIND.0 is SET (button NOT pressed)
    rjmp start_sequence ; Jump if it's 0 (button pressed)
    rjmp wait_button    ; Keep waiting

    wait_release:
    sbic PIND, 0           ; Wait until button is released (PIND.0 == 1)
    rjmp wait_release      ; Now wait for the next button press
    rjmp wait_button


start_sequence:
; Turn on  PD1
ldi R16, 0b00000010
out PORTD, R16
cbi PORTB, 0
cbi PORTB, 1
cbi PORTB, 2
 rjmp wait_release      ; Now wait for the next button press

; Blink PD2
ldi R16, 0b00000100
out PORTD, R16
rjmp wait_release      ; Now wait for the next button press


; Blink PD3
ldi R16, 0b00001000
out PORTD, R16
 rjmp wait_release      ; Now wait for the next button press

; Blink PD4
ldi R16, 0b00010000
out PORTD, R16

 rjmp wait_release      ; Now wait for the next button press

; Blink PD5
ldi R16, 0b00100000
out PORTD, R16
rjmp wait_release      ; Now wait for the next button press



; Blink PD6
ldi R16, 0b01000000
out PORTD, R16

rjmp wait_release      ; Now wait for the next button press

; Blink PB0
clr R16
out PORTD, R16
sbi PORTB, 0
cbi PORTB, 1
cbi PORTB, 2
rjmp wait_release      ; Now wait for the next button press



; Blink PB1
cbi PORTB, 0
sbi PORTB, 1
cbi PORTB, 2

    rjmp wait_release      ; Now wait for the next button press

; Blink PB2
cbi PORTB, 0
cbi PORTB, 1
sbi PORTB, 2

    rjmp wait_release      ; Now wait for the next button press

; Turn everything off
clr R16
out PORTD, R16
cbi PORTB, 0
cbi PORTB, 1
cbi PORTB, 2

ret

I am trying to manually switch on LED lights one at a time using the push button, but they aren't switching on even though the code runs and the connections are correct, what am i doing wrong?

3
  • Can you switch them by C program? Can you switch them unconditionally, i.e. without waiting for button press? How LEDs are connected to pins, directly or with buffer, active low or high? What current limiting resistors are used? Make sure your power supply can handle these 10 LEDs on without glitch in power bus. Commented Apr 28 at 9:33
  • Ah, you are trying to switch them sequentially. But at the end your main function exits and MCU halts. You can't even notice they blinked. You need button press debounce at least. Commented Apr 28 at 9:46
  • Also, depending on your target MCU, __SFR_OFFSET may be wrong. What is target MCU and how do you compile and link executable? Commented Apr 28 at 9:55

1 Answer 1

0
  • Maybe a WDT is active (depends on secret AVR device and secret fuses).
  • Debouncing of the buttons is missing, at least in software.
  • PD1...PD6 is 0x7e = 0b01111110, not 0xfd. You can use masks or binary constants.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.