adding all digits in a number, MCU 8051

Status
Not open for further replies.
Yes, I have seen that. But my OS is Windows XP Professional so perhaps in that error message 'millennium' refers to something else or MCU 8051 IDE has failed to identify the system correctly.

Regards
PG
 
I have been trawling through the net... It appears that the TCL library IS the fault.... However the only fixes on the net are for linux based builds.

I have been trying to find the location of the library so I can send you a copy of mine... you could then delete it and replace it with a working one.

If you want to help find it, all the info is on wiki..https://en.wikipedia.org/wiki/Tcllib... Its somewhere on your computer and its corrupt..

Just on a side note..

if you go to "Documents and settings\ian\mcu8051ide\" (obviously it won't be "ian" on your computer)

There are three configuration files... try deleting these three files
 
Last edited:

It's really very kind of you. I'm much obliged.

I have deleted those files but the issue is still there. And I noticed the word "TCL" in that error and searched about it. I even installed **broken link removed** package but it didn't do any good so I uninstalled it.

With best wishes
PG
 
Last edited:
Hi

Today I created a new user account to see if I could run MCU IDE from there. I wanted to do this because in the past I also encountered a similar issue with a C++ compiler and was able to run it in a secondary account (additionally I was also able to run virtual USB version of that compiler). And the trick worked this time too and I was able to run MCU there. I have also created a virtual version of MCU which runs from a USB drive but the virtual version also didn't work in my main account. Although it's not complete solution, I can still use MCU by switching user accounts. Thank you for being there to help me.

Regards
PG
 
Last edited:
Good trick.... That means there is something else in the user documents that is corrupt... I'll keep looking.

Well done... Others will find this helpfull.
 
Hi

Could you please help me with the code below? How can we write it otherwise without sacrificing simplicity? How do I interface a keypad and 7-segment display? Please have a look on the attachment. Thank you.

Regards
PG

Code:
; Interface a numeric keypad to PORT 1 and display the entered decimal digits
; ,1-9, on a 7-segment display connected to PORT 2

org 0x0

	Repeat:
	mov P1, #0x0FF	;Port 1 is not an input port
	mov A, P1	;the contents of P1 are moved into A
	
	CJNE A, #1, DigitIz2 ;if A=1, then this would mean entered digit was "1"
	mov P1, #1	  ;this will diplay "1" on 7-segment display
	SJMP Repeat	 ;execution of the program repeats
	
	DigitIz2:
	CJNE A, #2, DigitIz3
	mov P1, #2
	SJMP Repeat

	DigitIz3:
	CJNE A, #3, DigitIz4
	mov P1, #3
	SJMP Repeat

	DigitIz4:
	CJNE A, #4, DigitIz5
	mov P1, #4
	SJMP Repeat

	DigitIz5:
	CJNE A, #5, DigitIz6
	mov P1, #5
	SJMP Repeat

	DigitIz6:
	CJNE A, #6, DigitIz7
	mov P1, #6
	SJMP Repeat

	DigitIz7:
	CJNE A, #7, DigitIz8
	mov P1, #7
	SJMP Repeat

	DigitIz8:
	CJNE A, #8, DigitIz9
	mov P1, #8
	SJMP Repeat

	DigitIz9:
	CJNE A, #9, DigitIz0  ;here digit "0" stands for an error
	mov P1, #9
	SJMP Repeat

	DigitIz0:
	mov P1, #0
	SJMP Repeat

end
 
A keypad is usually read in a loop:-

..... start loop ...... set columns..... read rows...... if key return..... else add no of columns and start again....
 
Sorry, there was an error in the code in my last post. I want to do this code in the context of MCU IDE where I don't think either keypad or 7-segment display need any kind of programming. Could you please guide me with it? It's not urgent. Thank you

Code:
; Interface a numeric keypad to PORT 0 and display the entered decimal digits
; ,1-9, on a 7-segment display connected to PORT 1

