1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Assembly code microprocessor 8088 for seven segment LED

  1. Feb 2, 2010 #1

    nsc

    User Avatar

    1. The problem statement, all variables and given/known data
    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

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


    3. 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
     
  2. jcsd
  3. Feb 3, 2010 #2

    Mark44

    Staff: Mentor

    I formatted your code using [ code] and [ /code] (without the leading spaces) tags.
    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 -
    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.
     
  4. Feb 3, 2010 #3

    nsc

    User Avatar

    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
     
  5. Feb 3, 2010 #4
    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.
     
  6. Feb 3, 2010 #5
    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: May 4, 2017
  7. Feb 3, 2010 #6

    Mark44

    Staff: Mentor

    The 8088 was around only for the previous millennium, and at the very tail end at that.:biggrin:
     
  8. Feb 11, 2010 #7

    nsc

    User Avatar

    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 (Text):


    ;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

     
     
  9. Feb 12, 2010 #8
    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.
     
  10. Feb 12, 2010 #9

    Mark44

    Staff: Mentor

    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 (Text):

        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.
     
  11. Feb 23, 2010 #10

    nsc

    User Avatar

    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?
     
  12. Feb 23, 2010 #11

    Mark44

    Staff: Mentor

    Can you be clearer? What code did you try that made the loop shorten?
    I think this will work.
    Code (Text):

        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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Assembly code microprocessor 8088 for seven segment LED
Loading...