- CKCU_PeripClockConfig_TypeDef GPIOlock = {{ 0 }};
- GPIOlock.Bit.AFIO = 1;
- GPIOlock.Bit.PC = 1; //使能PC
- GPIOlock.Bit.PA = 1; //使能PC
- CKCU_PeripClockConfig(GPIOlock, ENABLE); //使能时钟
-
-
- AFIO_GPxConfig(GPIO_PA, AFIO_PIN_5|AFIO_PIN_6, AFIO_FUN_GPIO);
- AFIO_GPxConfig(GPIO_PA, AFIO_PIN_0|AFIO_PIN_1|AFIO_PIN_2|AFIO_PIN_3, AFIO_FUN_GPIO);
-
- GPIO_PullResistorConfig(HT_GPIOA, GPIO_PIN_5|GPIO_PIN_6, GPIO_PR_DOWN);
- GPIO_PullResistorConfig(HT_GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PR_DOWN);
-
- GPIO_DirectionConfig(HT_GPIOA, GPIO_PIN_5|GPIO_PIN_6, GPIO_DIR_OUT);
- GPIO_DirectionConfig(HT_GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_DIR_OUT);
使用宏定义的方式进行语句的使用,也方便移植到其他MCU 上。
模拟IIC部分
主函数,这里使用的是之前使用FreeRTOS的程序,灯依然会闪,只是加入了显示的部分。
- /*********************************************************************************************************//**
- * [url=home.php?mod=space&uid=288409]@file[/url] IP/Example/main.c
- * [url=home.php?mod=space&uid=895143]@version[/url] $Rev:: 4869 $
- * [url=home.php?mod=space&uid=212281]@date[/url] $Date:: 2020-08-05 #$
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program.
- *************************************************************************************************************
- * @attention
- *
- * Firmware Disclaimer Information
- *
- * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
- * code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
- * proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
- * other intellectual property laws.
- *
- * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
- * code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
- * other than HOLTEK and the customer.
- *
- * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
- * only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
- * the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
- * the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
- *
- * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
- ************************************************************************************************************/
- // <<< Use Configuration Wizard in Context Menu >>>
- /* Includes ------------------------------------------------------------------------------------------------*/
- #include "ht32.h"
- #include "ht32_board.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "delay.h"
- #include "QDTFT_demo.h"
- #include "Lcd_Driver.h"
- #include "ht32f5xxxx_gpio.h"
- /* Settings ------------------------------------------------------------------------------------------------*/
- /* Private types -------------------------------------------------------------------------------------------*/
- /* Private constants ---------------------------------------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------------------------------------*/
- void NVIC_Configuration(void);
- void CKCU_Configuration(void);
- void GPIO_Configuration(void);
- #if (ENABLE_CKOUT == 1)
- void CKOUTConfig(void);
- #endif
- //任务堆栈大小
- #define LED1_TASK_STACK 256
- #define LED2_TASK_STACK 215
- //任务优先级
- #define LED1_TASK_PRIORITY 5
- #define LED2_TASK_PRIORITY 3
- xTaskHandle startTask;
- xTaskHandle LED1Task;
- xTaskHandle LED2Task;
- portTASK_FUNCTION(vLED1Task, pvParameters)
- {
- while(1)
- {
- HT32F_DVB_LEDOn(HT_LED1);
- vTaskDelay(200);
- HT32F_DVB_LEDOff(HT_LED1);
- vTaskDelay(200);
- }
- }
- portTASK_FUNCTION(vLED2Task, pvParameters)
- {
- while(1)
- {
-
- HT32F_DVB_LEDOn(HT_LED2);
- vTaskDelay(500);
- HT32F_DVB_LEDOff(HT_LED2);
- vTaskDelay(500);
- }
- }
- /**********************************************************************************************************
- *函 数 名: vStartTask
- *功能说明: 系统启动任务,调用各类初始化函数,并创建消息队列和要运行的用户任务
- *形 参: 无
- *返 回 值: 无
- **********************************************************************************************************/
- portTASK_FUNCTION(vStartTask, pvParameters)
- {
- xTaskCreate(vLED1Task, (char const*)"SensorReadTask",LED1_TASK_STACK, NULL, LED1_TASK_PRIORITY, &LED1Task);
- xTaskCreate(vLED2Task, (char const*)"SensorUpdateTask",LED2_TASK_STACK, NULL,LED2_TASK_PRIORITY, &LED2Task);
-
- //删除本任务
- vTaskDelete(NULL);
- }
-
- /* Private macro -------------------------------------------------------------------------------------------*/
- /* Global variables ----------------------------------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------------------------------------*/
- /* Global functions ----------------------------------------------------------------------------------------*/
- /*********************************************************************************************************//**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program.
- * @retval None
- ***********************************************************************************************************/
- int main(void)
- {
-
- NVIC_Configuration(); /* NVIC configuration */
- CKCU_Configuration(); /* System Related configuration */
- GPIO_Configuration(); /* GPIO Related configuration */
- RETARGET_Configuration(); /* Retarget Related configuration */
- HT32F_DVB_LEDInit(HT_LED1);
- HT32F_DVB_LEDInit(HT_LED2);
- HT32F_DVB_LEDInit(HT_LED3);
- HT32F_DVB_LEDOn(HT_LED1);
- HT32F_DVB_LEDOff(HT_LED2);
- HT32F_DVB_LEDOn(HT_LED3);
- Lcd_Init();
- LCD_LED_SET;
- Lcd_Clear(GRAY0);
- Gui_DrawFont_GBK16(20,20,BLACK,GRAY0,"HT32 & 21ic");
- Gui_DrawFont_GBK16(20,40,BLACK,GRAY0,"1.8 TFT test");
- //创建启动任务
- xTaskCreate(vStartTask, "startTask", 128, NULL, 0, &startTask);
- // //OS调度器启动
- vTaskStartScheduler();
- }
- /*********************************************************************************************************//**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Configure the NVIC vector table.
- * @retval None
- ***********************************************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_SetVectorTable(NVIC_VECTTABLE_FLASH, 0x0); /* Set the Vector Table base location at 0x00000000 */
- }
- /*********************************************************************************************************//**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Configure the system clocks.
- * @retval None
- ***********************************************************************************************************/
- void CKCU_Configuration(void)
- {
- /*
- //<e0> Enable Peripheral Clock
- // <h> Communication
- // <q5> EBI
- // <q11> I2C0 <q12> I2C1
- // <q23> I2S
- // <q21> SCI0 <q22> SCI1
- // <q13> SPI0 <q14> SPI1
- // <q17> UART0 <q18> UART1
- // <q15> USART0 <q16> USART1
- // <q3> USB
- // </h>
- // <h> IO
- // <q7> GPIO Port A <q8> GPIO Port B <q9> GPIO Port C <q10> GPIO Port D
- // <q19> AFIO
- // <q20> EXTI
- // </h>
- // <h> System
- // <q32> ADC
- // <q4> CKREF
- // <q6> CRC
- // <q31> CMP
- // <q2> PDMA
- // <q26> PWRCU
- // </h>
- // <h> Timer
- // <q29> BFTM0 <q30> BFTM1
- // <q33> SCTM0 <q34> SCTM1 <q35> SCTM2 <q36> SCTM3
- // <q27> GPTM0 <q28> GPTM1
- // <q24> MCTM0
- // <q26> RTC <q25> WDT
- // </h>
- //</e>
- */
- #if 1
- CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
- CKCUClock.Bit.PDMA = 0;
- CKCUClock.Bit.USBD = 0;
- CKCUClock.Bit.CKREF = 0;
- CKCUClock.Bit.EBI = 0;
- CKCUClock.Bit.CRC = 0;
- CKCUClock.Bit.PA = 1;
- CKCUClock.Bit.PB = 1;
- CKCUClock.Bit.PC = 1;
- CKCUClock.Bit.PD = 1;
- CKCUClock.Bit.I2C0 = 0;
- CKCUClock.Bit.I2C1 = 0;
- CKCUClock.Bit.SPI0 = 0;
- CKCUClock.Bit.SPI1 = 0;
- CKCUClock.Bit.USART0 = 1;
- CKCUClock.Bit.USART1 = 0;
- CKCUClock.Bit.UART0 = 0;
- CKCUClock.Bit.UART1 = 0;
- CKCUClock.Bit.AFIO = 1;
- CKCUClock.Bit.EXTI = 0;
- CKCUClock.Bit.SCI0 = 0;
- CKCUClock.Bit.SCI1 = 0;
- CKCUClock.Bit.I2S = 0;
- CKCUClock.Bit.MCTM0 = 0;
- CKCUClock.Bit.WDT = 0;
- CKCUClock.Bit.BKP = 0;
- CKCUClock.Bit.GPTM0 = 0;
- CKCUClock.Bit.GPTM1 = 0;
- CKCUClock.Bit.BFTM0 = 0;
- CKCUClock.Bit.BFTM1 = 0;
- CKCUClock.Bit.CMP = 0;
- CKCUClock.Bit.ADC = 0;
- CKCUClock.Bit.SCTM0 = 0;
- CKCUClock.Bit.SCTM1 = 0;
- CKCUClock.Bit.SCTM2 = 0;
- CKCUClock.Bit.SCTM3 = 0;
- CKCU_PeripClockConfig(CKCUClock, ENABLE);
- #endif
- #if (ENABLE_CKOUT == 1)
- CKOUTConfig();
- #endif
- }
- #if (ENABLE_CKOUT == 1)
- /*********************************************************************************************************//**
- * @brief Configure the debug output clock.
- * @retval None
- ***********************************************************************************************************/
- void CKOUTConfig(void)
- {
- { /* Enable peripheral clock */
- CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
- CKCUClock.Bit.AFIO = 1;
- CKCU_PeripClockConfig(CKCUClock, ENABLE);
- }
- AFIO_GPxConfig(GPIO_PA, AFIO_PIN_9, AFIO_MODE_15);
- { /* Configure CKOUT */
- CKCU_CKOUTInitTypeDef CKOUTInit;
- CKOUTInit.CKOUTSRC = CKCU_CKOUTSRC_HCLK_DIV16;
- CKCU_CKOUTConfig(&CKOUTInit);
- }
- }
- #endif
- /*********************************************************************************************************//**
- * @brief Configure the GPIO ports.
- * @retval None
- ***********************************************************************************************************/
- void GPIO_Configuration(void)
- {
- /* !!! NOTICE !!!
- Shall be modified according to the part number.
- */
- #if (RETARGET_PORT == RETARGET_USART0)
- //AFIO_GPxConfig(GPIO_PA, AFIO_PIN_2 | AFIO_PIN_3, AFIO_FUN_USART_UART);
- #endif
- #if (RETARGET_PORT == RETARGET_USART1)
- //AFIO_GPxConfig(GPIO_PA, AFIO_PIN_4 | AFIO_PIN_5, AFIO_FUN_USART_UART);
- #endif
- #if (RETARGET_PORT == RETARGET_UART0)
- //AFIO_GPxConfig(GPIO_PC, AFIO_PIN_4 | AFIO_PIN_5, AFIO_FUN_USART_UART);
- #endif
- #if (RETARGET_PORT == RETARGET_UART1)
- //AFIO_GPxConfig(GPIO_PC, AFIO_PIN_1 | AFIO_PIN_3, AFIO_FUN_USART_UART);
- #endif
- }
- #if (HT32_LIB_DEBUG == 1)
- /*********************************************************************************************************//**
- * @brief Report both the error name of the source file and the source line number.
- * @param filename: pointer to the source file name.
- * @param uline: error line source number.
- * @retval None
- ***********************************************************************************************************/
- void assert_error(u8* filename, u32 uline)
- {
- /*
- This function is called by IP library that the invalid parameters has been passed to the library API.
- Debug message can be added here.
- Example: printf("Parameter Error: file %s on line %d\r\n", filename, uline);
- */
- while (1)
- {
- }
- }
- #endif
显示结果(在上面的程序基础上加入了其他显示功能):