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:
Actually, most 7-segment displays contain eight internal LED's as the eigth one is used for a decimal point, usually in one of the bottom corners of the display.
Common Anode Configuration For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Thus the various digits from 0 through 9 can be displayed using a 7-segment display as shown.
Seven-segment displays are commonly used as alphanumeric displays by logic and computer systems. A seven segment display is an arrangement of 7 LEDs (see below) that can be used to show any hex number between 0000 and 1111 by illuminating combinations of these LEDs.
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:
The port is connected like g, f, e, d, c, b, a That is: a is LSB.
The "missing" 8th bit shall always be programmed to 1, i.e. as 8 bit it will be port = 1gfedcba
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With