zoukankan      html  css  js  c++  java
  • 无线传感网——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();        //反复扫描按键状态
      }
    }
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    白盒,单元测试
    向数据库添加100W 条数据 性能测试
    软件测试
    软件需求工程-产品经理该如何更好地记录反馈、捕捉需求?
    Spring,Spring MVC,MyBatis,Hibernate总结
    Java基础总结
    Java8新特性_四大内置核心函数式接口
    Lambda表达式及相关练习
    Java 8新特性(Lambda,Stream API)
  • 原文地址:https://www.cnblogs.com/breads/p/12727526.html
Copyright © 2011-2022 走看看