找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2216|回复: 0
打印 上一主题 下一主题
收起左侧

松翰SN8F5703单片机PWM例程

[复制链接]
跳转到指定楼层
楼主
ID:856645 发表于 2020-12-8 11:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. //-----------------------------------------------------------------------------
  2. //  FILE:   PWM3_Pulse.c
  3. //-----------------------------------------------------------------------------
  4. //  Copyright 2014 Sonix Technology Corp. All rights reserved.
  5. //
  6. //  AUTHOR:     Sonix
  7. //  DATE:       2014/11/07
  8. //
  9. //  The program is an example of PWM3 one pulse function to implement it.
  10. //   
  11. //  PW3 pulse decription:
  12. //      1. when PW3EN = 1 ,
  13. //         PWM3 will output One Pulse PWM and than PW3EN to be 0
  14. //
  15. //  The system clock frequency is IHRC 32MHz
  16. //
  17. //  Device:     SN8F5708
  18. //  Tool chain: KEIL C51 V9.50a
  19. //

  20. //-----------------------------------------------------------------------------
  21. // Includes
  22. //-----------------------------------------------------------------------------
  23. #include <SN8F5703.h>
  24. //-----------------------------------------------------------------------------
  25. // Global Variables
  26. //-----------------------------------------------------------------------------

  27. //-----------------------------------------------------------------------------
  28. // Function Prototypes
  29. //-----------------------------------------------------------------------------
  30. void PWM1PLS_Init(void);

  31. //-----------------------------------------------------------------------------
  32. // Main loop
  33. //-----------------------------------------------------------------------------
  34. void main(void)
  35. {
  36.         CLKSEL = 0x06;                                                                        // Fcpu = 32M/2 = 16M
  37.         CLKCMD = 0X69;                                
  38.         CKCON = 0X10;                                                                                // From = 8M
  39.         
  40.   WDTR = 0x5A;                                            // clear watchdog if watchdog enable
  41.         
  42.         P0 = 0;
  43.         P0M = 0;
  44.         P0UR = 0xFF;
  45.         
  46.         P1 = 0;
  47.         P1M = 0xC0;
  48.         P1UR = 0xFF;
  49.         
  50.         P2 = 0;
  51.         P2M = 0x3C;
  52.         P2UR = 0xFF;
  53.         
  54.         PWM1PLS_Init();                                         // init PWM1

  55.     while (1)
  56.                 {
  57.         WDTR = 0x5A;                                // clear watchdog if watchdog enable
  58.                         

  59.                 }
  60. }
  61. //-----------------------------------------------------------------------------
  62. //  Function:    void PWM1PLS_Init(void)
  63. //  Description:
  64. //      init PWM1 pulse
  65. //                                
  66. //-----------------------------------------------------------------------------
  67. void PWM1PLS_Init(void)
  68. {
  69.                 PW1CH = 0x11;
  70.         
  71.     PW1M |= 0x70;                                   // PW1 rate is Fhosc/1     PWM输出频率危(32/1)/256 = 125KHZ   PWM周期为8uS

  72.     PW1M |= 0x08;                                   // enable PWM11 output (PWCH11)
  73.     PW1M |= 0x04;                                   // enable PWM10 output (PWCH10)

  74. //    PW1M |= 0x01;                                 // enable PW1 pulse output function (PW1PO)

  75.     PW1YH = 0x00;
  76.     PW1YL = 0xFF;                                                // set PW1 cycle control    256

  77.     PW1DH = 0x00;
  78.     PW1DL = 0x3F;                                   // set PWM duty control   64     占空比25%

  79.     // the dead band control : B point > A point (Must)
  80.     PW1BH = PW1DH;
  81.     PW1BL = PW1DL;                                  // B point dead band control

  82.     PW1A = 0x00;                                    // A point dead band control

  83.           PW1M |= 0x80;                                   // Enable PWM output function (PW1EN)
  84. }
复制代码


5703_PWM_20161103.rar

29.55 KB, 下载次数: 23, 下载积分: 黑币 -5

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表