Common Errors in Delay Functions in MCUs

Publisher:以泉换泉Latest update time:2015-12-23 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   Sometimes when a long delay is needed, you can use a loop or pass a larger parameter. However, when passing a larger parameter, you must clearly see the parameter type and the range of values ​​that this type can represent.
   For example, in the AD conversion program I wrote, the conversion time must be as long as 30ms to have valid data output. If the time is too short, it will not have an immediate effect. The maximum value of unsigned char is 255. If it is larger, a loop must be used.
   Below is the original code:
#include
#include
sbit wr = P3^6;
sbit rd = P3^7;
sbit dula = P2^6;
sbit wela = P2^7;
unsigned char j,k,aa;
void delay(unsigned char i)  //maximum value 255
{
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void main()
{
unsigned char a;
while(1)
{
wela = 1;  //select P0 of 74hc573
P0 = 0;        //select ADCS
wr = 0;   //start adc0804, write analog signal
_nop_();
wr = 1;
delay(10);
//          for(a = 20;a>0;a--)
delay(255); //wait for conversion
rd = 0;   //AD read enable
}
}
[Note] This code is passed in TX-1C
Keywords:MCU Reference address:Common Errors in Delay Functions in MCUs

Previous article:Cold and hot start problems of single chip microcomputer
Next article:Use Keil to write the program and download it to the microcontroller

Recommended ReadingLatest update time:2024-11-16 19:55

EM78 series single chip microcomputer--table lookup program design
在一个沒有規则性的内容转换中,查表程序是相当有用的,用户可以使用查表程序很快速的得到相关内容的转换。  例:设计一个程序,將如下图所示中的PORT5读到的一个数值,将输入内容做转换,然后输出到PORT6的7段显示器上。       上图中开关关闭,I/O引脚可以得到一个低电位,若是开关开启则I/O引脚可以得到一个高电位。  图 5.2  数码管 八段说明  7段显示器的接线图如上,我們要編一个表做为读入内容以及输出内容的对映。     7段显示器各脚位电位状态 PORT6输出 PORT5输入   H G F E D C B A 16进位数值 10进位数值   0 0 1 1 1 1 1 1 0X3F 0   0 0 0 0 0
[Microcontroller]
EM78 series single chip microcomputer--table lookup program design
51 MCU Design Schemes TOP10 (Part 4)
Real-time online environmental monitoring system based on MCS-51 single chip microcomputer    1 Introduction   The data collector based on GPRS and MCS-51 single-chip microcomputer is a real-time online environmental monitoring system. It uses the packet wireless service GPRS to transmit the real-time online det
[Analog Electronics]
51 MCU Design Schemes TOP10 (Part 4)
Design and implementation of a remote monitoring system for single-chip computers based on Web
1. Introduction The single-chip microcomputer system is more and more widely used in industrial control and daily life due to its simple and efficient characteristics. At present, most single-chip microcomputer systems are based on 51 single-chip microcomputers, which are combined with detection, servo and disp
[Microcontroller]
The microcontroller digital tube displays 0~9
mission details: A company undertook an LED digital display design task; the microcontroller was required to control a digital tube to display 0→1→2→3→4→5→6→7→8→9, with each state staying for 1 second. Please use a microcontroller to design its control system and debug it. Hardware circuit schematic diagram Par
[Microcontroller]
The microcontroller digital tube displays 0~9
Design of multi-channel calling system based on MCS-51 single chip microcomputer
With the development of information technology and the deepening reform of medical and health care, the implementation of the National Golden Health Project has greatly accelerated the process of hospital management informatization. More and more hospitals have realized that only through informatization construction an
[Microcontroller]
Design of multi-channel calling system based on MCS-51 single chip microcomputer
PIC16F15323 microcontroller (interrupt and timer Timer0)
The development environment selected is MPLAB X IDE v5.50 and xc8-v2.32-full-install-windows-x64-installer. 1 Basic principles 2 Implementation Code The code is mainly written based on FIGURE 25-1 and the interrupt logic block diagram, so that the code is readable and easy to understand. However, some registe
[Microcontroller]
PIC16F15323 microcontroller (interrupt and timer Timer0)
How to integrate the programming function of PIC microcontroller into ATE
To do ATE, the PIC microcontroller inside the DUT needs to be programmed online. I saw someone else's statement on the Internet (author Claud Zhang), which is as follows: --------------------------------------------------------- A simple, efficient and low-cost method for programming Microchip MCUs                  
[Microcontroller]
AVR single-chip fixed-point calculation and number system conversion subroutine
Since the advent of the AVR microcontroller, it has received widespread attention. It is a high-speed microcontroller that uses a reduced instruction set and a clock cycle as a machine cycle. It uses a fast register file (a total of 32 registers R0~R31, of which R16~R31 has strong general functions) and fast single-cyc
[Microcontroller]
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号