timer0_timer_1t.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "fw_hal.h"
  15. static uint16_t counter = 0;
  16. INTERRUPT(Timer0_Routine, EXTI_VectTimer0)
  17. {
  18. counter++;
  19. if (counter == 1000)
  20. {
  21. counter = 0;
  22. UART1_TxString("hello\r\n");
  23. }
  24. }
  25. void main(void)
  26. {
  27. // Set system clock. Remove this line if system clock is already set by STC-ISP
  28. SYS_SetClock();
  29. // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt
  30. UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
  31. TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000);
  32. EXTI_Timer0_SetIntState(HAL_State_ON);
  33. EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High);
  34. EXTI_Global_SetIntState(HAL_State_ON);
  35. TIM_Timer0_SetRunState(HAL_State_ON);
  36. while(1);
  37. }