/****************************************************************************************************************
*************************
*Author:JYW
*Time:2019_03_19
*Describe:LetAllLinesOfCodeSpeak
*****************************************************/
/****************************************
*Author:JYW
*Time:2019_03_19
*Describe:基础实验_05外部中断代码练习
**********************************/
#include<ioCC2530.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define LED1 P1_0
#define KEY P0_1
void DelayMS(uint msec)
{
uint i,j;
for(i= 0; i<msec;i++)
for(j= 0;j<535;j++);
}
void InitLed(void)
{
P1DIR |=0x01;
LED1 = 1;
}
void InitKey()
{
P0IEN |= 0x02;
P0IE = 1;
EA = 1;
PICTL |=0x01;
P0IFG = 0x00;
}
#pragma vector = P0INT_VECTOR
__interrupt void P0_Inter(void)
{
DelayMS(10);
LED1 = ~LED1;
P0IFG = 0;
P0IF = 0;
}
void main()
{
InitLed();
InitKey();
while(1)
{
}
}
/****************************************
*Author:JYW
*Time:2019_03_19
*Describe:基础实验_06外部中断控制
流水灯代码练习
**********************************/
#include<ioCC2530.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define LED1 P1_0
#define LED2 P1_1
#define LED3 P1_4
#define KEY1 P0_1
uchar KeyValue = 0;//中断标志
void DelayMS(uint msec)
{
uint i,j;
for(i=0; i<msec; i++)
for(j=0;j<535;j++)
}
void InitLed(void)
{
P1DIR |= 0x13;//0001 0011
LedOnOrOff(1);
}
void InitKey()
{
P0IEN |=0x02;
PICTL |=0x01;
IEN1 |=0x20;
P0IFG = 0x00;
EA = 1;
}
#pragma vector = P0INT_VECTOR
__interrupt void P0_ISR(void)
{
if(P0IFG>0)
{
DelayMS(10);
if(P0IFG > 0)
{
KeyValue = 1;
}
}
P0IFG = 0;
P0IF = 0;
}
void main()
{
InitLed();
InitKey();
while(1)
{
if(KeyValue == 1)
{
LED3 = !LED3;
DelayMS(200);
LED2 = !LED2;
DelayMS(200);
LED1 = !LED1;
DelayMS(200);
KeyVlaue = 0;
}
}
}