Information Technology Reference
In-Depth Information
16.6.11
Binary coded decimal (BCD) is used mainly in decimal displays and is equivalent
to the decimal system where a 4-bit code represents each decimal number. The
first 4 bits represent the units, the next 4 the tens, and so on. Write a program that
outputs to the parallel port a BCD sequence with a 1-second delay between
changes. A sample BCD table is given in Table 16.3. The output should count
from 0 to 99.
Hint : One possible implementation is to use two variables to represent the units
and tens. These would then be used in a nested loop. The resultant output value
will then be (tens << 4)+units . An outline of the loop code is given next.
for (tens=0;tens<10;tens++)
for (units=0;units<10;units++)
{
}
Table 16.3 BCD conversion
Digit
BCD
00
01
02
03
04
05
06
07
08
09
10
11
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00010000
00010001
.
.
.
.
.
.
97
98
99
10010111
10011000
10011001
16.6.12
Write a program which interfaces to a 7-segment display and displays an incre-
mented value every second. Each of the segments should be driven from one of
the data lines on the parallel port. For example:
G
V l e
gm t
H x
F
E
A B C D E F
G value
0 1 1 1 0 1 1 1 77h
D
1 0 0 1 0 0 1 0 12h
B
C
2 1 1 0 1 0 1 1 6Bh
:
:
:
9 0 0 1 1 1 1 1 1Fh
A
Two ways of implementing this is either to determine the logic for each segment
or to have a basic look-up table, such as:
 
Search WWH ::




Custom Search