free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
SGH
Wed Mar 28 2007, 10:02PM
 User Offline
Registered Member #672
Joined: Tue Mar 06 2007, 10:47PM

Posts: 38
Thanked 3 times in 3 posts
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.

count_down:
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

exit_count:
ret

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.
SGH


Back to top


Ajay
Thu Mar 29 2007, 05:17AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
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

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


SGH
Thu Mar 29 2007, 07:12PM
 User Offline
Registered Member #672
Joined: Tue Mar 06 2007, 10:47PM

Posts: 38
Thanked 3 times in 3 posts
Rickey, thanks for the hint. I'll try to rewrite the code.
Back to top


SGH
Sat Apr 21 2007, 08:56AM
 User Offline
Registered Member #672
Joined: Tue Mar 06 2007, 10:47PM

Posts: 38
Thanked 3 times in 3 posts
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.


SGH
Back to top

learning process   sgh   rewrite   


Ajay
Sat Apr 21 2007, 10:55AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
good keep trying.. you will reach to the target soon
for any assistance i am here.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


SGH
Wed May 30 2007, 08:37PM
 User Offline
Registered Member #672
Joined: Tue Mar 06 2007, 10:47PM

Posts: 38
Thanked 3 times in 3 posts
Rickey,

More hints please.

Thanks,
SGH
Back to top


Ajay
Wed May 30 2007, 10:53PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
you first tell me what you've done.. so i can tell you.. next..

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems