;*************************************************************************** ;* ;* ;* File Name :"Debounce.asm" ;* Title : Debouncing of a single key ;* Date : 09.01.05 13:09 ;* Version : 1.0 ;* Status : no known problems ;* ;* Target MCU :AT90S8515 ;* ;* DESCRIPTION : ;* Key 0 debounced toggling all LEDs ;* ;*************************************************************************** .include "8515def.inc" .def CNT = R25 ; Debounce Counter .def LEDOUT = R0 ; LED output register ;***** Code rjmp RESET ;Reset Handle RESET: ; Put Stack Pointer at End of Ram after each Reset ldi R16,low(RAMEND) ; Load low byte address of end of RAM into R16 out SPL,R16 ; Initialize stack pointer to end of int. RAM ldi R16,high(RAMEND); Load high byte address of end of RAM into R16 out SPH,R16 ; Initialize high byte of stack pointer ; Initialize Ports A,B,C and D at the beginning of the Program INITP: ser r16 ; Port C used as Outputs for LEDs out DDRC,r16 ; clr r16 ; Port D used as Inputs for Switches out DDRD,r16 ; mov r0,r16 out PORTC,r0 ; Switches all LEDS on ; Read key 0 and debounce Key0: clr CNT Again0: sbic PIND,0 rjmp Key0 ; Jump if key is not pressed or bouncing dec CNT brne Again0 Keypressvalid: com r0 out PORTC,r0 Not0: clr CNT Not0Ag: sbis PIND,0 rjmp Not0 ; Jump if key is not released yet or bouncing dec CNT brne Not0Ag Keyreleasevalid: rjmp Key0