• Support PF! Buy your school textbooks, materials and every day products Here!

Assembly code microprocessor 8088 for seven segment LED

  • Thread starter nsc
  • Start date
  • #1
nsc
4
0

Homework Statement


i've just started learning microprocessors, and we need to program the 7-segment LED to display numbers 0-9 in increments of 1
i'm trying to get a delay of 1second between each number (and i couldn't get it)
e.g., number 1 displays for 1 second, then number 2 displays for 1 second

Homework Equations


i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!


The Attempt at a Solution


attempt:

START:
MOV DX,0FF13H ;set 8255 mode 0
MOV AL,89H ;set port A mode 0 is output
OUT DX,AL ;set port c mode 0 is input
MOV DX,0FF10H ;output data from port A
MOV AL,00H ;copy data 01h to register AL
J1 : OUT DX,AL ;output data to port A
MOV CX,9999 ;
L1 : LOOP L1 ;time delay
INC AL
DAA
JMP J1 ;jump to label L1
 

Answers and Replies

  • #2
33,632
5,287
I formatted your code using [ code] and [ /code] (without the leading spaces) tags.

Homework Statement


i've just started learning microprocessors, and we need to program the 7-segment LED to display numbers 0-9 in increments of 1
i'm trying to get a delay of 1second between each number (and i couldn't get it)
e.g., number 1 displays for 1 second, then number 2 displays for 1 second

Homework Equations


i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!


The Attempt at a Solution


attempt:
Code:
START:	
	MOV	DX,0FF13H	;set 8255 mode 0
	MOV	AL,89H	;set port A mode 0 is output
	OUT	DX,AL		;set port c mode 0 is input
	MOV	DX,0FF10H	;output data from port A
	MOV	AL,00H		;copy data 01h to register AL
J1 :	OUT	DX,AL		;output data to port A
	MOV	CX,9999	;
L1 :	LOOP	L1		;time delay
	INC	AL
	DAA
	JMP	J1		;jump to label L1
Some of your comments are misleading or just plain wrong, which makes them unhelpful. It's very important to have good comments in assembly code, since assembly code is so arcane for people not used to it. For example, the MOV AL, 89H is apparently setting the mode of port A to input, yet the following line says "set port c mode 0 is input. In another line the instruction is MOV AL, 00h, but the comment says it is copying 01h to AL. The comments need to accurately reflect what the code is doing. If they don't, they might as well not be there.

I don't understand what you said here -
nsc said:
i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!
What does that mean?

If you need a longer time interval, you can put a larger number in CX. It's a 16-bit register, so can hold a signed value as large as 32767.
 
  • #3
nsc
4
0
the codes were originally given by the lab tutor for racing LED lights, and for the 7segment we only executed a binary code file. so the task is to create the assembly code for the 7-seg display

i noticed something wrong with the comments too like "time delay" is on the wrong line... i don't want to change them because honestly, i don't really understand the codes yet... guess i should have erased it.

at first, the tutor said to change the code to CX, 0001H to have a 1s delay
but the number just doesn't change...

anyway, i tried larger numbers but as the delay become longer as i enter a larger number (up to 40000), the delay became shorter at even larger numbers like >60000

must the numbers between 1-32767?

*thanks for editing the code, its my 1st post although i always look around the forums
 
  • #4
