LEDs are great small devices that emit light, yet do not consume much energy and do not emit heat. They
can be arranged in many fashions, to produce visual effects, one of the most common arrangement is to put
them in the form of a matrix, just like key pad. So if we have a matrix of 5 columns and 7 rows we have 35
LEDs. However when put in this format they do not have 35 lines to control them, instead they are con-
trolled by 12 lines, 7 for individual row and 5 for individual columns. The LED to be lightened is controlled
by selecting a row and column, the led at its intersection will light up. Thus by selecting the rows and col-
umns, very quickly and using persistence of vision, a number of patterns and animations can be made.
In this section we will discuss briefly Microtronics 8x32
matrix LED device.
This device contains 4, 8x8 matrix LED modules, con-
nected through shift registers. The entire module therefore
has 8 rows starting from top and 32 columns starting from
left.
The data is shifted one bit at a time, using Serial Parallel Interface, which is timed by clock signals.
The columns are negative and rows are positive. Thus a logical 0 on row will lighten up the corresponding LED.
This project is an excellent guide to understanding shift registers as well. In order to send 4 bytes, they are sent serially one bit at a time, along with clock signals, when all the data has been transferred, it is still in shift registers, to show data on pins, and therefore displays, the shift regis-ters are sent a latch impulse. When one row is displayed, the data is again sent and before latching, the row counter is given a pulse, so that next row is selected. The entire process is repeated 8 times till all rows are displayed, remember when a new row is selected the previous row is deselected. Thus you can display one row at a time. After all eight rows have been scanned, the row counter is sent a reset pulse, so that row 1 is selected again. This process is repeated again and again, and at very rapid speed, so that it looks that all rows are ON at the same time.
The connector on this board is a 10 pin connector, which is compatible with PIC-Lab-II connectors. The
various pins in this connector are arranged as:
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
SER
|
CLK
|
CLR
|
LAT
|
RCLK
|
RST
|
GND
|
VCC
|
The pin numbers start from left. The function of these pins is described below:
SER is serial data in pin, which receives one bit at a time.
CLK is the clock pin, which gets impulses to accept data on SER.
CLR is for clearing the shift registers.
LAT is to latch the shift register data to output lines.
RCLK is to clock the row selection
RST is to reset the row counter.
GND and VCC are 5V power supply from motherboard.
The board can have its own power supply, in that case a jumper on board has to be selected to select the
source either Mother board or external.
Programming The Display
Programming the display board is simple. However it can get quite complex, when you want to display
animations and special effects. The display itself does not stop you from any innovation. It simply requires
that one row of data , which is 32 bits or 8 bytes be clocked into the shift register, and the appropriate row
selected using row counter.
The following prototype examples are only basic guidelines on using this display. We will be using BASIC
as programming language, and PIC microcontrollers as controlling device. You may adapt these guidelines
to your particular scenario.
We assume following connections from microcontroller to display board and define them in our program as
constants.
Device=18F452Remember, if no data is clocked to shift registers, they will be in state of 0 on their outputs, and since 0 on a
XTAL=20
ALL_DIGITAL=true
Output PORTB
Symbol SER = PORTB.0 ' Serial data Pin
Symbol SRCLK = PORTB.1 ' Serial data Clock Pin
Symbol SRClr = PORTB.2 ' Serial data Clear
Symbol Latch = PORTB.3 ' Columns, Latch
Symbol RowClk = PORTB.4 ' Row clock, to select new row
Symbol Rowrst = PORTB.5 ' Row reset, selects row 0
High SRClr ' Turn off the serial register clear
column selects it, so all columns will be selected. A logical 1 on a column will turn the column off, and a 0
will turn the column ON.
CODE:
Device=18f452The PulsOut command gives a small high pulse on the specified pin. The
XTAL=20
ALL_DIGITAL=true
Output PORTB
Input PORTA
Symbol SER = PORTB.0 ' Serial data Pin
Symbol SRCLK = PORTB.1 ' Serial data Clock Pin
Symbol SRClr = PORTB.2 ' Serial data Clear
Symbol Latch = PORTB.3 ' Columns, Latch
Symbol RowClk = PORTB.4 ' Row clock, to select new row
Symbol Rowrst = PORTB.5 ' Row reset, selects row 0
High SRClr ' Turn off the serial register clear
PulsOut Rowrst,2 ' give a pulse on row reset pin, to select row 0
SHOut SER,SRCLK,lsbfirst,[%11111110,%11111111,%11111111,%11111111] ' send data
on serial pin
PulsOut Latch,4
End
number indicates duration of pulse. 2 in this case will give a 4us pulse.
However thgis timing is not crucial for the function of display.
SHOut is the command that transmits the contents of a byte, or word, as
a stream of bits on a single pin. The arguments are the pin, on which data
is to be transmitted, the Clock pin to be used to clock the shift registers,
lsbfirst is a reserved word, indicating least significant bit first. So it will
transmit, the bit 0 of data first and bit 7 last. The numbers in square
brackets are the data to be sent. These are 4 bytes of data the first byte is sent first, from left side, the next
three bytes push the first sent byte successively to right, so at the end of all 4 bytes the first Byte has been
sent to the right most 8 columns. You can play with these four bytes to make various leds, ON. You must
have noticed that the column corresponding to 0 is turned on. So to turn the entire row ON, just send this
data:
SHOut SER,SRCLK,lsbfirst,[000000,000000,000000,000000] ' send dataon serial pin
Device=18f452
XTAL=20
ALL_DIGITAL=true
Output PORTB
Input PORTA
Symbol SER = PORTB.0 ' Serial data Pin
Symbol SRCLK = PORTB.1 ' Serial data Clock Pin
Symbol SRClr = PORTB.2 ' Serial data Clear
Symbol Latch = PORTB.3 ' Columns, Latch
Symbol RowClk = PORTB.4 ' Row clock, to select new row
Symbol Rowrst = PORTB.5 ' Row reset, selects row 0
High SRClr ' Turn off the serial register clear
PulsOut Rowrst,2 ' give a pulse on row reset pin, to select row 0
SHOut SER,SRCLK,lsbfirst,[%11111110,%11111111,%11111111,%11111111] ' send data
on serial pin
PulsOut Latch,4
End
Now lets send some pattern, to show this
effect.
SHOut SER,SRCLK,lsbfirst,[%Notice the data, being sent, and the
11111110,%10101010,%11001100,%
00011100]
appearance of ON LEDs in Fig. 8. this
clearly shows that the first byte sent, goes
to extreme right, and last byte sent goes to extreme left.
If we want to reverse the pattern , we can send Most significant bit first.
Blinking an LED
In order to make an LED Blink, you have to turn the corresponding column On, and OFF repeatedly after a
set interval.
PulsOut Rowrst,2 ' give a pulse on row reset pin, to select row 0
Loop:
SHOut SER,SRCLK,lsbfirst,[%11111110,%11111111,%11111111,%11111111] ' send data
on serial pin ON
PulsOut Latch,4
DelayMS 500
SHOut SER,SRCLK,lsbfirst,[%11111111,%11111111,%11111111,%11111111] ' send data
on serial pin OFF
PulsOut Latch,4
DelayMS 500
GoTo Loop
End
Now lets make the entire row turn ON, and then select the next row, till all 8 rows are show, one after the
other.
Dim i As Byte
Loop:
PulsOut Rowrst,2 ' give a pulse on row reset pin, to select row 0
For i=0 To 7
SHOut SER,SRCLK,lsbfirst,[000000,000000,000000,000000]
PulsOut Latch,4
DelayMS 500
PulsOut RowClk,2
Next i
GoTo Loop
This code sends all columns on data, then waits for 500ms, and then gives a short pulse on RowClk pin.
This pulse will advance the row selection to next row, and the same data is sent again. The whole process is
repeated 8 times, till the last row, number 7 is displayed. After this the row counter is reset to select row 0
and the entire process is repeated.
So far so good. Now begins the real fun. Notice that
we have made a delay of 500ms between rows. If we
reduce this time, rows will be displayed quicker,. Fine,
if we go on reducing the time, a state will reach when
our eyes will not be able to perceive the individually
on rows, rather they will see all rows ON! When in
fact, still, one row is being turned on, at a time. Try
following timings, in place of 500. begin with 500 as
in above program and then try, 300, 200, 100, 50, 20,
10, 5, 2 . A delay of 2ms will produce the best result,
you will see an absolutely flicker free display.
As shown in figure 9. All 256 LEDs appear to be ON.
When in fact one row, of 32 are on at a time. This is due to persistence of vision.
Displaying Characters
As you have seen that, you can play with these bits, to show anything you want. Text characters are
similarly not a big problem. However you will need to make a
table or list of character maps, that you will send to the display.
Most characters can be easily mapped in 5 x 7 array. However
for simplicity of our work, we will design them as an 8 x 8
matrix. Selecting this matrix, will also be helpful in making
some other more feature rich graphics. Lets see how to work Up.
We are going to design letter ‘A’.
The adjacent fig shows the character map. The numbers in gray
column, are in hexadecimal, equivalent. 1 for Off and 0 for On.
Now we can store this character in bytes of memory. EEPROM
on microcontroller is a good place to keep such maps, which
once defined, have to be read in by the program. We have used
EData command to store the codes for each row byte for the letter in EEPROM. The size of table which
can be stored will depend upon the EEPROM of your microcontroller. If a larger table is required you can
use an external EEPROM. The loop fills in the appropriate bytes of display memory by reading the
associated bitmap image from EEPROM.
The index of letters to be displayed are stored in
an array z[4]. Number 0 is for letter ‘A’ as it is
defined in position 0 in EEPROM, and number
1 is for ‘B’ as it is in position 1 in EEPROM.
Notice how the position of first byte is
calculated.
Device=18F452
XTAL=20
ALL_DIGITAL=true
Output PORTB
Input PORTE
Symbol SER = PORTB.0 ' Serial data Pin
Symbol SRCLK = PORTB.1 ' Serial data Clock Pin
Symbol SRClr = PORTB.2 ' Serial data Clear
Symbol Latch = PORTB.3 ' Columns, Latch
Symbol RowClk = PORTB.4 ' Row clock, to select new row
Symbol Rowrst = PORTB.5 ' Row reset, selects row 0
Symbol SW1=PORTE.0
Symbol SW2=PORTE.1
High SRClr ' Turn off the serial register clear
Dim s[32] As Byte
Dim i As Byte
Dim n As Byte
Dim b As Byte
Dim c As Byte
Dim z[4] As Byte
z[0]=0
z[1]=1
z[2]=1
z[3]=0
' initialize the array by writing 0 to all bits
For i=0 To 31
s[i]=$FF
Next i
For c = 0 To 3
For i= 0 To 8
b=(i*4) + c
s[b]=ERead (z[c]*8)+i
Next i
Next c
Loop:
PulsOut Rowrst,2 ' give a pulse on row reset pin, to select row 0
For i=0 To 7
n=i*4
SHOut SER,SRCLK,lsbfirst,[s[n], s[n +1], s[n+2], s[n+3]]
PulsOut Latch,4
DelayMS 1
SHOut SER,SRCLK,lsbfirst,[$FF,$FF,$FF,$FF]
PulsOut Latch,4
PulsOut RowClk,2
Next i
GoTo Loop
End
EData $E3,$DD,$DD,$DD,$c1,$DD,$DD,$DD ' A
EData $C3,$DD,$DD,$DD,$C3,$DD,$DD,$C3 ' B
As we have defined the character map as 8 bits wide, whereas our actual character is using only 5 bits.
There are 3 bits empty, 1 on right and 2 on left side of each character. If we want to ignore the highest 2
bits, and we just want to send the lowest 6 bits to the display, for each character, we can do that by just
mentioning the number of bits in Shout command. Change the Shout command like this:
SHOut SER,SRCLK,lsbfirst,[s[n]\6, s[n +1]\6, s[n+2]\6, s[n+3]\6]
Notice the \6 with every byte sent. If this is not mentioned then default, 8 bits is assumed.
No comments:
Post a Comment