ru

05-20-2011

Basics of LED dot matrix display. Part 2. Circuit Setup and Software

Part 1. Theory

Circuit Setup

The circuit setup for this experiment is quite simple. You need seven 330 Ω resistors in series with rows R1 through R7 to limit the current through the LEDs. Then the rows are driven by RB0 through RB6 pins of PIC18F2550. The columns are connected to the five outputs of ULN2003A. The corresponding five input pins of ULN2003A IC are controlled by RA0 through RA4 pins of PIC18F2550. The microcontroller will, therefore, scan across the column by sending appropriate bits to PORTA. For example, setting RA0 to 1 and clearing RA1 through RA4 bits, will select the first column. The microcontroller will wait for about 1 ms before switching to the next column. At each column, the microcontroller will output the corresponding row value at PORTB to turn on the appropriate LEDs in the column that are required to display the specific character. The switching between columns is fast enough to deceive the human eyes and a steady character is displayed.

Software

The major part of this experiment is the software routine to scan the columns and feed the rows with appropriate values. The column-specific row values for display characters can be either defined in RAM or stored in the program memory in case the on-board RAM is not sufficient enough. In mikroC, the variables are saved in RAM and constants are stored in program memory. So, if your PIC does not have enough RAM, you can define a constant array to store the row values so that a part of the program memory is occupied by it to free up the on-board RAM. PIC18F2550 has quite a bit of RAM (2 KB), so I have used RAM to store the row values for alphabets A through Z. Here’s how I define it in mikroC,

```unsigned short Alphabets[130]=
{
0x7e, 0x09, 0x09, 0x09, 0x7e, // A
0x7f, 0õ49, 0õ49, 0õ49, 0õ36, // B
0x3e, 0õ41, 0õ41, 0õ41, 0õ22,
0x7f, 0õ41, 0õ41, 0õ22, 0x1c,
0x7f, 0õ49, 0õ49, 0õ49, 0õ63,
0x7f, 0õ09, 0õ09, 0õ09, 0õ01,
0x3e, 0õ41, 0õ41, 0õ49, 0x7a,
0x7f, 0õ08, 0õ08, 0õ08, 0x7f,
0õ00, 0õ41, 0x7f, 0õ41, 0õ00, // I
0õ20, 0õ40, 0õ41, 0x3f, 0õ01,
0x7f, 0õ08, 0õ14, 0õ22, 0õ41,
0x7f, 0õ40, 0õ40, 0õ40, 0õ60,
0x7f, 0õ02, 0õ04, 0õ02, 0x7f,
0x7f, 0õ04, 0õ08, 0õ10, 0x7f,
0x3e, 0õ41, 0õ41, 0õ41, 0x3e,
0x7f, 0õ09, 0õ09, 0õ09, 0õ06,
0x3e, 0õ41, 0õ51, 0õ21, 0x5e,
0x7f, 0õ09, 0õ19, 0õ29, 0õ46,
0õ46, 0õ49, 0õ49, 0õ49, 0õ31, // S
0õ01, 0õ01, 0x7f, 0õ01, 0õ01,
0x3f, 0õ40, 0õ40, 0õ40, 0x3f,
0x1f, 0õ20, 0õ40, 0õ20, 0x1f,
0x3f, 0õ40, 0õ30, 0õ40, 0x3f,
0õ63, 0õ14, 0õ08, 0õ14, 0õ63,
0õ07, 0õ08, 0õ70, 0õ08, 0õ07,
0õ61, 0õ51, 0õ49, 0õ45, 0õ43 // Z
}```

And this is how mikroC allows you to store arrays in the program memory.

```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
};```

I have written a simple program in mikroC to display the alphabets A through Z sequentially, and some special characters too. You can watch the video below to see how they look like on the dot matrix display.