Sunday, November 26, 2023

The falling edge detection code Using PIC16F877A and MikroC Compiler

The falling edge detection code for PIC16F877A and MikroC Compiler

The falling edge detection code Using PIC16F877A and MikroC Compiler

Edge activation is very important for counting or any enabling application. so here we are going to discuss falling edges to activate or detect the falling edges. This is a very important example we are sharing with all.
counter count on falling edge (press the button it will not count but when the button is released then counter increment or decrement depending on the application.

Related topic:

I have discussed the falling edge issue in this topic too, but the given topic is on Multiplexing of 7 segments.

Falling edge detection is very tough for electronic players so we are going to solve this problem in coding by using the compiler MikroC pro for PIC16F877A and Simulate it on Proteus 8.15 for testing.

What is Falling Edge?

The falling edge of the clock means that when the clock pulse goes to low from high level that makes high to low a shorter time edge. You can be seen here in the diagram as illustrated.

falling edge of the clock

On the way, we will also discuss the multi-press problem solution for the button here. 

What multi-press of buttons?

For example, we have created a counter application circuit using a PIC microcontroller and wrote the code to Count up when the push button is pressed. here is the problem when we write a simple code. we press one time but the microcontroller reads it many times and the counter scrolls up many numbers with a single click.

Code chunk example:

while(1){
if (button ===1){
counter++;
Lcd_Out(1,1,counter);
}
}

Multipress Problem:

In starting coding experiments I used delay before counter++  to solve this problem but it was not as practical as I wanted or you wanted to. then I have to use a method that works perfectly on the edges of the clock and also resolve the multipress problem.
Here we are sharing with you all. 

See the results here using Proteus 8.15 Simulations:

Proteus Oscilloscope


Circuit Diagrams

The falling edge detection code for PIC16F877A and MikroC Compiler

You can download the circuit in PDF format:
 

MikroC Coding Chunk:

while(1)
     {// UP counting using Falling Edge
      led=0;
      if(up==1){up_pr++;}
       // Here is a technique when we press the button then
       // increment in an int variable
      if(up==0 && up_pr>=1)
      // Now here apply the condition when (button depress
      // and up_pr>=1) then apply the action function as under
        {count++;led=1;Delay_ms(100);up_pr=0;}

      // DOWN counting using Falling Edge
      if(down==1){down_pr++;}
      if(down==0 && down_pr>=1){if(count>0){count--;}
                               down_pr=0;}

      if (rst==1){count=0;} // Reset the counter

So by this, I have Solve the Problem ..... Enjoy

Happy Emoji



No comments:
Write comments

I am very thankful for your precious time

Important Artical

Popular Articals

Total Page views in This Month

© 2019-20 Electronics Garage. Designed by Uzma 0101 & Distributed by elektronicsgarage1.blogspot.com