当前位置:   article > 正文

合泰HT32F52352红外NEC编码_nec遥控器编码格式

nec遥控器编码格式

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

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

图1.NEC编码时序图

图2.引导码及数据定义

逻辑1:560us低1680us高 逻辑0:560us低 560us高

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

图三.Repeat波形图

  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. NVIC_EnableIRQ(BFTM0_IRQn);
  44. BFTM_SetCounter(HT_BFTM0, 0);
  45. //BFTM_SetCompare(HT_BFTM1, SystemCoreClock);//定时1s产生中断
  46. BFTM_SetCompare(HT_BFTM0, SystemCoreClock/1000);//定时1ms产生中断 呼吸灯1us中断1000000
  47. BFTM_IntConfig(HT_BFTM0, ENABLE);//使能中断
  48. BFTM_EnaCmd(HT_BFTM0, ENABLE);//使能BFTM
  49. }
  50. void BFTM0_IRQHandler(void)
  51. {
  52. if(BFTM_GetFlagStatus(HT_BFTM0) != RESET )
  53. {
  54. count++;
  55. if(count == 500) //
  56. {
  57. count = 0;
  58. }
  59. //Capture_MainRoutine();
  60. BFTM_ClearFlag(HT_BFTM0);//清除中断标志
  61. }
  62. }
  63. void Capture_MainRoutine(void)
  64. {
  65. u32 Dval = 0;
  66. u32 data = 9;
  67. if (CaptureCHx.DataValid)
  68. {
  69. Dval = CaptureCHx.CapturePulse / (SystemCoreClock / 1000000ul);
  70. //printf("Capture: %d %8.2f uS\r\n", CaptureCHx.CapturePulse, ((float)CaptureCHx.CapturePulse / (SystemCoreClock / 1000000ul)));
  71. if(Dval>4200 && Dval<4700)
  72. {
  73. data = 3;
  74. }
  75. if(Dval>300 && Dval<800)
  76. {
  77. data = 0;
  78. rx_data <<= 1;
  79. rx_data |= 0;
  80. sum++;
  81. }
  82. if(Dval>1400 && Dval<1800)
  83. {
  84. data = 1;
  85. rx_data <<= 1;
  86. rx_data |= 1;
  87. sum++;
  88. }
  89. if(sum >= 32)
  90. {
  91. rx_data >>= 8;
  92. rx_data &= 0x00FF;
  93. key_sum++;
  94. switch (rx_data)
  95. {
  96. case 0xA2:succeed++;printf("%d:%d + %d = %d%% RX:CH-\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  97. case 0x62:succeed++;printf("%d:%d + %d = %d%% RX:CH\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  98. case 0xE2:succeed++;printf("%d:%d + %d = %d%% RX:CH+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  99. case 0x22:succeed++;printf("%d:%d + %d = %d%% RX:|<<\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  100. case 0x02:succeed++;printf("%d:%d + %d = %d%% RX:>>|\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  101. case 0xC2:succeed++;printf("%d:%d + %d = %d%% RX:>||\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  102. case 0xE0:succeed++;printf("%d:%d + %d = %d%% RX:-\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  103. case 0xA8:succeed++;printf("%d:%d + %d = %d%% RX:+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  104. case 0x90:succeed++;printf("%d:%d + %d = %d%% RX:EQ\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  105. case 0x68:succeed++;printf("%d:%d + %d = %d%% RX:0\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  106. case 0x98:succeed++;printf("%d:%d + %d = %d%% RX:100+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  107. case 0xB0:succeed++;printf("%d:%d + %d = %d%% RX:200+\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  108. case 0x30:succeed++;printf("%d:%d + %d = %d%% RX:1\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  109. case 0x18:succeed++;printf("%d:%d + %d = %d%% RX:2\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  110. case 0x7A:succeed++;printf("%d:%d + %d = %d%% RX:3\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  111. case 0x10:succeed++;printf("%d:%d + %d = %d%% RX:4\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  112. case 0x38:succeed++;printf("%d:%d + %d = %d%% RX:5\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  113. case 0x5A:succeed++;printf("%d:%d + %d = %d%% RX:6\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  114. case 0x42:succeed++;printf("%d:%d + %d = %d%% RX:7\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  115. case 0x4A:succeed++;printf("%d:%d + %d = %d%% RX:8\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  116. case 0x52:succeed++;printf("%d:%d + %d = %d%% RX:9\r\n",key_sum,succeed,fail,(succeed*100)/key_sum);break;
  117. 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;
  118. }
  119. rx_data = 0;
  120. sum = 0;
  121. }
  122. CaptureCHx.DataValid = FALSE;
  123. }
  124. }
  125. /*********************************************************************************************************//**
  126. * @brief Configures TM to capture waveform.
  127. * @retval None
  128. ***********************************************************************************************************/
  129. void Capture_Configuration(void)
  130. {
  131. { /* Enable peripheral clock */
  132. CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
  133. CKCUClock.Bit.AFIO = 1;
  134. CKCUClock.Bit.HTCFG_CAP_IPN = 1;
  135. CKCU_PeripClockConfig(CKCUClock, ENABLE);
  136. }
  137. /* Configure AFIO mode as TM function */
  138. AFIO_GPxConfig(HTCFG_CAP_GPIO_ID, HTCFG_CAP_AFIO_PIN, AFIO_FUN_MCTM_GPTM);
  139. { /* Time base configuration */
  140. /* !!! NOTICE !!!
  141. Notice that the local variable (structure) did not have an initial value.
  142. Please confirm that there are no missing members in the parameter settings below in this function.
  143. */
  144. TM_TimeBaseInitTypeDef TimeBaseInit;
  145. TimeBaseInit.Prescaler = 1 - 1; // Timer clock = CK_AHB / 1
  146. TimeBaseInit.CounterReload = 0xFFFF;
  147. TimeBaseInit.RepetitionCounter = 0;
  148. TimeBaseInit.CounterMode = TM_CNT_MODE_UP;
  149. TimeBaseInit.PSCReloadTime = TM_PSC_RLD_IMMEDIATE;
  150. TM_TimeBaseInit(HTCFG_CAP_PORT, &TimeBaseInit);
  151. /* Clear Update Event Interrupt flag since the "TM_TimeBaseInit()" writes the UEV1G bit */
  152. TM_ClearFlag(HTCFG_CAP_PORT, TM_FLAG_UEV);
  153. }
  154. { /* Channel n capture configuration */
  155. /* !!! NOTICE !!!
  156. Notice that the local variable (structure) did not have an initial value.
  157. Please confirm that there are no missing members in the parameter settings below in this function.
  158. */
  159. TM_CaptureInitTypeDef CapInit;
  160. TM_CaptureStructInit(&CapInit);
  161. CapInit.Channel = HTCFG_CAP_CH;
  162. CapInit.Polarity = TM_CHP_NONINVERTED;
  163. CapInit.Selection = TM_CHCCS_DIRECT;
  164. CapInit.Prescaler = TM_CHPSC_OFF;
  165. #if (LIBCFG_TM_652XX_V1)
  166. CapInit.Fsampling = TM_CHFDIV_1;
  167. CapInit.Event = TM_CHFEV_OFF;
  168. #else
  169. CapInit.Filter = 0x0;
  170. #endif
  171. TM_CaptureInit(HTCFG_CAP_PORT, &CapInit);
  172. }
  173. /* Enable TM Channel Capture and Update Event interrupts */
  174. TM_IntConfig(HTCFG_CAP_PORT, HTCFG_CAP_CCR | TM_INT_UEV, ENABLE);
  175. NVIC_EnableIRQ(HTCFG_CAP_IRQn);
  176. TM_Cmd(HTCFG_CAP_PORT, ENABLE);
  177. }
  178. /*********************************************************************************************************//**
  179. * @brief This function handles GPTM interrupt.
  180. * @retval None
  181. ***********************************************************************************************************/
  182. void HTCFG_CAP_IRQHandler(void)
  183. {
  184. bool update_flag = FALSE;
  185. /* store and clear all interrupt flags */
  186. u32 status = HTCFG_CAP_PORT->INTSR;
  187. u32 cnt = HTCFG_CAP_PORT->CNTR;
  188. #if 0
  189. if ((status & TM_INT_UEV) != (HTCFG_CAP_PORT->INTSR & TM_INT_UEV))
  190. {
  191. status = HTCFG_CAP_PORT->INTSR;
  192. cnt = HTCFG_CAP_PORT->CNTR;
  193. }
  194. #endif
  195. HTCFG_CAP_PORT->INTSR = ~status;
  196. if (status & TM_INT_UEV)
  197. {
  198. update_flag = TRUE;
  199. /* The OverflowCounter will stop at max value 0xFFFF */
  200. if (CaptureCHx.OverflowCounter != 0xFFFF)
  201. CaptureCHx.OverflowCounter++;
  202. }
  203. if (status & HTCFG_CAP_CCR)
  204. {
  205. u32 cap_value = TM_GetCaptureCompare(HTCFG_CAP_PORT, HTCFG_CAP_CH);
  206. bool isCapBeforeUpdate = (update_flag && (cap_value > cnt))? TRUE : FALSE;
  207. Capture_Process(&CaptureCHx, cap_value, isCapBeforeUpdate);
  208. TM_ChPolarityConfig(HTCFG_CAP_PORT, HTCFG_CAP_CH, CaptureCHx.ChannelPolarity);
  209. }
  210. }
  211. /*********************************************************************************************************//**
  212. * @brief Capture Process function.
  213. * @retval None
  214. ************************************************************************************************************/
  215. void Capture_Process(sPulseCaptureStructure* cap, u16 capture_value, bool isCapBeforeUpdate)
  216. {
  217. if (cap->ChannelPolarity == TM_CHP_NONINVERTED)
  218. {
  219. /* Reset OverflowCounter and store capture value when rising edge occurred */
  220. if (isCapBeforeUpdate)
  221. {
  222. cap->OverflowCounter = 1;
  223. }
  224. else
  225. {
  226. cap->OverflowCounter = 0;
  227. }
  228. cap->StartValue = capture_value;
  229. /* Change channel polarity to capture when falling edge occur */
  230. cap->ChannelPolarity = TM_CHP_INVERTED;
  231. }
  232. else
  233. {
  234. /* Compute pulse width in PCLK unit when falling edge occurred */
  235. if (isCapBeforeUpdate)
  236. cap->OverflowCounter--;
  237. cap->CapturePulse = (cap->OverflowCounter << 16) - cap->StartValue + capture_value + 1;
  238. if (cap->DataValid)
  239. cap->DataOverwrite = TRUE;
  240. else
  241. cap->DataValid = TRUE;
  242. /* Change channel polarity to capture when rising edge occur */
  243. cap->ChannelPolarity = TM_CHP_NONINVERTED;
  244. }
  245. }
  246. /*********************************************************************************************************//**
  247. * @brief Configures TM to output PWM waveform.
  248. * @retval None
  249. * @details Configuration as frequency 1 Hz and duty 2500 uS (10/4000).
  250. ***********************************************************************************************************/
  251. void PWM_OUT_Configuration(void)
  252. {
  253. { /* Enable peripheral clock */
  254. CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
  255. CKCUClock.Bit.AFIO = 1;
  256. CKCUClock.Bit.HTCFG_PWM_IPN = 1;
  257. CKCU_PeripClockConfig(CKCUClock, ENABLE);
  258. }
  259. /* Configure AFIO mode as TM function */
  260. AFIO_GPxConfig(HTCFG_PWM_GPIO_ID, HTCFG_PWM_AFIO_PIN, HTCFG_PWM_AFIO_FUN);
  261. { /* Time base configuration */
  262. /* !!! NOTICE !!!
  263. Notice that the local variable (structure) did not have an initial value.
  264. Please confirm that there are no missing members in the parameter settings below in this function.
  265. */
  266. TM_TimeBaseInitTypeDef TimeBaseInit;
  267. TimeBaseInit.Prescaler = (SystemCoreClock / 4000) - 1; // Timer clock = 4 kHz
  268. TimeBaseInit.CounterReload = 4000 - 1; // PWM frequency = 1 Hz
  269. TimeBaseInit.RepetitionCounter = 0;
  270. TimeBaseInit.CounterMode = TM_CNT_MODE_UP;
  271. TimeBaseInit.PSCReloadTime = TM_PSC_RLD_IMMEDIATE;
  272. TM_TimeBaseInit(HTCFG_PWM_PORT, &TimeBaseInit);
  273. /* Clear Update Event Interrupt flag since the "TM_TimeBaseInit()" writes the UEV1G bit */
  274. #if 0
  275. TM_ClearFlag(HTCFG_PWM_PORT, TM_FLAG_UEV);
  276. #endif
  277. }
  278. { /* Channel n output configuration */
  279. /* !!! NOTICE !!!
  280. Notice that the local variable (structure) did not have an initial value.
  281. Please confirm that there are no missing members in the parameter settings below in this function.
  282. */
  283. TM_OutputInitTypeDef OutInit;
  284. OutInit.Channel = HTCFG_PWM_CH;
  285. OutInit.OutputMode = TM_OM_PWM2;
  286. OutInit.Control = TM_CHCTL_ENABLE;
  287. OutInit.ControlN = TM_CHCTL_DISABLE;
  288. OutInit.Polarity = TM_CHP_NONINVERTED;
  289. OutInit.PolarityN = TM_CHP_NONINVERTED;
  290. OutInit.IdleState = MCTM_OIS_LOW;
  291. OutInit.IdleStateN = MCTM_OIS_HIGH;
  292. OutInit.Compare = 4000 - 10; // PWM duty = 10/4000 = 2500 us
  293. OutInit.AsymmetricCompare = 0;
  294. TM_OutputInit(HTCFG_PWM_PORT, &OutInit);
  295. }
  296. TM_Cmd(HTCFG_PWM_PORT, ENABLE);
  297. }
  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
  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. while(1)
  31. {
  32. Capture_MainRoutine();
  33. }
  34. }
  1. /*********************************************************************************************************//**
  2. * @file GPIO/InputOutput/ht32_board_config.h
  3. * @version $Rev:: 4728 $
  4. * @date $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. #define HTCFG_SPI_MASTER_SEL_AFIO_PIN (AFIO_PIN_2)
  81. #define HTCFG_SPI_MASTER_SCK_AFIO_PIN (AFIO_PIN_3)
  82. #define HTCFG_SPI_MASTER_MOSI_AFIO_PIN (AFIO_PIN_4)
  83. #define HTCFG_SPI_MASTER_MISO_AFIO_PIN (AFIO_PIN_5)
  84. #define HTCFG_SPI_MASTER_IRQHandler (SPI0_IRQHandler)
  85. #define HTCFG_SPI_SLAVE_CLOCK(CK) (CK.Bit.SPI1)
  86. #define HTCFG_SPI_SLAVE (HT_SPI1)
  87. #define HTCFG_SPI_SLAVE_IRQn (SPI1_IRQn)
  88. #define HTCFG_SPI_SLAVE_SEL_AFIO_PORT (GPIO_PA)
  89. #define HTCFG_SPI_SLAVE_SCK_AFIO_PORT (GPIO_PC)
  90. #define HTCFG_SPI_SLAVE_MOSI_AFIO_PORT (GPIO_PC)
  91. #define HTCFG_SPI_SLAVE_MISO_AFIO_PORT (GPIO_PC)
  92. #define HTCFG_SPI_SLAVE_SEL_AFIO_PIN (AFIO_PIN_4)
  93. #define HTCFG_SPI_SLAVE_SCK_AFIO_PIN (AFIO_PIN_5)
  94. #define HTCFG_SPI_SLAVE_MOSI_AFIO_PIN (AFIO_PIN_8)
  95. #define HTCFG_SPI_SLAVE_MISO_AFIO_PIN (AFIO_PIN_9)
  96. #define HTCFG_SPI_SLAVE_IRQHandler (SPI1_IRQHandler)
  97. #endif
  98. #if defined(USE_HT32F52352_SK)
  99. #define _HTCFG_UART_TX_GPIOX A
  100. #define _HTCFG_UART_TX_GPION 4
  101. #define _HTCFG_UART_RX_GPIOX A
  102. #define _HTCFG_UART_RX_GPION 5
  103. #define HTCFG_UART_IPN USART1
  104. #define HTCFG_TX_PDMA_CH (PDMA_USART1_TX)
  105. #define HTCFG_RX_PDMA_CH (PDMA_USART1_RX)
  106. #define HTCFG_PDMA_IRQ (PDMACH2_5_IRQn)
  107. #define HTCFG_PDMA_IRQHandler (PDMA_CH2_5_IRQHandler)
  108. #define HTCFG_PDMA_CURRENT_TRANSFER_SIZE (HT_PDMA->PDMACH2.CTSR >> 16)
  109. #endif
  110. #define HTCFG_CAP_GPIO_ID STRCAT2(GPIO_P, _HTCFG_CAP_GPIOX)
  111. #define HTCFG_CAP_AFIO_PIN STRCAT2(AFIO_PIN_, _HTCFG_CAP_GPION)
  112. #define HTCFG_CAP_PORT STRCAT2(HT_, HTCFG_CAP_IPN)
  113. #define HTCFG_CAP_CH STRCAT2(TM_CH_, _HTCFG_CAP_CHN)
  114. #define HTCFG_UART_TX_GPIO_ID STRCAT2(GPIO_P, _HTCFG_UART_TX_GPIOX)
  115. #define HTCFG_UART_RX_GPIO_ID STRCAT2(GPIO_P, _HTCFG_UART_RX_GPIOX)
  116. #define HTCFG_UART_TX_AFIO_PIN STRCAT2(AFIO_PIN_, _HTCFG_UART_TX_GPION)
  117. #define HTCFG_UART_RX_AFIO_PIN STRCAT2(AFIO_PIN_, _HTCFG_UART_RX_GPION)
  118. #define HTCFG_UART_PORT STRCAT2(HT_, HTCFG_UART_IPN)
  119. #define HTCFG_UART_IRQn STRCAT2(HTCFG_UART_IPN, _IRQn)
  120. #define HTCFG_UART_IRQHandler STRCAT2(HTCFG_UART_IPN, _IRQHandler)
  121. #define HTCFG_UART_RX_GPIO_CLK STRCAT2(P, _HTCFG_UART_RX_GPIOX)
  122. #define HTCFG_UART_RX_GPIO_PORT STRCAT2(HT_GPIO, _HTCFG_UART_RX_GPIOX)
  123. #define HTCFG_UART_RX_GPIO_PIN STRCAT2(GPIO_PIN_, _HTCFG_UART_RX_GPION)
  124. #define _HTCFG_CAP_GPIOX C
  125. #define _HTCFG_CAP_GPION 5
  126. #define HTCFG_CAP_IPN GPTM0
  127. #define _HTCFG_CAP_CHN 1
  128. #define HTCFG_CAP_CCR (TM_INT_CH1CC)
  129. #define _HTCFG_PWM_GPIOX B
  130. #define _HTCFG_PWM_GPION 4
  131. #define HTCFG_PWM_IPN SCTM0
  132. #define _HTCFG_PWM_CHN 0
  133. #if (LIBCFG_GPTM_GIRQ == 1)
  134. #define HTCFG_CAP_IRQn STRCAT2(HTCFG_CAP_IPN, _G_IRQn)
  135. #define HTCFG_CAP_IRQHandler STRCAT2(HTCFG_CAP_IPN, _G_IRQHandler)
  136. #else
  137. #define HTCFG_CAP_IRQn STRCAT2(HTCFG_CAP_IPN, _IRQn)
  138. #define HTCFG_CAP_IRQHandler STRCAT2(HTCFG_CAP_IPN, _IRQHandler)
  139. #endif
  140. #define HTCFG_PWM_GPIO_ID STRCAT2(GPIO_P, _HTCFG_PWM_GPIOX)
  141. #define HTCFG_PWM_AFIO_PIN STRCAT2(AFIO_PIN_, _HTCFG_PWM_GPION)
  142. #define HTCFG_PWM_AFIO_FUN STRCAT2(AFIO_FUN_, HTCFG_PWM_IPN)
  143. #define HTCFG_PWM_PORT STRCAT2(HT_, HTCFG_PWM_IPN)
  144. #define HTCFG_PWM_CH STRCAT2(TM_CH_, _HTCFG_PWM_CHN)
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif

图四.测试结果

图五.实物图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/493131
推荐阅读
相关标签
  

闽ICP备14008679号