2022中职国赛灯光控制系统

1|02022中职国赛灯光控制系统

image-1
image-2

#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 <stdio.h> #include <string.h> #include <stdarg.h> // 定义端口 #define LED1 P1_3 #define LED2 P1_4 #define LED3 P1_0 #define LED4 P1_1 #define SW1 P1_2 #define SW2 P0_1 #define lamp P1_7 #define fun P2_0 void touch_SW();//声明函数 /*****点对点通讯地址设置******/ #define RF_CHANNEL 1 // 频道 11~26 #define PAN_ID 0x1 //网络id #define MY_ADDR 0x1 //本机模块地址 #define SEND_ADDR 0x2 //发送地址 /**************************************************/ 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(); } unsigned char SW1_T = 0; unsigned char SW1_flag = 0; unsigned char SW2_T = 0; unsigned char SW2_flag = 0; void init(){ P1SEL &= ~0x9F; P1DIR |= 0x9B; P0SEL &= ~0x02; P0DIR &= ~0x02; P2SEL &= ~0x01; P2DIR |= ~0x01; P1 = P2 = P0 = 0; } void Delay(unsigned int time){ unsigned int i,j; for(i = 0; i < time;i ++){ for(j = 0;j < 240;j++){ touch_SW(); } } } unsigned char LED_R[] = {0xA5,0x06,0x00,0xA0,0xFF,0x00,0x00,0xEE,0x5A}; unsigned char LED_G[] = {0xA5,0x06,0x00,0xA0,0x00,0xFF,0x00,0xEE,0x5A}; unsigned char LED_B[] = {0xA5,0x06,0x00,0xA0,0x00,0x00,0xFF,0xEE,0x5A}; unsigned char LED_C[] = {0xA5,0x06,0x00,0xA0,0x00,0x00,0x00,0xEE,0x5A}; void touch_SW(){//按键检测 // SW1 if(SW1 == 0){ SW2_flag = 0; while(SW1 == 0); halMcuWaitMs(150); if(SW1 == 0){//是否是双击 while(SW1 == 0); SW1_flag = 22; } else SW1_flag ++; } if(SW1_flag == 23){//反复执行 SW1_flag = 1; } //SW2 if(SW2 == 0){ SW1_flag = 0; while(SW2 == 0); halMcuWaitMs(150); if(SW2 == 0){//是否是双击 while(SW2 == 0); SW2_flag = 22; }else SW2_flag ++; } if(SW2_flag == 23){//反复执行 SW2_flag = 1; } } void LSD1(){ LED1 = LED2 = LED3 = LED4 = 0; LED4 = 1; Delay(800); LED3 = 1; LED4 = 0;halUartWrite(LED_R,sizeof(LED_R)); Delay(800); LED3 = 0; LED2 = 1;halUartWrite(LED_G,sizeof(LED_G)); Delay(800); LED2 = 0; LED1= 1;halUartWrite(LED_B,sizeof(LED_B)); Delay(800); LED1 = 0; } void LSD2(){ LED1 = LED2 = 0; LED3 = LED4 = 1; Delay(5000); LED3 = LED4 = 0; LED1 = LED2 = 1; Delay(5000); } /********************MAIN************************/ void main(void) { halBoardInit();//选手不得在此函数内添加代码 //ConfigRf_Init();//选手不得在此函数内添加代码 init(); while(1) { /* user code start */ touch_SW(); if(SW1_flag == 1){LED1 = LED2 = LED3 = LED4 = 0; LED4 = 1; halUartWrite(LED_R,sizeof(LED_R)); Delay(2000); } if(SW1_flag == 2){LED1 = LED2 = LED3 = LED4 = 0; LED4 = 0;LED3 = 1; halUartWrite(LED_G,sizeof(LED_G)); Delay(2000); } if(SW1_flag == 3){LED1 = LED2 = LED3 = LED4 = 0; LED2 = 1;LED3 = 0; halUartWrite(LED_B,sizeof(LED_B)); Delay(2000); } if(SW1_flag == 22){LED1 = LED2 = LED3 = LED4 = 0; //SW1双击 LSD1(); } if(SW2_flag == 1){ lamp = 1;fun = 0; LSD2(); } if(SW2_flag == 2){LED1 = LED2 = LED3 = LED4 = 0; fun = 1; lamp = 0; LED1 = LED2 = LED3 = LED4 = 1; } if(SW2_flag == 22){//SW2双击 fun = 0; lamp = 0; LED1 = LED2 = LED3 = LED4 = 0; halUartWrite(LED_C,sizeof(LED_C)); Delay(2000); } /* user code end */ } }

__EOF__

本文作者~内个臣呐~
本文链接https://www.cnblogs.com/Xin-chen/p/16770145.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   ~内个臣呐~  阅读(207)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示