当前位置:首页 > 单片机 > 单片机
[导读]#include#include#define GPIO_LED P2//外部中断的IOsbit K3=P3^2;sbit K4=P3^3;void IntConfiguration();void Delay(unsigned int n);unsigned char KeyValue=0;void main(void){GPIO_LED=0Xfe;IntConfiguration();

#include

#include


#define GPIO_LED P2

//外部中断的IO

sbit K3=P3^2;

sbit K4=P3^3;


void IntConfiguration();

void Delay(unsigned int n);

unsigned char KeyValue=0;

void main(void)

{

GPIO_LED=0Xfe;

IntConfiguration();

while(1)

{

if(KeyValue)

GPIO_LED=_crol_(GPIO_LED,1);

else

GPIO_LED=_cror_(GPIO_LED,1);

Delay(2000);

}

}

void IntConfiguration()

{

//设置INT0

IT0=1;//跳变沿出发方式(下降沿)

EX0=1;//打开INT0的中断允许。

//设置INT1

IT1=1;

EX1=1;

EA=1;//打开总中断

}


void Delay(unsigned int n) //延时50us误差 0us

{

unsigned char a,b;

for(;n>0;n--)

{

for(b=1;b>0;b--)

for(a=22;a>0;a--);

}

}


void Int0() interrupt 0 //外部中断0的中断函数

{

Delay(1); //延时消抖

if(K3==0)

KeyValue=1;

}


void Int1() interrupt 2 //外部中断1的中断函数

{

Delay(1); //延时消抖

if(K4==0)

KeyValue=0;

}


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