Thread Starter

sahilbh2000

Joined Sep 7, 2020
5
So we've been instructed to write an assembly language program to display numbers 0-9 on a common anode 7 Segment Display and simulate it using the Proteus Software. (8051 microcontroller) (And 0-F as well)
I'm a complete beginner in this field and was hoping that I'd get some help here from the experts.
In desperate need of help
 

Thread Starter

sahilbh2000

Joined Sep 7, 2020
5
Hey... first of all... thanks for responding..
I'll tell you the issue...
I have written a code...and it builds without any error or warnings...when I simulate it in the software...I do not get any results...
I have no clue whether there's an error in the code or if there's an error in interfacing.
Here's the code:
Code:
ORG 00H
START: MOV R1,#10
       MOV DPTR, #400H
BACK: CLR A
      MOVC A, @A+DPTR
      MOV P2,A
      ACALL DELAY
      INC DPTR
      DJNZ R1, BACK
      SJMP START
ORG 400H
    DB 7EH,30H,6DH,79H,33H,5BH,5FH,70H,7FH,7BH
        DELAY: MOV R2, #08H
        UP2: MOV R4, #0FFH
        UP1: MOV R3, #0FFH
        HERE: DJNZ R3, HERE
              DJNZ R4, UP1
              DJNZ R2, UP2
RET
END
Please check it and tell me if you can spot any error
Thanks
 
Last edited by a moderator:

Papabravo

Joined Feb 24, 2006
14,393
Hey... first of all... thanks for responding..
I'll tell you the issue...
I have written a code...and it builds without any error or warnings...when I simulate it in the software...I do not get any results...
I have no clue whether there's an error in the code or if there's an error in interfacing.
Here's the code:
ORG 00H
START: MOV R1,#10
MOV DPTR, #400H
BACK: CLR A
MOVC A, @A+DPTR
MOV P2,A
ACALL DELAY
INC DPTR
DJNZ R1, BACK
SJMP START
ORG 400H
DB 7EH,30H,6DH,79H,33H,5BH,5FH,70H,7FH,7BH
DELAY: MOV R2, #08H
UP2: MOV R4, #0FFH
UP1: MOV R3, #0FFH
HERE: DJNZ R3, HERE
DJNZ R4, UP1
DJNZ R2, UP2
RET
END
Please check it and tell me if you can spot any error
Thanks
The program looks OK. It repeatedly writes 10 bytes of data, with a delay between each write, to P2 which is connected to something. Can you elaborate on: "I do not get any results...".
Can you step through the simulation, one instruction at a time?
 

Thread Starter

sahilbh2000

Joined Sep 7, 2020
5
The program looks OK. I repeatedly writes 10 bytes of data to P2 which is connected to something. Can you elaborate on: "I do not get any results...".
Can you step through the simulation, one instruction at a time?
I've attached a few screenshots of the interfacing with the 8051 Microcontroller and the Common Anode 7 Segment Display.
Please check the interfacing.
As you can see, there's total gibberish on the display.
 

Attachments

Hey.. First rule . Write comments. especially for assy language.

You might start in really baby steps like turn on one segment or turn on all segments.

Where are the current limiting resistors.

Does the port have enough drive to drive the displays (assuming 10-20 mA) per segment.

Bet you need a transistor or seven and 14 resistors.

You can even leave the processor out of the equation first, but make certain your signals simulated are what the port can supply.
 
You won't get any where the way your going.

Code:
ORG 00H
START:                MOV R1,#10                        ; some comment
                            MOV DPTR, #400H             ; another comment
I used [code]program[/code] tags to enclose the code segment. You will get scroll bars too.

Well, it's supposed to work
 

Thread Starter

sahilbh2000

Joined Sep 7, 2020
5
Hey.. First rule . Write comments. especially for assy language.

You might start in really baby steps like turn on one segment or turn on all segments.

Where are the current limiting resistors.

Does the port have enough drive to drive the displays (assuming 10-20 mA) per segment.

Bet you need a transistor or seven and 14 resistors.

You can even leave the processor out of the equation first, but make certain your signals simulated are what the port can supply.
Hey...thanks for responding.
Now per se this is simply a college assignment to me. I've been trying to run this code for the past 2 days now. I looked everywhere on the web but couldn't find anything. No offense to anyone on this on forum but I'm really not into writing codes and really don't see myself working in this field in the future. As I said this is simply a college assignment to me that I want to get through.

