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
Post a Comment