Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
13Activity
0 of .
Results for:
No results containing your search query
P. 1
An Easy Timer in C Language

An Easy Timer in C Language

Ratings:

4.5

(4)
|Views: 5,113 |Likes:
Published by Emanuele
A good exercise for a beginner is to implement a module that pretends a timer.
To do this we have used the following functions that already exist in C library
A good exercise for a beginner is to implement a module that pretends a timer.
To do this we have used the following functions that already exist in C library

More info:

Published by: Emanuele on Apr 23, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/17/2012

pdf

text

original

 
An easy timer in C languagehttp://dev.emcelettronica.com/print/517111 di 223/04/2008 12.13
Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > Blog > arag61's blog > Content
An easy timer in C language
By arag61Created 15/03/2008 - 10:48
BLOGA good exercise for a beginner is to implement a module that pretends a timer.To do this we have used the following functions that already exist in C library:delay() – suspends execution for interval [ milliseconds ] ( defined in DOS.H )kbhit() – checks for currently available keystrokes ( defined in CONIO.H )printf() - outputs a formattes message to video. (STDIO.H)clrscr() – clears text mode window ( defined in CONIO.H )Below there is the module code :
#include <stdio.h>#include <dos.h>#include <conio.h>
void timer(float cycle){float count=0.0;int goLoop=1; while(goLoop){if(kbhit()){// Keypressed, exitgoLoop=0;}else{delay(100);count+=0.1;if(count> cycle){// Time expired, exitgoLoop=0;}}clrscr();printf(“ The timer is %06.1f seconds\n”, cycle);} // end for} // end module
As we can see there is one “while” loop using the (blocking) library function delay(), (e.g. delay(1000) = 1second ;delay(10) = 0,01 second), we here use a 1 tenth of second delay (delay(100)).For each loop the variable count is increment by 1 tenth then an end of interval control is done (if(count> cycle)).We used as well function kbhit() to stop the timer on demand ( with just a keypress).Variable “cycle” is obviously a float type to get a 1 tenth of second resolution.Morover timer value is output to video using printf with a format specifier %06,1f (e.g. 0014.5).To use this timer every time we want, we have to :Create an header file where the TIMER prototype must be declared.Include this header file in the main program.In the main program code we must call this module using the same type variable ( float in this case ).Compile this module and see if any errors occur.A possible header file code could be :#ifndef __TIMER_H__ #define __TIMER_H__ 

Activity (13)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Hari Hara Prasad liked this
Samuel Mundo liked this
Adrian Paa liked this
farhat_101 liked this
aleris-says liked this
aleris-says liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->