org 0x0

	Repeat:
	mov P0, #0x0FF	;Port 1 is not an input port
	mov A, P1	;the contents of P1 are moved into A
	
	CJNE A, #1, DigitIz2 ;if A=1, then this would mean entered digit was "1"
	mov P1, #1	  ;this will diplay "1" on 7-segment display
	SJMP Repeat	 ;execution of the program repeats
	
	DigitIz2:
	CJNE A, #2, DigitIz3
	mov P1, #2
	SJMP Repeat

	DigitIz3:
	CJNE A, #3, DigitIz4
	mov P1, #3
	SJMP Repeat

	DigitIz4:
	CJNE A, #4, DigitIz5
	mov P1, #4
	SJMP Repeat

	DigitIz5:
	CJNE A, #5, DigitIz6
	mov P1, #5
	SJMP Repeat

	DigitIz6:
	CJNE A, #6, DigitIz7
	mov P1, #6
	SJMP Repeat

	DigitIz7:
	CJNE A, #7, DigitIz8
	mov P1, #7
	SJMP Repeat

	DigitIz8:
	CJNE A, #8, DigitIz9
	mov P1, #8
	SJMP Repeat

	DigitIz9:
	CJNE A, #9, DigitIz0  ;here digit "0" stands for an error
	mov P1, #9
	SJMP Repeat

	DigitIz0:
	mov P1, #0
	SJMP Repeat

end
 
Hi Rogers

I have checked it and am sure that the keypad and 7-segment display don't need any kind of programming in MCU IDE. I have just noticed that the segments of 7-segment display need LOW voltage in order to get activated. For example, in the linked video you can notice that all the segments turn on when "0" is moved into the Port 1 at the end of the code. I think there is some problem with the code and the code doesn't read the keypad's input. This time as you can see I have used simple keypad instead of matrix keypad. Now please help me. Thank you.

Video: https://www.youtube.com/watch?v=8IsqWjMUaMQ

Regards
PG
 
Last edited:
Hi Rogers

I have fixed the code and it works. Will upload the new code and a video soon. Thank you.

Regards
PG
 
Hi

I have attached the project file; you can open it in MCU IDE. As you can see I was only able to display digits up to "8" because there are only eight switches on the keypad. Let me know if you have any suggestion. Thank you.

Video: https://www.youtube.com/watch?v=ivz0hWWivxw

Regards
PG
 
Last edited:
Hi Rogers

I hope you will check it soon; I mean in next two or three weeks! Just kidding. I understand that you could be busy and didn't have much time. Whenever you give it a look, do let me if you have any suggestion. Thanks.

Best wishes
PG
 
Sorry.. I didn't know you were waiting for a response...... you can always use the switches as a binary input... that way you could have 0 to 255 input
 
Hi Rogers

To make a port input one, we need to write 1's to it. How do we configure it as an output port? By writing 0's to it? Please let me know. Thank you.

Regards
PG
 
By the nature of the pin circuitry, the outputs are latched when a 1 or 0 is written to the pin... If you write a 1 to the pin, the fet is off therefore the pullup circuitry show a 1 on the pin

If a 0 is written then the fet is on and a 0 is shown on the pin... Contention occurs when you write a 0 to the pin and then you input a 1... For that reason you MUST make sure the latches are all set BEFORE you read a 1 on the pin... The circuitry is based on the D type Flipflop, the read buffers are simple switches, and output control is a fet.
 
There is no special "input" or "output" mode. The 8051 ports are not to be thought of in that way. They are not a tri-state port like PIC ports.

When a 1 is written to a pin, it can function as either input or output. Write instructions treat it as an output while read instructions treat it as an input.

When a 0 is written to a pin, the output driver is turned on, which pulls the pin down to the GND pin. The pin can only function as an output in this mode as there is no way to externally pull a pin high that has been pulled low internally.

PIC microcontrollers have tri-state IO ports that have full push pull outputs and you can turn both output drivers completely off, placing the pin in a high impedance state so that it can operate as an input port. However, 8051 ports are not full push pull. They use weak internal pull ups so there is no need to switch both output drivers off for the pin to function as an input.
 
Last edited:
Just a comment:

Your original problem could have been approached as follows.
Use essentially an array of bytes. You can null terminate or have the structure contain the length first.
ASCII(48) is a '0' and ASCII(48+n) is really the ascii character of the digit n. e.g. 48 = '0', 49 = '1'
So your code becomes something like: (Yea, I know your doing assembly, but this is pseudocode)
sum=0
for i = 1 to len(A$)
Check validity of A$(i); i.e. ISDIGIT
sum=sum+A$(i)-48; changes the character to a number
next i
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…