protues仿真stm32f103输出PWM 附程序IC解密
- IC解密#include "pbdata.h"
- u16 fre;
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void TIM3_Configuration();
- void Delay (uint32_t nCount)
- {
- for(; nCount != 0; nCount--);
- }
- int main(void)
- {
- u16 arr=42000;
- u16 led_dt = arr/2;
- RCC_Configuration(); //系统时钟初始化
- GPIO_Configuration();//端口初始化
- TIM3_Configuration(arr);//定时器和pwm配置
-
- while(1)
- {
- TIM_SetCompare2(TIM3,led_dt); //用的是TIM3的通道2,输出PWM 送到相应的寄存器中 //满占空比为900
-
- GPIO_SetBits(GPIOB,GPIO_Pin_5); //LED 发光
- Delay(0x2ffff);
- GPIO_ResetBits(GPIOB,GPIO_Pin_5);//LED 熄灭
- Delay(0x2ffff);
-
-
- // if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7)== Bit_RESET)
- // {
- // //LED 发光
- // GPIO_SetBits(GPIOB,GPIO_Pin_5);
- // }
- // else
- // {
- // //LED 熄灭
- // GPIO_ResetBits(GPIOB,GPIO_Pin_5);
- // }
- }
- }
- void RCC_Configuration(void)
- {
- SystemInit();
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);//这个是必须的,仿真软件必须的
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//端口复用,一定在APB2的时钟线
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- //PWM
- GPIO_InitStructure.GPIO_Pin= GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //通过PWM控制,端口为复用方式输出
- GPIO_Init(GPIOA,&GPIO_InitStructure);
-
- //LED
- GPIO_InitStructure.GPIO_Pin= GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
-
- //BUTTON
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;
- GPIO_Init(GPIOC,&GPIO_InitStructure);
- }

芯片解密