|
- //-----------------------------------------------------------------------------
- // FILE: PWM3_Pulse.c
- //-----------------------------------------------------------------------------
- // Copyright 2014 Sonix Technology Corp. All rights reserved.
- //
- // AUTHOR: Sonix
- // DATE: 2014/11/07
- //
- // The program is an example of PWM3 one pulse function to implement it.
- //
- // PW3 pulse decription:
- // 1. when PW3EN = 1 ,
- // PWM3 will output One Pulse PWM and than PW3EN to be 0
- //
- // The system clock frequency is IHRC 32MHz
- //
- // Device: SN8F5708
- // Tool chain: KEIL C51 V9.50a
- //
- //-----------------------------------------------------------------------------
- // Includes
- //-----------------------------------------------------------------------------
- #include <SN8F5703.h>
- //-----------------------------------------------------------------------------
- // Global Variables
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // Function Prototypes
- //-----------------------------------------------------------------------------
- void PWM1PLS_Init(void);
- //-----------------------------------------------------------------------------
- // Main loop
- //-----------------------------------------------------------------------------
- void main(void)
- {
- CLKSEL = 0x06; // Fcpu = 32M/2 = 16M
- CLKCMD = 0X69;
- CKCON = 0X10; // From = 8M
-
- WDTR = 0x5A; // clear watchdog if watchdog enable
-
- P0 = 0;
- P0M = 0;
- P0UR = 0xFF;
-
- P1 = 0;
- P1M = 0xC0;
- P1UR = 0xFF;
-
- P2 = 0;
- P2M = 0x3C;
- P2UR = 0xFF;
-
- PWM1PLS_Init(); // init PWM1
- while (1)
- {
- WDTR = 0x5A; // clear watchdog if watchdog enable
-
- }
- }
- //-----------------------------------------------------------------------------
- // Function: void PWM1PLS_Init(void)
- // Description:
- // init PWM1 pulse
- //
- //-----------------------------------------------------------------------------
- void PWM1PLS_Init(void)
- {
- PW1CH = 0x11;
-
- PW1M |= 0x70; // PW1 rate is Fhosc/1 PWM输出频率危(32/1)/256 = 125KHZ PWM周期为8uS
- PW1M |= 0x08; // enable PWM11 output (PWCH11)
- PW1M |= 0x04; // enable PWM10 output (PWCH10)
- // PW1M |= 0x01; // enable PW1 pulse output function (PW1PO)
- PW1YH = 0x00;
- PW1YL = 0xFF; // set PW1 cycle control 256
- PW1DH = 0x00;
- PW1DL = 0x3F; // set PWM duty control 64 占空比25%
- // the dead band control : B point > A point (Must)
- PW1BH = PW1DH;
- PW1BL = PW1DL; // B point dead band control
- PW1A = 0x00; // A point dead band control
- PW1M |= 0x80; // Enable PWM output function (PW1EN)
- }
复制代码
|
|