Stopwatch using 89c52

Thread Starter

Kazadi11

Joined May 1, 2019
4
How would I make a code for a stop watch using the 89c52 or does anyone have any examples of one?

Mod edit: More descriptive title - JohnInTX
 
Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
6,962
Depends on what the code is running on, how many digits you want, how you wire the 7 segment displays and a whole bunch of things.

Unless you have 7 times the # of digits pins available, you’re going to need additional hardware to display the digits. And you have a choice of using, for example, shift registers or multiplexing. Both require their own code to display a digit.

Overall, you’re going to need code to extract individual digits from the time value.

Then you’re going to need code to translate that digit to a seven segment pattern.

Then you’re going to need code to move the seven segment pattern to the displays.

Then, depending on the hardware, you’re going to need code to actually display the digit.

Which part do you need help with?
 

Thread Starter

Kazadi11

Joined May 1, 2019
4
Depends on what the code is running on, how many digits you want, how you wire the 7 segment displays and a whole bunch of things.

Unless you have 7 times the # of digits pins available, you’re going to need additional hardware to display the digits. And you have a choice of using, for example, shift registers or multiplexing. Both require their own code to display a digit.

Overall, you’re going to need code to extract individual digits from the time value.

Then you’re going to need code to translate that digit to a seven segment pattern.

Then you’re going to need code to move the seven segment pattern to the displays.

Then, depending on the hardware, you’re going to need code to actually display the digit.

Which part do you need help with?
I need help with the code to translate the digit to seven segment and to move the seven segment patterns
 

djsfantasi

Joined Apr 11, 2010
6,962
The first is easy. But your code seems to be assembly and I don’t know the assembly particular to your microprocessor. In C, I would define a two dimensional array, 10x7. The 10 index defines the digit and the 7 values correspond to the 7 segments, a-g. If you understand how two dimensional arrays are stored, this is not difficult in assembly. For example, if b represents the base address of the array, then the starting point, s, for a digit d, is s=b+d*7. Then the value v, for the segments a-g is v=s+n, where n is the ordinal of the segments starting at 0.

The latter, moving the segment values to the display, is completely dependent on how you’ve designed the hardware and how many digits there are. So I can’t provide much guidance there without your final design.
 
Last edited:

LesJones

Joined Jan 8, 2017
2,726
I will try asking the question again. What processor is the code written to run on. We can't help you if you will not answer questions. Post a schematic of your stop watch so we know what type of display you are using.

Les.
 

JohnInTX

Joined Jun 26, 2012
4,344
What should I add to this code to make the stop watch display on a 7 segment display
A LOT. The code you show
1) Waits for the Start button
2) Counts delays in an 8 bit R0, value 0-255
3) Outputs R0 to PORT P0 - complemented so that a 1 in R0 is 0 at the port to sink to turn on one of 8 LEDs presumably.
4) If you press the Stop button it resets and waits, if you don't it overflows R0 over and over.

To get a 'stopwatch' display, you would need to - for each dig:
1) convert the binary R0 to a BCD value in 3 digits up to 2 5 5
2) decode each digit to a 7 segment value
3) output that value to a 7 segment display.

If you don't have enough IO to drive 3*7=21 segments, you will have to multiplex the display. You can use a BCD-7 segment decoder to help you out or look up the segment patterns in an array indexed by the digit value for the segment outputs. The hardware can be simplified using something with built in logic like the LTM-8255. Or you can use a Dot Matrix LCD module. That will require converting the digits to ASCII (simple , just add 30H).

Lots of options but you are a long way from a stopwatch.

Good luck!
 

Attachments

Last edited:

djsfantasi

Joined Apr 11, 2010
6,962
To get a 'stopwatch' display, you would need to - for each dig:
1) convert the binary R0 to a BCD value in 3 digits up to 2 5 5
2) decode each digit to a 7 segment value
3) output that value to a 7 segment display.
I like the suggestion of using BCD to 7-segment controllers.

Are you using a microcontroller? You’ve not answered requests to identify which one.

Here are my comments regarding JohnInTxs comments.
  1. To convert to bcd, divide the counter by 10 and get the remainder. The remainder is the successive BCD value of each digit, from the least significant to most significant digit. Loop for all three digits. For example, assume the number is 147. The first divide by 10 yields a remainder of 7. The next time through. The number is 15 and dividing that by 10 yields a remainder of 4. The remaining number is 1, and we can just set the output digit to 1.
  2. I mentioned using a lookup table in code. If your using a decoder, you can output the digits. Otherwise, C code to decode each digit to 7-segments can be found here
EDIT: Corrected autocorrect
 
Last edited:
Top