Created
March 31, 2019 21:54
-
-
Save malustewart/dce01bb8bcd1da805f2d4159caacfdda to your computer and use it in GitHub Desktop.
Blink external led connected to PB4 (Pin 12 arduino uno). Assembly Atmega328p.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" { | |
// function prototypes | |
void start(); | |
void blink(); | |
} | |
void setup() { | |
start(); | |
} | |
void loop() { | |
blink(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Blink LED on PB4(Arduino Leonardo pin 8, Arduino Uno pin 12) | |
; http://forum.arduino.cc/index.php?topic=159572#msg1194604 | |
; https://forum.arduino.cc/index.php?topic=413151.msg2844634#msg2844634 | |
; https://gist.github.com/mhitza/8a4608f4dfdec20d3879 | |
#define __SFR_OFFSET 0 | |
#include "avr/io.h" | |
.global start | |
.global blink | |
start: | |
sbi DDRB,4 ; Set PB4 as output | |
ret | |
blink: | |
ldi r20,100 ; Set the delay duration in ms. Maximum value is 255. | |
call delay_n_ms | |
sbi PORTB,4 ; Set PB4 HIGH | |
ldi r20,250 | |
call delay_n_ms | |
cbi PORTB,4 ; Set PB4 LOW | |
ret | |
delay_n_ms: | |
; Delay about r20*1ms. Destroys r20, r30, and r31. | |
; One millisecond is about 16000 cycles at 16MHz. | |
; The basic loop takes about 5 cycles, so we need about 3000 loops. | |
ldi 31, 3000>>8 ; high(3000) | |
ldi 30, 3000&255 ; low(3000) | |
delaylp: | |
sbiw r30, 1 | |
brne delaylp | |
subi r20, 1 | |
brne delay_n_ms | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment