Skip to main content

LED Matrix implementation with 8051 microcontroller

LED Matrix

Figure 1 shows how to interface the LED to microcontroller. As you can see the Anode is connected through a resistor to Vcc & the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.

LED dot matrices are very popular means of displaying information as it allows both static and animated text and images. Perhaps, you have encountered them at gas stations displaying the gas prices, or in the public places and alongside highways, displaying advertisements on large dot matrix panels.

Theory of LED dot matrix display

In a dot matrix display, multiple LEDs are wired together in rows and columns. This is done to minimize the number of pins required to drive them. For example, a 8×8 matrix of LEDs (shown below) would need 64 I/O pins, one for each LED pixel. By wiring all the anodes together in rows (R1 through R8), and cathodes in columns (C1 through C8), the required number of I/O pins is reduced to 16. Each LED is addressed by its row and column number. In the figure below, if R4 is pulled high and C3 is pulled low, the LED in fourth row and third column will be turned on. Characters can be displayed by fast scanning of either rows or columns. This tutorial will discuss the method of column scanning.

 
 structure of 8x8 LED matrix

How to display an image

Suppose, we want to display the alphabet A. We will first select the column C1 (which means C1 is pulled low in this case), and deselect other columns by blocking their ground paths (one way of doing that is by pulling C2 through C5 pins to logic high). Now, the first column is active, and you need to turn on the LEDs in the rows R2 through R7 of this column, which can be done by applying forward bias voltages to these rows. Next, select the column C2 (and deselect all other columns), and apply forward bias to R1 and R5, and so on. Therefore, by scanning across the column quickly (> 100 times per second), and turning on the respective LEDs in each row of that column, the persistence of vision comes in to play, and we perceive the display image as still. 


You should have noted that across each row, one pin is sourcing the current for only one LED at a time, but a column pin may have to sink the currents from more than one LED. For example, the column C1 should be able to sink the currents from 6 LEDs while displaying the alphabet ‘A’. A microcontroller’s I/O pin cannot sink this much of current, so external transistor arrays are required.

Hexadecimal values for each Alphabets:

unsigned short Alphabets[130] =

0x7e, 0×09, 0×09, 0×09, 0x7e, //A
0x7f, 0×49, 0×49, 0×49, 0×36, //B
0x3e, 0×41, 0×41, 0×41, 0×22, //C
0x7f, 0×41, 0×41,0×22, 0x1c, //D
0x7f, 0×49, 0×49, 0×49, 0×63, //E
0x7f, 0×09, 0×09, 0×09, 0×01, //F
0x3e, 0×41, 0×41, 0×49, 0x7a, //G
0x7f, 0×08, 0×08, 0×08, 0x7f, //H
0×00, 0×41, 0x7f, 0×41, 0×00, // I
0×20, 0×40, 0×41, 0x3f, 0×01, //J
0x7f, 0×08, 0×14, 0×22, 0×41, //K
0x7f, 0×40, 0×40, 0×40, 0×60, //L
0x7f, 0×02, 0×04, 0×02, 0x7f, //M
0x7f, 0×04, 0×08, 0×10, 0x7f, //N
0x3e, 0×41, 0×41, 0×41, 0x3e, //O
0x7f, 0×09, 0×09, 0×09, 0×06, //P
0x3e, 0×41, 0×51, 0×21, 0x5e, //Q
0x7f, 0×09, 0×19, 0×29, 0×46, //R
0×46, 0×49, 0×49, 0×49, 0×31, //S
0×01, 0×01, 0x7f, 0×01, 0×01, //T
0x3f, 0×40, 0×40, 0×40, 0x3f, //U
0x1f, 0×20, 0×40, 0×20, 0x1f, //V
0x3f, 0×40, 0×30, 0×40, 0x3f, //W
0×63, 0×14, 0×08, 0×14, 0×63, //X
0×07, 0×08, 0×70, 0×08, 0×07, //Y
0×61, 0×51, 0×49, 0×45, 0×43 //Z
};

Hexadecimal value for other characters:

const unsigned short characters[30]=
{
0×24, 0x2A, 0x7f, 0x2A, 0×12, // $
0×08, 0×14, 0×22, 0×41, 0×00, // <
0×41, 0×22, 0×14, 0×08, 0×00, // >
0×14, 0×14, 0×14, 0×14, 0×14, // =
0×36, 0×49, 0×55, 0×22, 0×50, // &
0×44, 0x3c, 0×04, 0x7c, 0×44, // PI
};

Code:

#include "REG52.h"

#define ROW P3
#define COL P0

sbit R1=P3^0;
sbit R2=P3^1;
sbit R3=P3^2;
sbit R4=P3^3;
sbit R5=P3^4;
sbit R6=P3^5;
sbit R7=P3^6;
sbit R8=P3^7;

sbit C1=P0^0;
sbit C2=P0^1;
sbit C3=P0^2;
sbit C4=P0^3;
sbit C5=P0^4;
sbit C6=P0^5;
sbit C7=P0^6;
sbit C8=P0^7;

long int i,j;
void main()
{

ROW=0x00;
COL=0xFF;
for(i=0;i<45000;i++);
while(1)
{
ROW=0x7C; //To display alphabet A
COL=0xFE;
for(i=0;i<20;i++);
COL=0xFF;

ROW=0x12;
COL=0xFD;
for(i=0;i<20;i++);
COL=0xFF;

ROW=0x11;
COL=0xFB;
for(i=0;i<20;i++);
COL=0xFF;

ROW=0x12;
COL=0xF7;
for(i=0;i<20;i++);
COL=0xFF;

ROW=0x7C;
COL=0xEF;
for(i=0;i<20;i++);
COL=0xFF;
}
}



Explanation of code:

- LED Matrix consists of Rows and Columns. So, hexadecimal values are encoded accordingly as shown in chart above. After writing, hexadecimal values for each character, you can display anything on LED matrix. for example, take 8x8 LED matrix where you can switch ON any LED and switch OFF other so that eyes see the character on it by the combination of ON LEDs.

In this code, Columns are made ON and after delay they are OFF so that other character can also be displayed.

Comments

Popular posts from this blog

Buzzer interface with 8051 microcontroller

Buzzer  is a electronic device that converts the electronic signal into buzzing noise, that is applied to it. It can be used as electronic bell or as quiz buzzer in many applications around us. Here, i world like to discuss the interfacing of a small buzzer with 8051 microcontroller and how different projects can be constructed. Buzzer Interfacing: This project shows the interface with AT89S52 microcontroller to a buzzer. When a push button is pressed, the buzzer will get ON and OFF ( number of times set in the code ) and then stops. Circuit Diagram: - The port P1 of the microcontroller is connected to buzzer. This type of connection is possible, if the current requirements of the buzzer is not more than 20mA. The output is in current source mode so that buzzer will turn ON when the output of the port is logic LOW. Switch is connected to port P3 which remains at logic HIGH by pull up resistor.  Code: #include "REG52.h" #define buz P1 sbit SW=P3^0; long int i; voi

Different ways to generate delays in 8051

The delay length in 8051 microcontroller depends on three factors: The crystal frequency the number of clock per machine the C compiler. The original 8051 used 1/12 of the crystal oscillator frequency as one machine cycle. In other words, each machine cycle is equal to 12 clocks period of the crystal frequency connected to X1-X2 pins of 8051. To speed up the 8051, many recent versions of the 8051 have reduced the number of clocks per machine cycle from 12 to four, or even one. The frequency for the timer is always 1/12th the frequency of the crystal attached to the 8051, regardless of the 8051 version. In other words, AT89C51, DS5000, and DS89C4x0 the duration of the time to execute an instruction varies, but they all use 1/12th of the crystal's oscillator frequency for the clock source. 8051 has two different ways to generate time delay using C programming, regardless of 8051 version. The first method is simply using Loop   program function in which Delay() function i

How to Switch OFF Citizen Calculator

You might be confused on seeing no OFF button on your calculator. Actually, these are general calculator available at low cost in the market. They process simple calculations like division, subtraction, Addition, Multiplication. But, how will you OFF that calculator having no option on them. There is always a trick which OFF them. It depends on the company calculator and their series to which they belong. I can tell you about Citizen Calculator CT-500 (as you can see in the image), how can you switch OFF it and can save battery too. If you leave calculator idle for 6-7 minutes, it will goes OFF automatically. My calculator goes OFF in 6.50 minutes from the point of leaving it idle. But, this is not the power saving trick for these types of calculator having not much backup battery. To save the power of your normal calculator, here is the trick to switch OFF it. Press ' /(divide sign)', 'x(multiply sign)', '%(percentage sign)', 'autoreplay option(