راه اندازی برد آموزشی HT32F12345
#NickanPishroTeck#HT32F12345#HT32STARTER KIT
گروه نیکان پیشرو تک در این مطلب، کدهای لازم برای راه اندازی GPIO های میکرو HT32F12345 در بورد آموزشی HT32 از شرکت HOLTEK (هولتک) را نمایش داده است. محیط برنامه نویسی Keil MDK uvission5 است.
لینک دانلود
http://www.rozup.ir/info/Test2
void NVIC_Configuration(void);
void CKCU_Configuration(void);
void GPIO_Configuration(void);
#if (ENABLE_CKOUT == 1)
void CKOUTConfig(void);
#endif
//----------------------------------------------------------------------
static void __Delay(u32 count);
//-------------------------------------------------------------------------
int main(void)
{
s32 input;
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);
for (input = 0; input < 10; input++)
{
__Delay(4000000);
HT32F_DVB_LEDToggle(HT_LED1);
HT32F_DVB_LEDToggle(HT_LED2);
HT32F_DVB_LEDToggle(HT_LED3);
}
HT32F_DVB_LEDOn(HT_LED2);
HT32F_DVB_LEDOn(HT_LED3);
for (input = 0; input < 100; input++)
{
printf("Hello World! %d\r\n", input);
}
while (1) /* Infinite loop */
{
printf("Please input key for printf....");
SERIAL_Flush();
input = getchar();
printf("\r\nYour input is %c[0x%x]\r\n\r\n", input, input);
SERIAL_Flush();
HT32F_DVB_LEDToggle(HT_LED1);
HT32F_DVB_LEDToggle(HT_LED2);
HT32F_DVB_LEDToggle(HT_LED3);
}
}
//---------------------------------------------------------------------------------------------------------
void NVIC_Configuration(void)
{
NVIC_SetVectorTable(NVIC_VECTTABLE_FLASH, 0x0); /* Set the Vector Table base location at 0x00000000 */
}
//-------------------------------------------------------------------------------------------------------------
void CKCU_Configuration(void)
{
CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
CKCUClock.Bit.USART0 = 1;
CKCUClock.Bit.USART1 = 1;
CKCUClock.Bit.UART0 = 1;
CKCUClock.Bit.UART1 = 1;
CKCUClock.Bit.AFIO = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
#if (ENABLE_CKOUT == 1)
CKOUTConfig();
#endif
}
//--------------------------------------------------------------------------------------------------------------
#if (ENABLE_CKOUT == 1)
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_8, AFIO_MODE_15);
{ /* Configure CKOUT */
CKCU_CKOUTInitTypeDef CKOUTInit;
CKOUTInit.CKOUTSRC = CKCU_CKOUTSRC_HCLK_DIV16;
CKCU_CKOUTConfig(&CKOUTInit);
}
}
#endif
//------------------------------------------------------------------------------------------------------------
#if (ENABLE_CKOUT == 1)
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_8, AFIO_MODE_15);
{ /* Configure CKOUT */
CKCU_CKOUTInitTypeDef CKOUTInit;
CKOUTInit.CKOUTSRC = CKCU_CKOUTSRC_HCLK_DIV16;
CKCU_CKOUTConfig(&CKOUTInit);
}
}
#endif
//----------------------------------------------------------------------------------------------------------------
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)
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
//--------------------------------------------------------------------------------------------------------------
static void __Delay(u32 count)
{
while (count--)
{
__NOP(); // Prevent delay loop be optimized
}
}