cc2530-projects/show_password/source/code.c
2021-09-24 23:06:46 +08:00

78 lines
1.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <ioCC2530.h>
#define LED1 (P1_0) //D3
#define LED2 (P1_1) //D4
#define SW1 (P1_2) //开关SW1
#define SW2 (P1_6) //SW2 存在问题
#define LED3 (P1_3) //D5
#define LED4 (P1_4) //D6
unsigned char count = 0;
//初始化端口
void initial_gpio(){
P1SEL &=~0X1F; //设置GPOD 0001 1111 0:通用 1:外设
P1DIR |=0X1B; //设置0,1,3,4为输出, xxx1 1x11 0:为输入,1:为输出
P1DIR &=~0X44; //设置2为输入 xxxx x0xx
P1INP &=~0X44; //设置2为上/下拉状态 xxxx x0xx 0:为上/下拉 1:三态
P2INP &=~0X40; //设置2为上拉状态 x0xx xxxx 0:上拉,1:下拉
P1 = 0X1B; //点亮四个LED
}
//初始化中断
void initial_interrupt(){
EA = 1; //总中断
IEN2 |=0X10; // 中断源P1端口
P1IEN |=0X44; //0:中断禁止 1:中断使能
PICTL |=0X06; //0:为上升沿,1:下降沿
}
#pragma vector = P1INT_VECTOR
__interrupt void P1_ISR(void){
if(P1IFG == 0X04){
count++;
switch(count){
case 1:
LED1 =1; //D3
LED2 =1; //D4
LED3 = 0; //D5
LED4 = 0; //D6
break;
case 2:
LED1 =1;
LED2 =0;
LED3 = 0;
LED4 = 1;
break;
case 3:
LED1 =0;
LED2 =0;
LED3 = 1;
LED4 = 1;
break;
case 4:
LED1 =0;
LED2 =1;
LED3 = 1;
LED4 = 0;
break;
default:
LED1=0;
LED2=0;
LED3=0;
LED4=0;
}
}
if(P1IFG == 0X40){
count = 0;
P1 = 0X1B;
}
P1IF = 0X00;
P1IFG = 0X00;
}
void main(void){
initial_gpio();
initial_interrupt();
while(1)
{ ; }
}