一、简介
二、修改主频
1. This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
* factors, AHB/APBx prescalers and Flash settings).
* This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f10x_xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* #define SYSCLK_FREQ_HSE HSE_VALUE */
#define SYSCLK_FREQ_24MHz 24000000
#else
/* #define SYSCLK_FREQ_HSE HSE_VALUE */
/* #define SYSCLK_FREQ_24MHz 24000000 */
/* #define SYSCLK_FREQ_36MHz 36000000 */
/* #define SYSCLK_FREQ_48MHz 48000000 */
/* #define SYSCLK_FREQ_56MHz 56000000 */
#define SYSCLK_FREQ_72MHz 72000000
#endif
三、睡眠模式
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Serial.h"
uint8_t RxData;
int main(void)
{
OLED_Init();
Serial_Init();
while(1)
{
if (Serial_GetRxFlag() == 1)
{
RxData = Serial_GetRxData();
}
OLED_ShowHexNum(1, 1, RxData, 8);
OLED_ShowString(2, 1, "Running");
Delay_ms(100);
OLED_ShowString(2, 1, " ");
Delay_ms(100);
__WFI();//开启睡眠模式
}
}
四、停止模式
void PWR_DeInit(void);//回复初始配置
void PWR_BackupAccessCmd(FunctionalState NewState);//使能备用区域的访问
void PWR_PVDCmd(FunctionalState NewState);//使能PVD功能
void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);//设置PVD的阈值电压
void PWR_WakeUpPinCmd(FunctionalState NewState);//使能WAKEUO引脚
void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);//进入停止模式
void PWR_EnterSTANDBYMode(void);//进入待机模式
FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);//获取标志位
void PWR_ClearFlag(uint32_t PWR_FLAG);//清除标志位
#include "stm32f10x.h" // Device header
#include "OLED.h"
#include "Delay.h"
#include "CountSensor.h"
int main(void)
{
OLED_Init();
CountSensor_Init();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//开启外部时钟,必须要开启
//OLED_ShowChar(1,1,'A');
OLED_ShowString(1,1,"Name:Mingen");
OLED_ShowString(2,1,"Scores:");
// OLED_ShowString(3,1,"Name:Jingnan");
// OLED_ShowString(4,1,"Scores:");
// OLED_ShowNum(2,1,12345,6);//显示无符号十进制数
// OLED_ShowSignedNum(2,7,-66,2);//显示有符号十进制
// OLED_ShowHexNum(3,1,0xAA55,4);//显示16进制
// OLED_ShowBinNum(4,1,0xAA55,16);//显示2进制
//OLED_Clear();//清屏
while(1)
{
OLED_ShowNum(2,8,CountSesor_GET(),5);
OLED_ShowString(3, 1, "Running");
Delay_ms(500);
OLED_ShowString(3, 1, " ");
Delay_ms(500);
PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);//进入停止模式的函数,停止唤醒后主频为8
SystemInit();//重新启动72M
}
}
五、待机模式
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "MYRTC.h"
int main(void)
{
OLED_Init();
MyRTC_Init();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//开启PWR时钟
OLED_ShowString(1, 1, "CNT:");
OLED_ShowString(2, 1, "ALR:");
OLED_ShowString(3, 1, "ALRF:");
PWR_WakeUpPinCmd(ENABLE);//wakeup引脚唤醒
uint32_t Alarm = RTC_GetCounter() + 10;
RTC_SetAlarm(Alarm);
OLED_ShowNum(2 , 6, Alarm, 10);
while(1)
{
OLED_ShowNum(1, 6, RTC_GetCounter(), 10);
OLED_ShowNum(3, 6, RTC_GetFlagStatus(RTC_FLAG_ALR), 1);
OLED_ShowString(4, 1, "Running");
Delay_ms(100);
OLED_ShowString(4, 1, " ");
Delay_ms(100);
OLED_ShowString(4, 1, "STANDBY");
Delay_ms(1000);
OLED_ShowString(4, 1, " ");
Delay_ms(1000);
OLED_Clear();//关闭外设
PWR_EnterSTANDBYMode();//待机模式唤醒后程序从头开始
}
}