外部中斷嵌套的操作
通過修改中斷控制的寄存器IP可以使中斷嵌套,同時可以修改中斷優(yōu)先級。具體c程序如下:
#include
#include
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)//延時函數(shù)
{
while(z--);
}
void main()
{
//uint i,j;
// i=0xfe;
//j=0x01;
EA=1;
EX0=1;
EX1=1;
PX0=0;
PX1=1;
}
void intt0() interrupt 0
{
uint i=0xfe;
while(1)
{
i=_crol_(i,1);
P2=i;
delay(50000);
}
}
void intt1() interrupt 2
{
uint j=0x01;
while(1)
{
j=_crol_(j,1);
P2=j;
delay(50000);
}
}
#include
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)//延時函數(shù)
{
while(z--);
}
void main()
{
//uint i,j;
// i=0xfe;
//j=0x01;
EA=1;
EX0=1;
EX1=1;
PX0=0;
PX1=1;
}
void intt0() interrupt 0
{
uint i=0xfe;
while(1)
{
i=_crol_(i,1);
P2=i;
delay(50000);
}
}
void intt1() interrupt 2
{
uint j=0x01;
while(1)
{
j=_crol_(j,1);
P2=j;
delay(50000);
}
}
匯編語言程序如下:
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP INTT0
ORG 0013H
AJMP INTT1
ORG 0030H
MAIN:SETB EA
SETB EX0
SETB EX1
CLR PX0
SETB PX1
AJMP $
INTT0:MOV A,#0FEH
LOOP1:MOV P2,A
RR A
ACALL DELAY
AJMP LOOP1
RETI
INTT1:MOV A,#01H
LOOP2:MOV P2,A
RR A
ACALL DELAY
AJMP LOOP2
RETI
DELAY:MOV R6,#255
LP: MOV R7,#100
DJNZ R7,$
DJNZ R6,LP
RET
END
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP INTT0
ORG 0013H
AJMP INTT1
ORG 0030H
MAIN:SETB EA
SETB EX0
SETB EX1
CLR PX0
SETB PX1
AJMP $
INTT0:MOV A,#0FEH
LOOP1:MOV P2,A
RR A
ACALL DELAY
AJMP LOOP1
RETI
INTT1:MOV A,#01H
LOOP2:MOV P2,A
RR A
ACALL DELAY
AJMP LOOP2
RETI
DELAY:MOV R6,#255
LP: MOV R7,#100
DJNZ R7,$
DJNZ R6,LP
RET
END
評論