51 single chip microcomputer timing control light

Publisher:Mingyue1314Latest update time:2018-06-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Let the first small light turn on for 0.5 seconds and then turn off for 0.5 seconds.

Let's write a program to make a small light flash, taking the first small light as an example:


[objc]  view plain  copy

  1. #include   

  2.    

  3. sbit L1=P1^0;  

  4. void main()  

  5. {   

  6.     int a;  

  7.     while(1)  

  8.     {  

  9.         a=66666;  

  10.         L1=0;  

  11.         while(a--);  

  12.         a=66666;  

  13.         L1=1;  

  14.         while(a--);  

  15.     }  

  16. }  


So how do you know how long this little light has been on?


We can debug to know when the small light is on.

First, we need to set the clock frequency of the simulator. Click Target options—>Target above, and then adjust the value in Xtal to the clock frequency of the microcontroller, which is generally 11.0592MHZ.

Then click debug to debug, double-click line 14 to make a red block appear in front of it (so that the program will pause when it reaches the red block). The page is as follows:



Then click the RST button above to rerun the program, then click Run, and then pay attention to the data in the sec item in the left column. sec represents the time it takes for the program to run to the red block.



It shows that it took 0.50006944 seconds for the program to run to the red block.

This means that the small light is on for 0.50006944 seconds.

Then we can adjust the value of a to make the small light turn on for 0.5 seconds and then turn off for 0.5 seconds.


Reference address:51 single chip microcomputer timing control light

Previous article:51 MCU timer interrupt function variable initialization problem
Next article:51 single chip microcomputer flashes a small light

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号