123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /**
- ******************************************************************************
- * @file Project/main.c
- * @author MCD Application Team
- * @version V2.3.0
- * @date 16-June-2017
- * @brief Main program body
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm8s.h"
- #include "hw_init.h"
- #include "sc7a20.h"
- #include "key.h"
- #include "led.h"
- #include "tasks.h"
- /* Private defines -----------------------------------------------------------*/
- uint32_t Global_Timing_Counter;
- uint8_t PeriodCnt_5ms;
- uint8_t PeriodCnt_20ms;
- uint8_t PeriodCnt_100ms;
- uint16_t AD_Value;
- uint8_t AD_FinishFlag = 0;
-
- /* Private function prototypes -----------------------------------------------*/
-
- /* Private functions ---------------------------------------------------------*/
- void main(void)
- {
- /* Hardware Init */
- HW_Init();
- SC7A20_Init();
-
- /* Task Init */
- Global_Timing_Counter = 0U;
- PeriodCnt_5ms = 0;
- PeriodCnt_20ms = 0;
- PeriodCnt_100ms = 0;
-
- /* Infinite loop */
- while (1)
- {
- //5ms
- if(PeriodCnt_5ms >= 5)
- {
- PeriodCnt_5ms = 0;
- taskA(); //按键扫描
- }
- //10ms
- if(PeriodCnt_20ms >= 20)
- {
- PeriodCnt_20ms = 0;
- taskB(); //加速度读取
- }
- //100ms
- if(PeriodCnt_100ms >= 100)
- {
- PeriodCnt_100ms = 0;
- taskC(); //AD采集,电量指示灯
- }
- }
-
- }
- INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- if(Global_Timing_Counter == 0x9A7EC800) //30days
- {
- Global_Timing_Counter = 0U;
- }
- else
- {
- Global_Timing_Counter++;
- }
- PeriodCnt_5ms++;
- PeriodCnt_20ms++;
- PeriodCnt_100ms++;
- Tim4_Isr_CallBack();
- TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
- }
- INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- ADC1->CSR &= ~0x80; // 转换结束标志位清零 EOC
- //默认左对齐 读数据时先读高高8位 再读低8位
- AD_Value = (ADC1->DRH << 2);
- AD_Value += ADC1->DRL;
- AD_FinishFlag = 1; // ADC中断标志 置1
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval : None
- */
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|