Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Up down counter on using 8051 Microcintroller

Not open for further replies.


Newbie level 5
Aug 25, 2009
Reaction score
Trophy points
Activity points
Hi, I need to implement an up down counter on DS5000 board. Whne DIP34 is in up pos, with each INT1 the counter should increment and with DIP34 in down pos with each INT1 press it should decrement.

Can you explain what triggers the interrupt? Is it a push of a switch? Where is the interrupt routine?

A schematic diagram would help, along with all of your code, Post it all, you will get lots of responses,

Pallavipatil said:
Whne DIP34 is in up pos, with each INT1 the counter should increment and with DIP34 in down pos with each INT1 press it should decrement. I'm completely new to asm code.

What is UP? What is down? Without a schematic it's really hard to see what you are trying to do. When the switch is down, is it connected to GND? What happens when the switch is UP? Connected to 5V or left floating? Is there a pullup resistor on the switches? Which microcontroller are you using, DS5000? How do you program it? Did you set the partition?

If you can edit your post and this time select Code tags, paste the code between the tags, it will make it easier to read, allowing more people to look at your code and possibly help you to solve your problem.

Actually i dony know how it wrks internally.

this should get you started (you see what I mean about using code tags)
;the following ASSumes that when Int1 is pressed,
;the pin is brought low (grounded)
;also ASSumes that both P34 and P36 switches are low when UP

Int1	equ	p3.2 ;not sure about this one since there is no schematic
P34	equ	p3.4
P36	equ	p3.6
count	equ	08h
;here you can either check P36 or check Int1
;don't do anything if P36 is down
;I checked it below
	jb	Int1,Main	;loop until INT1 is pressed
				;change to jnb if switch is high when on

;if it is pressed, wait until it is released

	lcall	Delay50mS	;need this for debouncing

;do a google search on "switch debouncing"

	jnb	Int1,Main1	;here we wait until the switch is released
				;change to jb if switch is high when on
	jb	P36,Main	;P36 off, function disabled
				;change to jnb if switch is high when on

	jb	P34,Down	;P34 high, decrement counter, else increment counter
				;change to jnb if switch is high when on
;here you increment counter
	inc	count
	mov	a,count
	cjne	a,#100,UP_Exit
	mov	count,#0

;go write the value of count to LED here

	sjmp	main		;go wait for Int1 to be pressed again
	mov	a,count		;check if count = 0
	jz	restore_count	;if it is, restore it
	dec	count			;else decrement	
	sjmp	Down_Exit

	mov	count,#100

;go write the value of count to LED here
	sjmp	main		;go wait for Int1 to be pressed again

Now I am all for helping people, but I won't do it all for you. You have to learn on your own.

The right way would be to use interrupts. But since you are new at this, it can be confusing, which is why I did not try to explain it.

For the delay, you will need to figure that one out on your own.

LEARN to use the 8051 simulator!! STOP whatever you are doing right now and DO whatever it takes to learn how to use it. Buy a simulator program if you have to!
(there are lots of free simulators available, but for $20 you can get a decent one) I use simulator 2003 myself.

The simulator allows you to see what is happening, what the values of each register are, and much more, in a step by step process. You can also check timing delays down to the microsecond. It's a valuable tool.

When I was learning 8051, I never started to make progress until I learned how to use the simulator!! I then kicked myself for having wasted years without it!

Also remember that with a DS5000, how you program the chip has a lot to do with whether or not your code will work or not. You can partition the chip to separate rom from external ram, wherever you choose in the memory. If you are not partitioning the chip, you have nothing to worry about (I am basing this on the code you posted above).

Best of Luck

Pallavipatil said:
Hello, Sorry to bother you again, but I tried with your code also but the display doesn't work. It seems to be working fine in the debug mode. What could the problem be?
I have to assume that you copied my code to your asm file. Before writing the counter value to the display you should copy the register "count" to the accumulator like so:
mov a,count
then call the routine that writes the display.

Good Luck

No actually I've moved the count value to accumulator before displaying on LEDs. Don't know what the problem is.

You have two extra end directives in your code. With the assembler I am using, the code won't assemble unless these are removed.

Can you post your hex file here between code tags? Click on "Code" under the subject when you are replying. Paste your hex file. Then click "Code" again.

If my hunch is correct, your hex file will have nothing in it!
Something like this:

Not open for further replies.

Part and Inventory Search

Welcome to