今天捣鼓了一下PWM,用STC板子做示波器测量波形
代码:
#include "SC_Init.h" //MCU Init header,Include all IC resource headers
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "HeadFiles\SysFunVarDefine.h"
/**************************************Generated by EasyCodeCube*************************************/
/*************************************.Generated by EasyCodeCube.************************************/
/*****************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
******************************************************************************************************/
void main(void)
{
/*<Generated by EasyCodeCube begin>*/
/*<UserCodeStart>*//*<SinOne-Tag><3>*/
SC_Init(); /*** MCU init***/
/*<UserCodeEnd>*//*<SinOne-Tag><3>*/
/*<UserCodeStart>*//*<SinOne-Tag><4>*/
/*****MainLoop*****/
while(1)
{
/*<UserCodeStart>*//*<SinOne-Tag><5>*/
/*****User program*****/
/*<UserCodeEnd>*//*<SinOne-Tag><5>*/
/*<Begin-Inserted by EasyCodeCube for Condition>*/
}
/*<UserCodeEnd>*//*<SinOne-Tag><4>*/
/*<Generated by EasyCodeCube end>*/
}
/*****************************************************
*函数名称: SC_Init
*函数功能: MCU初始化函数
*入口参数:void
*出口参数:void
*****************************************************/
void SC_Init(void)
{
SC_GPIO_Init();
SC_OPTION_Init();
SC_PWM0_Init();
/*write initial function here*/
EA = 1;
}
/*****************************************************
*函数名称: SC_PWM0_Init
*函数功能: PWM0初始化函数
*入口参数:void
*出口参数:void
*****************************************************/
void SC_PWM0_Init(void)
{
/*PWM0独立模式*/PWM_Init(PWM0_PRESSEL_FHRC_D1,1000);
/*PWM06波形反相*/PWM_PolarityConfig(PWM06, PWM_POLARITY_INVERT);
/*PWM06 独立模式*/PWM_IndependentModeConfigEX(PWM06,500, PWM_OUTPUTSTATE_ENABLE);
/*PWM0*/PWM_Aligned_Mode_Select(PWM0_Center_Alignment_Mode);
/*PWM0*/PWM_FaultDetectionConfigEX(PWM0_Type,DISABLE);
/*PWM0*/PWM_FaultDetectionModeConfigEX(PWM0_Type,PWM0_Immediate_Mode,PWM0_FaultDetectionVoltage_Low,PWM0_WaveFilteringTime_0us);
/*PWM0中断使能*/PWM_ITConfigEX(PWM0_Type,DISABLE,LOW);
/*PWM0开关*/PWM_CmdEX(PWM0_Type,ENABLE);
/*PWM0_Init write here*/
}
效果图:
|