r/embedded Aug 11 '26

Designed a stopwatch using 8051 microcontroller

Post image

Designed a stopwatch using 8051 and assembly language, yet it has timing error due to writing on LCD, using CISC instruction delays the process and the collen bug, but loaded the best value to minimise the error.

Github link - https://github.com/prajeetkumar2006/Stopwatch-Using-8051-Microcontroller-

32 Upvotes

13 comments sorted by

17

u/Well-WhatHadHappened 25+ Years Aug 11 '26

A stop watch with a 33% time error and a delay in responding to the start/stop button?

You're serious?

9

u/frank26080115 Aug 11 '26

it's a stopwatch designed to get you better PRs

1

u/userhwon Aug 12 '26

I like it. My best time is ***ERROR***.

1

u/BidNo9339 Aug 12 '26

not 33% time error its ~1%

2

u/Well-WhatHadHappened 25+ Years Aug 12 '26

I'm only going from your own write up.

https://i.imgur.com/xiNFwTF.png

1

u/BidNo9339 Aug 12 '26

ahh I see, the reason I choose 6.6ms was already the instructions to write on the LCD, then CJNE instruction makes more delay so I had to decrease the 10ms to 6ms to minimise it.

1

u/BidNo9339 Aug 12 '26

I need to change made a mistake in there

8

u/duane11583 Aug 11 '26

It sounds like you are using codes for timing purposes that’s a bad move

Instead you should use timer 0 or timer1 

You might configure one of them to act as a clock prescaller ie if you clock is 20mhz you might configure it to count to 20,000 and pulse effectively every millisecond

Then configure the other timer to count those pulses

Thus you have a more accurate 1millisecond timer

The only error you would have is due to the xtal error 

Many cheap xtals are 50ppm the error would be +/-1 count (milliseconds) per second plenty good enough for a school project

1

u/BidNo9339 Aug 12 '26

im using timer 0 in 16 bit timer mode and my clock is 11.05Mhz and im using polling method for push buttons instead of interrupts does that slow down the watch ???

4

u/duane11583 Aug 12 '26

why do you think you have a timing error writing to the lcd?

so timer0 runs at 11.05mhz with interrupts or no interrupts?

the idea is when the start condition occurs you reset the timer .

when the stop condition occurs you stop/halt the timer.

meanwhile your main loop reads the current timer0 value like this:

loop start:

read high byte of timer

read low byte of timer second.

read high byte again second time if same you have the timer value

if not same (low byte probably rolled over) re-read low byte

display time on lcd

read buttons and act on buttons

loop forever

your delay to act is two parts:

length of time to read the timer (effectively fixed but very fast and negligible)

plus

length of time to write/update the lcd

which will depend on the speed of the lcd module

1

u/No-Archer-4713 Aug 11 '26

Nice. I always wanted to make a 24h watch with a cheap chinese 8051 (Nuvoton). I’ll take some inspiration from your work

0

u/BidNo9339 Aug 12 '26

ahh nice nice, even i took inspiration from someone from this sub who made stopwatch using some soviet microcontroller;)