Interrupted Learning 2

Publisher:跳跃龙珠Latest update time:2015-09-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include   //header file

 

#define GPIO_LED P2

//External interrupt IO

sbit K3=P3^2;

sbit K4=P3^3;   //define the io port values ​​of k3 and k4 to be p3.2   p3.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 value

GPIO_LED=_crol_(GPIO_LED,1);

else

GPIO_LED=_cror_(GPIO_LED,1);

Delay(2000);

}

}

 

void IntConfiguration()

{

//Set INT0

IT0=1; // Jump edge start mode (falling edge)

EX0=1; //Turn on the interrupt enable of INT0.

//Set INT1

IT1=1;

EX1=1;


EA=1; //Open the general interrupt

}

 

 

void Delay(unsigned int n)    //Delay 50us error 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 //interrupt function of external interrupt 0

  {

  Delay(1);

  if(K3==0) //Press P3^2 key to trigger external interrupt 0
 
  KeyValue=1; //Interrupt handler 0 will assign KeyValue to 1

  }
  void Int1() interrupt 2 //Interrupt function of external interrupt 1

  {

  Delay(1);

  if(K4==0)//When P3^3 is pressed, external interrupt 1 will be triggered

  KeyValue=0; //      Interrupt handler 0 will set KeyValue to 0

  }

//The two external interrupt hardware are connected to P3^3 and P3^2
. //For example, if the P3^2 key is pressed, external interrupt 0 is triggered, and interrupt handler 0 will assign KeyValue to 1.
//At this time, the main loop will execute GPIO_LED=_crol_(GPIO_LED,1

//); Similarly, when P3^3 is pressed, external interrupt 1 will be triggered
//, and interrupt handler 0 will assign KeyValue to 0; at this time, the main loop will execute GPIO_LED=_cror_(GPIO_LED,1).

Reference address:Interrupted Learning 2

Previous article:Design and experiment of MCU music program
Next article:Interrupted learning

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号