這個很容易嘛,你先設置一個寄存器,然後一直掃描兩個按鍵(假設K1按下為加,K2按下為減),假設檢測到K1被按下,寄存器就加1,如果檢測到K2被按下,寄存器就減1;然後再調用顯示函數就OK了。、 ORG 0000H
LJMP START
ORG 0030H
START:
MOV R2, #1
LOOP:
CALL DISP
JB P1.6, NEXT
CALL DL10MS
JB P1.6, NEXT
JNB P1.6, $
DJNZ R2, NEXT
MOV R2, #10
NEXT:
JB P1.7, LOOP
CALL DL10MS
JB P1.7, LOOP
JNB P1.7, $
INC R2
CJNE R2, #11, LOOP
JMP START
;----------------------------------------
DISP:
MOV A, R2
DEC A
MOV DPTR, #TAB
MOVC A, @A + DPTR
MOV P2, A
RET
DL10MS:
MOV R6, #20
DJNZ R7, $
DJNZ R6, $ - 2
RET
;----------------------------------------
TAB:
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H
DB 92H, 82H, 0F8H, 80H, 90H
;----------------------------------------
END
② c51單片機怎麼用兩個按鍵控制兩個數碼管的加減,加到99就好,求程序
1、首先先在proteus畫出模擬圖,方便模擬程序。
③ 單片機 用匯編語言怎麼編寫兩個按鍵控制一個LED自加自減的程序
;共陽數碼管
COUNTEQU30H
SP1EQUP3.6
SP2EQUP3.7
ORG0
AJMPMAIN
ORG30H
MAIN:MOVCOUNT,#0
MAIN1:MOVA,COUNT
MOVB,#10
DIVAB
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
MOVA,B
MOVCA,@A+DPTR
MOVP1,A
K1:JBSP1,K2
JBSP1,$
LCALLDLY
JNBSP1,$
INCCOUNT
MOVA,COUNT
CJNEA,#100,MAIN1
LJMPMAIN
K2:JBSP2,K1
JBSP2,$
LCALLDLY
JNBSP2,$
MOVA,COUNT
CJNEA,#0,DEC1
MOVCOUNT,#100
DEC1:DECCOUNT
MOVA,COUNT
CJNEA,#100,MAIN1
LJMPMAIN
DLY:MOVR7,#20
D1:MOVR7,#248
DJNZR7,$
DJNZR6,$-4
RET
TAB:DB0C0H,0F9H,0A4H,0B0H,99H,092H,82H,0F8H,080H,090H