Created
November 20, 2014 00:27
-
-
Save BobBurns/c96ecad1b6ab0921389d to your computer and use it in GitHub Desktop.
AVR Assembly simple debouncer
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
;example program using debouncing | |
;from AVR Programming by Elliot Williams p.115 | |
; | |
;compile with gavrasm debouncer.asm | |
;flash with avrdude -c avrisp -p m168 -P /dev/tty.usbmodem1411 -b 19200 -U flash:w:debouncer.hex | |
; | |
.def temp = r16 | |
.device atmega168 | |
;--- inits --- | |
.def b_pressed = r17 | |
.def eoReg = r18 | |
sbi PORTD,PD2 ;set pullup bit on button | |
sbi DDRB,PB0 ;set ddr output on led pin | |
loop: | |
rcall debounce | |
brcc else | |
tst b_pressed | |
brne loop | |
in temp,PORTB | |
ldi eoReg,(1 << PB0) | |
eor temp,eoReg | |
out PORTB,temp | |
ldi b_pressed,1 | |
rjmp loop | |
else: | |
ldi b_pressed,0 | |
rjmp loop | |
;--- suboutines --- | |
debounce: | |
.equ d_time = 1000 | |
sbic PIND,PD2 ;bit is clear=button is pressed | |
rjmp bitSet | |
ldi r25,high(d_time) | |
ldi r24,low(d_time) | |
delay: sbiw r25:r24,1 | |
brne delay | |
sbic PIND,PD2 ;button still pressed? | |
rjmp bitSet | |
sec | |
ret | |
bitSet: | |
clc | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment