[其它] 合泰HT32F52352红外NEC编码

[复制链接]
 楼主| 高级安全大使 发表于 2023-2-25 11:19 | 显示全部楼层 |阅读模式

红外遥控协议类型:①NEC编码②RC5③RC6


NEC编码格式:①引导码②地址码③地址反码④控制码⑤控制码反码




图1.NEC编码时序图





图2.引导码及数据定义


 楼主| 高级安全大使 发表于 2023-2-25 11:19 | 显示全部楼层
逻辑1:560us低1680us高 逻辑0:560us低 560us高

一个完整的周期为108ms,当我们一直按住 同一个按键的时候,就会隔一段时间发一个引导码(重复)。


图三.Repeat波形图

 楼主| 高级安全大使 发表于 2023-2-25 11:20 | 显示全部楼层
  1. #include "ht32.h"
  2. #include "usart.h"
  3. #include "Delay.h"
  4. #include "led.h"
  5. #include "key.h"
  6. #include "stdio.h"
  7. #include "lcd.h"
  8. #include "gui.h"
  9. #include "test.h"
  10. #include "Initerface.h"
  11. #include "rtc.h"
  12. #include "time.h"
  13. #include "ht32_board_config.h"

  14. #define BreatheMax 600 //定时器呼吸灯

  15. uint8_t data[7] = {0};

  16. uint16_t count = 0;  //计时

  17. uint8_t puff[4] = {0};

  18. u8 sum = 0;
  19. u32 succeed = 0;
  20. u32 fail = 0;
  21. u32 key_sum = 0;
  22. u32 rx_data = 0;
  23. typedef struct
  24. {
  25.   u32 OverflowCounter;
  26.   u32 StartValue;
  27.   u32 CapturePulse;
  28.   TM_CHP_Enum ChannelPolarity;
  29.   bool DataValid;
  30.   bool DataOverwrite;
  31. } sPulseCaptureStructure;

  32. void Capture_Configuration(void);
  33. void Capture_MainRoutine(void);
  34. void Capture_IRQHandler(void);
  35. void Capture_Process(sPulseCaptureStructure* cap, u16 capture_value, bool isCapBeforeUpdate);

  36. void PWM_OUT_Configuration(void);


  37. sPulseCaptureStructure CaptureCHx;

  38. void Timer_Init(void)
  39. {   
  40.     CKCU_PeripClockConfig_TypeDef CKCUClock= {{0}};
  41.     CKCUClock.Bit.BFTM0 = 1;  //开启中断时钟
  42.     CKCU_PeripClockConfig(CKCUClock, ENABLE);
  43.    
  44.     NVIC_EnableIRQ(BFTM0_IRQn);
  45.    
  46.     BFTM_SetCounter(HT_BFTM0, 0);
  47.     //BFTM_SetCompare(HT_BFTM1, SystemCoreClock);//定时1s产生中断
  48.     BFTM_SetCompare(HT_BFTM0, SystemCoreClock/1000);//定时1ms产生中断 呼吸灯1us中断1000000
  49.     BFTM_IntConfig(HT_BFTM0, ENABLE);//使能中断
  50.     BFTM_EnaCmd(HT_BFTM0, ENABLE);//使能BFTM
  51. }


  52. void BFTM0_IRQHandler(void)
  53. {
  54.         if(BFTM_GetFlagStatus(HT_BFTM0) != RESET )
  55.         {   
  56.         
  57.             count++;            
  58.             if(count == 500) //
  59.             {   
  60.                
  61.                 count = 0;
  62.             }
  63.             
  64.             //Capture_MainRoutine();
  65.             BFTM_ClearFlag(HT_BFTM0);//清除中断标志
  66.         }
  67. }

  68. void Capture_MainRoutine(void)
  69. {
  70.     u32 Dval = 0;
  71.   u32 data = 9;

  72.    
  73.   if (CaptureCHx.DataValid)
  74.   {
  75.         Dval = CaptureCHx.CapturePulse / (SystemCoreClock / 1000000ul);
  76.     //printf("Capture: %d %8.2f uS\r\n", CaptureCHx.CapturePulse, ((float)CaptureCHx.CapturePulse / (SystemCoreClock / 1000000ul)));
  77.         
  78.         if(Dval>4200 && Dval<4700)
  79.     {
  80.         data = 3;
  81.     }
  82.    
  83.         if(Dval>300 && Dval<800)
  84.    {
  85.      data = 0;
  86.        rx_data <<= 1;
  87.        rx_data |= 0;
  88.        sum++;
  89.    }

  90.     if(Dval>1400 && Dval<1800)
  91.     {
  92.        data = 1;
  93.        rx_data <<= 1;
  94.        rx_data |= 1;
  95.        sum++;
  96.     }

  97.     if(sum >= 32)
  98.     {
  99.         rx_data >>= 8;
  100.         rx_data &= 0x00FF;
  101.         key_sum++;
  102.         switch (rx_data)
  103.         {
  104.             case 0xA2:succeed++;printf("%d:%d + %d = %d%%  RX:CH-\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  105.             case 0x62:succeed++;printf("%d:%d + %d = %d%%  RX:CH\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  106.             case 0xE2:succeed++;printf("%d:%d + %d = %d%%  RX:CH+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  107.             case 0x22:succeed++;printf("%d:%d + %d = %d%%  RX:|<<\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  108.             case 0x02:succeed++;printf("%d:%d + %d = %d%%  RX:>>|\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  109.             case 0xC2:succeed++;printf("%d:%d + %d = %d%%  RX:>||\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  110.             case 0xE0:succeed++;printf("%d:%d + %d = %d%%  RX:-\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  111.             case 0xA8:succeed++;printf("%d:%d + %d = %d%%  RX:+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  112.             case 0x90:succeed++;printf("%d:%d + %d = %d%%  RX:EQ\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  113.             case 0x68:succeed++;printf("%d:%d + %d = %d%%  RX:0\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  114.             case 0x98:succeed++;printf("%d:%d + %d = %d%%  RX:100+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  115.             case 0xB0:succeed++;printf("%d:%d + %d = %d%%  RX:200+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  116.             case 0x30:succeed++;printf("%d:%d + %d = %d%%  RX:1\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  117.             case 0x18:succeed++;printf("%d:%d + %d = %d%%  RX:2\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  118.             case 0x7A:succeed++;printf("%d:%d + %d = %d%%  RX:3\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  119.             case 0x10:succeed++;printf("%d:%d + %d = %d%%  RX:4\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  120.             case 0x38:succeed++;printf("%d:%d + %d = %d%%  RX:5\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  121.             case 0x5A:succeed++;printf("%d:%d + %d = %d%%  RX:6\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  122.             case 0x42:succeed++;printf("%d:%d + %d = %d%%  RX:7\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  123.             case 0x4A:succeed++;printf("%d:%d + %d = %d%%  RX:8\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  124.             case 0x52:succeed++;printf("%d:%d + %d = %d%%  RX:9\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  125.             default:fail++;printf("%d:%d + %d = %d%%  RX:%X Error! Please reset the reboot!\r\n",key_sum,succeed,fail,(succeed*100)/key_sum,rx_data);break;
  126.         }
  127.         rx_data = 0;
  128.         sum = 0;
  129.     }
  130.             
  131.     CaptureCHx.DataValid = FALSE;
  132.   }
  133. }

  134. /*********************************************************************************************************//**
  135.   * [url=home.php?mod=space&uid=247401]@brief[/url]  Configures TM to capture waveform.
  136.   * @retval None
  137.   ***********************************************************************************************************/
  138. void Capture_Configuration(void)
  139. {
  140.   { /* Enable peripheral clock                                                                              */
  141.     CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
  142.     CKCUClock.Bit.AFIO = 1;
  143.     CKCUClock.Bit.HTCFG_CAP_IPN = 1;
  144.     CKCU_PeripClockConfig(CKCUClock, ENABLE);
  145.   }

  146.   /* Configure AFIO mode as TM function                                                                     */
  147.   AFIO_GPxConfig(HTCFG_CAP_GPIO_ID, HTCFG_CAP_AFIO_PIN, AFIO_FUN_MCTM_GPTM);

  148.   { /* Time base configuration                                                                              */

  149.     /* !!! NOTICE !!!
  150.        Notice that the local variable (structure) did not have an initial value.
  151.        Please confirm that there are no missing members in the parameter settings below in this function.
  152.     */
  153.     TM_TimeBaseInitTypeDef TimeBaseInit;

  154.     TimeBaseInit.Prescaler = 1 - 1;                         // Timer clock = CK_AHB / 1
  155.     TimeBaseInit.CounterReload = 0xFFFF;
  156.     TimeBaseInit.RepetitionCounter = 0;
  157.     TimeBaseInit.CounterMode = TM_CNT_MODE_UP;
  158.     TimeBaseInit.PSCReloadTime = TM_PSC_RLD_IMMEDIATE;
  159.     TM_TimeBaseInit(HTCFG_CAP_PORT, &TimeBaseInit);

  160.     /* Clear Update Event Interrupt flag since the "TM_TimeBaseInit()" writes the UEV1G bit                 */
  161.     TM_ClearFlag(HTCFG_CAP_PORT, TM_FLAG_UEV);
  162.   }

  163.   { /* Channel n capture configuration                                                                      */

  164.     /* !!! NOTICE !!!
  165.        Notice that the local variable (structure) did not have an initial value.
  166.        Please confirm that there are no missing members in the parameter settings below in this function.
  167.     */
  168.     TM_CaptureInitTypeDef CapInit;

  169.     TM_CaptureStructInit(&CapInit);
  170.     CapInit.Channel = HTCFG_CAP_CH;
  171.     CapInit.Polarity = TM_CHP_NONINVERTED;
  172.     CapInit.Selection = TM_CHCCS_DIRECT;
  173.     CapInit.Prescaler = TM_CHPSC_OFF;
  174.     #if (LIBCFG_TM_652XX_V1)
  175.     CapInit.Fsampling = TM_CHFDIV_1;
  176.     CapInit.Event = TM_CHFEV_OFF;
  177.     #else
  178.     CapInit.Filter = 0x0;
  179.     #endif
  180.     TM_CaptureInit(HTCFG_CAP_PORT, &CapInit);
  181.   }

  182.   /* Enable TM Channel Capture and Update Event interrupts                                                  */
  183.   TM_IntConfig(HTCFG_CAP_PORT, HTCFG_CAP_CCR | TM_INT_UEV, ENABLE);
  184.   NVIC_EnableIRQ(HTCFG_CAP_IRQn);

  185.   TM_Cmd(HTCFG_CAP_PORT, ENABLE);
  186. }

  187. /*********************************************************************************************************//**
  188.   * @brief  This function handles GPTM interrupt.
  189.   * @retval None
  190.   ***********************************************************************************************************/
  191. void HTCFG_CAP_IRQHandler(void)
  192. {
  193.   bool update_flag = FALSE;

  194.   /* store and clear all interrupt flags                                                                    */
  195.   u32 status = HTCFG_CAP_PORT->INTSR;
  196.   u32 cnt = HTCFG_CAP_PORT->CNTR;
  197.   #if 0
  198.   if ((status & TM_INT_UEV) != (HTCFG_CAP_PORT->INTSR & TM_INT_UEV))
  199.   {
  200.     status = HTCFG_CAP_PORT->INTSR;
  201.     cnt = HTCFG_CAP_PORT->CNTR;
  202.   }
  203.   #endif
  204.   HTCFG_CAP_PORT->INTSR = ~status;

  205.   if (status & TM_INT_UEV)
  206.   {
  207.     update_flag = TRUE;
  208.     /* The OverflowCounter will stop at max value 0xFFFF                                                    */
  209.     if (CaptureCHx.OverflowCounter != 0xFFFF)
  210.       CaptureCHx.OverflowCounter++;
  211.   }

  212.   if (status & HTCFG_CAP_CCR)
  213.   {
  214.     u32 cap_value = TM_GetCaptureCompare(HTCFG_CAP_PORT, HTCFG_CAP_CH);
  215.     bool isCapBeforeUpdate = (update_flag && (cap_value > cnt))? TRUE : FALSE;
  216.     Capture_Process(&CaptureCHx, cap_value, isCapBeforeUpdate);
  217.     TM_ChPolarityConfig(HTCFG_CAP_PORT, HTCFG_CAP_CH, CaptureCHx.ChannelPolarity);
  218.   }
  219. }

  220. /*********************************************************************************************************//**
  221. * @brief   Capture Process function.
  222. * @retval  None
  223. ************************************************************************************************************/
  224. void Capture_Process(sPulseCaptureStructure* cap, u16 capture_value, bool isCapBeforeUpdate)
  225. {
  226.   if (cap->ChannelPolarity == TM_CHP_NONINVERTED)
  227.   {
  228.     /* Reset OverflowCounter and store capture value when rising edge occurred                              */
  229.     if (isCapBeforeUpdate)
  230.     {
  231.       cap->OverflowCounter = 1;
  232.     }
  233.     else
  234.     {
  235.       cap->OverflowCounter = 0;
  236.     }

  237.     cap->StartValue = capture_value;

  238.     /* Change channel polarity to capture when falling edge occur                                           */
  239.     cap->ChannelPolarity = TM_CHP_INVERTED;
  240.   }
  241.   else
  242.   {
  243.     /* Compute pulse width in PCLK unit when falling edge occurred                                          */
  244.     if (isCapBeforeUpdate)
  245.       cap->OverflowCounter--;

  246.     cap->CapturePulse = (cap->OverflowCounter << 16) - cap->StartValue + capture_value + 1;

  247.     if (cap->DataValid)
  248.       cap->DataOverwrite = TRUE;
  249.     else
  250.       cap->DataValid = TRUE;

  251.     /* Change channel polarity to capture when rising edge occur                                            */
  252.     cap->ChannelPolarity = TM_CHP_NONINVERTED;
  253.   }
  254. }

  255. /*********************************************************************************************************//**
  256.   * @brief   Configures TM to output PWM waveform.
  257.   * @retval  None
  258.   * [url=home.php?mod=space&uid=1543424]@Details[/url] Configuration as frequency 1 Hz and duty 2500 uS (10/4000).
  259.   ***********************************************************************************************************/
  260. void PWM_OUT_Configuration(void)
  261. {
  262.   { /* Enable peripheral clock                                                                              */
  263.     CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
  264.     CKCUClock.Bit.AFIO = 1;
  265.     CKCUClock.Bit.HTCFG_PWM_IPN = 1;
  266.     CKCU_PeripClockConfig(CKCUClock, ENABLE);
  267.   }

  268.   /* Configure AFIO mode as TM function                                                                     */
  269.   AFIO_GPxConfig(HTCFG_PWM_GPIO_ID, HTCFG_PWM_AFIO_PIN, HTCFG_PWM_AFIO_FUN);

  270.   { /* Time base configuration                                                                              */

  271.     /* !!! NOTICE !!!
  272.        Notice that the local variable (structure) did not have an initial value.
  273.        Please confirm that there are no missing members in the parameter settings below in this function.
  274.     */
  275.     TM_TimeBaseInitTypeDef TimeBaseInit;

  276.     TimeBaseInit.Prescaler = (SystemCoreClock / 4000) - 1;  // Timer clock = 4 kHz
  277.     TimeBaseInit.CounterReload = 4000 - 1;                  // PWM frequency = 1 Hz
  278.     TimeBaseInit.RepetitionCounter = 0;
  279.     TimeBaseInit.CounterMode = TM_CNT_MODE_UP;
  280.     TimeBaseInit.PSCReloadTime = TM_PSC_RLD_IMMEDIATE;
  281.     TM_TimeBaseInit(HTCFG_PWM_PORT, &TimeBaseInit);

  282.     /* Clear Update Event Interrupt flag since the "TM_TimeBaseInit()" writes the UEV1G bit                 */
  283.     #if 0
  284.     TM_ClearFlag(HTCFG_PWM_PORT, TM_FLAG_UEV);
  285.     #endif
  286.   }

  287.   { /* Channel n output configuration                                                                       */

  288.     /* !!! NOTICE !!!
  289.        Notice that the local variable (structure) did not have an initial value.
  290.        Please confirm that there are no missing members in the parameter settings below in this function.
  291.     */
  292.     TM_OutputInitTypeDef OutInit;

  293.     OutInit.Channel = HTCFG_PWM_CH;
  294.     OutInit.OutputMode = TM_OM_PWM2;
  295.     OutInit.Control = TM_CHCTL_ENABLE;
  296.     OutInit.ControlN = TM_CHCTL_DISABLE;
  297.     OutInit.Polarity = TM_CHP_NONINVERTED;
  298.     OutInit.PolarityN = TM_CHP_NONINVERTED;
  299.     OutInit.IdleState = MCTM_OIS_LOW;
  300.     OutInit.IdleStateN = MCTM_OIS_HIGH;
  301.     OutInit.Compare =  4000 - 10;                           // PWM duty = 10/4000 = 2500 us
  302.     OutInit.AsymmetricCompare = 0;
  303.     TM_OutputInit(HTCFG_PWM_PORT, &OutInit);
  304.   }

  305.   TM_Cmd(HTCFG_PWM_PORT, ENABLE);
  306. }
 楼主| 高级安全大使 发表于 2023-2-25 11:20 | 显示全部楼层
  1. #ifndef __TIME_H
  2. #define __TIME_H     


  3. void Timer_Init(void);
  4. void Led_chang(void);
  5. void show_time(void);

  6. void Capture_Configuration(void);
  7. void Capture_MainRoutine(void);
  8. void Capture_IRQHandler(void);

  9. void PWM_OUT_Configuration(void);
  10. #endif
 楼主| 高级安全大使 发表于 2023-2-25 11:21 | 显示全部楼层
  1. #include "ht32.h"
  2. #include "usart.h"
  3. #include "Delay.h"
  4. #include "led.h"
  5. #include "key.h"
  6. #include "stdio.h"
  7. #include "lcd.h"
  8. #include "gui.h"
  9. #include "test.h"
  10. #include "Initerface.h"
  11. #include "rtc.h"
  12. #include "time.h"
  13. #include "ht32_board_config.h"


  14. uint8_t urtrx_data[7];

  15. void delay(u32 nCount)
  16. {
  17.   vu32 i;
  18.   for (i = 0; i < 10000 * nCount; i++){}
  19. }


  20. int main(void)
  21. {
  22.         USART_Configuration();   
  23.         LED_Init();
  24.         Timer_Init();
  25.         RETARGET_Configuration();
  26.         Capture_Configuration();

  27.         PWM_OUT_Configuration();
  28.         Led_on();
  29.         printf("START!\r\n");
  30.         
  31.         while(1)
  32.         {
  33.             Capture_MainRoutine();
  34.         }
  35. }
 楼主| 高级安全大使 发表于 2023-2-25 11:21 | 显示全部楼层
  1. /*********************************************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]    GPIO/InputOutput/ht32_board_config.h
  3. * [url=home.php?mod=space&uid=895143]@version[/url] $Rev:: 4728         $
  4. * [url=home.php?mod=space&uid=212281]@date[/url]    $Date:: 2020-04-07#$
  5. * @brief   The header file of board configuration.
  6. *************************************************************************************************************
  7. * @attention
  8. *
  9. * Firmware Disclaimer Information
  10. *
  11. * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
  12. *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
  13. *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
  14. *    other intellectual property laws.
  15. *
  16. * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
  17. *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
  18. *    other than HOLTEK and the customer.
  19. *
  20. * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
  21. *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
  22. *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
  23. *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
  24. *
  25. * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
  26. ************************************************************************************************************/
  27. /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
  28. #ifndef __HT32_BOARD_CONFIG_H
  29. #define __HT32_BOARD_CONFIG_H

  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif

  33. /* Settings ------------------------------------------------------------------------------------------------*/
  34. #if defined(USE_HT32F52352_SK)
  35.   #define HTCFG_OUTPUT_LED0_ID                                  (GPIO_PC)
  36.   #define HTCFG_OUTPUT_LED1_ID                                  (GPIO_PC)
  37.   #define HTCFG_OUTPUT_LED2_ID                                  (GPIO_PC)
  38.   #define HTCFG_INPUT_WAKE_ID                                   (GPIO_PB)
  39.   #define HTCFG_INPUT_KEY1_ID                                   (GPIO_PD)
  40.   #define HTCFG_INPUT_KEY2_ID                                   (GPIO_PD)

  41.   #define HTCFG_OUTPUT_LED0_CLK(CK)                             (CK.Bit.PC)
  42.   #define HTCFG_OUTPUT_LED1_CLK(CK)                             (CK.Bit.PC)
  43.   #define HTCFG_OUTPUT_LED2_CLK(CK)                             (CK.Bit.PC)
  44.   #define HTCFG_INPUT_WAKE_CLK(CK)                              (CK.Bit.PB)
  45.   #define HTCFG_INPUT_KEY1_CLK(CK)                              (CK.Bit.PD)
  46.   #define HTCFG_INPUT_KEY2_CLK(CK)                              (CK.Bit.PD)

  47.   #define HTCFG_LED0                                            (HT_GPIOC)
  48.   #define HTCFG_LED1                                            (HT_GPIOC)
  49.   #define HTCFG_LED2                                            (HT_GPIOC)
  50.   #define HTCFG_WAKE                                            (HT_GPIOB)
  51.   #define HTCFG_KEY1                                            (HT_GPIOD)
  52.   #define HTCFG_KEY2                                            (HT_GPIOD)

  53.   #define HTCFG_OUTPUT_LED0_AFIO_PIN                            (AFIO_PIN_14)
  54.   #define HTCFG_OUTPUT_LED1_AFIO_PIN                            (AFIO_PIN_15)
  55.   #define HTCFG_OUTPUT_LED2_AFIO_PIN                            (AFIO_PIN_1)
  56.   #define HTCFG_INPUT_WAKE_AFIO_PIN                             (AFIO_PIN_12)
  57.   #define HTCFG_INPUT_KEY1_AFIO_PIN                             (AFIO_PIN_1)
  58.   #define HTCFG_INPUT_KEY2_AFIO_PIN                             (AFIO_PIN_2)

  59.   #define HTCFG_OUTPUT_LED0_GPIO_PIN                            (GPIO_PIN_14)
  60.   #define HTCFG_OUTPUT_LED1_GPIO_PIN                            (GPIO_PIN_15)
  61.   #define HTCFG_OUTPUT_LED2_GPIO_PIN                            (GPIO_PIN_1)
  62.   #define HTCFG_INPUT_WAKE_GPIO_PIN                             (GPIO_PIN_12)
  63.   #define HTCFG_INPUT_KEY1_GPIO_PIN                             (GPIO_PIN_1)
  64.   #define HTCFG_INPUT_KEY2_GPIO_PIN                             (GPIO_PIN_2)
  65. #endif






  66. /* Settings ------------------------------------------------------------------------------------------------*/
  67. #if defined(USE_HT32F52230_SK)
  68.   #error "This example code does not apply to the chip you selected."
  69. #endif




  70. #if defined(USE_HT32F52352_SK)
  71.   #define HTCFG_SPI_MASTER_SEL_GPIO_ID             (HT_GPIOB)
  72.   #define HTCFG_SPI_MASTER_SEL_CLOCK(CK)           (CK.Bit.PB)

  73.   #define HTCFG_SPI_MASTER_CLOCK(CK)               (CK.Bit.SPI0)
  74.   #define HTCFG_SPI_MASTER                         (HT_SPI0)
  75.   #define HTCFG_SPI_MASTER_IRQn                    (SPI0_IRQn)
  76.   #define HTCFG_SPI_MASTER_SEL_AFIO_PORT           (GPIO_PB)
  77.   #define HTCFG_SPI_MASTER_SCK_AFIO_PORT           (GPIO_PB)
  78.   #define HTCFG_SPI_MASTER_MOSI_AFIO_PORT          (GPIO_PB)
  79.   #define HTCFG_SPI_MASTER_MISO_AFIO_PORT          (GPIO_PB)
  80.    
  81.   #define HTCFG_SPI_MASTER_SEL_AFIO_PIN            (AFIO_PIN_2)
  82.   #define HTCFG_SPI_MASTER_SCK_AFIO_PIN            (AFIO_PIN_3)
  83.   #define HTCFG_SPI_MASTER_MOSI_AFIO_PIN           (AFIO_PIN_4)
  84.   #define HTCFG_SPI_MASTER_MISO_AFIO_PIN           (AFIO_PIN_5)
  85.   #define HTCFG_SPI_MASTER_IRQHandler              (SPI0_IRQHandler)

  86.   #define HTCFG_SPI_SLAVE_CLOCK(CK)                (CK.Bit.SPI1)
  87.   #define HTCFG_SPI_SLAVE                          (HT_SPI1)
  88.   #define HTCFG_SPI_SLAVE_IRQn                     (SPI1_IRQn)
  89.   #define HTCFG_SPI_SLAVE_SEL_AFIO_PORT            (GPIO_PA)
  90.   #define HTCFG_SPI_SLAVE_SCK_AFIO_PORT            (GPIO_PC)
  91.   #define HTCFG_SPI_SLAVE_MOSI_AFIO_PORT           (GPIO_PC)
  92.   #define HTCFG_SPI_SLAVE_MISO_AFIO_PORT           (GPIO_PC)
  93.   #define HTCFG_SPI_SLAVE_SEL_AFIO_PIN             (AFIO_PIN_4)
  94.   #define HTCFG_SPI_SLAVE_SCK_AFIO_PIN             (AFIO_PIN_5)
  95.   #define HTCFG_SPI_SLAVE_MOSI_AFIO_PIN            (AFIO_PIN_8)
  96.   #define HTCFG_SPI_SLAVE_MISO_AFIO_PIN            (AFIO_PIN_9)
  97.   #define HTCFG_SPI_SLAVE_IRQHandler               (SPI1_IRQHandler)
  98. #endif





  99. #if defined(USE_HT32F52352_SK)
  100.   #define _HTCFG_UART_TX_GPIOX                    A
  101.   #define _HTCFG_UART_TX_GPION                    4
  102.   #define _HTCFG_UART_RX_GPIOX                    A
  103.   #define _HTCFG_UART_RX_GPION                    5
  104.   #define HTCFG_UART_IPN                          USART1
  105.    

  106.   #define HTCFG_TX_PDMA_CH                        (PDMA_USART1_TX)
  107.   #define HTCFG_RX_PDMA_CH                        (PDMA_USART1_RX)
  108.   #define HTCFG_PDMA_IRQ                          (PDMACH2_5_IRQn)
  109.   #define HTCFG_PDMA_IRQHandler                   (PDMA_CH2_5_IRQHandler)
  110.   #define HTCFG_PDMA_CURRENT_TRANSFER_SIZE        (HT_PDMA->PDMACH2.CTSR >> 16)
  111. #endif


  112. #define HTCFG_CAP_GPIO_ID                         STRCAT2(GPIO_P,         _HTCFG_CAP_GPIOX)
  113. #define HTCFG_CAP_AFIO_PIN                        STRCAT2(AFIO_PIN_,      _HTCFG_CAP_GPION)
  114. #define HTCFG_CAP_PORT                            STRCAT2(HT_,             HTCFG_CAP_IPN)
  115. #define HTCFG_CAP_CH                              STRCAT2(TM_CH_,         _HTCFG_CAP_CHN)

  116. #define HTCFG_UART_TX_GPIO_ID                     STRCAT2(GPIO_P,         _HTCFG_UART_TX_GPIOX)
  117. #define HTCFG_UART_RX_GPIO_ID                     STRCAT2(GPIO_P,         _HTCFG_UART_RX_GPIOX)
  118. #define HTCFG_UART_TX_AFIO_PIN                    STRCAT2(AFIO_PIN_,      _HTCFG_UART_TX_GPION)
  119. #define HTCFG_UART_RX_AFIO_PIN                    STRCAT2(AFIO_PIN_,      _HTCFG_UART_RX_GPION)
  120. #define HTCFG_UART_PORT                           STRCAT2(HT_,             HTCFG_UART_IPN)
  121. #define HTCFG_UART_IRQn                           STRCAT2(HTCFG_UART_IPN, _IRQn)
  122. #define HTCFG_UART_IRQHandler                     STRCAT2(HTCFG_UART_IPN, _IRQHandler)

  123. #define HTCFG_UART_RX_GPIO_CLK                    STRCAT2(P,              _HTCFG_UART_RX_GPIOX)
  124. #define HTCFG_UART_RX_GPIO_PORT                   STRCAT2(HT_GPIO,        _HTCFG_UART_RX_GPIOX)
  125. #define HTCFG_UART_RX_GPIO_PIN                    STRCAT2(GPIO_PIN_,      _HTCFG_UART_RX_GPION)

  126. #define _HTCFG_CAP_GPIOX                        C
  127. #define _HTCFG_CAP_GPION                        5
  128. #define  HTCFG_CAP_IPN                          GPTM0
  129. #define _HTCFG_CAP_CHN                          1
  130. #define  HTCFG_CAP_CCR                          (TM_INT_CH1CC)

  131. #define _HTCFG_PWM_GPIOX                        B
  132. #define _HTCFG_PWM_GPION                        4
  133. #define  HTCFG_PWM_IPN                          SCTM0
  134. #define _HTCFG_PWM_CHN                          0

  135. #if (LIBCFG_GPTM_GIRQ == 1)
  136.   #define HTCFG_CAP_IRQn                          STRCAT2(HTCFG_CAP_IPN,  _G_IRQn)
  137.   #define HTCFG_CAP_IRQHandler                    STRCAT2(HTCFG_CAP_IPN,  _G_IRQHandler)
  138. #else
  139.   #define HTCFG_CAP_IRQn                          STRCAT2(HTCFG_CAP_IPN,  _IRQn)
  140.   #define HTCFG_CAP_IRQHandler                    STRCAT2(HTCFG_CAP_IPN,  _IRQHandler)
  141. #endif

  142. #define HTCFG_PWM_GPIO_ID                         STRCAT2(GPIO_P,         _HTCFG_PWM_GPIOX)
  143. #define HTCFG_PWM_AFIO_PIN                        STRCAT2(AFIO_PIN_,      _HTCFG_PWM_GPION)
  144. #define HTCFG_PWM_AFIO_FUN                        STRCAT2(AFIO_FUN_,       HTCFG_PWM_IPN)
  145. #define HTCFG_PWM_PORT                            STRCAT2(HT_,             HTCFG_PWM_IPN)
  146. #define HTCFG_PWM_CH                              STRCAT2(TM_CH_,         _HTCFG_PWM_CHN)

  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif
 楼主| 高级安全大使 发表于 2023-2-25 11:21 | 显示全部楼层
 楼主| 高级安全大使 发表于 2023-2-25 11:22 | 显示全部楼层
belindagraham 发表于 2023-3-7 13:50 | 显示全部楼层
红外能不能发送32位字节的数据              
louliana 发表于 2023-3-7 14:00 | 显示全部楼层
如何编写红外遥控器 ?              
lzmm 发表于 2023-3-7 20:26 | 显示全部楼层
分析红外NEC信号时要注意什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

59

主题

445

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部