907
2
Yes, since 8088 is a 16-bit processor, the initial value of CX should be either up to 32767 or up to 65535 (depends on the implementation of LOOP - you'd have to check the documentation; since your test indicates that larger numbers result in shorter delays, 32767 is probably the limit.)

8088's have clock frequencies of multiple MHz, so, each pass through your "L1" loop takes less than a microsecond. You will need to do two nested loops or to make a call to the operating system.
 
  • #5
125
0
Designing a timing loop is done by adding up the clock cycles needed to run the loop's body. One cycle needs 1/processor frequency.
For decent processors the manufacturer states the cycles needed to execute each instructions. For 8088 I found it incredibly hard to find a decent reference, but this page has cycles up from 286:
http://home.comcast.net/~fbui/intel.html [Broken]

I would design the loop for 286 cycles (or invest more effort to find reference for 8088), this will give you a good estimate. After that you can measure the length of time your 0-9 show runs, and adjust accordingly if needed.

I have found one way to understand assembly: read the reference manual carefully.
(I am sorry for you having to learn assembly with that crap processor from the previous millenia. I would teach atmega if I would teach assembly.)
 
Last edited by a moderator:
  • #6
33,632
5,287
magwas said:
(I am sorry for you having to learn assembly with that crap processor from the previous millenia.
The 8088 was around only for the previous millennium, and at the very tail end at that.:biggrin:
 
  • #7
nsc
4
0
thanks for all the replies, they helped me in writing the report...which i already passed up.
anyway, i would still like to know how to do the code properly... i tried the looping, but 5 loops is needed for only a 1s delay. tested it and it worked. i want to know if theres any other way to do the delay? like a simpler way? what if i need to have a 1minute delay? thats a lot of loops!

Code:
;LED
JMP	START

START:	
	MOV	DX,0FF13H
	MOV	AL, 89H
	OUT	DX, AL
	MOV	DX, 0FF10H
	MOV	AL, 00H

J1:	
	OUT	DX, AL
	MOV	CX, 6000H

L1:	LOOP	L1
L2:	LOOP	L2
L3:	LOOP	L3
L4:	LOOP	L4
L5:	LOOP	L5

	INC	AL
	DAA
	JMP	J1
 
  • #8
125
0
You can nest the loops, and thus you need only two.
Decent processors have timer/counter units. You just tell the unit to generate an interrupt in say 1 second, and go ahed to do something meaningful.
However it is good to know how to do this type of timing. There are cases when the time delay needed is
too short to give away to timer, or you run out of resources.
 
  • #9
33,632
5,287
Your first loop (at label L1) will iterate for 6000H times, but the other loops are going to just fall through.

Just before your first loop starts, you're setting the CX register to 6000H. Each time the LOOP instruction executes it decrements CX, then executes the same LOOP instruction. When CX gets down to 0, control flows to the next instruction at label L2. However, CX is still 0, so control flows to the next instruction at label L3. And so on.

Try this instead:
Code:
	MOV	CX, 6000H
L1:	LOOP	L1

	MOV	CX, 6000H
L2:	LOOP	L2

	MOV	CX, 6000H
L3:	LOOP	L3

	MOV	CX, 6000H
L4:	LOOP	L4

	MOV	CX, 6000H
L5:	LOOP	L5
That should give you around a 5-sec. delay. Another way to do things is to put a loop inside of a loop (nested loop) rather than the sequential loops you are using.
 
  • #10
nsc
4
0
thanks, now i get what u said about the loop and the decrement. but, i tried the code on the 8088 and i don't get why the delay seem to shorten instead.

can you also show me how you would do the nested loops?
 
  • #11
33,632
5,287
thanks, now i get what u said about the loop and the decrement. but, i tried the code on the 8088 and i don't get why the delay seem to shorten instead.
Can you be clearer? What code did you try that made the loop shorten?
can you also show me how you would do the nested loops?
I think this will work.
Code:
	MOV	CX, 200H
L1:	...                        ; beginning of outer loop
             ...
             ...
             PUSH     CX
             MOV      CX, 30H

L2:         ...           ; beginning of inner (nested) loop
             ...
             ...
         
	LOOP	L2   ; end of inner loop

             POP       CX
             LOOP     L1   ; end of outer loop
The reason for the PUSH and POP instructions is that we're using the CX register for two different loop counters. So, just before the start of the inner loop, we save the current value of CX by pushing it onto the stack. Then we put a new value into CX for the inner loop.

Each time the outer loop runs, the inner loop runs 30H times. Since the outer loop runs 200H times, every instruction in the inner loop runs 6000H times.
 

Related Threads on Assembly code microprocessor 8088 for seven segment LED

  • Last Post
Replies
9
Views
10K
Replies
4
Views
646
  • Last Post
Replies
1
Views
5K
  • Last Post
Replies
6
Views
5K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
2
Views
6K
  • Last Post
Replies
9
Views
3K
  • Last Post
Replies
3
Views
9K
  • Last Post
Replies
6
Views
2K
Replies
2
Views
13K
Top