Seven-segment LEDs are widely used to display decimal numbers. Their major applications are in digital clocks, electronic meters and other numeral displays. Here we present the software program to replicate a digital clock with AM and PM display.
The program (digi_cloc.c) is written in ‘C’ language and uses the current time from a PC’s real-time clock. A 39.6cm (15.6-inch) LG Flatron W1643C monitor with 1366×768 resolution was used to test the program. The screenshot shows the output of this program.
The program requires the egavga.bgi graphics file to be stored in the same folder as the executable file. When the program is run, the graphics system is initialised by loading a graphics driver from the system’s hard disk. The main functions used in the program for digital clock display are described below.
gdriver and gmode. These functions specify the graphics driver and graphics mode, respectively. The mode is set by the system automatically.
gettime( ). This function extracts the current time from the real-time system clock as structure time t. Here ‘t’ is the structure variable, which is used to access the hour element (ti_hour), minute element (ti_min) and second element (ti_sec). The structure is separated to digits and the corresponding seven-segment symbols displayed on the screen.
kbhit( ). This function returns a non-zero value when a key is pressed.
delay( ). It provides the required time delay in milliseconds.
closegraph( ). It switches the screen from graphics mode back to text mode.
Download source code: click here
The author is an assistant professor in electrical and electronics engineering at SACS M.A.V.M.M Engineering College, Madurai, Tamil Nadu