Stopwatch using 8051 assembly code


  • 7 Segment Display Interfacing with Pic Microcontroller
  • Digital stopwatch using microcontroller
  • Digital Stopwatch
  • COUNTER PROGRAMMING
  • Seven segment interfacing with 8051 – Single and Quad module
  • Introduction to 8051 Programming in Assembly Language
  • Interfacing Seven segment display to 8051
  • 7 Segment Display Interfacing with Pic Microcontroller

    My alarm clock includes, a clock that runs in hour time, an alarm, a count down timer, and a stopwatch. Everything displays to the nearest second. You can set the clock, alarm, and count down timer to the nearest minute. The alarm outputs a simple beeping signal from the headphone jack. The prototyping board has most of the pins from the processo r output to a double row of headers on one side of the board.

    Professor Stirling in our engineering department had designed a board called DL6 to interface with the Cygnal board. I decided to get an LCD and connect it to the processor via the breadboard on the DL6 and use the buttons on the DL6 as the inputs for the clock.

    I got and LCD and went hunting to figure out how to use it. I finally found a tutorial on www. The first problem I had was my DL6, and Cygnal boards would only output 3. After I figured that out it was no small task to get 5 volts out of my board. After much hard work, we had to remove one of the pull down resistors from the DL6 board and add a pull up resistor. This got 8 outputs from P0 to 5 volts.

    However, you can run the LCD in 4 bit mode using only use 4 data lines, but this is a little more complicated on the software end. Since I only had 8 output lines I decided to try 4 bit. Despite heroic trouble shooting on my part, and going over the example 4 bit code from I could only get it to clear, sometimes.

    Back to the drawing board, my only option was 8-bit so I needed another 3 outputs. To get to them I soldered 3 more lines straight onto my Cygnal board, and added pull-up resistors to them. I got that working in short order the The Software: The code seemed like it would be very easy at first but it rapidly got longer then I thought it would be. None of it was particularly challenging but there was just a lot of it to write.

    Basically I have a main code loop that runs through looking for one of the latches or momentary buttons to be set and that puts you in the appropriate mode loop i. The clock, and various timers chronograph and countdown timer are kept track of with independent timers that interrupt when they overflow. If you start the countdown timer or chronograph it starts a timer that will overflow and interrupt to increment or decrement the appropriate time. And of course there is always a timer running in the background to keep track of the clock time.

    You can run the chronograph, timer and clock simultaneously and switch around through the different modes depending on the one you want to watch, while the rest will keep track of their respective times in the background. The latching buttons are used to go into the various set modes, except LAT0.

    MOM0 is the mode button, when you press it, it will cycle you through the three modes, clock default , timer, and chronograph. MOM2 also double as the add minute button when you are in set mode and MOM3 is the add hour button in set mode. When the timer reaches zero, or the alarm reaches its set time provided the alarm enable LAT0 is set it will trigger the alarm.

    The alarm outputs an annoying beeping signal from the headphone jack. You can hear it significantly well with headphones, but if you want bigger speakers hooked up they have to be powered speakers. If the timer sets off the alarm it will beep for approximately 30 sec, if the set alarm goes off it will beep for approximately 1 min and 30 sec.

    Overall my alarm clock has nearly all of the features you would expect in a wristwatch, or an alarm clock you would have on your nightstand. Well except for snooze, and displaying tenths or hundredths of a second for the stopwatch to be featured in version 2. The Finished Product: A copy of my source code can be found here.

    Share this:.

    Digital stopwatch using microcontroller

    END About the program. Execution of this instruction will add the value in the accumulator A with the content of the program counter address of the next instruction and will move the data present in the resultant address to A. In the program, initial value in A is B. The result will be the address of label DB 3FH line15 and the data present in this address ie 3FH digit drive pattern for 0 gets moved into the accumulator. Moving this pattern in the accumulator to Port 1 will display 0 which is the first count.

    The reason why accumulator is loaded with B 9 in decimal initially is that the instructions from line 9 to line 15 consumes 9 bytes in total. This table defines the digit drive patterns for 7 segment display as bytes in hex format. MOVC operator fetches the byte from this table based on the result of adding PC and contents in the accumulator.

    Register B is used as a temporary storage of the initial value of the accumulator and the subsequent increments made to accumulator to fetch each digit drive pattern one by one from the look up table LUT. Note:- In line 6, Accumulator is incremented by 1 each time each loop iteration to select the next digit drive pattern. The digit drive patterns are arranged consecutively in LUT. Register R0 is used as a counter which counts from 10 down to 0.

    This ensures that digits from o to 9 are continuously displayed in the 7 segment LED. You may note lines 4, 11, 12, and 13 in the above program. Line 4 initializes R0 to 10 OAh. When the program counter reaches line 11 for the first time, 7 segment LED has already displayed 0.

    So we can reduce one count and that is why we have written DEC Ro. We need to continuously check if R0 has reached full count that is 0. In order to do that lines 12 and 13 are used. We move R0 to accumulator and then use the Jump if Zero JZ instruction to check if accumulator has reached zero. If Acc not equal to zero, we continue the program to display the next digit check line Multiplexing 7 segment display to Suppose you need a three digit display connected to the Each 7 segment display have 8 pins and so a total amount of 24 pins are to the connected to the microcontroller and there will be only 8 pins left with the microcontroller for other input output applications.

    Also the maximum number of displays that can be connected to the is limited to 4 because has only 4 ports. More over three 3 displays will be ON always and this consumes a considerable amount of power. All these problems associated with the straight forward method can be solved by multiplexing.

    In multiplexing all displays are connected in parallel to one port and only one display is allowed to turn ON at a time, for a short period.

    This cycle is repeated for at a fast rate and due to the persistence of vision of human eye, all digits seems to glow. The main advantages of this method are Fewer number of port pins are required. Consumes less power. More number of display units can be interfaced maximum The circuit diagram for multiplexing 2 seven segment displays to the is shown below. Initially the first display is activated by making P3. In the mean time P3. This condition is maintained for around 1ms and then P3.

    Now both displays will be OFF. Then the second display is activated by making P3. This condition is maintained for another 1ms and then port 3. Transistor Q1 drives the first display D1 and transistor Q2 drives the second display D2. R11 and R12 are the base current limiting resistors of Q1 and Q2.

    The purpose of other components are explained in the first circuit.

    Digital Stopwatch

    This is achieved by first sending the address location 64 to LCD command register. Next, the bitmap values 31, 4, 14, 21, 13, 4, 4, 0 are sent to the LCD data register. This topic explains how to create dynamic effects with the text displayed in LCD.

    A string or message can be displayed on LCD by sending its characters to data register after configuring the command register of LCD. To create a particular effect, any of these code s can be used in a pattern. For example, shifting the entire display right 5H in a loop will keep moving the text to right. To create oscillating text, first keep shifting the string to right for say, 8 positions and then shift it to left.

    This left-right shifting can be done in an infinite loop. Pin 3 is connected to a preset of 10k to adjust the contrast on LCD screen.

    COUNTER PROGRAMMING

    At many instances it is required to display a number like on LCD. Displaying this number is tricky. If the data port of the LCD is loaded with the numberthen the character corresponding to it will be displayed. This article shows the concepts behind displaying a number on LCD. The article uses microcontroller AT89C51 to demonstrate the above principle.

    The circuit is divided into two units: the controller unit and the display unit. The controller unit consists of a microcontroller circuit. A single character can be displayed on LCD by properly configuring its data and command registers. A string is nothing but a sequential arrangement of several characters that can be displayed on LCD by using the following algorithm. Here P2 port of the microcontroller is used as output port which sends the data byte to data pins of the LCD.

    Read more to find out how LCD is interfaced with the microcontroller and how does the circuit work. This is achieved by displaying their status on a small display module. These modules are replacing seven segments and other multi segment LEDs for these purposes. LCD can be easily interfaced with a microcontroller to display a message or status of a device. This LCD has two registers.

    Seven segment interfacing with 8051 – Single and Quad module

    August 3, Automatic bidirectional visitor counter using microcontroller AT89C51 A counter that can change its state in either direction, under control of an up—down selector input, is known as an up—down counter. It can be used to count the number of persons entering a hall in the up mode at entrance gate. In the down mode, it can count the number of persons leaving the hall by decrementing the count at exit gate. It can also be used at gates of parking areas and other public places.

    Introduction to 8051 Programming in Assembly Language

    This circuit divided in three parts: sensor, controller and counter display. The same count is displayed on a set of 7-segment displays through the controller. Read more to find out about working of the circuit and how microcontroller is coded. August 3, Up down counter using microcontroller AT89C51 This article shows an easy to build up down counter. The counter is based around the microcontroller AT89C The switches can also be replaced by sensors to increment or decrement.

    In this circuit, four seven segment display are used to show the value of count. The maximum value of count is The circuit uses the concept of multiplexing of seven segment to display the value of count. In this circuit data output for the seven segment is given on the port P2 of the microcontroller AT89C The control signals for enabling the seven segment displays are given on pin no. The input of switches is taken on pin number P3. Switch connected on pin P3.

    The seven segment used here are common anode. August 3, Stopwatch using microcontroller AT89C51 A stopwatch is a timepiece that measures the amount of time between any two occurrences. 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 displaysusing microcontroller AT89C 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 The control options are provided by means of tactile switches which are active low. This circuit uses three such switches for following operations.

    Read more to find out how the circuit is made and how microcontroller can be programmed to do the task of a stopwatch. August 3, Countdown timer using microcontroller AT89C51 A countdown timer is a down counter that counts from a specified time to This countdown timer has three states: the running state where it counts down, the pause state where it displays the paused time and the reset state to set the countdown.

    The countdown is displayed on a set of four seven segment displays using the microcontroller AT89C A buzzer sounds when the countdown gets over.

    The countdown timer keeps the track of time the same way as a simple digital clock does. As soon as the Vcc supply is provided to the circuit, the timer goes in reset mode with display state on seven segments. The segment to be set can then be selected in cyclic order each time S2 is pressed. After selecting the desired segment, its value can be changed by using S3.

    August 3, Alarm Clock using 7-Segment Display and microcontroller AT89C51 An alarm clock is a clock that indicates a pre-set time by producing sound at that time. The project is built around the microcontroller AT89C The option to set alarm is provided by providing an extra switch S5, with the microcontoller At89C51, which is made active low. Timer 0 with External Input Mode 2 Figure The program will generate the second, the minute, and the hour out of this input frequency and display the result on an LCD.

    This will be a nice digital clock, but not a very accurate one. Before we finish this chapter, we need to state two important points.

    Interfacing Seven segment display to 8051

    You are right. There is a solution to this: the use of interrupts. By using interrupts we can go about doing other things with the microcontroller. When the TF flag is raised it will inform us. This important and powerful feature of the is discussed in Chapter They belong to a register called TCON, which is discussed next.

    These bits are part of a register called TCON timer control. This register is an 8-bit register. The lower four bits are set aside for controlling the interrupt bits, which will be discussed in Chapter We must notice that the TCON register is a bit-addressable register. Table shows replacements of some of the instructions we have seen so far.

    This allows us to start or stop the timer externally at any time via a simple switch.


    thoughts on “Stopwatch using 8051 assembly code

    Leave a Reply

    Your email address will not be published. Required fields are marked *