Microcontroller Embedded C Programming Lecture 127| LED on with software delay

  • Post author:
  • Post category:Blog

 

LED on with software delay

 

 

 

Exercise

  • Write a LED toggle program by creating a software delay between the LED on and LED off. 
  • LED should continuously toggle with a certain time delay forever.

 

Introduction:

In this exercise, we’ll explore the concept of implementing time delays in a program using software-based methods. While hardware peripherals such as timers provide more accurate delay control, we’ll focus on a software-based approach for the sake of simplicity.

 

Introducing time delay in a program

  • Software delay 

– Introduced time delay using loops statements 

  • Hardware delay

– Introduced time delay using hardware peripherals such as timers.

For this exercise, we will be using software delay.  

 

Software time delay

  • To introduce software delay, you should make the processor busy in a software loop doing nothing.
  • This method is not an accurate method to obtain the desired time delay. 

The accurate method is using hardware peripherals such as timers. But we don’t want accuracy in this application, so we just want a certain amount of delay between LED on and LED off a human observable delay. Precision is not required in this application. So, just a random delay which can be perceived by human eyes, in order to distinguish between LED on and LED off. 

  • The processor will keep wasting the execution cycles until a certain delay is met. 

Create a new project and try to modify the LED on program into a LED toggle program. And for the loop implementation, you can either use a while loop or for loop. And try to attempt this exercise and I will explain it in the following article.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.