GPIO_Init(GPIOA,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Slow);
GPIO_Init(GPIOB,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7,GPIO_Mode_Out_PP_Low_Slow);
GPIO_Init(GPIOC,GPIO_Pin_1|GPIO_Pin_4,GPIO_Mode_Out_PP_Low_Slow);
GPIO_Init(GPIOD,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Slow);
/********************************************************************/
UART1_Init();
ADC1_Config();
RTC_Init();
//TIM4_Config();
ADC_Value_1 = Read_ADC_Value();
// IWDG_Config(); //Independent watchdog
WWDG_Config(); //Window watchdog
enableInterrupts(); //Enable total interrupt
printf("The System Startrn");
AWU_RTC(600); //Set wakeup every 10 minutes
while(1)
{
WWDG_SetCounter(COUNTER_INIT); //Feed the window watchdog
RTC_Print(); //Print RTC time
if(Ws_Flag==1) //If it is morning time, check ADC
{
ADC_Value_1 = Read_ADC_Value();
ADC_Value=(ADC_Value_1*3300)/4096;
if(ADC_Value<2450)
{
GPIO_ResetBits(GPIOC,GPIO_Pin_4);
printf("***Insufficient power detected, power turned off***rn");
}
else if(ADC_Value>=2540)
{
GPIO_SetBits(GPIOC,GPIO_Pin_4);
printf("***Sufficient power, power on***rn");
}
printf("ADC:%ldmvrn",ADC_Value);
}
else //Turn off the power if the night time is off
{
GPIO_ResetBits(GPIOC,GPIO_Pin_4);
}
halt(); //Enter active halt mode, the program is blocked here
}
}
Unlike STM32 and STM8, this microcontroller requires manual interrupt enablement, i.e. code enableInterrupts(); //Open the general interrupt, otherwise the alarm interrupt cannot be entered.
The alarm interrupt and wake-up interrupt share an interrupt service function as follows:
INTERRUPT_HANDLER(RTC_CSSLSE_IRQHandler,4)
{
if(RTC_GetITStatus(RTC_IT_ALRA))//Judge the alarm interrupt flag
{
if(Close_Flag==1)
{
Time_print();
}
else if(Open_Flag==1)
{
Time_print();
}
}
RTC_ClearITPendingBit(RTC_IT_ALRA); //Clear flag bit
RTC->ISR2 &= (uint8_t)(~0x04);
}
For the initialization code of other peripherals, please refer to the link below:
http://bbs.21ic.com/home.php?mod=space&uid=1875788&do=thread&view=me&order=dateline&from=space&page=2
Previous article:STM8L ultra-low power programming tutorial, easy to understand
Next article:STM8L052C6 low power consumption + LCD display experience sharing
Recommended ReadingLatest update time:2024-11-15 16:52
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- A TOF "image" sensor that is worth playing with, VL53L5CX
- ARM immediate number explanation--the difference between LDR and MOV
- TI C5000 compiler error message list
- TI Award-winning Live Broadcast: Talking about "packaged antenna" smart millimeter wave sensors, even novices can handle industrial robots
- The voltage of the TPS73033 buck chip drops to 0.7V after the load is connected
- Wi-Fi 6 is here to provide network coverage for the entire home. Will you adopt it?
- Common APDU instruction error codes for CPU cards
- [GigaDevice GD32F310 Review] +ADC Data Collection
- [Mill Edge AI Computing Box FZ5 Review] Development Board Target Classification Demo
- [Domestic RISC-V Linux Board Fang·Starlight VisionFive Trial Report] GPIO Development Basics: From Principle to Practice