📄 main.c
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 28/07/2003
* Description : This file gives an example on the PWM generation.
* The device is configured to generate a PWM wave with a
* pulse equal to 0x30 timer clock ticks and a full period
* equal to 0xC0.
********************************************************************************
* History:
* 03/07/03 : First Version
*******************************************************************************/
#include "71x_lib.h"
#include "Main.h"
#include "LED.h"
u32 Note = 0x800, Period;
void PlayNextTone(void)//play the tone,period1=0x1000,period2=period1/2=0x800
{
if(Period)
Period--;
else
{
TIM_PWMOModeConfig(TIM1, Note >> 1, TIM_HIGH, Note, TIM_LOW);
Note ^= 0x1000;
Period = 0x200;
LED_Set(LED3,GPIO1,2);
}
}
void Main(void)
{
#ifdef DEBUG
debug();
#endif
RCCU_Div2Config(ENABLE);//CLK2=CLK/2
RCCU_MCLKConfig(RCCU_DEFAULT);//RCCU_DEFAULT=0x00 MCLK=RCLK
RCCU_FCLKConfig(RCCU_RCLK_2); //RCCU_RCLK_2=0x01 FCLK=RCLK/2 (APB1)
RCCU_PCLKConfig(RCCU_RCLK_2); //RCCU_RCLK_2=0x01 PCLK=RCLK/2 (APB2)
RCCU_RCLKSourceConfig(RCCU_CLOCK2);//RCLK=CLK2
// at this step the PCLK2 signal should be equal to 4 MHz
//-------------------------------------------------------------------------
// Initialization
//-------------------------------------------------------------------------
// Configure the GPIO1 Port
// Timer 1 Output Compare function pin (P1.7) configured as Alternate function pushpull
GPIO_Config(GPIO1, 0x0080, GPIO_AF_PP);
// Initialize the Timer
TIM_Init(TIM1);
// Configure the TIM Prescaler
TIM_PrescalerConfig(TIM1, 1); // 2 MHz
// Enable the OverFlow Interrupt
TIM_ITConfig(TIM1, TIM_TO_IT, ENABLE);
TIM_CounterConfig(TIM1, TIM_START);
//-------------------------------------------------------------------------
// Configure the EIC Timer1 IRQ channel
//-------------------------------------------------------------------------
// Enable the IRQ0 for timer 1
EIC_Init();
EIC_IRQChannelConfig(T1TIMI_IRQChannel, ENABLE);
EIC_IRQChannelPriorityConfig(T1TIMI_IRQChannel, 1);
EIC_IRQConfig(ENABLE);
LED_Init();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -