CC2530单片机:Interrupt中断服务子程序

参考代码:
#include <ioCC2530.h>
#deflne uint unsigned 
#deflne uchar unsigned uchar
	
#deflne LED1 P1_0
#deflne LED2 P1_1
#deflne LED3 P0_4
#deflne KEY1 P0_1

uchar Keyvalue = 0;
uint KeyTouchTimes = 0;

void Delay(uint n)
{
	uint i;
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
	for(i=0;i<n;i++);
}

void InitKeyINT(void)		   //Interrupt 中断、打断
{
	POINP |= 0x80;			     //0000 0010 0x02
	POIEN |= 0xF0;			     //Interrupt enable 0000 0010 0x02
	PICTL |= 0x80;			     //POICON P0 Interrupt control
  EA = 1;	
	IEN1 |= 0x20;            //0010 0000 0x20
  P0TFG |= 0x80;			
}

void InitIO(void)
{
	P1DIR |= 0x03;     //0000 0011 0x03  P1_0,P1_1
	P0DIR |= 0x10;      //0001 0000 0x10  P0_4
	LED1 = 1;
	LED1 = 1;
	LED1 = 1;
}
#prqgma vector = P0INT_VECTOR     //中断函数入口地址
 interrupt void P0_ISR(void)      //中断服务子程序
 {
	 if(P0IFG>0)
	 {
		 P0IFG = 0;
		 Delay(100);
		 if(P0IFG = 0);
		 {
			 Delay(100);
			 KeyTouchTimes=KeyTouchTimes+1;
		 }
	 }
	 P0IF = 0;      //中断复位
 }
 
void main(void)
{
	InitIO();
	InitKeyINT();
	
	while(1)
	{
		if(KeyTouchTimes == 1)
		{
			LED1 = !LED1;
			Delay(500);
			LED2 = !LED2;
			Delay(500);
			LED3 = !LED3;
			Delay(500);
			KeyTouchTimes = 0;
		}
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值