完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/**************************************************************************//**
* @file main.c * @version V2.10 * $Revision: 2 $ * $Date: 16/10/25 4:29p $ * @brief Hardware divider(HDIV) Sample Code * * @note * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved. * ******************************************************************************/ #include #include "NUC029xGE.h" #define PLLCON_SETtiNG CLK_PLLCON_72MHz_HXT #define PLL_CLOCK 72000000 void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable HIRC clock (Internal RC 22.1184MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk); /* Wait for HIRC clock ready */ CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); /* Select HCLK clock source as HIRC and and HCLK source divider as 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); /* Set PLL to Power-down mode and PLLSTB bit in CLK_STATUS register will be cleared by hardware.*/ CLK_DisablePLL(); /* Enable HXT clock (external XTAL 12MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Wait for HXT clock ready */ CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(PLL_CLOCK); /* Enable UART module clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART module clock source as HXT and UART module clock divider as 1 */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1)); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set multi-function pins for UART0 RXD and TXD */ SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk); SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_UART0_RXD | SYS_GPA_MFPL_PA2MFP_UART0_TXD); } void UART0_Init() { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ UART_Open(UART0, 115200); } void HDIV_Init(void) { /* Enable Hardware Divider Clock */ CLK->AHBCLK |= CLK_AHBCLK_HDIVCKEN_Msk; } /*---------------------------------------------------------------------------------------------------------*/ /* MAIN function */ /*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Disable register write-protection function */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /* Init Divider */ HDIV_Init(); printf("+----------------------------------------------+\n"); printf("| Hardware Divider(HDIV) Sample Code |\n"); printf("+----------------------------------------------+\n"); printf("\n"); printf("12341 / 123 = %d\n", HDIV_Div(12341, 123)); printf("12341 %% 123 = %d\n", HDIV_Mod(12341, 123)); /* Lock protected registers */ SYS_LockReg(); printf("Done\n"); while(SYS->PDID); return 0; } /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/ |
|
相关推荐
1个回答
|
|
de "NUC029xAN.h"
int32_t main() { int32_t dividend = 200000; int32_t divisor = 17; int32_t quotient, remainder; SYS_Init(); /* Init System, IP clock and multi-function I/O. */ /* Configure UART0 and set UART0 baud rate */ UART_Open(UART0, 115200); /* Enable HDIV clock */ CLK_EnableModuleClock(HDIV_MODULE); /* Configure HDIV peripheral */ HDIV_Open(HDIV, HDIV_CON_DIVIDE_UNSIGNED, HDIV_CON_HINT_DISABLE); /* Perform division */ HDIV_Div(HDIV, dividend, divisor, "ient, &remainder); printf("Dividend = %dn", dividend); printf("Divisor = %dn", divisor); printf("Quotient = %dn", quotient); printf("Remainder = %dn", remainder); while(1); } 使用NUC029的HDIV进行除法运算,可以大大加快计算速度。使用CPU进行除法运算需要多个指令来完成,而HDIV是硬件威廉希尔官方网站 ,可以在一个时钟周期内完成除法运算。具体的速度差异会因为除数被除数的大小而有所不同。一般来说,当除数和被除数都比较大的时候,使用HDIV的速度优势会更加明显。 |
|
|
|
只有小组成员才能发言,加入小组>>
818 浏览 0 评论
1162 浏览 1 评论
2536 浏览 5 评论
2871 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2720 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1114浏览 3评论
198浏览 2评论
465浏览 2评论
382浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
463浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 10:28 , Processed in 1.061624 second(s), Total 78, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号