我现在想实现这样的功能: 按1号键p3输出0000000b 按2号键p3输出0000001b 按3号键p3输出0000010b 按4号键p3输出0000011b 很简单的程序 但是现在我编的程序在电脑上调试完全正常,下载到单片机中就出问题 1.2.4号键都对 只有二号键,怎么弄都是输出00000000b 无语了 大家帮忙 key1 bit p2.4 key2 bit p2.5 key3 bit p2.6 key4 bit p2.7 L1 BIT P2.0 L2 BIT P2.1 L3 BIT P2.2 L4 BIT P2.3 key equ r7 org 00h jmp main org 030h main: mov sp,#30h lcall rest lp: lcall qh jmp lp rest: mov p0,#00h mov p1,#01h mov p2,#00h mov p3,#00h ret qh: mov key,#00h lcall pro_key mov a,key jnz S ret pro_key:setb key1 setb key2 setb key3 setb key4 jb key1,ke1 mov key,#1 lcall delay20ms jmp pro_key ke1: jb key2,ke2 mov key,#2 lcall delay20ms jmp pro_key ke2: jb key3,ke3 mov key,#3 lcall delay20ms jmp pro_key ke3: jb key4,ke4 mov key,#4 lcall delay20ms jmp pro_key ke4: ret S: cjne a,#1,AAA mov key,#00h SETB P1.0 CLR L1 CLR L2 CLR L3 CLR L4 mov p3,#00000000b CLR P1.0 SETB L1 JMP LP AAA: cjne a,#2,BBB mov key,#00h SETB P1.0 CLR L1 CLR L2 CLR L3 CLR L4 mov p3,#00000001b CLR P1.0 SETB L2 JMP LP BBB: cjne a,#3,CCC mov key,#00h SETB P1.0 CLR L1 CLR L2 CLR L3 CLR L4 LCALL MMM CLR P1.0 SETB L3 JMP LP MMM: MOV P3,#00000001B RET CCC: cjne a,#4,DDD mov key,#00h SETB P1.0 CLR L1 CLR L2 CLR L3 CLR L4 mov p3,#00000011b CLR P1.0 SETB L4 DDD: JMP LP delay20ms: push psw clr psw.3 clr psw.4 mov r0,#2 mov r1,#250 mov r2,#1 dl1:djnz r0,dl1 mov r0,#250 dl2:djnz r1,dl1 mov r0,#240 mov r1,#248 dl3:djnz r2,dl1 nop pop psw ret END |