Now to answer your other question about adding resistors,
Well I ran the same code for a Common Cathode 7 Segment Display (with the change in hex codes ofcourse) and it simulated fine. hence, I don't see the need for resistors here. The problem arises when I try to use the common anode display.
I really need your help here as the assignment is due soon :)
 
I looked here https://technobyte.org/ports-8051-functions-specifications-four/ and the ports are not created equal.

https://www.tutorialspoint.com/microprocessor/microcontrollers_8051_input_output_ports.htm here say open drain and can sink 10 mA, so you still need to limit the current.

So, you have to size a transistor or logic FET to switch.

So, basically an NPN transistor on each segment. use the max value of Vd. e.g 2.1 V, and VCE(sat) of whatever (usually 0.6V)
So R<= (5-2.1-0.6)/10mA; if the segments are 10 mA, V_Led=2.1V and Vce(sat) 0.6V.

10mA is pushing the limits.

The ports can only sink current, so you have to futz with that. Use the DC current gain and make Ib about 10x what's required/
Have your port "take away" base current with the open drain. So, you have 5v applied to a series resistor and have the open drain, kill the base current. A 2n3904 to sink the segment current is probably fine.

So, you need a base resistor and a LED current limiting resistor. Use the Open drain to take away base current.

if all ports are inputs, then all segments should be on.

Simulation doesn't always work. Sometimes stuff will work in simulation without a power supply. Components don;t burn out in simulation either.

I had to do a similar project in my courses back in the 1980's. We had to use a motorola 6800. The board was designed for us.
It had a hex keypad and 4 digits. We had to enter the hex digits to the display and scan the keyboard. This is considerably more difficult. Inter-digit blanking comes into play.

I also did the layout for a digital clock at a Hewlett-Packard Explorer's post for an MM5314? clock chip. Inter-digit blanking was not done.



I computerized a Gantry crane back in the 1980's using an RCA 1802 processor. The entire program was compiled by hand.
the 1802 had no gosub or return instruction, instead any register could be the program counter. That was plain silly. The first routines, I wrote were gosub and return routines. I needed one more input because the loading dock had to stop at a slightly different position for load and unload.

Later, I did the same thing using BASIC and was able to move both gantries at the same time.

Since the right hand (my client) and left hand (me) didn't know what each was doing, there were changes made that i was unaware of.
1. The logic of the dock switches were different.
2. A coiled cord was replaced with a sliding contact, so the crane could move slightly up/down.
We changed to a potentiometer limits, but I used it as a comparitor and not a servo.

Things I did know about:
1. Potentiometer feedback
2. load/unload was a switch that sensed if cargo was present.

Comments in your code will help a LOT. Like a whole bunch.
 
Last edited:

Thread Starter

sahilbh2000

Joined Sep 7, 2020
5
I looked here https://technobyte.org/ports-8051-functions-specifications-four/ and the ports are not created equal.

https://www.tutorialspoint.com/microprocessor/microcontrollers_8051_input_output_ports.htm here say open drain and can sink 10 mA, so you still need to limit the current.

So, you have to size a transistor or logic FET to switch.

So, basically an NPN transistor on each segment. use the max value of Vd. e.g 2.1 V, and VCE(sat) of whatever (usually 0.6V)
So R<= (5-2.1-0.6)/10mA; if the segments are 10 mA, V_Led=2.1V and Vce(sat) 0.6V.

10mA is pushing the limits.

The ports can only sink current, so you have to futz with that. Use the DC current gain and make Ib about 10x what's required/
Have your port "take away" base current with the open drain. So, you have 5v applied to a series resistor and have the open drain, kill the base current. A 2n3904 to sink the segment current is probably fine.

So, you need a base resistor and a LED current limiting resistor. Use the Open drain to take away base current.

if all ports are inputs, then all segments should be on.

Simulation doesn't always work. Sometimes stuff will work in simulation without a power supply. Components don;t burn out in simulation either.

I had to do a similar project in my courses back in the 1980's. We had to use a motorola 6800. The board was designed for us.
It had a hex keypad and 4 digits. We had to enter the hex digits to the display and scan the keyboard. This is considerably more difficult. Inter-digit blanking comes into play.

