Click here to Skip to main content
13,455,257 members (54,450 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 5 Oct 2004

Get hold of system time without using inbuilt functions (Can be used with Turbo C++)

, 10 Jul 2006
Rate this:
Please Sign up or sign in to vote.
Getting system timer without using inbuilt system calls


You all might have used CTime or CTimeSpan to manipulate the system timer. Here is an article to show you how your system timer works. I will give you an idea of port communications behind the system clock manipulations. Those who are a little biased on hardware and software interfacing practices would find this article of great help.

About the basic routines

Those who have gone through conio.h header file would have found two interesting functions _outp() and _inp(). I will explain each of these functions in detail. _outp: This is a function used to send data to a port. This function sends a byte to a specified port. The syntax of the function is int _outp(unsigned short port, int databyte). The function returns with the data sent. _inp: This is a function used to receive data from a port. The function read a byte from a specified port. The function returns with the data read from the port. The syntax for the function is: _inp(unsigned port). For getting the system clock, we should initialize the timer first. This is done by the command: _outp(0x70,0x95); Port no 0x70 is reserved for system clock. The current time information would then be stored in port 0x71(Memory address). If you send data 0x10, the content of the 0x71 address will be seconds value of timer. If you send data 0x02, the content of the 0x71 address will be minutes value of timer. If you send data 0x04, the content of the 0x71 address will be hours value of timer. That's it... The system clock manipulations revoloves round these two absic functions. These functions are useful for those writing device drivers.

Explaining the code

I am implementing the whole process in a class called CBaseTime. You can find the wrappings of the process in BaseTime.h and BaseTime.cpp.
// Constructor: Indirectly initializes the clock. 

// Get current time CString 
	CString curTime; 
	seconds = _inp(0x71); 
	minutes = _inp(0x71);
	hours = _inp(0x71); 
	curTime.Format("%x:%x:%x",hours,minutes,seconds); return curTime; 

// Get current hours 
CString CBaseTime::GetCurrentHours() 
	CString retHours; 
	hours = _inp(0x71); 
	return retHours; 

// Get current minutes 
CString CBaseTime::GetCurrentMinutes() 
	CString retMins; 
	minutes = _inp(0x71); 
	return retMins; 

// Get current seconds 
CString CBaseTime::GetCurrentSeconds() 
	CString retSecs; 
	seconds = _inp(0x71); 
	return retSecs; 


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sreekanth Muralidharan
Technical Lead
India India
I am a personality from Trivandrum , a green peaceful place in Kerala, South India.
I have been an enthusiast of Windows programming when I started creating simple windows when I learnt VC++ in LCC in Trivandrum. From then on its all about Windows in my flesh and blood.
My career graph moves like this:
1. I started working as a C/C++ programmer in a company in Trivandrum where I learnt the ABCs of Software Industry. I worked with them for about 1 year. I could not contine since I was in contract for 1 year.
2. Then I joined another organization in Trivandrum who gave me challenges to love. They made me mad about VC++ and Windows.
I was mad about Embedded Systems which made me, Myself = Embedded Systems + VC++.
3. Software Engineer in a telecom company in Hyderabad, Andhra Pradesh, S.India.
4. Currently working with a telecom company in Bangalore.
I totally, so, have experience of about 4.5 years.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
starschen12-Jan-11 2:52
memberstarschen12-Jan-11 2:52 
GeneralMy vote of 5 Pin
atishax5-Oct-10 15:06
memberatishax5-Oct-10 15:06 
GeneralArticle suggestion Pin
Jörgen Sigvardsson6-Oct-04 12:04
memberJörgen Sigvardsson6-Oct-04 12:04 
GeneralKnowing how it really works. Pin
Randor6-Oct-04 9:22
memberRandor6-Oct-04 9:22 
GeneralRe: Knowing how it really works. Pin
Neville Franks6-Oct-04 10:33
memberNeville Franks6-Oct-04 10:33 
GeneralRe: Knowing how it really works. Pin
Randor6-Oct-04 11:22
memberRandor6-Oct-04 11:22 
GeneralRe: Knowing how it really works. Pin
Sreekanth Muralidharan6-Oct-04 19:04
memberSreekanth Muralidharan6-Oct-04 19:04 
GeneralRe: Knowing how it really works. Pin
Jörgen Sigvardsson6-Oct-04 22:06
memberJörgen Sigvardsson6-Oct-04 22:06 
GeneralShould not work on any current version of windows. Pin
John M. Drescher6-Oct-04 6:09
memberJohn M. Drescher6-Oct-04 6:09 
GeneralRe: Should not work on any current version of windows. Pin
Rory Solley6-Oct-04 21:57
memberRory Solley6-Oct-04 21:57 
GeneralRe: Should not work on any current version of windows. Pin
John M. Drescher7-Oct-04 4:51
memberJohn M. Drescher7-Oct-04 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180321.1 | Last Updated 11 Jul 2006
Article Copyright 2004 by Sreekanth Muralidharan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid