Created
November 22, 2014 19:50
-
-
Save BobBurns/edbb781aa9e9dc62d1d7 to your computer and use it in GitHub Desktop.
AVR Interrupts. Assembly version of Elliot Williams helloInterrupts.c
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
;Interrupt 0 Example | |
; Flashes LED0 at a fixed rate, interrupting whenever button is pressed | |
; | |
.device atmega 168 | |
.def temp = r16 | |
.def temp2 = r17 | |
.org 0 | |
; | |
;Interrupt Vector Table | |
jmp reset | |
jmp chg_btn ;int0 | |
;Interrupt code overlaps the IVT b/c its not used | |
chg_btn: | |
sbic PIND,PD2 | |
rjmp b_set | |
cbi PORTB,PB1 | |
reti | |
b_set: sbi PORTB,PB1 | |
reti | |
;Start of program | |
reset: | |
ldi temp,high(RAMEND) | |
out SPH,temp | |
ldi temp,low(RAMEND) | |
out SPL,temp ;stack init required for interrupts | |
sbi EIMSK,INT0 ;enable int0 | |
lds temp,EICRA | |
sbr temp,ISC00 | |
sts EICRA,temp ;set external interrupt control register to interrupt change | |
sei ;set global interrupt | |
sbi PORTD,PD2 ;set pullup on button pin | |
ldi temp,0xff | |
out DDRB,temp ;set led's active | |
.equ d_cnt = 50000 | |
loop: | |
ldi r24,low(d_cnt) | |
ldi r25,high(d_cnt) | |
delay: sbiw r25:r24,1 | |
brne delay | |
in temp,PORTB | |
ldi temp2,0b00000001 | |
eor temp,temp2 | |
out PORTB,temp | |
rjmp loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment