永发信息网

汇编语言 中断程序中有循环如何在下次中断键按下回到主程序

答案:2  悬赏:40  手机版
解决时间 2021-02-03 07:03
  • 提问者网友:饥饿走向夜
  • 2021-02-02 16:52
主程序为6个LED灯跑马 中断内为前4个灯亮 ,如何在中断中4个灯亮的时候再按一次中断键后回到跑马程序
最佳答案
  • 五星知识达人网友:狂恋
  • 2021-02-02 18:03
如果是在中断中,并没有从中断返回,就不能再用中断回到主程序了,而是要查询按键状态,因在同一个中断中是不能再次响应本中断的,假设按键定义为INS1,则这样写
LOOPI:中断中的循环程序
...............
JB INS1, LOOPI ;不按键就继续循环
CLR IE0 ;清中断请求标志位,如果是INT1,则换成IE1
RETI ;按键了,从中断返回
全部回答
  • 1楼网友:冷風如刀
  • 2021-02-02 18:40
这个没分做,好像有点..... 我这里有一个以前做的4*4键盘扫描,数码管显示的例程,供参考 keyval equ 30h keytm equ 31h keyscan equ 32h dat equ 33h dcnt equ 37h t0l equ 38h t0h equ 39h speed equ 3ah scanled equ 3bh chkcnt equ 3ch dlycnt equ 3dh org 0000h ljmp main org 000bh ljmp t0isr org 0030h main: mov sp,#5fh mov tmod,#01h mov t0l,#0f0h mov t0h,#0d8h mov th0,#0d8h mov tl0,#0f0h mov keyval,#0 mov p2,#00h mov dcnt,#0 mov scanled,#0 mov 33h,#10h mov 34h,#10h mov 35h,#10h mov 36h,#10h mov chkcnt,#11h mov speed,#100 mov dlycnt,#0 setb ea setb et0 setb tr0 loop: lcall keysel mov a,keyval cjne a,#0ffh,loop1 sjmp loop loop1: cjne a,#10,loop2 ;“on”启动led测试 mov dcnt,#0ffh sjmp loop loop2: cjne a,#14,loop3 ;“-”速度快 mov a,speed clr c subb a,#10 mov speed,a sjmp loop loop3: cjne a,#15,loop4 ;“+”速度慢 mov a,speed add a,#10 mov speed,a sjmp loop loop4: cjne a,#11,loop5 ;“=”停止测试,接受数字键 mov 33h,#10h mov 34h,#10h mov 35h,#10h mov 36h,#10h mov dcnt,#0 sjmp loop loop5: cjne a,#10,loop6 ;数字键 loop6: jc loop7 ljmp loop loop7: mov 33h,34h mov 34h,35h mov 35h,36h mov 36h,keyval ljmp loop ;------------------ keysel: mov keyval,#0 mov keyscan,#0efh lcall getkey mov a,keytm jz keys1 mov keyval,a sjmp keyrtn keys1: mov keyscan,#0dfh lcall getkey mov a,keytm jz keys2 clr c add a,#4 mov keyval,a sjmp keyrtn keys2: mov keyscan,#0bfh lcall getkey mov a,keytm jz keys3 clr c add a,#8 mov keyval,a sjmp keyrtn keys3: mov keyscan,#7fh lcall getkey mov a,keytm jz keyrtn clr c add a,#12 mov keyval,a keyrtn: lcall chgkey ret ;-------------------- getkey: mov keytm,#0 mov a,keyscan mov p3,a nop mov a,p3 anl a,#0fh xrl a,#0fh jz nokey mov r2,#10 lcall delay mov a,p3 anl a,#0fh xrl a,#0fh jz nokey mov a,p3 anl a,#0fh mov r7,a sf: mov a,p3 anl a,#0fh xrl a,#0fh jnz sf mov a,r7 cjne a,#0eh,nk1 mov keytm,#1 sjmp nokey nk1: cjne a,#0dh,nk2 mov keytm,#2 sjmp nokey nk2: cjne a,#0bh,nk3 mov keytm,#3 sjmp nokey nk3: cjne a,#07h,nokey mov keytm,#4 nokey: ret ;-------------------- delay: mov r3,#50 delay1: mov r4,#100 djnz r4,$ djnz r3,delay1 djnz r2,delay ret ;-------------------- t0isr: push acc clr tr0 mov th0,t0h mov tl0,t0l setb tr0 mov dptr,#ledtab mov a,dcnt ;段显示 jz t000 mov a,chkcnt movc a,@a+dptr mov p2,#0fh cpl a mov p0,a inc dlycnt mov a,dlycnt cjne a,speed,t021 mov dlycnt,#0 inc chkcnt mov a,chkcnt cjne a,#1ah,t020 t020: jc t021 mov chkcnt,#11h t021: pop acc reti t000: ;数字显示 mov r0,#dat mov a,scanled add a,r0 mov r0,a mov a,scanled jnz t001 mov p2,#01h sjmp t0dis t001: dec a jnz t002 mov p2,#02h sjmp t0dis t002: dec a jnz t003 mov p2,#04h sjmp t0dis t003: mov p2,#08h t0dis: mov a,@r0 movc a,@a+dptr cpl a mov p0,a inc scanled mov a,scanled anl a,#03h mov scanled,a pop acc reti ;-------------------- chgkey: mov a,keyval jz kv16 dec a jnz kv01 mov keyval,#7 ret kv01: dec a jnz kv02 mov keyval,#4 ret kv02: dec a jnz kv03 mov keyval,#1 ret kv03: dec a jnz kv04 mov keyval,#10 ret kv04: dec a jnz kv05 mov keyval,#8 ret kv05: dec a jnz kv06 mov keyval,#5 ret kv06: dec a jnz kv07 mov keyval,#2 ret kv07: dec a jnz kv08 mov keyval,#0 ret kv08: dec a jnz kv09 mov keyval,#9 ret kv09: dec a jnz kv10 mov keyval,#6 ret kv10: dec a jnz kv11 mov keyval,#3 ret kv11: dec a jnz kv12 mov keyval,#11 ret kv12: dec a jnz kv13 mov keyval,#12 ret kv13: dec a jnz kv14 mov keyval,#13 ret kv14: dec a jnz kv15 mov keyval,#14 ret kv15: dec a jnz kv16 mov keyval,#15 ret kv16: mov keyval,#0ffh ret ;-------------------- ledtab: db 0fch ;"0" 00h db 60h ;"1" 01h db 0dah ;"2" 02h db 0f2h ;"3" 03h db 66h ;"4" 04h db 0b6h ;"5" 05h db 0beh ;"6" 06h db 0e0h ;"7" 07h db 0feh ;"8" 08h db 0f6h ;"9" 09h db 0eeh ;"a" 0ah db 3eh ;"b" 0bh db 9ch ;"c" 0ch db 7ah ;"d" 0dh db 9eh ;"e" 0eh db 8eh ;"f" 0fh db 00h ;" " 10h db 80h db 40h db 20h db 10h db 08h db 04h db 02h db 01h db 0ffh ;-------------------- end
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