参考代码:
#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;
}
}
}
CC2530单片机:Interrupt中断服务子程序
于 2024-04-20 18:53:20 首次发布