|
NOTE: Although the SLED4C display modules are no longer available, we are leaving this project online for students & hobbyists. The SLED4C display used the MC14489B display driver IC. The MC14489B display driver ICs' are still available from several sources. If you build this project, you will also need to acquire the MC14489B IC and build your own LED display. |
||||||||||||||
|
If you've ever used a serial LCD with your BASIC Stamp projects, then you know how convenient they are. LCDs are great, but almost impossible to see from a few feet away. If the LCD is exposed to direct sunlight or bright ambient light, even tougher. This is when a 7-segment LED display really shines. The SLED4C offers the convenience of serial control with a bright and easy to see display in any lighting condition.
The 20K potentiometer shown above in figure #1 is optional, and may be replaced with a CDS photocell, a fixed resistor, or eliminated altogether. A photocell will react to changes in ambient lighting, and automatically dim the display in darkness, or brighten it in daylight. If you don't need automatic display brightness control, simply leave pin #1 un-connected or use the equation below to calculate a fixed resistor value for your preferred brightness level. The SLED4C has an onboard 10K 1% resistor to set the default display brightness to an acceptable level under most normal indoor lighting conditions. To change this, place a resistor from ground to pin #1 on the SLED4C. This will place the external resistor in parallel to the onboard 10K resistor. The SLED4C uses a 4-digit common cathode Super RED 7-segment display module. Care should be taken to not exceed 25mA per LED segment to avoid damaging the LED display. We recommend the use of a potentiometer or CDS photocell, but the equation below will aid in selecting a fixed value resistor if required. Example: To set the SLED4C peak LED segment current value to ~18mA, use a 2K 1% resistor connected between ground and pin #1 for an Rt (resistance total) value of ~1.6K. Note: When placing an external display intensity control resistor between the display pin #1 and ground, the external resistor will be in parallel with the onboard SLED4C 10K 1% Rx resistor. The following equation may be used to determine the total parallel resistance. Rt = Parallel
resistance total Rt = R1 x R2 /
R1 + R2. To set the approximate maximum current at 18mA per segment, use an
external resistor value of 2K.
This project is a collection of useful sub-routines showing how to use the BASIC Stamp2 to cycle through several display test utilities. These examples include the following sub-routines.
From these simple test sub-routines you'll get an idea of how to control the various display segments, use the power-down feature, display simple text messages, and switch between different modes.
How It Works: We recommend you download the SLED4C display datasheet located HERE to follow along with the explanations below. The datasheet covers a few additional details not shown on this page.
As shown above in figure #4, the 4-digit common cathode LED clock display module is wired to the display controller a, b, c, d, e, f, g and dp cathode drivers. The leftmost LED digit is labeled #5. The rightmost LED digit is labeled #2. LED digits 5 through 2 are controlled by the anode "bank" drivers. The bank 1 anode driver controls the clock display colon (labeled L1 and L2), and the third upper right-hand decimal point LED labeled L3. Writing data to the leftmost LED digit (Bank 5) requires sending code to the display register for the Bank 5 digit position. Writing data for display on the rightmost LED digit or Bank 2, we send data for Bank 2. The colon LEDs and upper right hand decimal point LED labeled L3 are turned ON or OFF by writing data to the Bank 1 register. Here's how it works. The Configuration Register The configuration register requires a single byte value to configure the decode mode, and control the power-down/normal power modes. The decode mode for each bank driver determines how data will be displayed on each digit of the LED display. Example: If the display driver IC receives a hex value of $A for display on the LED digit connected to Bank 5, and Bank 5 is in HEX decode mode, then the LED connected to Bank 5 will display the capital letter A. If the display driver receives a hex value of $A for Bank 5, and Bank 5 is configured for "special decode" mode, then the LED digit connected to Bank 5 will display the special character which is the capital letter U. The chart in the datasheet HERE shows the characters for all three decode modes. This byte sized configuration value has to be sent to the SLED4C before sending data to the display register. This configuration byte consists of 7 bits of decode mode data + 1 bit to control the display power-down or normal power mode. Refer to figure #5 below for details. Refer to the datasheet for the different decode modes, and characters associated with each mode.
You will notice how the configuration byte is loaded with the correct configuration bits in the code example below. Depending on the data we want to display, we need to first configure the display to decode data as expected for each bank before sending the data to be displayed. Look at the short example below while referring to figure #5 above. Look in the LampTest sub-routine below to see how changing the LSB of the control byte is used to toggle the display ON and OFF by switching between power-down & normal power modes. Note: Something else you may find interesting about the power-down mode is that whatever data was displayed on the LEDs at the time you entered power-down mode, will be restored when you return to normal power mode. This is a really neat feature of the SLED4C display. It maintains the contents of the Display Register and restores the display to the same state on return to normal power mode. You'll see how this works also in the LampTest routine. We power-down the display, then power-up, and the LampTest data with all digits ON is still shown. The Display Register After sending the configuration byte, the display is ready to receive & decode data for display. The Display Register is 24 bits wide. Data is sent to the display MSB first. We use the BASIC Stamp SHIFTOUT command to send all data to the display MSB first. You must send all 24 bits when sending data to the display register. Sending only 8 bits, the display assumes the data is for the configuration register. Sending 24 bits, the display knows the data received is for the display register. If you refer to the SLED4C datasheet you'll see the MSB bits D23, D22, D21 and D20 are used for control of the display brightness, and for control of the 7-segment display DP's or decimal points. Bit D23 sets the display brightness. If bit D23 = 0 then the display brightness will be set to approximately 50% of the value determined by the Rx resistor. If bit D23 = 1, then the display will be at 100% brightness. Again, as set by the Rx resistor. This single bit in the 24-bit data stream controls the LED brightness. If you refer to the OUCH sub-routine in the example below, you'll see something like this. Note that the code snippet below is out of context, and only presented here for a quick example;
Y = %00001000 ' Set Y bit 3 for toggling
brightness, all DP's OFF
Notice from the code example above that
even if even though we have assigned an 8-bit value to variable Y, that only
the lower 4-bits of this byte value are shifted out. This is because we're
instructing the
Special Note: The data and clock lines may be shared on a common serial bus. What this means is that several of the SLED4C displays can share the same data and clock lines. To address or control a particular display you only need to connect the "enable" pin for each additional display module to another Stamp I/O-pin, and wire the additional display clock & data pins directly into the first display clock and data pins. Pretty cool feature. Only "1" single I/O-pin is required for each additional 4-digit LED display module you string onto the bus. They all share the same a "common" communications data & clock bus line.
Note: The display test routines shown below should work equally well on any BS2 series Stamp. Simply change the header to indicate the version you're using. The BASIC Stamp Code: '{$STAMP BS2p}
'{$PBASIC 2.5}
'****************************************************************
'* Name : SLED4_2.BSp *
'* Author : Bruce Reynolds *
'* Version : 1.0 *
'* Notes : These are a collection of routines for exercising *
'* : the SLED4C serial LED display with the BASIC Stamp*
'* : These should work equally well on any BS2 series *
'****************************************************************
'Pin assignments
'---------------------------------------------------------------------------------------
EN PIN 0 ' Connect to SLED4C enable pin #5
CLK PIN 2 ' Connect to SLED4C clock pin #4
DOUT PIN 3 ' Connect to SLED4C data pin #3
'Variables
'---------------------------------------------------------------------------------------
X VAR Word ' GP var
Y VAR Byte ' GP var
' Bank #1 controls the colon ":"
D2 VAR Byte ' SLED4C bank #2 digit (right)
D3 VAR Byte ' SLED4C bank #3
D4 VAR Byte ' SLED4C bank #4
D5 VAR Byte ' SLED4C bank #5 digit (left)
CFG VAR Byte ' Holds display configuration value
'Initialization
'---------------------------------------------------------------------------------------
DIRL = 255
CFGN CON %11000001
'Main program
'---------------------------------------------------------------------------------------
Main:
GOSUB Counter2 ' Count from 0 to 1000
GOSUB LampTest ' Lamp test with 8.8.:8.8. + blinking
GOSUB Clock ' 4-digit clock from 16:50 to 17:00 w/blinking colon
GOSUB Counter0 ' Colon ON, count on right 2, then on left 2
GOSUB Help ' Display H.E.L.P. pulsing brightness from 50% to 100%
GOSUB Counter1 ' Count from 9994 to 0000 @ 50% brightness
GOSUB Ouch ' Display OUCH pulsing brightness from 50% to 100%
GOTO Main
Counter0: ' Count 00-14h on right 100% bright, then left @ 50% bright
CFG = %11110001 ' Digits 5,4 special decode/OFF, 3,2,1 HEX decode
GOSUB Config ' Configure display
' Now write data to the display
FOR X = 0 TO 20 ' Count from 0 to 14h on digits 3,2 with leading 0 blank
EN = 0 ' Display banks 5 4 3\2 :=ON
SHIFTOUT DOUT, CLK, MSBFIRST, [%0000\4, $0\4, $0\4, X, $2\4]
EN = 1 ' Transfer data into display registers
PAUSE 150 ' Pause 150mS
NEXT
CFG = %11001101 ' Digits 5,4,1 HEX decode, 3,2 special/OFF
GOSUB Config ' Configure display
FOR X = 0 TO 20 ' Count from 0 to 14h on digits 5,4 with leading 0 blank
EN = 0 ' Enable data input 5\4 3 2 :=ON
SHIFTOUT DOUT, CLK, MSBFIRST, [%0000\4, X, $0\4, $0\4, $2\4]
EN = 1 ' Transfer data into display registers
PAUSE 150 ' Display count from 0 to 14h
NEXT
PAUSE 500
RETURN
Counter1: ' Count from 9994 to 0000
CFG = %11000011 ' Digits 5,4,3,2 HEX decode, 1 special decode
GOSUB Config ' Configure display
' Now write data to the display
D5=9 : D4=9 : D3=9 : D2=4 ' Load counter with 9994 on start
FOR X = 0 TO 6 ' Count from 9994 to 0000
EN = 0 ' Enable data input
IF D2 > 9 THEN D2=0 : D3=D3+1 ' Increment each higher digit # on 9
IF D3 > 9 THEN D3=0 : D4=D4+1 ' value of each lower digit # for BCD
IF D4 > 9 THEN D4=0 : D5=D5+1 ' counting
IF D5 > 9 THEN D5=0 ' dim 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, $0\4]
EN = 1 ' Transfer data into display registers
PAUSE 500 ' Without pause, display can count from 0 to 9999 in ~6 seconds
D2=D2+1 ' Increment counter
NEXT
PAUSE 500
RETURN
Counter2: ' Count from 0 to 1000
CFG = %11000011 ' Digits 5,4,3,2 HEX decode, 1 special decode
GOSUB Config ' Configure display
' Now write data to the display
D2=0 : D3=0 : D4=0 : D5=0 ' Load counter with 0000 on start
FOR X = 0 TO 1000 ' Count from 0 to 1000
EN = 0 ' Enable data input
IF D2 > 9 THEN D2=0 : D3=D3+1 ' Increment each higher digit # on 9
IF D3 > 9 THEN D3=0 : D4=D4+1 ' value of each lower digit # for BCD
IF D4 > 9 THEN D4=0 : D5=D5+1 ' counting
IF D5 > 9 THEN D5=0' dim 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, $0\4]
EN = 1 ' Transfer data into display registers
PAUSE 5 ' Pause
D2=D2+1 ' Increment counter
NEXT
PAUSE 500
RETURN
Help: ' Display H.E.L.P. while toggling brightness from 100% to 50%
CFG = %11101111 ' Digits 5,3,2,1 special decode, 4 HEX decode
GOSUB Config ' Configure display
' Now write H.E.L.P. to display blinking 50% to 100% brightness
Y = %00001111 ' Setup bit 3 for toggling display brightness
FOR X = 0 TO 4 ' and all DP's ON
EN = 0 ' Enable data input
Y.BIT3 = Y.BIT3 ^ 1' Flip Y.bit3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' Y = brightness & DP's 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [Y\4, $2\4, $E\4, $5\4, $8\4, $0\4]
EN = 1 ' Transfer data into display registers
PAUSE 200
NEXT
PAUSE 500
RETURN
Ouch: ' Display OUCH while toggling brightness from 100% to 50%
CFG = %11010111 ' Special decode 4,2,1. 3,5 HEX decode
GOSUB Config ' Configure display
' Now write OUCH to display
Y = %00001000 ' Set bit 3 for toggling brightness, all DP's OFF
FOR X = 0 TO 4
EN = 0 ' Enable data input
Y.BIT3 = Y.BIT3 ^ 1' Flip Y.bit.3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [Y\4, $0\4, $A\4, $C\4, $2\4, $0\4]
' ^--- bit 3 of 4-bit value toggles brightness
EN = 1 ' Transfer data into display registers
PAUSE 200
NEXT
PAUSE 500
RETURN
LampTest: ' Lamp test to display 8.8.:8.8.
CFG = CFGN ' All digits normal HEX decode
GOSUB Config ' Configure display
' Now write 8.8.:8.8.
EN = 0 ' 5=8 4=8 3=8 2=8 :=ON
SHIFTOUT DOUT, CLK, MSBFIRST, [$F\4, $8\4, $8\4, $8\4, $8\4, $2\4]
' ^-- bright display + all DP's ON
EN = 1 ' Transfer data into display registers
PAUSE 250
' Now blink display ON & OFF 3 times
' Note: Toggling bit.0 of the 8-bit config byte toggles the
' display ON (1) & OFF (0) for normal/low power modes
FOR X = 0 TO 2
CFG = %11000000 ' All digits HEX decode / display off
GOSUB Config ' Configure display
PAUSE 250
CFG = %11000001 ' All digits HEX decode / display ON
GOSUB Config ' Configure display
PAUSE 250
NEXT
RETURN
Clock: ' 24-hour clock counts from 16:50 to 17:00 w/blinking colon
CFG = %11000011 ' 5,4,3,2 HEX decode, 1 special decode
GOSUB Config ' Configure display
Y = 8 ' Used to toggle colon. 8 = ON, 0 = OFF
' Now write data to the display
D5=1 : D4=6 : D3=5 : D2=0 ' Set clock time to 16:50
FOR X = 0 TO 10 ' Display clock time from 16:50 to 17:00
EN = 0 ' Enable data input
IF D2 > 9 THEN D2=0 : D3=D3+1 ' Increment each higher digit on 9
IF D3 > 5 THEN D3=0 : D4=D4+1 ' Roll-over from 59 minutes
IF D4 > 9 THEN D4=0 : D5=D5+1 ' Roll-over from hours to tens hours
IF D5 > 2 THEN D5=0 ' Never > 2 for 10's hour digit
IF (D5 = 2) AND (D4 > 3) THEN ' Roll-over from 23:59 to 00:00
D5 = 0 : D4 = 0
ENDIF
SHIFTOUT DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, Y\4]
Y = Y ^ 8 ' 8^8=0, 0^8=8
EN = 1 ' Transfer data into display registers
PAUSE 250 ' Update frequency or clock ticks
D2=D2+1 ' Increment low digit counter
NEXT
PAUSE 500
RETURN
'Configuration routine
'---------------------------------------------------------------------
Config:
EN = 0 ' Enable data input
SHIFTOUT DOUT, CLK, MSBFIRST, [CFG] ' Write to display config register
EN = 1 ' Transfer data into display registers
RETURN
END
dimensions in mm You can purchase the new SLEDC4 serial seven-segment display modules HERE. Until the next project - have fun - and don't blow anything up...;o] Regards, -Bruce
|