功能描述

正常情况下(p3.2为高电平), p3.3的电平以一定的频率连续翻转,当p3.2为低电平时,触发int0外部中断,进入中断服务程序,另p3.3保持低电平,并将p1端口加1。p3.2外接一个按键开关时,中断服务程序有防抖动的功能,这时通过一定的延时(通常为10ms–20ms)来实现的。

程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 	org 	8000h		;定位
	ljmp 	start
	org 	8003h		;中断向量
	ljmp	int_0
	org 	8100h
start:
	mov 	sp, #60h
	setb	ex0		;开int0中断
	setb 	ea		;开总中断
	mov	tcon, #00h	;低电平触发
	mov	r3, #00h
	mov	a, r3
	cpl	a
loop3:				;死循环
	mov	p1, a
	cpl	p3.3		;翻转
	lcall	DELAY		;延时
	sjmp	loop3
 
int_0:				;中断服务子程序
	push	psw
	lcall	DELAY		;防抖动
	setb	p3.3
	inc	r3
	mov	a, r3
	cpl	a
	mov	p1, a
	jnb	p3.2, $		;查询,防止多次中断
	lcall	DELAY		;还是防抖动
	pop	psw
	reti
 
DELAY:  PUSH 06H
	PUSH 07H
	MOV R7, #70H
LABEL1:
	MOV R6, #70H
LABEL2:
	DJNZ R6, $
	DJNZ R7, LABEL1
	POP 07H
	POP 06H
	RET
	END

[warning]This is original article, you could copy it freely with my site links!
此日志为dutor原创,您可以自由转载,添加原文链接我将万分感激![/warning]

Tags: ,.
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Home

Be the first to comment on this entry.

Name(required)
Mail (required),(will not be published)

RFC: Request For Comments. Orz..

Website(recommended)