[DemoCode下载] ML51低功耗模式下也可以使用PWM

[复制链接]
 楼主| 734774645 发表于 2020-5-31 22:00 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //***********************************************************************************************************

  10. //***********************************************************************************************************
  11. //  File Function: ML51 simple GPIO toggle out demo code
  12. //***********************************************************************************************************

  13. #include "ML51.h"
  14. /**
  15. * [url=home.php?mod=space&uid=247401]@brief[/url]       PWM output run under low power run mode
  16. * @param       None
  17. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  18. * [url=home.php?mod=space&uid=1543424]@Details[/url]     Initial all PWM output, setting PWM
  19. */

  20. void main (void)
  21. {
  22. /* Setting Multi function pin setting for GPIO toggle
  23.    * include gipo.c in Common for GPIO mode setting  */

  24.     ALL_GPIO_QUASI_MODE;
  25.   
  26.     PWM0_ClockSource(PWM_FSYS,1);                                  // define PWM0 clock source is FSYS, since this time .
  27.   
  28.     MFP_P05_PWM0_CH0;                                                // multi function pin define P0.5 as PWM0 channel 0 output
  29.     P05_PUSHPULL_MODE;                                             
  30.     PWM0_ConfigOutputChannel(0,Independent,EdgeAligned,0x6FF,10);    // setting PWM channel 0 as 10% duty high of 0x6FF PWM period = 0x00B3
  31.   
  32.     MFP_P24_PWM0_CH1;                                                // multi function pin define P2.4 as PWM0 channel 1 output
  33.     P24_PUSHPULL_MODE;
  34.     PWM0_ConfigOutputChannel(1,Independent,EdgeAligned,0x6FF,20);    // setting PWM channel 1 as 20% duty high of 0x6FF PWM period = 0x0166
  35.   
  36.     MFP_P03_PWM0_CH2;                                                // multi function pin define P0.3 as PWM0 channel 2 output
  37.     P03_PUSHPULL_MODE;
  38.     PWM0_ConfigOutputChannel(2,Independent,EdgeAligned,0x6FF,30);    // setting PWM channel 2 as 30% duty high of 0x6FF PWM period = 0x0219
  39.   
  40.     MFP_P22_PWM0_CH3;                                                // multi function pin define P2.2 as PWM0 channel 3
  41.     P22_PUSHPULL_MODE;
  42.     PWM0_ConfigOutputChannel(3,Independent,EdgeAligned,0x6FF,40);    // setting PWM channel 3 as 40% duty high of 0x6FF PWM period = 0x02CC
  43.   
  44.     MFP_P01_PWM0_CH4;                                                // multi function pin define P0.1 as PWM0 channel 4
  45.     P01_PUSHPULL_MODE;
  46.     PWM0_ConfigOutputChannel(4,Independent,EdgeAligned,0x6FF,50);    // setting PWM channel 4 as 50% duty high of 0x6FF PWM period = 0x037F
  47.    
  48.     MFP_P20_PWM0_CH5;                                                // multi function pin define P0.5 as PWM0 channel 0
  49.     P20_PUSHPULL_MODE;
  50.     PWM0_ConfigOutputChannel(5,Independent,EdgeAligned,0x6FF,60);    // setting PWM channel 5 as 60% duty high of 0x6FF PWM period = 0x0432
  51.    

  52. /* Enable Low power run mode */
  53.     FsysSelect(FSYS_LIRC);
  54.     PWM0_RUN();
  55.     set_PCON_LPR;
  56.    

  57.     while(1);
  58.       
  59. }





598330983 发表于 2020-5-31 22:05 | 显示全部楼层
所有IO设置成准双向是最好的?
xinxianshi 发表于 2020-5-31 22:35 | 显示全部楼层
这就牛了,CPU休眠,片上外设还可以继续稳定工作。
zhuotuzi 发表于 2020-5-31 22:48 | 显示全部楼层
PWM模式还是非常好用的。不仅可以正常使用,低功耗都不影响。
643757107 发表于 2020-5-31 23:30 来自手机 | 显示全部楼层
这个系列不错
heimaojingzhang 发表于 2020-6-6 14:39 | 显示全部楼层
非常感谢楼主分享
keaibukelian 发表于 2020-6-6 14:39 | 显示全部楼层
好神奇啊 呵呵
labasi 发表于 2020-6-6 14:40 | 显示全部楼层
果然很强大
paotangsan 发表于 2020-6-6 14:41 | 显示全部楼层
代码很简洁
renzheshengui 发表于 2020-6-6 14:41 | 显示全部楼层
楼主辛苦了
huahuagg 发表于 2020-6-6 15:18 | 显示全部楼层
非常感谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

210

主题

3585

帖子

15

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

210

主题

3585

帖子

15

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