Advertisement
metalx1000

GCC basic time delay without using timer.h

Oct 24th, 2017
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2017 Kris Occhipint.
  3.  * http://filmsbykris.com
  4.  *
  5.  * Basic Delay example without using time.h
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify  
  8.  * it under the terms of the GNU General Public License as published by  
  9.  * the Free Software Foundation, version 3.
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.  * General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19. #include<stdlib.h>
  20. #include<stdio.h>
  21.  
  22. int delay(){
  23.   int c = 1, d = 1;
  24.   for ( c = 1 ; c <= 32767 ; c++ )
  25.     for ( d = 1 ; d <= 32767 ; d++ )
  26.     {}
  27.   return 0;
  28. }
  29.  
  30. int loop(){
  31.   for (int i=1;i<=10;i++){
  32.     fflush(stdout);
  33.     printf("\rI'm counting: %d", i);
  34.     delay();
  35.   }
  36.   //end with new line
  37.   printf("\n");
  38.   return 0;
  39. }
  40.  
  41. int main(){
  42.   printf("I'm going to count...\n");
  43.   loop();
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement