1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

microcontroller code using c

Discussion in 'C' started by aza, Apr 12, 2012.

  1. aza

    aza New Member

    Joined:
    Apr 12, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hello
    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.
    Code:
    do{
          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
                  a++;
          temp= a*120;
          b=temp; 
          B=b; // I considered B as the port for the output
    }
    while ( d=1)
    
    thanks in advanced for the help.
     
    Last edited by a moderator: Apr 13, 2012
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    Replace your for loop with this do...while
    Code:
     
    #include <ctime>
     
    int seconds = 30;
    time_t timeout = time(NULL) + seconds;
    do
    {
        // counting pulses
    } while (time(NULL) < timeout);
    
     
    shabbir likes this.

Share This Page