练习一下对外部中断有关的寄存器的控制,代码如下:
;==================================================================== ; Main.asm file generated by New Project wizard ; ; Created: 周日 4月 29 2018 ; Processor: AT89C51 ; Compiler: ASEM-51 (Proteus) ;==================================================================== $NOMOD51 $INCLUDE (8051.MCU) ;==================================================================== ; DEFINITIONS ;==================================================================== ;==================================================================== ; VARIABLES ;==================================================================== ;==================================================================== ; RESET and INTERRUPT VECTORS ;==================================================================== ; Reset Vector org 0000h jmp Start org 0003h ljmp INT0_ ;==================================================================== ; CODE SEGMENT ;==================================================================== org 0100h Start: ; Write your code here MOV A,#00H MOV SP,#50H LOOP1: MOV TCON,#01H MOV IE,#81H MOV P1,A INC A LCALL DELAY SJMP LOOP1 INT0_: PUSH ACC MOV B,#3 LOOP2: MOV P1,#0FFH LCALL DELAY MOV P1,#00H LCALL DELAY DJNZ B,LOOP2 POP ACC RETI DELAY: MOV R4,#0ffH DELAY2: MOV R3,#0ffH DELAY1: NOP NOP DJNZ R3,DELAY1 DJNZ R4,DELAY2 RET Loop: jmp Loop ;==================================================================== END
下面给出仿真设计的电路图。
编程中注意循环的操作以及现场保护和现场还原,否则在中断服务子程序执行完后,回不到当初的状态。