📄 prog26.asm
字号:
; PROG26 - Using Interrupts to Debounce a Button
;
; This Application Toggles the LED at P1.0 After the Button on
; P3.2 (Int0 Pin) has been debounced.
;
; Myke Predko
; 98.03.01
;
; Hardware Notes:
; 80C520 Running at 4 MHz
; The 80C520's Clock will be running at 1/4 Second "Ticks"
; P1.0 is Connected to a Set of LEDs
define PressButton=P3.2 ; P3.2 is Connected to a Button that pulls down the Pin
; Variable Declarations
Flags EQU 020h ; When Bit 0 Set, then Button Pressed
org 000h
ajmp Mainline
org 003h ; Int0 Pin
mov TH0,#2*256/3 ; Wait 20 msec for Key to be Active
setb IE.1 ; Enable Timer Interrupts
clr TCON.5 ; Make Sure Overflow is Turned Off
reti
org 00Bh ; Timer0 (Real Time) Interrupt
; When This is Executed, Set Flags.0
; and Turn Off Interrupts
mov IE,#%10000001 ; Enable Button Interrupts
jb P3.2,IntT0_End ; If Button Not Pressed, Don't Mark it
setb 0 ; Set the Button Interrupt
IntT0_End: ; End of T0 Overflow Interrupt
reti
org 020h ; Program Mainline
Mainline:
mov CKCON,#%00001000 ; Use Internal /4 Clock for Timer0
mov TMOD,#%00000001 ; Timer0 - Uses Internal Clock
; - Run in Mode 1
mov TCON,#%00010001 ; Start Timer0 running
; Make Edge Triggered Interrupts
mov IE,#%10000001 ; Enable Button Interrupts
; Now, Do the Looping Output
MainLoop: ; Come Back Here After Inverting the LED
jnb PressButton,MainLoop ; Loop Waiting for the Button to be Pressed
clr 0 ; Clear the Button Press Flag
ButtonLoop: ; Wait for the Button to be Pressed
jnb 0,ButtonLoop ; Wait for the Bit to be Set
cpl P1.0 ; Invert the LED State
ajmp MainLoop ; Wait to Decrement the Next Time
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -