• 无线传感网——zigbee基础实验-按键控制灯光开关


    #include "ioCC2530.h"
    #define D3  P1_0
    #define D4  P1_1
    #define D5  P1_3
    #define D6  P1_4
    #define SW1 P1_2
    #define SW2 P0_1
    /*=======================简单的延时函数========================*/
    void Delay(unsigned int t)
    {
      while(t--);
    }
    /*======================端口初始化函数========================*/
    void Init_Port()
    {
      P1SEL &= ~0x1b;     //P1_0、P1_1、P1_3和P1_4作为通用I/O端口
      P1DIR |= 0x1b;      //P1_0、P1_1、P1_3和P1_4端口输出
     
      P1SEL &= ~0x04;     //P1_2作为通用I/O端口
      P1DIR &= ~0x04;     //P1_2端口输入
      P1INP &= ~0x04;     //P1_2设置为上拉/下拉模式
      P2INP &= ~0x40;     //P1_2设置为上拉
     
      P0SEL &= ~0x02;     //P0_1作为通用I/O端口
      P0DIR &= ~0x02;     //P0_1端口输入
      P0INP &= ~0x02;     //P0_1设置为上拉/下拉模式
      P2INP &= ~0x20;     //P0_1设置为上拉
     
      D3 = 0;         
      D4 = 0;         
      D5 = 0;          
      D6 = 0;
    }
    /*=======================按键扫描函数=========================*/
    void Scan_Keys()
    {
      if(SW1 == 0)            //发现有SW1按键信号
      {
        Delay(100);           //延时片刻,去抖动处理
        if(SW1 == 0)          //确认为SW1按键信号
        {
          while(SW1 == 0);    //等待按键松开
          D3 = ~D3;           //切换D3灯的开关状态
        }
      }   
     
      if(SW2 == 0)  
      {
        Delay(100);
        if(SW2 == 0)
        {
          while(SW2 == 0);
          D4 = ~D4;
        }
      }   
    }
    /*=========================主函数============================*/
    void main()
    {
      Init_Port();         //端口初始化
      while(1)
      {
        Scan_Keys();        //反复扫描按键状态
      }
    }
  • 相关阅读:
    mysql使用命令备份和导入导出数据
    jmeter中json提取器提取多个参数给下游接口传参
    jmeter使用正则提取器返回多个参数给下游接口入参使用
    linux下分布式部署jmeter
    使用java远程启动jmeter服务报错,报错内容:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
    Java中看今天是星期几,礼拜几
    java读取xml文件的四种方法
    Oracle 恢复删除的表
    重启Oracle命令
    Android 资源
  • 原文地址:https://www.cnblogs.com/breads/p/12727526.html
Copyright © 2020-2023  润新知