STM8-Use the timing function of TIM2 to make the light flash every 1S

Publisher:SparklingStar22Latest update time:2015-12-31 Source: eefocusKeywords:STM8  TIM2 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Purpose: To familiarize yourself with the use of the timer function (automatic reload)
#include"stm8s.h"
#include "stm8s_gpio.h"
#include "stm8s_tim2.h"
void CLK_Configuration();
void TIM2_Configuration_set_1ms(void);
void GPIO_Configuration();
void main()
{
 
  CLK_Configuration();
 
  TIM2_Configuration_set_1ms();
 
  GPIO_Configuration();
enableInterrupts();//使能总中断
  while(1)
  {
  }
}
void CLK_Configuration()
{
  CLK_DeInit();
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//HSI16MHZ,1分频
}
 
void TIM2_Configuration_set_1ms(void)
{
  TIM2_DeInit();
  TIM2_TimeBaseInit( TIM2_PRESCALER_16,1000);
  TIM2_ITConfig( TIM2_IT_UPDATE , ENABLE);
  
  TIM2_SetCounter(0x0000); 
  
  TIM2_Cmd(ENABLE);
 
}
void GPIO_Configuration()
{
  GPIO_DeInit(GPIOD);
  GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
}
#pragma vector=13+2
__interrupt void TIM2_IRQ()
{
  static unsigned int j;
  j++;
  if(j==1000)
  {
    j=0;
    GPIO_WriteReverse(GPIOD, GPIO_PIN_0);//1s取一次反
 }
 
   TIM2_ClearITPendingBit(TIM2_IT_UPDATE); //清中断标志位

}
Keywords:STM8  TIM2 Reference address:STM8-Use the timing function of TIM2 to make the light flash every 1S

Previous article:STM8-Use external interrupt to write two buttons to control the light on and off
Next article:WDT is used as a timer to generate a timer interrupt to make the light turn on and off in a cycle

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号