UCR EE/CS120B: Digital Systems
Lab 8
Decimal Counter Using Two 7-segment displays and an 8051.
Introduction
The purpose of this lab is to implement a
decimal counter which counts from 0 to 99. You will have to write
a C program for the 80X51 micro-controller. You will then compile
your C program using C51 compiler and burn it unto an 8051 stand
alone chip. You will also have to do some wiring in this lab. The
8051 chip requires some connections to function properly, and the
7-segment displays need to be wired to the 8051. Schematics are
provided below.
Before you can write your C program, you have to understand how
the 7-segment displays work. The 7-segment displays used in the
lab are the LSD5061-11 display. Each of the segment corresponds
to a pin (see below for the pinout). In order to light up a
particular segment, it's pin must be set to 0V. Since these pins
are connected to the 8051, we simply set the corresponding pin on
the 8051 to '0'. To turn a segment off, the pin must be set to
5V. This is done by setting the corresponding pin on the 8051 to
"1".
Instead of going through each of the seven pins and setting them
to '1' or '0' each time we want to display a number, we will use
a lookup table unsigned char LookupTable[11] = { }. The
location of the entry in the table corresponds to the correct pin
settings to display that number. Simply, LookupTable[0] returns
the correct pin settings to display a "0" on the
7-segment display.
Now we have to figure out the correct entries into the table. We
know that in order to display a "0" on the 7-segment
display we need to turn on segments s1, s2, s3, s4, s5, and s6.
To turn a segment on, we set the corresponding pin to
"0". Segment s7 will need to be turned off. To turn off
this segment we set the corresponding pin to "1".
Therefore, the pins will need to be assigned the following
values:
P2^0 = 0;
P2^1 = 0;
P2^2 = 0;
P2^3 = 0;
P2^4 = 0;
P2^5 = 0;
P2^6 = 0;
P2^7 = 1;
P2^8 = 1; //don't care what this value is since it is not used. We
set it to 1 because the 8051 pins are by default 1
The bit pattern desired is 1100 0000 (remeber that pin 8 is the
highest bit). We then convert the values into hexadecimal 1100
-> C and 0000 -> 0. We fill in the table with this value
0xC0. The "0x" is needed before the actual value to
indicate to the compiler that it is a hexadecimal value. Now when
we call LookupTable[0] it will return the proper configuration to
display a "0" on the 7-segment display. You will need
to fill in the rest of the values (1-9). LookupTable[10] will
indicate an error has occured, at this location segment s7 will
be on, the remaining segments will be off.
Segment number | LSD5061-11 Pin number | 8051 pin number (One's place display) |
8051 pin number (Ten's place display) |
s1 | pin 1 | P2.0 | P3.0 |
s2 | pin 2 | P2.1 | P3.1 |
s3 | pin 4 | P2.2 | P3.2 |
s4 | pin 6 | P2.3 | P3.3 |
s5 | pin 7 | P3.4 | P2.4 |
s6 | pin 9 | P2.5 | P3.5 |
s7 | pin 10 | P2.6 | P3.6 |
Assignment
In this lab :
Apparatus Required
Schematic
Program
#pragma SMALL DB #include/* P0, P1, P2 and P3 are predefined port names and are bit addressable */ unsigned char SetDisplay(unsigned char value){ unsigned char LookupTable[11] = { 0xC0, ... }; /* check to see if "value" is in bounds, if not return an error */ if( ) { /* return appropriate value */; } else { /* return error value */; } } /* Delay function */ void delay() { int i, j; for(i=0; i<1000; i++) for(j="0;" j<100; j++) i="i" + 0; } void main(void){ unsigned char count="0;" /* value held in one's place */ while(1) { /* determine and display the one's place */ /* determine and dipslay the ten's place */ /* update the counter (remember to keep it within bounds)*/ delay(); } }
Procedure
Hardware
Software
c51 count.c
bl51 count.obj to count.omf
oh51 count.omf
copy count.hex A:\count.hex
Burning A Chip - Programmer: MP-51
Testing Your Program