I also did the layout for a digital clock at a Hewlett-Packard Explorer's post for an MM5314? clock chip. Inter-digit blanking was not done.



I computerized a Gantry crane back in the 1980's using an RCA 1802 processor. The entire program was compiled by hand.
the 1802 had no gosub or return instruction, instead any register could be the program counter. That was plain silly. The first routines, I wrote were gosub and return routines. I needed one more input because the loading dock had to stop at a slightly different position for load and unload.

Later, I did the same thing using BASIC and was able to move both gantries at the same time.

Since the right hand (my client) and left hand (me) didn't know what each was doing, there were changes made that i was unaware of.
1. The logic of the dock switches were different.
2. A coiled cord was replaced with a sliding contact, so the crane could move slightly up/down.
We changed to a potentiometer limits, but I used it as a comparitor and not a servo.

Things I did know about:
1. Potentiometer feedback
2. load/unload was a switch that sensed if cargo was present.

Comments will help a LOT. Like a whole bunch.
Thank you so much dude...that really helped a lot. And yes, I will remember the comments thing in the future. Sorry for the trouble :)
 
If you delay your port configuration for say 5 seconds, you get a new "feature". A display test.

Start with the data sheets and know what your connecting too and what the limitations are.

When I grew up, everything was TTL or ECL. Although, I was around the RTL ERA.

None of this multiple personalities for ports and no relativeley high level functions on the chip. The 8051 has been around for a long time.
 

Papabravo

Joined Feb 24, 2006
14,393
Why are there no other connections to the processor. How about a crystal and a reset circuit. How about the EA pin, don't you have to set that to a defined value?
 

djsfantasi

Joined Apr 11, 2010
6,792
Hey...thanks for responding.
Now per se this is simply a college assignment to me. I've been trying to run this code for the past 2 days now. I looked everywhere on the web but couldn't find anything. No offense to anyone on this on forum but I'm really not into writing codes and really don't see myself working in this field in the future. As I said this is simply a college assignment to me that I want to get through.

Now to answer your other question about adding resistors,
Well I ran the same code for a Common Cathode 7 Segment Display (with the change in hex codes ofcourse) and it simulated fine. hence, I don't see the need for resistors here. The problem arises when I try to use the common anode display.
I really need your help here as the assignment is due soon :)
If the code works for a common cathode display, you have to invert the output for a common anode display.

In common cathode, without a driver transistor, you have to supply a 1 to turn a segment on. With common anode, you have to supply a 0!

It looks like the first output is a 7EH. If you invert the bits, the value becomes 81H.

Try changing just one value and see what happens.
 

sagor

Joined Mar 10, 2019
248
Your first picture of the sim shows a hex 33 on Port2, which is defined in your data at 400. So, you are outputting something that you defined. Second picture (Capture2) shows hex 5B, which is the next character in your data table.
If you are not getting the display you expect, then it is possible your data is not defined properly, or you might have something not wired as expected. Start with one digit first, like Zero. Define which segments have to light up, then trace back to which pins on Port2 have to be active to trigger those LED segments (regardless of interfacing or buffering)
 

kaindub

Joined Oct 28, 2019
24
I guessed from your first post it was a college assignment.
I am surprised that you seem to not understand the basic concepts of what you are studying.
Your teacher would not have given you this assignment if the basic material had not been covered in class.
My suggestion is to approach your teacher or tutor to go over the basic concepts. It’s no shame.
And the purpose of an assignment is to reinforce what you have learnt. Whilst its tempting and convenient to have this forum give you the solution, unless you understand the basics you’re going to be coming back here again and again.
Remember that at the end of the course you need pass an exam where you will nit have the benefit o& this forum.
 
So we've been instructed to write an assembly language program to display numbers 0-9 on a common anode 7 Segment Display and simulate it using the Proteus Software. (8051 microcontroller) (And 0-F as well)
I'm a complete beginner in this field and was hoping that I'd get some help here from the experts.
In desperate need of help
Make life easy for yourself. Acquire an old 74LS47 TTL 7-Segment Decoder/Driver chip (https://www.futurlec.com/74LS/74LS47pr.shtml) and instead output a 4 bit BCD code from your C-51 directly to the decoder/driver and your pretty much done. The outputs of the 74LS47 will sink 24mA and should be able to drive most 7-segment LED displays. If your teacher is an old digital engineer he'll likely be impressed.
 
Top