Sunday, April 8, 2018
Arduino UNO Blinking with Timer on Assembly
.equ DELOOP=10
.MACRO CPL ; Macro to complemen pin
sbi 0x1E, @1 ; use this register to xor the pin
in r17, 0x1E
in r16, @0
eor r16, r17
out @0, r16
.ENDMACRO
.ORG 0x0000 ; The beginning of everything
rjmp START ; the reset vector: jump to "main"
.ORG 0x0020 ; interrupt vector: timer0 overflow
rjmp timer0_overflow ; jump to interrupt handler
.ORG 0x0034 ; memory address start of "main function"
START:
ldi r22, DELOOP ; initial value for timer looping
ldi r16, 0xFF
out DDRB, r16 ; set Port B as output
ldi r16, 0x0000
out TCCR0A, r16 ; timer 0 run in normal mode
ldi r16, 0x0001
sts TIMSK0, r16
ldi r16, 0b00000101 ; Set r16 with prescaler 1024 value
out TCCR0B, r16 ; Set the TCCROB to 1024
SEI ; enable global interrupt
LOOP:
rjmp LOOP ; jump to loop
timer0_overflow:
dec r22
breq toggle
reti
toggle: ; the subroutine:
ldi r22, DELOOP
CPL PortB, 5 ; toggle the LED
reti
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment