[DemoCode下载] 系统时钟切换操作

[复制链接]
1078|8
 楼主| antusheng 发表于 2019-6-30 23:10 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 System clock select demo code
  14. //***********************************************************************************************************

  15. #include "N76E003.h"
  16. #include "SFR_Macro.h"
  17. #include "Function_define.h"
  18. #include "Common.h"
  19. #include "Delay.h"

  20. //========================================================================
  21. //  The test process:
  22. //        1. Power on is run as default HIRC, show LED Fsys tickle faster
  23. //         2. toggle P3.0 to GND.
  24. //        2. call modify Fsys code to LIRC.
  25. //        3. LED tickle speed slowly than before.
  26. //========================================================================
  27. void main(void)
  28. {

  29. /* Note
  30.   MCU power on system clock is HIRC (16 MHz)
  31.         Please keep P3.0 HIGH before you want to modify Fsys to LIRC
  32. */
  33.        
  34.           Set_All_GPIO_Quasi_Mode;                           // In Common.h define
  35.     set_CLOEN;                                                                                                                            // Also can check P1.1 CLO pin for clock to find the Fsys change.
  36.                 set_P30;
  37.                 while (P30)                                                                                                                                        // when P3.0 keep high, clock out HIRC
  38.                 {   
  39.                                 clr_GPIO1;                                                                                                                        // Check LED output tickle time
  40.         Timer0_Delay1ms(200);
  41.         set_GPIO1;
  42.         Timer0_Delay1ms(200);
  43.                 }
  44.        
  45. ////------------------------------------------------------------------------------------------------------
  46. ///*********************************** Change system closk source ***************************************/
  47. ////------------------------------------------------------------------------------------------------------
  48.               
  49. ////***** HIRC enable part *****               
  50. //                set_HIRCEN;                                                                                                //step1: enable HIRC clock source run
  51. //                while((CKSWT&SET_BIT5)==0);                                //step2: check ready
  52. //                clr_OSC1;                                                                                                        //step3: switching system clock source if needed
  53. //                clr_OSC0;
  54. //                while((CKEN&SET_BIT0)==1);                                //step4: check system clock switching OK or NG
  55. //
  56. ////***** LIRC enable part*****
  57. ////** Since LIRC is always enable, switch to LIRC directly
  58.                 set_OSC1;                                                                                                        //step3: switching system clock source if needed
  59.                 clr_OSC0;  
  60.                 while((CKEN&SET_BIT0)==1);                                //step4: check system clock switching OK or NG        
  61.                 clr_HIRCEN;
  62.    
  63. ////--------------------------------------------------------------------------------------------------------
  64.    
  65. /*
  66.   Now Fsys = LIRC , LED tickle slowly.
  67. */
  68.     while(1)
  69.     {
  70.                                 clr_GPIO1;                                                                                                                        // Check LED output tickle time
  71.         clr_P00;
  72.         set_GPIO1;
  73.         set_P00;
  74.     }
  75. /* =================== */
  76. }



 楼主| antusheng 发表于 2019-6-30 23:11 | 显示全部楼层
这个例子演示了如何切换时钟。
zhuomuniao110 发表于 2019-7-22 13:34 | 显示全部楼层
工作中可以切换吗,比如不同的应用子函数采用不同的时钟
xuanhuanzi 发表于 2019-7-23 11:38 | 显示全部楼层
运行中可以切换非常好。
xinxianshi 发表于 2019-7-23 21:25 | 显示全部楼层
时钟的切换一般很少用
xixi2017 发表于 2019-7-25 13:13 | 显示全部楼层
可以通过Blink看到效果。
mintspring 发表于 2019-7-26 00:11 | 显示全部楼层
可以自由切换。
捉虫天师 发表于 2019-7-28 23:27 | 显示全部楼层
一般都是先预定好。
幸福小强 发表于 2019-7-29 09:21 | 显示全部楼层
看起来很容易,不需要寄存器保护。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

86

主题

1521

帖子

5

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