Discussion in "Project Help" started by    SGH    Mar 29, 2007.
Thu Mar 29 2007, 05:02 AM
Hi all, I'm newbie in microcontroller and try to write a code for 4 digit count down counter with AT89S51.

Here are portion of the code.

mov a,count1
dec a
mov count1,a
cjne a,#-1,exit_count
mov count1,#9
mov a,count2
dec a
mov count2,a
cjne a,#-1,exit_count
mov count2,#9
mov a,count3
dec a
mov count3,a
cjne a,#-1,exit_count
mov count3,#9
mov a,count4
dec a
mov count4,a
cjne a,#-1,exit_count
mov count4,#0


The problem were if I put in following value, count1 = 0, count2 = 0, count3 = 1 and count4 = 0, it dosn't display correctly as everytime the 'dec' command was execute it fill in number 9 to previous count varible.

How to fix this problem ?. One more thing, at the end of count down, it doesn't display 0000, instead it display 9990.

Thanks all.
Thu Mar 29 2007, 12:17 PM
Well making a down counter is little tricky, i mean.. its not like simple decrement you need to check and wait till all zero and then exit.
cjne a,#-1,exit_count
mov count1,#9

this will surely make count 1 = 9 coz, after you dec count1 it will become -1 from 0. so according to statement, cjne(compare and jump if not equal) it will exit only if its not equal, but here its equal so, it will execute the next statement, so 9 is loaded in count1. so u are getting that result.

I made a program, but i want you to try it first, so giving you hint, you need to decrement the last digit, untill it become zero and when it become zero decrement the second digit, keep on doing this, utill u end up with all zeros!
i hope you got some idea, how to implement it, there are lot of compare jumps to be made i think, try it, if you don't get result, i will help you
Fri Mar 30 2007, 02:12 AM
Rickey, thanks for the hint. I'll try to rewrite the code.
Sat Apr 21 2007, 03:56 PM
I'm still trying to rewrite the code. I solved one problem but create another problem in the code.

So my progress in this code is slow. It is ok for me as this is part of the learning process.

Tags learning processsghrewrite
Sat Apr 21 2007, 05:55 PM
good keep trying.. you will reach to the target soon
for any assistance i am here.
Thu May 31 2007, 03:37 AM

More hints please.

Thu May 31 2007, 05:53 AM
you first tell me what you've done.. so i can tell you.. next..

Get Social


Powered by e107 Forum System


Sat May 15 2021, 11:47 AM
Derek Wolcott
Geometric Energy Corporation announced the dogecoin-funded mission on Sunday, with DOGE-1 representing a 40 kilogram cube satellite flying as a payload on a Falcon 9 rocket.
Thu May 13 2021, 07:18 PM
Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly. https://mkfinstitute.com Trisha Trisha
Wed May 12 2021, 01:23 PM
Jed Roan
Now you can promote your site all over the internet for FREE: http://www3.listofsitesthatacceptfreeads.club
Wed May 12 2021, 08:20 AM
If some one wants to be updated with most recent technologies afterward he must be visit this web page and be up to date every day. annual credit report https://creditscoresetf.com
Wed May 12 2021, 06:11 AM
Great website. A lot of useful information here. I'm sending it to some pals ans also sharing in delicious. And of course, thanks on your effort! annual credit report https://creditscorecheckn.com



Thu Jun 25 2020, 03:46 PM
Mon Jun 22 2020, 03:03 PM
Tue Jun 16 2020, 05:10 PM
Sat Jun 13 2020, 09:43 PM
Thu May 21 2020, 12:44 PM
Thu May 21 2020, 01:28 AM
Wed May 20 2020, 07:05 PM
Wed May 20 2020, 11:52 AM


Guests: 85, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123