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. (If you want, you can also look at the 7-segment display datasheet.)


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

  1. 330 resistors (4)
  2. 7-segment display (2)
  3. 5V power supply
  4. 8051 chip
  5. 12MHz crystal (clock)

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

  1. Wire up the circuit as shown in the schematic.
  2. Pinouts are also available:
    1. 8051
    2. 7-segment display
Software
  1. Map your network drive to P:\\Peart\cs122
  2. Run the batch file cs122.bat
  3. Create a directory for your program on the C: drive (i.e. C:\Temp\counter)
  4. Using a text editor (i.e. notepad, etc...) type in the program provided and add any necessary code to your program.
  5. Compile your program to generate object file count.obj
    	   c51 count.c
    	   
  6. Link the object file to create your executable file count.omf.
  7. 	   bl51 count.obj to count.omf
    	   
  8. Create a hex file, count.hex, used to burn your program unto the 8051 chip
               oh51 count.omf
               
  9. Copy your hex file to a floppy
               copy count.hex A:\count.hex
               
Burning A Chip - Programmer: MP-51
  1. Place the chip to be programmed on the slot making sure that the correct side is up
  2. Use the arrow keys on the keyboard to choose options
  3. Choose Type -> 51Controller -> PC89C52U
  4. Choose File -> Load and enter the pathname of your hex file (i.e. A:\counter.hex)
  5. Choose Command -> Program -> DeviceMemory -> Program Device Memory
  6. The chip will be programmed. Remove it from the chip from the socket. It is now ready to be plugged into your board.
Testing Your Program
  1. Make sure that your chip has the power and ground connections as specified by the schematic.
  2. Connect pin 9 to ground.
  3. Supply power to your board (make sure the power supply is set to 5V, if it is higher you will damage the 8051 chip.)
  4. Pulse pin 9 to power then return it to ground.
  5. Your program should now be running. Test to see if it is working correctly.
  6. If your program is not working as desired you will have to modfiy your program, then compile and download unto the chip again.