Search code examples
cx86-16seven-segment-display

Calculating hexadecimal values for 7-segment LED on MDA-8086


I was trying to display 7-segment LED on MDA-8086 kit, but I am stuck at calculating the hexadecimal values for respective digits. I have the code with me, but I don't understand how it actually works. For example, 0 is represented by hexadecimal value 0xc0 [I guess]. I am wondering, how the values have been calculated here?

C Code for 7-segment LED display:

#include"mde8086.h"

int data[11] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x00 };

void wait(long del)
{
    while( del-- );
}

void main(void)
{
    int *data1;

    /* 8255 -1 Initialization */
    outportb( PPI1_CR, 0x80 );
    outportb( PPI1_B, 0xf0 );
    outportb( PPI1_C, 0x00 );

    //main loop
    do {
        data1 = data;
        while( *data1 != 0x00 )
        {
            outportb( PPI1_A, *data1 );
            wait(30000);
            data1++;
        }
    } while(1);
}

The output has been generated from here:

7-Segment display


Solution

  • This is about how your HW hook-up is, i.e. how the pins of the display is connected to the port and whether it requires a 0 or 1 on the port to turn on a segment.

    From your numbers it seems:

    1. The port is connected like g, f, e, d, c, b, a That is: a is LSB.

    2. The "missing" 8th bit shall always be programmed to 1, i.e. as 8 bit it will be port = 1gfedcba

    3. It takes a 0 to turn on a segment in the display.

    So

    0xc0 -> 1100.000 -> 1    1    0    0    0    0    0    0
                        ^    ^    ^    ^    ^    ^    ^    ^
                        |    |    |    |    |    |    |    |
                    unused   g    f    e    d    c    b    a
                            off  on   on   on   on   on   on
    

    which results in a zero on the display.

    Now for 0xf9

    0xf9 -> 1111.1001
    

    so only segment b and c will turn on and the display will display 1

    Check the rest yourself.

    EDIT Looking at the sigment picture, it could be that the 8th bit (that I called "unused") is actually controlling the "DP" part of the segment. This is just a guess but maybe if you write 0x40 to the port, you'll see 0. on the display.

    When you only display numbers, there are many unused combinations. Some of these look like letters, e.g. H. So for fun (aka an exercise) you can make the display spell words like "HELLO", "CACAO", "BEEF" and many more.