microcontroller code using c

aza's Avatar, Join Date: Apr 2012
Newbie Member
i m working on a project involving microcontroller,
i have square wave pulse as an input to my 16f877a microcontroller (the amplitude of the waves is rather 0v or 5v) i want to count how many pulse i have in 30 seconds, multiply it y 120 and then output the result on a 7segment display.
i know C++, i tried to think of how to do it and came up with the following.
      int a=0; // a is used to count the number of pulses every 30 seconds
      int temp=0; 
      int b; // b contains the value to be outputted
      int d=1; // d is used to have an infinite loop
      for(int t=0; t<30; t++) // t represent 30 seconds
// i should be able to count all the pulse in every second. but didnt know how. 
           if( A==high) // I considered that A is the input and by high i mean 5V
      temp= a*120;
      B=b; // I considered B as the port for the output
while ( d=1)
thanks in advanced for the help.

Last edited by shabbir; 13Apr2012 at 09:17.. Reason: Code blocks
DRK's Avatar
Go4Expert Member
Replace your for loop with this do...while
#include <ctime>
int seconds = 30;
time_t timeout = time(NULL) + seconds;
    // counting pulses
} while (time(NULL) < timeout);
shabbir like this