zigbee(题型整理4)
来源:互联网 发布:c抓取网页数据 编辑:程序博客网 时间:2024/06/04 23:36
题目:Zigbee节点板通电,程序开始运行时D5闪烁,2S后该LED变常亮,其余灯灭单击模块上的SW1(按下时间不超过1秒),D5、D6、D3、D4、依次闪烁1s后变常亮;长按“SW”,所有灯灭
本题难点是判断短按还是长按,所以我使用了一个计时器来判断。
核心代码是判断,返回temp
uint8 scankey(){ if(KEY1==0) { delay(100); count1=0; if(KEY1==0) { while(!KEY1){ temp=count1; if(temp==100){ break; } } return 1; } } return 0;}
#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 22 // 频道 11~26#define PAN_ID 0x8888 //网络id #define MY_ADDR 0x1015 //本机模块地址#define SEND_ADDR 0xAC3A //发送地址/**************************************************/ static basicRfCfg_t basicRfConfig;// 无线RF初始化#define LED3 P1_0#define LED4 P1_1#define KEY1 P1_2#define LED5 P1_3#define LED6 P1_4uint8 txdata_1[1]={1};uint8 txdata_2[1]={2};uint8 rxdata[1];uint8 count_stat=0;long long count_timer=0;long long count1=0;long long temp=0;void ConfigRf_Init(void){ basicRfConfig.panId = PAN_ID; basicRfConfig.channel = RF_CHANNEL; basicRfConfig.myAddr = MY_ADDR; basicRfConfig.ackRequest = TRUE; while(basicRfInit(&basicRfConfig) == FAILED); basicRfReceiveOn();}void init(){ P1SEL &=~0X1f; P1DIR |=0X1b;//led P1DIR &=~0x04;//key LED4=LED5=LED3=LED6=0; T3CTL |=0X06;//0000 0110 溢出中断屏蔽,模式是模模式 T3CTL |=0X08;// 0000 1000 出中断屏蔽 EA=1; T3IE=1; T3CTL |=0Xe0;//1110 0000 128分频 T3CTL &=~0x03; T3CC0 =0Xfa;//250 T3CTL |=0X10;//启动定时器}void delay(int xms){ int i,j; for (i=0;i<xms;i++) for (j=0;j<240;j++) { asm("NOP");asm("NOP");asm("NOP"); }}uint8 scankey(){ if(KEY1==0) { delay(100); count1=0; if(KEY1==0) { while(!KEY1){ temp=count1; if(temp==100){ break; } } return 1; } } return 0;}void main(void){ halBoardInit();//选手不得在此函数内添加代码 ConfigRf_Init();//选手不得在此函数内添加代码 init(); while(1) { /* user code start */ if(scankey()) { if(temp<=50){ halMcuWaitMs(350); basicRfSendPacket(SEND_ADDR,txdata_1,1); temp=0; } else if(temp==100){ halMcuWaitMs(350); basicRfSendPacket(SEND_ADDR,txdata_2,1); temp=0; } } if(basicRfPacketIsReady()){ halMcuWaitMs(350); if((basicRfReceive(rxdata,1,NULL)>0)) { if(rxdata[0]==1) { LED4=1; } else if(rxdata[0]==2) { LED4=0; } } } /* user code end */ }}#pragma vector=T3_VECTOR__interrupt void T1_int (void){ IRCON =0X00; count_timer++; if (count_timer==10) { count1++; count_timer=0; } if(count1>1500) count1=0;}
阅读全文
0 0
- zigbee(题型整理4)
- zigbee(题型整理1)
- zigbee(题型整理2)
- zigbee(题型整理3)
- 线段树题型整理
- PAT甲级真题目录(按题型整理)
- ZigBee基本概念整理
- 面试中常见链表题型整理
- zigbee协议及开发(4)- 基础知识
- zigbee协议及开发(4)- 基础知识
- IBM笔试题整理,包括题型和真题
- IT笔试面试常见题型及答案整理
- 面试中各类二叉树题型的整理
- zigbee 名词定义(zigbee definitions)
- 学习zigbee入门-4
- Zigbee休眠(cc2430)
- 关注zigbee(一)
- ZigBee
- webServer
- 将字符串json写入到服务器文件中
- Google官方刷题资源-基础题-第四题~第八题
- Android6.0 Sensor架构和问题分析
- Druid中coordinator的介绍
- zigbee(题型整理4)
- 494. Target Sum
- 鸡尾酒排序
- Nginx+tomcat 负载均衡需要注意的问题
- Log4j初学
- 典型的网络安全威胁
- mxnet安装记录
- 从请求对象中获取客户端ip
- ubuntu连接不上secureCRT 和cuteFTP问题