主函数
#include "ioCC2530.h"
#define uint unsigned int
#define uchar unsigned char
#define slave_node
#ifdef master_node
#define LED1 P1_0
#define LED2 P1_1
#else
#define LED1 P1_1
#define LED2 P1_0
#endif
#define ON 1
#define OFF 0
#ifdef master_node
#define K1 P1_3
#define K2 P0_1
#else
#define K1 P0_1
#define K2 P0_7
#endif
char i =0;
uchar Keyvaule=0;
int key1_flag=0;
int key2_flag=0;
void Delay(uint);
void InitLed(void);
void InitKey(void);
void LEDfun(void);
uchar KeyScan(void);
void Delay(uint n)
{
uint t;
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
}
void InitLed()
{
P1SEL&=~0x03;
P1DIR|=0x03;
LED2=ON;
LED1=OFF;
}
void LEDfun(){
LED1=0;
LED2=0;
if(key1_flag==0&&key2_flag==0){
LED1=0;
LED2=0;
}
else if(key1_flag==1&&key2_flag==0){
LED1=!LED1;
Delay(100);Delay(100);Delay(100);
LED1=!LED1;
}
else if(key1_flag==0&&key2_flag==1){
LED2=!LED2;
Delay(100);Delay(100);Delay(100);
LED2=!LED2;
}
else if(key1_flag==1&&key2_flag==1){
LED1=!LED1;LED2=!LED2;
Delay(100);Delay(100);Delay(100);
LED1=!LED1;LED2=!LED2;
}
}
void InitKey()
{
#ifdef master_node
P0SEL &=~0x02;
P0DIR &=~0x02;
P0INP |=0x02;
P1SEL &=~0x08;
P1DIR &=~0x08;
P1INP |=0x08;
#else
P0SEL &=~0x82;
P0DIR &=~0x82;
P0INP |=0x82;
#endif
}
uchar KeyScan(void)
{
if(K1==0)
{
Delay(100);
if(K1==0)
{
while(!K1);
return(1);
}
}
else if(K2==0)
{
Delay(100);
if(K2==0)
{
while(!K2);
return(2);
}
}
else
;
return(Keyvaule);
}
void main(void)
{
InitLed();
InitKey();
while(1)
{
LEDfun();
Keyvaule=KeyScan();
if(Keyvaule == 1)
{
key1_flag=!key1_flag;
Keyvaule=0;
}
if(Keyvaule == 2)
{
key2_flag=!key2_flag;
Keyvaule=0;
}
}
}
完整代码下载