#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?
__SFR_OFFSETmay be wrong. What is target MCU and how do you compile and link executable?