找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1881|回复: 0
打印 上一主题 下一主题
收起左侧

ESP8266 RTOS CHQ1838接收遥控数据命令源程序

[复制链接]
跳转到指定楼层
楼主
CHQ1838引脚示意图



源程序如下:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>

  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/task.h"
  6. #include "freertos/queue.h"

  7. #include "driver/gpio.h"

  8. #include "esp_log.h"
  9. #include "esp_system.h"

  10. static const char *TAG = "main";


  11. #define GPIO_INPUT_IO_2     2   // D4
  12. #define GPIO_INPUT_PIN_SEL  (1ULL<<GPIO_INPUT_IO_2)

  13. static xQueueHandle gpio_evt_queue = NULL;

  14. extern uint32_t esp_get_time(void);                                                                                 // 获取当前启动毫秒数

  15. static void gpio_task_example(void *arg)
  16. {
  17.     uint32_t interval_us,ms;

  18.     for (;;) {
  19.         if (xQueueReceive(gpio_evt_queue, &interval_us, portMAX_DELAY)) {
  20.             // ESP_LOGI(TAG, "GPIO failling edge interval time: %d\n", interval_us);
  21.             // printf("data is: ");
  22.             ms = interval_us / 100;
  23.             if (ms <= 150 && ms >= 120 )    // 在 12 - 15 ms之间认为是前导码
  24.             {
  25.                 printf("\n start ");
  26.             }
  27.             else if (ms < 20 && ms >= 10)  // 在 1 - 2 ms之间认为是0
  28.             {
  29.                 printf("0 ");
  30.             }
  31.             else if (ms <= 30 && ms >= 20)  // 在2 - 3 ms之间认为是1
  32.             {
  33.                 printf("1 ");
  34.             }
  35.         }
  36.     }
  37. }

  38. uint32_t first_time = 0, second_time = 0,interval_time = 0;

  39. static void monitor_chq1838_break(void *arg){
  40.     first_time = second_time;
  41.     second_time = esp_get_time();
  42.     interval_time = second_time - first_time;
  43.     xQueueSendFromISR(gpio_evt_queue, &interval_time, NULL);
  44. }

  45. void app_main(void)
  46. {
  47.     gpio_config_t io_conf;
  48.     io_conf.intr_type = GPIO_INTR_NEGEDGE;
  49.     io_conf.mode = GPIO_MODE_INPUT;
  50.     io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  51.     io_conf.pull_down_en = 0;
  52.     io_conf.pull_up_en = 1;
  53.     gpio_config(&io_conf);

  54.     gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));
  55.     xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);

  56.     gpio_install_isr_service(0);
  57.     gpio_isr_handler_add(GPIO_INPUT_IO_2, monitor_chq1838_break, (void *) GPIO_INPUT_IO_2);

  58.     while (1) {
  59.         vTaskDelay(1000 / portTICK_RATE_MS);
  60.     }
  61. }


复制代码

手册下载:
CHQ1838.PDF (806.72 KB, 下载次数: 11)

评分

参与人数 1黑币 +20 收起 理由
admin + 20 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表