51 MCU Learning Notes——1. Custom delay function lights up and controls the flashing seconds of LED and uses Proteus to simulate

Publisher:Harmonious222Latest update time:2022-06-09 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

#define LED P0

void delay(); //delay for one second

void main() //Bitwise operation to light up the small light 

{

  unsigned int i;

  while(1)

  {

  for(i = 0;i<8;i++)

{

LED = ~(0X01< delay();

}

  }

  } 

void delay()   //delay for one second

{

  unsigned int i,j;

  for(i = 0;i<83;i++)

{

for(j = 0;j<1000;j++)

{

;

}

}

 }


Since the blogger is at home during the winter vacation and does not have a 51 single-chip microcomputer, I used Proteus to build a simple circuit, wrote the file with keil5 to generate a .hex file, and then added it to Proteus to run. The specific operations are as follows:

insert image description here

Then check the following options:

insert image description here

Then save the written code and finally open the Proteus software.

Build the circuit as follows:

insert image description here

Then insert the code to combine with the circuit:

insert image description here
insert image description here
insert image description here

Select the .hex file to confirm, then run in the lower left corner:

insert image description here

The operation is as follows, blue means the small light is running normally:

insert image description here
insert image description here

We can see the small lights cycle from the first light to the eighth light.

Careful friends can see that the delay time set by our delay() function is one second. Why is it one second? The control here is quite clever. Two for() loop statements are used. The outer loop is executed 83 times and the inner loop is executed 1000 times, which means that the total execution is 83 * 1000 times. In C language, the number of seconds to execute a statement can be observed by setting breakpoints before and after. In order to deeply understand why the program can reach 1 second after executing 83 * 1000 times, we set a breakpoint before and after this statement respectively, and roughly judge the program's pointing time by observing the time difference between the two endpoints:


Reference address:51 MCU Learning Notes——1. Custom delay function lights up and controls the flashing seconds of LED and uses Proteus to simulate

Previous article:51 MCU Learning Notes——3. Several different ways of lighting LED (array form) and key detection, delay debounce
Next article:Learn MCU interrupts in 1 day - basic knowledge

Recommended ReadingLatest update time:2024-11-23 11:07

Application of AVR microcontroller in LED remote control lighting
Abstract: Based on AVR microcontroller, a LED remote control lighting system is designed. The design method of infrared receiving module and LED driving module, as well as the software program flow are given. After testing, the scheme is feasible and has certain application value. introduction LED lighting has ent
[Microcontroller]
Application of AVR microcontroller in LED remote control lighting
Innovative design of buck regulator transformed into smart dimmable LED driver
LEDs are expected to transform the lighting industry with their long life and low power consumption , but a major barrier to their rapid adoption is the high cost of the LEDs themselves. The cost of LED luminaires (complete electric lighting equipment) varies, but the cost of LEDs typically accounts for about 25% to 4
[Power Management]
Innovative design of buck regulator transformed into smart dimmable LED driver
LED UV irradiation box design and production process (illustration)
Introduction A few months ago I was looking for some LED suppliers and found out there were UV LEDs. My heart went straight to upgrading my not so big setup so I started looking for information on the internet. Turns out some other people have done it and this instructable confirmed that it is really possible.
[Power Management]
LED UV irradiation box design and production process (illustration)
Common Problems and Analysis of LED Lighting Design
LED (Light Emitting Diode) is a solid-state semiconductor device that can directly convert electricity into light. The heart of an LED is a semiconductor chip. When current acts on this chip through a wire, electrons and holes are pushed into a quantum well, where they recombine and then emit energy in the form
[Power Management]
Common Problems and Analysis of LED Lighting Design
Electronics Encyclopedia Knowledge: The structure of LED light-emitting diodes
LED Lamp is mainly composed of five materials: bracket, silver glue, chip, gold wire and epoxy resin. 1. Bracket: 1) Function of the bracket: used for conduction and support 2) Composition of the bracket: The bracket is formed by electroplating the bracket material. From the inside to the outside, it is compose
[Power Management]
University of Waterloo develops LED flexible fabric display
Recently, researchers at the University of Waterloo have developed an innovative display that can display electronic information through clothing and other fabrics.     Figure 1. Interactive vocabulary images displayed using different types of clothing and pockets: (a) the number 5 displayed through cotton pants; (b
[Embedded]
University of Waterloo develops LED flexible fabric display
LED lights randomly light up
#include "reg52.h" #include "stdlib.h" typedef unsigned int u16; void delay(u16 i) { while(i--) {}; } void main() { srand(0); while(1) { P2=rand()&0xff; delay(
[Microcontroller]
Color LED Large Screen Control System Based on FPGA
As an important medium for modern information release, LED (Light Emitting Diode) large screens are receiving great attention from all walks of life, especially the business and advertising circles. With the advancement of science and technology, full-color LED display screens (RGB three primary colors) are gradually
[Power Management]
Color LED Large Screen Control System Based on FPGA
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号