KEY1 BIT P3.0
KEY2 BIT P3.1
KEY3 BIT P3.2
KEY4 BIT P3.3
按键处理程轿简序:薯帆春
-----------------------------------
READ_KEY:
JBKEY1, K2
CALL DELAY
JBKEY1, K2
JNB KEY1, $
PUSH ACC
INC 75H
MOV A, 75H
CJNE A, #10, ZINT01
MOV 75H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K2: JBKEY2, K3
CALL DELAY
JBKEY2, K3
JNB KEY2, $
PUSH ACC
INC 76H
MOV A, 76H
CJNE A, #10, ZINT01
MOV 76H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K3: JBKEY3, K4
CALL DELAY
JBKEY3, K4
JNB KEY3, $
PUSH ACC
DEC 75H
MOV A, 75H
CJNE A, #255, ZINT03
MOV 75H, #9
ZINT03:
POP ACC
JMP K_EXIT
---------------
K4: JBKEY4, K_EXIT
CALL DELAY
JBKEY4, K_EXIT
JNB KEY4, $
PUSH ACC
DEC 76H
MOV A, 76H
CJNE A, #255, ZINT04
MOV 76H, #9
ZINT04:
POP ACC
K_EXIT:
RET
---------------
DELAY:
DJNZ R7, $
DJNZ R7, $
RET
-----------------------------------
#include<reg52.h>unsigned char ID
sbit k1 = 胡歼P3 ^ 7 // 定义按键端口
void delay()
{
TMOD = 0x10 // 定时器的工作方式
TH1=0xd8
TL1=0xf0
TR1=1
while(!TF1) 裤世冲// 这里错了,是定时器返喊1
TF1=0
}
void main()
{
while(1)
{
if(k1==0)
{
delay() //去抖动
if(k1==0) //检测按键确实按下,进行按键处理
{
ID++
if(ID==0)
{
ID=0
}
while(!k1) //这里错了,多余的加了==0
}
}
switch(ID)
{
case 0:P1=0x3fbreak
case 1:P1=0x06break
case 2:P1=0x5bbreak
case 3:P1=0x4fbreak
case 4:P1=0x66break
case 5:P1=0x6dbreak
case 6:P1=0x7dbreak
case 7:P1=0x07break
case 8:P1=0x7fbreak
case 9:P1=0x6fbreak
default:break
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)