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.

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

SGH
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
Rickey,

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

### Information

#### Conversation

Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

### Recent

ananyagupta
Tue Dec 03 2019, 07:53 AM
wells
Mon Nov 25 2019, 08:25 PM
auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM

#### Online

Guests: 37, Members: 0 ...

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

Members: 38107
Forum Activity
##### Posted By ExperimenterUK
Fri Nov 29 2019, 04:24 AM
" Is it possible to interface a fingerprint scanne...
##### Posted By ilylily07
Thu Nov 28 2019, 03:50 PM
You will not find any code for an 8051 as no one w...
##### Posted By ExperimenterUK
Tue Nov 26 2019, 05:44 PM
You will not find any code for an 8051 as no one w...
##### Posted By ilylily07
Tue Nov 26 2019, 04:13 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
##### Posted By ExperimenterUK
Tue Nov 26 2019, 12:08 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
##### Posted By ilylily07
Mon Nov 25 2019, 04:38 PM
The 8051 has too little memory to do anything us...
##### Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
##### Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
##### Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
##### Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
Thanks for support,[email protected]