Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   microcontroller code using c (http://www.go4expert.com/forums/microcontroller-code-using-c-t28180/)

aza 12Apr2012 22:00

microcontroller code using c
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.

DRK 13Apr2012 17:41

Re: microcontroller code using c
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);

All times are GMT +5.5. The time now is 07:01.