程序目的:按下K1 數(shù)字加一,按下K2,數(shù)字減一,按下K3連減. 現(xiàn)在的問(wèn)題是,上電后能正常顯示數(shù)字,當(dāng)按下任一鍵后數(shù)據(jù)會(huì)變化,但松手后數(shù)碼管卻不會(huì)亮了,按下開關(guān)不松手就會(huì)亮,手一松就滅了,按下開關(guān)時(shí)也能看到數(shù)據(jù)的加一或是減一.學(xué)生請(qǐng)老師們指點(diǎn)為謝. org 0000h jmp main org 0013h jmp int1_1 k0 bit p1.1;定義4個(gè)開關(guān) k1 bit p1.0 k2 bit p1.2 k3 bit p1.3 main: setb ea setb ex1 clr p1.5;關(guān)蜂鳴器 mov 40h,#250;上電時(shí)要顯示的數(shù) ma_1: call divcx;調(diào)用除法子程序 lcall display;調(diào)用顯子程序 ajmp ma_1;跳回 int1_1:clr ea;中斷入口 clr ex1 jnb k1, key1;判斷哪個(gè)鍵按下,按下后轉(zhuǎn)對(duì)應(yīng)的鍵處理程序 jnb k2 , key2 jnb k3 , key3 jnb k0 , key0 fh: setb ea ;中斷返回,開中斷 setb ex1 reti key1: call delay10ms;K1處理程序 jb k1,fh ;不為0是干擾,返回 mov a,40h ;K1每按下一次對(duì)40H加一 inc a mov 40h,a k_1: jnb k1,xx1;按下沒松開轉(zhuǎn),不斷的顯示,防止數(shù)碼管不亮 cjne a,#0ffh,fh;沒加到255,中斷返回 jmp fh key2: call delay10ms;K2處理程序,減法 jb k2,fh mov a,40h dec 40h call divcx k_2: jnb k2,xx2 cjne a,#0,fh jmp fh key3: call delay10ms;這里是連減程序 jb k3,fh dec 40h;40H減一 mov a,40h cjne a,#0,zdj1; K3按下不松,轉(zhuǎn)延時(shí)一秒繼續(xù)減 jmp fh
zdj1:call delay1s jmp key3 jmp fh xx0: call display jmp key0 xx1: call display jmp k_1 xx2: call display jmp k_2 divcx:mov a, 40h;除法子程序,把40H中的數(shù)轉(zhuǎn)換為BCD數(shù) mov r0,#43 mov b,#100 div ab mov @r0,a;百位在43H dec r0 mov 44h,b xch a,44h mov b,#10 div ab mov @r0,a;十位在42H dec r0 mov 44h,b xch a,44h mov @R0,A;個(gè)位在41H ret display: MOV R0,#41 ;取顯示數(shù)據(jù)的首地址 MOV R3,#00000001 ;位掃描初值 play: MOV P2,#0H ;關(guān)閉位掃描 MOV A,R3 ;掃描初值入A MOV P2,A ;掃描初值送到P2口 MOV A,@R0 ;取要顯示的數(shù)據(jù) MOV DPTR,#TAB MOVC A,@A+DPTR MOV P0,A CALL DELAY1MS INC R0 ;顯示數(shù)據(jù)的地址加一 MOV A,P2 ;讀入P2口數(shù)據(jù) JB ACC.2,ENDOUT ;判斷P2口是否掃描到第3位,到了退出子程序 RL A ;沒到把P2口數(shù)據(jù)左移一位 MOV R3,A ;把左移后的數(shù)據(jù)裝入R3 MOV P2,#0H ;關(guān)位掃描數(shù)據(jù),防止產(chǎn)生鬼影 JMP PLAY ;跳回PLAY繼續(xù)顯示 ENDOUT:MOV P0,#0FFH ;子程序返回時(shí)關(guān)閉位顯示與段顯示 MOV P2,#0H ; RET DELAY1MS:mov r3,#2 d1: mov r4,#250 d2: djnz r4,$ djnz r3,d1 ret delay10ms: call display ;10ms子程序,調(diào)用一次顯示子程序約3ms,調(diào)兩次約10ms call display call display ret delay1s:mov r5,#20 d3:call delay10ms djnz r5,d3 ret bb:setb p1.5 ;蜂鳴器響的子程序 call delay1s clr p1.5 call delay1s ret
TAB:db 48h,0ebh,52h,62h,0e1h,64h,44h,0eah,40h,60h end
|