Writing of C51 delay function delay

Publisher:shmilydeLatest update time:2018-07-20 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

For example, to write a delay function with a delay of 10ms: (12M crystal oscillator)



void delay_10ms()

{

     unsigned char i,j,k;

     for(i=5;i>0;i--)

     {

           for(j=4;j>0;j--)

           {

                   for(k=248;j>0;j--);

            }

      }

}

Principle: 3 layers of for loops, the number of loops is NUM = 4X5X248 = 4960 times. Each loop has a conditional judgment (such as i > 0) and a self-decrement statement (such as i--), so each loop consumes two machine cycles.

     Therefore, the total machine cycles consumed is SUM = NUM ​​x 2 = 9920


     Because the frequency of the 12M crystal oscillator is 1us per machine cycle, the time taken for this function is 9920us = 9.920 ms, which is approximately 10ms. If the assignment statement, stack push and pop operations are included, the total time is about 10ms.


Keywords:C51 Reference address:Writing of C51 delay function delay

Previous article:Two modes of external interrupts of microcontrollers
Next article:Delay and timer of 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-15 17:18

4×4 keyboard C51 MCU program source code sharing
/*MCU:AT89S52*/ #include  #include  #define uchar unsigned char int key; int of; void Key_Scan(void); /************Main program*************/ void main(void) {  void Key_Scan(void); void delay(int); while(1) {    Key_Scan();     delay(2000); } } /********Matrix key search key value 4*4 procedure******/ void Key_Scan(v
[Microcontroller]
4×4 keyboard C51 MCU program source code sharing
C51 MCU interrupt recognition
Contains five interrupt sources, two levels of interrupt priority, and programmable priority settings, which can be set through IP: PX0 (IP.0), external interrupt 0 priority setting bit; PT0 (IP.1), timer/counter T0 priority setting bit; PX1 (IP.2), external interrupt 0 priority setting bit; PT1 (IP.3), timer/counte
[Microcontroller]
C51 MCU interrupt recognition
How does the C51 tool perform coverage analysis?
The C51 tools are optimized for the limited memory resources of the 8051 microcontroller. To make the most efficient use of memory, automatic variables and function parameters are overwritten in memory according to a method that is easily explained. First, the connector generates a call tree based on the source pr
[Microcontroller]
C51 interrupt application interrupt and using
The basic structure of the 8051 series MCU includes: 32 I/O ports (4 groups of 8-bit ports); two 16-bit timer counters; full-duplex serial communication; 5 interrupt sources (2 external interrupts, 2 timer/counter interrupts, 1 serial port input/output interrupt), two-level interrupt priority; 128 bytes of built-in RA
[Microcontroller]
Application and feature analysis of Keil c51
Keil c51 is known as the best development environment for 51 series microcontrollers, and everyone must be familiar with it. Everyone knows some of its common features (it is also mentioned in books), such as: because the RAM in 51 is very small, C51 functions do not pass parameters through the stack (except for reent
[Microcontroller]
The role of data, idata, xdata, pdata, and code in C51
In terms of data storage type, the 8051 series has on-chip and off-chip program memory, on-chip and off-chip data memory. The on-chip program memory is also divided into direct addressing area and indirect addressing area. Data: Store the data in the 128B RAM space from 0x00 to 0x7f. You can use acc to read and
[Microcontroller]
A non-preemptive operating system architecture based on C51 single-chip microcomputer
Abstract: Starting from the memory space management method of Keil C51, this paper focuses on the reentry problem of real-time operating system during task scheduling, and analyzes some basic ways and methods to solve reentry: analyzing the preemptiveness of task scheduling in real-time operating system, and proposing
[Microcontroller]
Tip 1 -- Add STC model in Keil C51
Some MCUs are STC models. When creating a project in Keil C51, there is no corresponding chip model...   Solution: Go to the STC official website and download the STC model plug-in. Here is the extraction code for the 115 network disk as a backup: For Keil uVision2 (uv2 for short), plugin extraction code: bewxzw
[Microcontroller]
Tip 1 -- Add STC model in Keil C51
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号