0% found this document useful (0 votes)
116 views

Stop Watch

This digital stopwatch uses an 8051 microcontroller to display the elapsed time on four 7-segment displays. It works similarly to a digital clock by keeping track of time as an up counter from 00:00. There are three tactile switches to start, stop, and reset the stopwatch. When power is applied, it displays 00:00. Pressing the start switch begins timing. Pressing the stop switch pauses the display. The reset switch returns it to 00:00. The microcontroller interfaces with the 7-segment displays and switches to control the stopwatch functions.

Uploaded by

Gaurav Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views

Stop Watch

This digital stopwatch uses an 8051 microcontroller to display the elapsed time on four 7-segment displays. It works similarly to a digital clock by keeping track of time as an up counter from 00:00. There are three tactile switches to start, stop, and reset the stopwatch. When power is applied, it displays 00:00. Pressing the start switch begins timing. Pressing the stop switch pauses the display. The reset switch returns it to 00:00. The microcontroller interfaces with the 7-segment displays and switches to control the stopwatch functions.

Uploaded by

Gaurav Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

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) .

Description

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 referDigital 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 P 2 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).

//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;

}
}

Transistor BC547

BC547 is an NPN bi-polar junction transistor. A transistor, stands for transfer of resistance, is commonly used to amplify current. A small current at
its base controls a larger current at collector & emitter terminals.
 
BC547 is mainly used for amplification and switching purposes. It has a maximum current gain of 800. Its equivalent transistors are BC548 and
BC549.
 
The transistor terminals require a fixed DC voltage to operate in the desired region of its characteristic curves. This is known as the biasing. For
amplification applications, the transistor is biased such that it is partly on for all input conditions. The input signal at base is amplified and taken at
the emitter. BC547 is used in common emitter configuration for amplifiers. The voltage divider is the commonly used biasing mode. For switching
applications, transistor is biased so that it remains fully on if there is a signal at its base. In the absence of base signal, it gets completely off.
 
SEVEN SEGMENT DISPLAY

A seven segment display is the most basic electronic display device that can display digits from 0-9. They find wide application in devices that
display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. The most common configuration has an array of
eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure ‘8’. Every LED is assigned a name from 'a'
to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'h' is used to display the dot/decimal.
 
A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are
common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC
configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a particular LED
glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to
display a number.
PIEZO BUZZER

The piezo buzzer produces sound based on reverse of the piezoelectric effect. The generation of pressure variation or
strain by the application of electric potential across a piezoelectric material is the underlying principle. These buzzers can
be used to alert a user of an event corresponding to a switching action, counter signal or sensor input. They are also
used in alarm circuits.
                                                   
 
The buzzer produces a same noisy sound irrespective of the voltage variation applied to it. It consists of piezo crystals
between two conductors. When a potential is applied across these crystals, they push on one conductor and pull on the
other. This, push and pull action, results in a sound wave. Most buzzers produce sound in the range of 2 to 4 kHz.
The red lead is connected to the input and the black lead to the ground.
 
MICROCONTROLLER 89C51

AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. AT89C51 has 4KB of Flash programmable and erasable read only memory
(PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 10... AT89C51 is an 8-bit microcontroller and belongs to
Atmel's 8051 family. AT89C51 has 4KB of Flash programmable and erasable read only memory (PEROM)and 128 bytes of RAM. It can be erased
and program to a maximum of 1000 times.
In 40 pin AT89C51, there are four ports designated as P 1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both
input and output ports. Except P 0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins,
they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed
individually.
 
Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has
multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external
memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timer &
hardware interrupts, it has a total of six interrupts.
 
 Pin No Function Name
1 P1.0
2 P1.1
3 P1.2
4 P1.3
8 bit input/output port (P1) pins
5 P1.4
6 P1.5
7 P1.6
8 P1.7
9 Reset pin; Active high Reset
10 Input (receiver) for serial communication RxD P3.0
11 Output (transmitter) for serial communication TxD P3.1
12 External interrupt 1 Int0 P3.2
13 External interrupt 2 Int1 8 bit input/output port P3.3
14 Timer1 external input T0 (P3) pins P3.4
15 Timer2 external input  T1 P3.5
16 Write to external data memory Write P3.6
17 Read from external data memory Read P3.7
18 Crystal 2
Quartz crystal oscillator (up to 24 MHz)
19 Crystal 1
20 Ground (0V) Ground
21 P2.0/ A8
22 P2.1/ A9
23 8 bit input/output port (P2) pins P2.2/ A10
24 / P2.3/ A11
25 High-order address bits when interfacing with external memory P2.4/ A12
26   P2.5/ A13
27 P2.6/ A14
28 P2.7/ A15
29 Program store enable; Read from external program memory PSEN
Address Latch Enable ALE
30
Program pulse input during Flash programming Prog
External Access Enable;  Vcc for internal program executions EA
31
Programming enable voltage; 12V (during Flash programming) Vpp
32 P0.7/ AD7
33 P0.6/ AD6
34 8 bit input/output port (P0) pins P0.5/ AD5
35   P0.4/ AD4
36 Low-order address bits when interfacing with external memory P0.3/ AD3
37   P0.2/ AD2
38 P0.1/ AD1
39 P0.0/ AD0
40 Supply voltage; 5V (up to 6.6V) Vcc

You might also like