Discussion in "Project Help" started by    SGH    Mar 29, 2007.
Thu Mar 29 2007, 10:32 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, 05:47 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, 07:42 am
Rickey, thanks for the hint. I'll try to rewrite the code.
Sat Apr 21 2007, 09:26 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, 11:25 pm
good keep trying.. you will reach to the target soon
for any assistance i am here.
Thu May 31 2007, 09:07 am

More hints please.

Thu May 31 2007, 11:23 am
you first tell me what you've done.. so i can tell you.. next..

Get Social


Powered by e107 Forum System



Tue May 21 2024, 02:06 am
Sun May 19 2024, 05:39 pm
Sun May 19 2024, 03:06 pm
Sun May 19 2024, 07:39 am
Sat May 18 2024, 07:28 am
Fri May 17 2024, 06:14 pm
Fri May 17 2024, 10:28 am
Fri May 17 2024, 10:19 am