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

Publisher:MysticalEssenceLatest update time:2020-09-01 Source: eefocusKeywords:STM8 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 Reference address:STM8-Use the timing function of TIM2 to make the light flash every 1S

Previous article:stm8s development (three) UART usage: serial communication!
Next article:stm8s development (nine) use of EEPROM: use EEPROM to store data!

Recommended ReadingLatest update time:2024-11-15 07:23

About Atomthreads, a real-time operating system that can run on STM8
A friend asked a question like this: I don't want to run an operating system on the STM8 microcontroller. When I need to process some business logic, I also need to detect short presses, long presses, and multiple buttons being pressed at the same time. How can I achieve this? Without running an operating system,
[Microcontroller]
About Atomthreads, a real-time operating system that can run on STM8
STM8 study notes---timer TIM1 function implementation
Timer 1 of the STM8 microcontroller is a 16-bit timer Timer 1 is an advanced timer with the following main features: Timer 1 has more registers. If you only use the timing function, you don't need so many registers. The registers that need to be set for the timing function mainly include the auto-reload registe
[Microcontroller]
STM8 study notes---timer TIM1 function implementation
STM8 learning nRF24L01
Introduction: nRF24L01 requires programming for both the transmitter and receiver. If an error occurs during debugging, it is difficult to determine which side made the error, so separate debugging can be used. Sending and receiving process: Send - Wait for ACK - (Automatic resend) - Generate interrupt Receive -
[Microcontroller]
STM8 hardware I2C configuration
First of all, I would like to thank my friends who shared information online. There are many tutorials on configuring STM8 hardware I2C online, but some say that STM8 hardware I2C has problems. However, I have already adjusted STM8 hardware I2C through actual projects, so I would like to share my experience here. 1.
[Microcontroller]
STM8->EXTI
Interrupts, especially external interrupts, are an important means for MCU to implement complex functions. Interrupt sources and vectors:     All I/O pins have external interrupt capability, and each port has an independent interrupt vector and independent flag.     Interrupts of various functional peripheral
[Microcontroller]
STM8->EXTI
IAR For STM8 project renamed
Rename an old IAR For STM8 project for editing and modifying the new project.  1. In the EWSTM8 path, there are the following 4 files.    2. Rename these 4 files    3. Open the renamed Templates.eww file with Notepad and modify the following places.    4. After modification, it is as follows:    5. Clean the proje
[Microcontroller]
IAR For STM8 project renamed
Contiki clock module
一、functions for handling system time clock_time_t clock_time(void);//return the current system time in clock ticks unsigned long clock_seconds(void);//return the system time in seconds void clock_set_seconds(unsigned long ec);//set the value of the platform seconds These functions are platform dependent, and we impl
[Microcontroller]
Design of transceiver system based on STM8 and USX1231
In 2008, the Chinese government added operating frequencies of 868MHz to 868.6MHz for micropower (short-range) radio applications. The RF requirements for radio equipment are as follows: (1) Transmit power limit: 5mW (erp); (2) Transmit signal duty cycle limit: 1%; (3) Carrier frequency tolerance: 100×10-6; And cl
[Microcontroller]
Design of transceiver system based on STM8 and USX1231
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号