Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Stopwatch using 8051 microcontroller (AT89C51)

By Himanshu Choudhary August 3, 2010

A stopwatch is a timepiece that measures the amount of time between any two occurrences. Usually, at the first occurrence, the stopwatch is started while at the second it is stopped. To use it again, a reset option is also provided with the stopwatch. The total time elapsed can thus be obtained. A stopwatch is very commonly used in racing competitions and other gaming activities. The circuit given here is a digital stopwatch that displays time on four seven segment displays using 8051 microcontroller (AT89C51) .

 


 

The stopwatch keeps the track of time the same way as a simple digital clock does. It is basically an up time counter that starts from 00:00. The control options are provided by means of tactile switches which are active low. This circuit uses three such switches for following operations:
Switch 1 (S1)   :           Start               
Switch 2 (S2)   :           Stop                
Switch 3 (S3)   :           Reset              
 
Initially when Vcc supply is provided to the circuit, the stopwatch goes in reset mode with 00:00 display state on seven segments. The stopwatch starts running when S1 is pressed. The time is displayed on four seven segments (in common anode configuration) by using the concept of multiplexing. (Also refer Digital Clock) On pressing S2, the stopwatch stops and displays the total time elapsed since the start. It can be taken to reset mode at any instant by using S3.
The seven segments are interfaced to port P2 of the microcontroller AT89C51 through its data pins (a – h). The enable pins are connected to pins 1-4 of port P1 (P1^0 – P1^3). The switches S1-S3 are connected to pins 5-7 of port P1 (P1^4 – P1^6).

 

Project Source Code

###

//Program to make a stopwatch

#include<reg51.h>
#define msec 1
unsigned int sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;

unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0;  // Declare the control pins of seven segments
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4;  // Start pin to start the watch.
sbit stop_pin = P1^5;  // Stop pin to stop the watch.
sbit reset_pin = P1^6;  // Reset pin to reset the watch.
int s,t;

void mplex_delay(unsigned int time)  // Function to provide a time delay of approximatelty one second using Timer 1
{
int i,j;
for (i=0;i<=time;i++)
  for(j=0;j<=50;j++);
}

void digi_out(unsigned int current_num)
{
    P2=digi_val[current_num];
     mplex_delay(msec);
}

void display(unsigned int dig1,unsigned int dig2)  // Function to display the digits on seven segmnet. For more details refer seven segment multiplexing.
{
    sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01;  //Enable Timer 0
TL0=0xFF;
TH0=0xDB;
TR0=1;  // Triger Timer 0
while(TF0==0)
{
  dig_ctrl_1 = 1;
  dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
  digi_out(sec1_1);
  dig_ctrl_2 = 1;
  dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
  digi_out(sec1_2);
  dig_ctrl_3 = 1;
  dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
  digi_out(sec2_1);
  dig_ctrl_4 = 1;
  dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
  digi_out(sec2_2);
}

TR0=0;
TF0=0;
}

void main()
{
while(1)
{
start:  // Segment to start the stop watch
  start_pin = 1;
  stop_pin = 1;
  reset_pin = 1; 
  dig_ctrl_1 = 0;
  dig_ctrl_2 = 0;
  dig_ctrl_3 = 0;
  dig_ctrl_4 = 0;
  P2 = 0xFF;
  s = t = 0;
  while(start_pin == 1)// Check if start pin is pressed
  {
  display(0,0);
  }

stopwatch:  // Segment to stop the watch
  for (sec1=s;sec1<=99;sec1++)
  {
   if (stop_pin == 0 )  //Check if stop pin is pressed
   break;
    for (sec2=t;sec2<=99; sec2++)
    {
    if (stop_pin == 0 )  //Check if stop pin is pressed
    break;
    t=0;
    display(sec1,sec2);
    }
  }
  stop_pin = 1;
  s = sec1;
  t = sec2;
 
  while ( start_pin != 0 && reset_pin != 0 )  //Check if start pin or reset pins are not pressed
  {
  display(sec1,sec2);
  }
 
  if (start_pin == 0)  //Check if start pin is pressed
  {
  goto stopwatch;
  }
  else
  {
   if (reset_pin == 0 )  //Check if reset pin is pressed
   {
   s = t = 0;
   goto start;
   }
  }
}
}

###

 


Circuit Diagrams

Circuit-Diagram-of-Stopwatch-using-8051-microcontroller-AT89C51

Project Components

  • AT89C51 Microcontroller
  • Piezo Buzzer
  • Seven Segment Display
  • Transistor BC547

Project Video


Filed Under: 8051 Microcontroller
Tagged With: 8051, clock, microcontroller, stopwatch
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Testing 5kW Grid Tied inverter over 200-253VAC
  • Single ended measuring ports and balanced antenna
  • Thermal modelling of repetitive power pulse
  • Resistor Selection for Amplifier Layout
  • Cadence LVS bug I do not understand on 12T XOR gate

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Can I make two inputs from one??
  • Behlke swich
  • Beats Solo 4
  • Simple LED Analog Clock Idea

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe