Sunday 29 December 2013

8051 SEVEN SEGMENT DISPLAY (SSD) INTERFACE

Seven Segment Display which is most commonly known as SSD is an output device which can be used to display information. As discussed in my previous post, it is necessary for a system to have proper input/output devices for assisting the user and SSD serves the very same purpose by displaying some useful information to the user. You can easily connect/interface it with 8051 MCU for output once you understand it properly. After reading this article, you will get to know everything about it. 


SEVEN SEGMENT DISPLAY (SSD)

It is an output device and this is how it looks like so don't get confused when you face it as you're about to get familiar with it in the most basic way. Don't worry, I will explain the output pins soon enough.

Seven Segment Display (SSD)

As you can see, it's called Seven Segment Display because it has actually got Seven Segments (that's too obvious I guess). These seven segments can be used to display different shapes but it is designed such that it's meaningful to display only numbers on it. And this is how they will actually look like


SSD Output (Numbers)

You can think of the segments as individual LEDs which can be turned ON/OFF. There you are, I just told you the working secret behind it. So when it comes down to LEDs, you already know that it looks like this

LED Symbol

And I hope you also know that it will glow ONLY when current flows from ANODE towards CATHODE. Before moving forward, you can read my article about LEDs and interfacing them to 8051 if you want to know more about them. However, let's stay focused on SSD here. SSDs are also composed of individual LEDs and work on the very same principle. So basically they come in two forms

  1. Common Anode
  2. Common Cathode
Common Cathode

Common Anode

Turning ON an LED in these scenarios is quite an easy job, right? Let's move forward then. Just for the sake of convenience, each segment of the SSD is given some name so we can easily talk about it. Here is the pin description of a standard SSD that you will have to deal with.


Pin Description of SSD

It is getting easier, right? Now I will show you how to turn ON a specific segment in both configurations. Suppose you want to enable segment 'a'

FOR COMMON CATHODE
  • Connect INPUT VOLTAGE to A
  • Connect GROUND to COMMON (either upper or lower as both are shorted) 

FOR COMMON ANODE
  • Connect INPUT VOLTAGE to COMMON
  • Connect GROUND to A

As you can see, they are opposite in operation so it's your job to know the nature of your SSD. Now don't ask me how to do it as I just explained it. I hope you've got the hold of it by now and if I'm not wrong, let me assume that you know what it is and how it works. Let's continue to more interesting things.


8051 SSD INTERFACE

Till now, you might have noticed that displaying something on the SSD is all about giving it the right type of sequence. The SSD itself is just a combination of LEDs. It's your job to know what you're doing. For instance, you have to turn ON segment 'b' and 'c' for displaying '1' (verify from above diagram). You require seven control lines to completely utilize an SSD for display i-e a, b, c, d, e, f, and g (dot is optional). As for the common pin, connect it to

  • GROUND for Common Cathode
  • 3-5V for Common Anode

For interfacing it with 8051 MCU, you can use 74LS47 IC. It is basically BCD to 7-segment Decoder/Driver which is specially designed for driving an SSD. It's function is such that it gives out the corresponding sequence for SSD when the MCU sends a number 0-9. You can find more details about the IC in it's datasheet Here is the truth table for common cathode configuration

BCD to 7-SEGMENT Decoder Truth Table 

As you can see, providing the number (0-9) as INPUT will produce the corresponding SEQUENCE at its output which is used to display that number on the SSD. However, I'm not going to use this IC for interfacing. Why complicate things by introducing some extra hardware when you can manage it through software? I am going to present an interfacing scheme for SSD which doesn't include any other component. I won't keep you waiting, here it is

8051 SSD Interface

And trust me when I say it, it's as simple as it looks. Nothing more, nothing less. I have directly connected the SSD to 8051 because the MCU don't have the 'guts' to damage it and the program code can take care of the sequences which is even more simpler! You can have a look by yourself

SSD Interface C language Code

Also have a look at the Proteus Simulation diagram (download all files from the link given below). The input at PORT1 shows 00000101 (binary) which is 5 and thus the output at SSD is also 5

Proteus Simulation Diagram

I have connected the SSD (Common Cathode) directly to PORT2 and interfaced switches to whole of PORT1 so I can provide my desired input. The hardware portion is pretty simple. Let me explain the code then.

The only tricky portion in the code is the SSD Sequence Information array that I have used. Here is how I did it.

  • SSD is Common Cathode so writing a 1 (HIGH) to any PIN will enable that segment.
  • Write down bit sequences for all numbers (in my case 0-F)  
  • Convert them into HEX

You will get the same values as above. For example, the sequence for 0 is 1111110 (binary) and thus it is 0x7E (hex). It is important to remember the bit sequence for hardware connection - in my case, it is abcdefg. You can use any combination as long as you connect it accordingly. You will be needing this sequence whenever you are working with SSD but this is only for Common Cathode Configuration. It's your assignment to generate sequence for Common Anode Configuration which is nothing but opposite values.  

I have taken advantage of the array indexes by placing the sequence of some number in that corresponding index location i-e sequence for 0 is at ssd[0], sequence for 1 is at ssd[1] and so on. When I read the input (from the four switches), I use that number as index to take that particular sequence and give it to the SSD at PORT2. This way, I can easily display the corresponding number on the SSD.

Now I think you're capable of using the Seven Segment Display according to taste. I hope you didn't face any problem following this tutorial but if you did, let me know in the comments section. I may have forgotten something. As usual, I will attach all the files that I have used in this tutorial.


This ZIP package contains the following files
  • C Language Code
  • Compiled HEX file
  • Proteus Design File
You can use all these files at your will but remember that they are for the sake of understanding the concept. You have to know what's going on and then it won't hurt if you just copy/paste but if you do it without caring about understanding, well all I can say is that it's not good for development. 


9 comments:

  1. really awesome explanation.......hatsoff

    ReplyDelete
  2. in what way u have enter unsigned char keypad[ROWS * COLUMNS] = { 0x30, 0x6D, 0x79, 0,
    0x33, 0x5B, 0x5F, 0,
    0x70, 0x7F, 0x7B, 0,
    0, 0x7E, 0, 0 };
    plz explain.What does 0x30,0x5B,0x5F,0x7B.....,hex values represent?How can i implement this using a 16x2 LCD?,What would i see on 16x2 LCD if suppose i press Key '5' or Button '5' on the Keypad?Please help me out.My name is Abhishek.You can also reply me on my Email ID:-abhishek.mane20@gmail.com

    ReplyDelete
  3. Each value represent a specific pin ON/OFF sequence for displaying numbers on the SSD. You can't use this sequence for LCD as it operates on ASCII characters.

    For a brief explanation, imagine that you need to display a number on LCD and SSD when user presses that button on keyboard. Suppose the number is 5.

    For common cathode SSD, the pin sequence for displaying 5 is 1011011 (abcdefg). That's 0x5B in HEX. So assign 0x5B to the port where SSD is attached and 5 will be displayed.

    For LCD, simply send any of these values below to the port where LCD is attached and 5 will be displayed
    '5' (directly as ASCII character)
    53 (decimal value for ASCII character 5)
    0x35 (hexadecimal value for ASCII character 5)

    ReplyDelete
  4. Super explanation....very very useful for beginners....

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete