cc2530-projects/task011/task004/source/code.c
2021-11-03 10:23:24 +08:00

92 lines
1.3 KiB
C

#include<ioCC2530.h>
#define LED1 P1_0
#define LED2 P1_1
#define SW1 P1_2
#define LED3 P1_3
#define LED4 P1_4
#define JD1 P1_7 //¼ÌµçÆ÷1
#define JD2 P2_0 //¼ÌµçÆ÷2
unsigned char key_down = 0;
void initial_gpio(){
P1SEL &=~0X9F;
P1DIR |=0X9B; //P1_7
P1DIR &=~0X04;
P1INP &=~0X04;
P2INP &=~0X40;
P2SEL &=~0X01; //P2_0
P2INP |=0X01;
IEN2 |=0X10; //°´Å¥ÖжÏ
P1IEN |=0X04;
PICTL |=0X02;
EA = 1;
JD1 = 0;
JD2 = 0;
P1 &=~0x1F;
}
void delay(int time){
int i , j;
for(i = 0;i<time;i++){
for(j = 0;j<255;j++);
}
}
#pragma vector = P1INT_VECTOR
__interrupt void P1_INT(void){
if(P1IFG & 0X04){
while(!SW1);
if(key_down == 0){
key_down = 1;
}else{
key_down = 0;
P1 &=~0x1F;
}
P1IFG &=~0X04;
}
P1IF = 0;
}
void main(){
initial_gpio();
while(1){
// if(SW1 == 0){
// delay(10);
// if(SW1 == 0){
// while(!SW1);
// if(key_down == 0){
// key_down = 1;
// }else{
// key_down = 0;
// }
// }
// }
if(key_down){
LED2 = 1;
delay(2000);
LED2 = 0;
LED1 = 1;
delay(2000);
LED1 = 0;
LED4 = 1;
JD1 = 1;
delay(2000);
LED4 = 0;
JD1 = 0;
LED3 = 1;
delay(2000);
LED3 = 0;
}else{
P1 &=~0x1F;
}
}
}