CH552/examples/PWM/Main.C
2018-10-17 16:44:45 +08:00

56 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************** (C) COPYRIGHT *******************************
* File Name : Main.C
* Author : WCH
* Version : V1.0
* Date : 2017/01/20
* Description : CH554 PWM初始化占空比设置PWM默认电平设置
支持中断方式修改PWM占空比
*******************************************************************************/
#include "..\Public\CH554.H"
#include "..\Public\Debug.H"
#include "PWM.H"
#include "stdio.h"
#pragma NOAREGS
main( )
{
CfgFsys( ); //CH554时钟选择配置
mDelaymS(5); //配置时钟后,建议延时稳定时钟
mInitSTDIO( ); //串口0初始化
printf("start ...\n");
P1_MOD_OC &= ~(bPWM1 | bPWM2); //设置PWM引脚为推挽输出
P1_DIR_PU |= bPWM1 | bPWM2;
SetPWMClk(4); //PWM时钟配置 4分频
ForceClearPWMFIFO( ); //强制清除PWM FIFO和COUNT
CancleClearPWMFIFO( ); //取消清除PWM FIFO和COUNT
PWM1OutEnable( ); //允许PWM1输出
PWM2OutEnable( ); //允许PWM2输出
PWM1OutPolarHighAct( ); //PWM1输出默认低高有效
PWM2OutPolarLowAct( ); //PWM2输出默认高低有效
#if PWM_INTERRUPT
PWMInterruptEnable();
EA = 1;
SetPWM1Dat(0x10);
SetPWM2Dat(0x40);
while(1);
#endif
SetPWM1Dat(0x10); //占空比0x10/256
SetPWM2Dat(0x40);
while(1){
if(PWM_CTRL&bPWM_IF_END){
PWM_CTRL |= bPWM_IF_END; //清除PWM中断
SetPWM1Dat(0x10);
SetPWM2Dat(0x40);
#ifdef DE_PRINTF
printf("PWM_CYC_END %02X\n",(UINT16)PWM_CTRL);
#endif
}
}
}