我这个是让P0_1作为按键通过外部中断来控制P1_0led灯,一般设置外部中断要开中断,组中断,位中断等
#include <iocc2530.h>
void delay(){
int i,j;
for(i=0;i<1000;i++);
for(j=0;j<100;j++);
}
void init_led(){
P1SEL &=0xFE; //让P1_0处于普通IO口 非外设1111 1110
P1DIR |=0x01; //让P1_0的方向为输出 0000 0001
}
//P0_1
void main(){
//通用IO 1111 1101
P0SEL &=0xFD;
//输入1111 1101
P0DIR &=0xFD;
//上拉 1111 1101
P0INP &=0xFD;
//P0组 上拉1111 1101
P2INP &=0xFD;
//总中断
EA=1;
//组中断
P0IE=1;
//位中断 0000 0010
P0IEN |=0x02;
//P0组全设为下降沿触发 按下 0000 0001
PICTL |=0x01;
init_led();
while(1);
}
//外部中断0的向量入口
#pragma vector = P0INT_VECTOR
__interrupt void test(){
//0000 0010
if(P0IFG>0){
delay();
if(0==P0_1){
P1_0=!P1_0;
}
}
P0IF=1;
P0IFG=0;
}
现象: