估计太简单了,所以木有人愿意写
估计太简单了,所以木有人愿意写
抢答器哦,,这网上的例子多了,实在不会写,随便找个例子,移植一下呀,,。。哪有现成的菜?
路过看看
void EnAnswer(void)
{
uchar KeyValue =0xff;
KeyValue & = P1;
if(EnAns == 1)
{
switch(KeyValue)
{
case 0xfe:
{ LEDDATA = 0x01;
SMGDATA = SMGTable[1];
} break;
case 0xfd:
{ LEDDATA = 0x02;
SMGDATA = SMGTable[2];
} break;
case 0xfb:
{ LEDDATA = 0x04;
SMGDATA = SMGTable[3];
} break;
case 0xf7:
{ LEDDATA = 0x08;
SMGDATA = SMGTable[4];
} break;
case 0xef:
{ LEDDATA = 0x10;
SMGDATA = SMGTable[5];
} break;
case 0xdf:
{ LEDDATA = 0x20;
SMGDATA = SMGTable[6];
} break;
case 0xbf:
{ LEDDATA = 0x40;
SMGDATA = SMGTable[7];
} break;
case 0x7f:
{ LEDDATA = 0x80;
SMGDATA = SMGTable[8];
} break;
default :break;
}
}
}
[ 本帖最后由 zhujialiang 于 2012-12-11 10:13 编辑 ]
硬件设计不够严谨,会造成5条指令期间,用户按键不响应。如果用中断来处理,就把不响应按键的时间减少到一个机器周期,可靠性提高。
ORG 0000H
MAIN:MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#0FFH
SETB P3.7
MOV P0,#0C0H ;显示0
JB P3.7,$
LCALL DELAY
JB P3.7,$
JNB P3.7,$
LCALL DELAY
JNB P3.7,$
MOV P0,#8CH ;显示P
LOOP:MOV P1,#0FFH
MOV A,P1
MOV P1,#0
XRL A,#0FFH
JZ LOOP
LAB0: CJNE A,#0FEH,LAB1
MOV P2,#0FEH
MOV P0,#0F9H ;
LJMP WAIT
LAB1:CJNE A,#0FDH,LAB2
MOV P2,#0FDH
MOV P0,#0A4H
LJMP WAIT
LAB2:CJNE A,#0FBH,LAB3
MOV P2,#0FBH
MOV P0,#0B0H
LJMP WAIT
LAB3:CJNE A,#0F7H,LAB4
MOV P2,#0F7H
MOV P0,#99H
LJMP WAIT
LAB4:CJNE A,#0EFH,LAB5
MOV P2,#0EFH
MOV A,#92H
LJMP WAIT
LAB5:CJNE A,#0DFH,LAB6
MOV P2,#0DFH
MOV A,#82H
LJMP WAIT
LAB6:CJNE A,#0BFH,LAB7
MOV P2,#0BFH
MOV P0,#0F8H
LJMP WAIT
LAB7:CJNE A,#7FH,LOOP
MOV P2,#7FH
MOV P0,#80H
LJMP WAIT
WAIT:LJMP $
DELAY:MOV R5,#5
L1: MOV R6,#250
L2: DJNZ R6,L2
DJNZ R5,L1
END
不好意思,延时程序最后少些一条返回指令RET,你加上!
比较转移指令的值写错了,正确的是:
LAB0:CJNE A,#01H,LAB1
LAB1:CJNE A,#02H,LAB2
LAB2:CJNE A,#04H,LAB3
LAB3:CJNE A,#08H,LAB4
LAB4:CJNE A,#10H,LAB5
LAB5:CJNE A,#20H,LAB6
LAB6:CJNE A,#40H,LAB7
LAB7:CJNE A,#80H,LOOP