-
Notifications
You must be signed in to change notification settings - Fork 1
/
Task1.txt
143 lines (139 loc) · 3.57 KB
/
Task1.txt
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
;Author: PanChuguang Institute: SCU
;对"独立按键的按键次数进行计数"
;8个独立按键的计数值采用16进制分别显示在8个"共阴极数码管"
;每位计数值溢出时,控制蜂鸣器报警
;8个独立按键连接P1口,P0口连接数码管的段选端口
;P2.0, P2.1, P2.2分别连接译码器的A, B, C口
;P3.7连接蜂鸣器
;每个独立按键的计数值分别存放在内部RAM的30H~37H单元
ORG 0000H
AJMP MAIN
ORG 000BH
LJMP TIMER0
ORG 0040H
MAIN:
MOV SP, #50H; 初始化堆栈指针
MOV TMOD, #01H; 设置Timer0 16位定时模式
MOV TH0, #3CH;
MOV TL0, #0B0H; 定时50ms
SETB EA; 开启中断总开关
SETB ET0; 开启Timer0中断
MOV R3 ,#0C8H; 驱动蜂鸣器的脉冲个数
KEYSCAN:
LCALL DISPALY; 数码管动态显示
MOV A, P1; 读取按键状态
XRL A, #0FFH; 判断是否某个按键按下
JZ KEYSCAN; 没有按键按下,继续扫描
LCALL DELAY; 延迟10ms消除抖动
MOV A, P1; 继续读取
XRL A, #0FFH; 判断是否每个按键按下
JZ KEYSCAN; 没有按键按下,继续扫描
MOV R2, A; 保存按键状态,用于后续处理
WAIT:
LCALL DISPALY
MOV A, P1; 读取按键状态
XRL A, #0FFH; 判断是否释放
JNZ WAIT; 未释放,继续等待
LCALL DELAY; 延迟消除抖动
MOV A, P1; 读取按键状态
XRL A, #0FFH; 判断是否释放
JNZ WAIT; 未释放,继续等待
KEY1:
CJNE R2, #01H, KEY2; 是否为KEY1按下
INC 30H; KEY1计数值加1
MOV A, 30H;
CJNE A, #10H, L1; 判断是否溢出#10H=16
MOV 30H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L1: LJMP KEYSCAN
KEY2:
CJNE R2, #02H, KEY3; 是否为KEY2按下
INC 31H; KEY2的计数值加1
MOV A, 31H;
CJNE A, #10H, L2; 判断是否溢出
MOV 31H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L2: LJMP KEYSCAN
KEY3:
CJNE R2, #04H, KEY4; 是否为KEY3按下
INC 32H; KEY3的计数值加1
MOV A, 32H;
CJNE A, #10H, L3; 判断是否溢出
MOV 32H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L3: LJMP KEYSCAN
KEY4:
CJNE R2, #08H, KEY5; 是否为KEY4按下
INC 33H; KEY4的计数器加1
MOV A, 33H;
CJNE A, #10H, L4; 判断是否溢出
MOV 33H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L4: LJMP KEYSCAN
KEY5:
CJNE R2, #10H, KEY6; 是否为KEY5按下
INC 34H; KEY5的计数器加1
MOV A, 34H;
CJNE A, #10H, L5; 判断是否溢出
MOV 34H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L5: LJMP KEYSCAN
KEY6:
CJNE R2, #20H, KEY7; 是否为KEY6按下
INC 35H; KEY6的计数值加1
MOV A, 35H;
CJNE A, #10H, L6; 判断是否溢出
MOV 35H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L6: LJMP KEYSCAN
KEY7:
CJNE R2, #40H, KEY8; 是否为KEY7按下
INC 36H; KEY7的计数值加1
MOV A, 36H;
CJNE A, #10H, L7; 判断是否溢出
MOV 36H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L7: LJMP KEYSCAN
KEY8:
INC 37H; KEY8的计数值加1
MOV A, 37H;
CJNE A, #10H, L8; 判断是否溢出
MOV 37H, #00H; 溢出则清零
SETB TR0; 蜂鸣器报警
L8: LJMP KEYSCAN
DISPALY:
MOV R7, #08H; 需要显示8位
MOV R0, #30H; 显示数据区首地址
MOV P2, #00H; 数码管位选
MOV DPTR, #TAB; 共阴极段码表
LOOP:
MOV A, @R0;
MOVC A, @A+DPTR;
MOV P0, A;
LCALL DELAY
MOV P0, #00H;
INC R0;
INC P2;
DJNZ R7, LOOP;
RET
DELAY:
MOV R4, #0C8H
LOOP1: MOV R5, #30H
DJNZ R5, $
DJNZ R4, LOOP1
RET
TIMER0:
CPL P3.7
MOV TH0, #3CH
MOV TL0, #0B0H
DJNZ R3, RETURN
CLR TR0
MOV R3, #0C8H
RETURN:
RETI
TAB:
DB 3FH, 06H, 5BH, 4FH
DB 66H, 6DH, 7DH, 07H
DB 7FH, 6FH, 77H, 7CH
DB 39H, 5EH, 79H, 71H
END