IAR for STM8 exact delay function __delay

Source: Internet
Author: User
Tags mongodb postgresql
"Finishing" 61ic.com
"Provider" llz77
"Detailed description" IAR for STM8 exact delay function

With the IAR for STM8, there is a project to accurately know the number of delay line delay time is how many, the Internet search under unexpectedly did not, and found that a lot of people ask how such a function, I use oscilloscope measurement to do a precise delay function, to share with you friends. The clock start function (16M crystal oscillator) is
void Clkinit (void) 
{ 
    Clk_eckr |=0x1;         Open the external clock while  
    (!) ( clk_eckr&0x2)); Wait for the external clock rdy  
    CLK_CKDIVR &= 0xf8;     CPU No frequency Division 16M 
    CLK_SWR = 0xb4;         Select the external clock while  
    (!) ( clk_swcr&0x8)); 
    CLK_SWCR |=0x2;         Enable external clock 
delay function 
//---  microsecond delay-------------------------- 
void Delayus (void) 
{  
    ASM ("NOP"); An ASM ("NOP") function is tested by an oscilloscope to represent 
    the 100ns asm ("NOP"); 
    ASM ("NOP"); 
    ASM ("NOP");  
} 

----Millisecond delay program----------------------- 
void delayms (unsigned int time) 
{ 
    unsigned int i; 
    while (time--) for   
    (i=900;i>0;i--) 
    Delayus ();  
} 

I hope it works for everyone.

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.