#include "ioCC2530.h" #define LED1 P1_0 #define LED2 P1_1 #define JD1 P1_7//继电器1 #define JD2 P2_0//继电器第二联 #define SW1 P1_2//按键1 unsigned char count=0; unsigned char Num=0; void delay(int time) { while(time--) { for(int i=0;i<240;i++); } } void Init_Port() { P1SEL &=~ 0x9f;//设置P1口的通用输入输出端口 P1DIR |=0x9b; P1DIR &=~0x04; P1INP &=~0x04;//设置输入模式 P2INP &=~0x40; P2SEL &=~0x01;//设置P2口的通用输入输出端口 P2DIR |=0x01; } void Timer_Init() { T1CC0L =0xD4; T1CC0H = 0x30; T1CCTL0 |=0x04; T1IE=1; EA=1; T1CTL =0x0e; } #pragma vector=T1_VECTOR __interrupt void Timer1_int() { T1STAT &=~0x20; if(SW1 !=0 && Num !=0) { count++; } } void Scan() { if(SW1==0) { delay(100); if(SW1==0) { while(SW1==0); count=0; Num++; if(Num>2) { Num=2; } } } if(count>5) { if(Num==1) { JD1 =!JD1;//继电器1 的状态改变 LED2=1; LED1=0; } else if(Num==2) { JD2=!JD2;//继电器2的状态改变 LED1=1; LED2=0; } count=0; Num=0; } } void main(void) { Init_Port(); Timer_Init(); LED1=1; LED2=1; JD1=0; JD2 =0; while(1) { Scan(); } }
2022-08-02 10:47:47 1KB CC253 单击双 双联继电 SW
1
while(1) { /* user code start */ if(basicRfPacketIsReady()){ basicRfReceive(buf,1,NULL); if(buf[0]==0x01){ P1_7=!P1_7; P1_0=1;4 } else if(buf[0]==0x00) { P1_7=!P1_7; P1_0=0; } else if(buf[0]==0x03) { P2_0=!P2_0; P1_1=1; } else if(buf[0]==0x02) { P2_0 =!P2_0; P1_1=0; } } /* user code end */ }
2020-01-03 11:17:33 391KB 单片 CC2530 双联继电
1