您的位置 首页 IC

中止学习

includeinclude头文件defineGPIO_LEDP2外部中断的IOsbitK3=P3^2;sbitK4=P3^3;定义k3,k4的io口值为p32p33voidIntConf

#include

#include//头文件

#define GPIO_LED P2

//外部中止的IO

sbit K3=P3^2;

sbit K4=P3^3;//界说k3,k4的io口值为p3.2p3.3

void IntConfiguration();

void Delay(unsigned int n);

unsigned char KeyValue=0;

void main(void)

{

GPIO_LED=0X01;// led=0000 – 0001

IntConfiguration();

while(1)

{

if(KeyValue)//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) //按下P3^2键,触发外部中止0

KeyValue=1;//中止处理程序0就会将KeyValue赋1

}

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

{

Delay(1);

if(K4==0)//当按下P3^3,就会触发外部中止1

KeyValue=0; //中止断处理程序0就会将KeyValue赋0

}

//两个外部中止硬件上便是与P3^3和P3^2衔接的
//,比如说按下P3^2键,触发外部中止0,中止处理程序0就会将KeyValue赋1
//,这时主循环就会履行GPIO_LED=_crol_(GPIO_LED,1

//);同理,当按下P3^3,就会触发外部中止1
//,中止处理程序0就会将KeyValue赋0;这时主循环就会履行GPIO_LED=_cror_(GPIO_LED,1)。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/257394.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部