1

I want to blink a led using assembly language and arduino I want the circuit to have a normal state of 5 hz blinking frequency Then use two push buttons to increase or decrease the blinking frequency The up button will increment the blinking frequency by 5 hz step until the led seems to be continuously on While the down button will decrement the blinking frequency by 5 hz step until the normal state again Is this achievable ? And if any one can point me where to start as this the first time i am using assembly language but i am familiar with arduino

asked Dec 27, 2021 at 23:17
4
  • Have you seen these Q+As? arduino.stackexchange.com/search?q=assembly Commented Dec 27, 2021 at 23:33
  • Totally achievable. Have you looked into some assembler tutorials for AVR microcontrollers/Arduinos? A short search seems to give promising results. What have you tried so far? Have you tried building the code step by step, starting with turning on an LED, then blinking it, then reading a button? Commented Dec 27, 2021 at 23:34
  • 2
    It is achievable, yes. After all, the C++ compiler turns code into assembly code. But why do you want to do this? Is it a homework exercise? Commented Dec 27, 2021 at 23:35
  • 1-No i haven't looked at the q&a but i will thank you 2- no i haven't tried anything yet since i am total newbie in assembly language and i was looking for guidance 3- yes and no , this is an optional assignment in my course that has no credit but our instructor gave it for our benefit Commented Dec 29, 2021 at 1:48

1 Answer 1

1

Here is one example of how to blink an LED in assembly coding on an Arduino UNO. You can attempt to solve your challenge. If you are stuck, please post the code and the connections and I am sure, you will get help again.

The code is here

#define __SFR_OFFSET 0
#include "avr/io.h"
.global main
main:
 sbi DDRB, 5 ; Set PB5 as output
blink:
 sbi PINB, 5 ; Toggle PINB
 ldi r25, hi8(1000)
 ldi r24, lo8(1000)
 call delay_ms
 jmp blink
delay_ms:
 ; Delay about (r25:r24)*ms. Clobbers r30, and r31.
 ; One millisecond is about 16000 cycles at 16MHz.
 ; The inner loop takes 4 cycles, so we repeat it 3000 times
 ldi r31, hi8(4000)
 ldi r30, lo8(4000)
1:
 sbiw r30, 1
 brne 1b
 sbiw r24, 1
 brne delay_ms
 ret

Link to the project: https://wokwi.com/arduino/projects/290348681199092237 enter image description here

answered Jan 1, 2022 at 11:07
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.