zigbee 单击、双击、三连击程序

#include "hal_defs.h"
#include "hal_cc8051.h"
#include "hal_int.h"
#include "hal_mcu.h"
#include "hal_board.h"
#include "hal_led.h"
#include "hal_rf.h"
#include "basic_rf.h"
#include "hal_uart.h" 
#include "sensor_drv/sensor.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/*****点对点通讯地址设置******/
#define RF_CHANNEL                11         // 频道 11~26
#define PAN_ID                    0x1111     //网络id 
#define MY_ADDR                   0x1111     //本机模块地址
#define SEND_ADDR                 0x2222     //发送地址
/**************************************************/

#define LED1 P1_0
#define LED2 P1_1
#define SW1  P1_2

static basicRfCfg_t basicRfConfig;
// 无线RF初始化
void ConfigRf_Init(void)
{
    basicRfConfig.panId       =   PAN_ID;
    basicRfConfig.channel     =   RF_CHANNEL;
    basicRfConfig.myAddr      =   MY_ADDR;
    basicRfConfig.ackRequest  =   TRUE;
    while(basicRfInit(&basicRfConfig) == FAILED);
    basicRfReceiveOn();
}

/********************MAIN************************/

uint8 startFlag=0;
uint8 count=0;
uint8 countResult;

void keyScan(){
  if(SW1==0){
    halMcuWaitMs(10);
    if(SW1==0){
        startFlag=1;
        count++;  
        if(count>3)  
          count=3;  
      while(SW1==0);
      //如果在0.5秒内,再次按下,重新进入按键函数
      for(int i=0;i<50;i++){ 
        halMcuWaitMs(10);
        if(SW1==0) return;    
      }
      //如果0.5秒内没有按下,记录按下的次数,并重新计数
      countResult =count;  
      count=0;
      startFlag=0;
    } 
  }
}

void main(void)
{
    halBoardInit();//选手不得在此函数内添加代码
    ConfigRf_Init();//选手不得在此函数内添加代码
    
    P1DIR = 0X03;
    
    LED2 = 0;
    LED1 = 0;
    
    while(1)
    {
    /* user code start */
      keyScan();
      if(startFlag==0){
        switch(countResult){
          case 0: LED1 = 0;
                  LED2 = 0; break;
          case 1: LED1 = 1;
                  LED2 = 0; break;
          case 2: LED1 = 0;
                  LED2 = 1; break;
        
          case 3: LED1 = 1;
                  LED2 = 1; break;
            
        }    
      }

    /* user code end */
    }
}

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值