stm8 time1 precise delay

Publisher:MysticDreamerLatest update time:2020-02-17 Source: eefocusKeywords:stm8  time1 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

// Initialize the millisecond unit

void Timer_Init()

{

TIM1_PSCRH = (unsigned char) ( ( (F_CPU / 1000) - 1) >> 8); /* 16M system clock is pre-divided by f=fck/(PSCR+1) */

TIM1_PSCRL = (unsigned char) ( (F_CPU / 1000) - 1); /* PSCR=0x3E7F, f=16M/(0x3E7F+1)=1000Hz, each counting cycle is 1ms */


TIM1_ARRH = 0; /* I don't know why these three lines need to be initialized first. If they are not used regularly for the first time, they will not work properly*/

TIM1_ARRL = 1; /* */

TIM1_CR1 = 0x01; /* Enable the counter and start counting */

}



/* In ms, the timer is used for more accurate calculation*/

void Delay( unsigned int ticks )

{

TIM1_CR1 = 0x00; /* Counter off */

TIM1_SR1 = 0; /* Clear the update interrupt flag */

TIM1_CNTRH = 0;

TIM1_CNTRL = 0; /* Clear the counter */

TIM1_ARRH = (ticks >> 8); /* Auto-reload register ARR=0x01F4=500 */

TIM1_ARRL = ticks; /* Generate an interrupt every 500 ticks, i.e. 500ms */



TIM1_CR1 = 0x01; /* Enable the counter and start counting */

while ( !(TIM1_SR1 & 0x01) )

;

TIM1_CR1 = 0x00; /* Counter stops counting */

TIM1_SR1 = 0; /* Clear timer 0 flag */

}

Keywords:stm8  time1 Reference address:stm8 time1 precise delay

Previous article:STM8S delay function
Next article:Why simple software delay does not work when developing STM8 with IAR

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

STM8 external interrupt does not respond
I was confused for a long time when programming a simple key input interrupt for STML152K4. I made a summary to help others fill the gap. BUG pit phenomenon void key_init(void) { GPIO_Init(POWER_KEY, GPIO_Mode_In_FL_IT); EXTI_DeInit(); EXTI_SetPinSensitivity(EXTI_Pin_4, EXTI_Trigger_Falling); //Falling edge
[Microcontroller]
STM8 external interrupt does not respond
ADC0832 acquisition and Bluetooth communication system based on STM8
I recently found a single-chip microcomputer, STM8, while browsing Taobao. Compared with the 8-bit AVR I have been using before, STM8 feels more powerful. The chip features are as follows: Core: Harvard architecture with 3-stage pipeline, extended instruction set Program memory: 8K bytes Flash; RAM: 1K bytes Data me
[Microcontroller]
ADC0832 acquisition and Bluetooth communication system based on STM8
STM8 clock configuration
#include  "stm8s.h"   #include  "stm8s_conf.h"   void    SystemClockOutput(void)   {         GPIO_Init(GPIOE,GPIO_PIN_0,GPIO_MODE_OUT_PP_LOW_FAST);         CLK_CCOConfig( CLK_OUTPUT_CPUDIV8 );   }   void    SystemClockConfigHSE(void)   {         CLK_HSECmd(ENABLE); //External clock on           //CLK_LSICmd(ENABLE); /
[Microcontroller]
stm8 debugging hardware I2C experience
This time, debugging the hardware of stm8 was really hard. I didn't expect it to be so annoying! It took me 5 days to do it. I referred to many examples on the Internet and Fengchi's stm8 explanation! And my own practice, I finally figured it out! I would like to share some of my experiences in the debugging process w
[Microcontroller]
Introduction of Weixue Electronics STM8 QFP44 Test Socket
STM8 dedicated programming seat burning seat QFP44 0.8mm original imported seat Only for STM8 QFP44 package 0.8mm pin spacing MCU programming and testing, support models see the introduction Model STM8-QFP44 Product Introduction Product Usage Program and test the STM8 QFP44 package 0.8mm pin spacing microco
[Microcontroller]
Introduction of Weixue Electronics STM8 QFP44 Test Socket
STM8's interrupt system and external interrupt details
STM8 has a maximum of 32 interrupt systems, and the interrupt processing is similar to the cortexm series chips. First, each interrupt vector is solidified inside the system, and the user needs to write the interrupt processing function to the corresponding interrupt vector flash location. Second, each interrupt vecto
[Microcontroller]
STM8 Controller Area Network (beCAN)
Introduction to STM8 Controller Area Network (beCAN) beCAN is the abbreviation of Basic Extended CAN, which supports CAN protocol 2.0A and 2.0B. Its design goal is to efficiently process a large number of received messages with minimal CPU load. It also supports priority requirements for message sending (priority char
[Microcontroller]
STM8 Controller Area Network (beCAN)
STM8 study notes 1: CPU introduction
Written in front   Recently, the project involves some low-level driver designs with high real-time requirements. After writing them in C language under IAR, I always feel that the response is not fast enough. I usually see many embedded experts writing them directly through assembly on the Internet, and the effect is
[Microcontroller]
STM8 study notes 1: CPU introduction
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号