' ========================================================================= ' ' File...... MC14489.BS2 ' Purpose... MC14489 LED Multiplexer Demo ' Author.... Jon Williams -- Parallax, Inc. ' E-mail.... jwilliams@parallax.com ' Started... ' Updated... ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This simple demo shows how to connect a BS2 to the MC14489 LED multi- ' plexer. This part is not quite as flexible as the MAX7219, but it is ' cheaper (less than half MAX7219 price) and in better supply. ' ' Use a 10K resistor for Rx -- the rest of the connections are straight to ' a group of common-cathod 7-segment LEDs. The PDB is a great tool ' for experimenting with the MC14489 and 7-segment LED control. ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Enable PIN 5 ' enable (MC14489.10) SClock PIN 6 ' shift clock (MC14489.11) SData PIN 7 ' shift data (MC14489.12) ' -----[ Constants ]------------------------------------------------------- IsDim CON 0 IsBright CON 1 ' -----[ Variables ]------------------------------------------------------- config VAR Byte ' decode configuration dpCtrl VAR Nib ' decimal point control segs5 VAR Nib ' segs - digit 5 segs4 VAR Nib segs3 VAR Nib segs2 VAR Nib segs1 VAR Nib ' segs - digit 1 brCtrl VAR dpCtrl.BIT3 ' dim/bright control counter VAR Word idx VAR Nib ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH Enable brCtrl = IsBright ' -----[ Program Code ]---------------------------------------------------- Main: FOR counter = 0 TO 999 GOSUB Show_NLZ_Value PAUSE 100 NEXT Show_On: config = 0 GOSUB Update_Cfg ' blank display config = %01111011 ' setup for "On" segs5 = 0 segs4 = 0 segs3 = 0 segs2 = 0 ' "O" segs1 = 6 ' "n" GOSUB Update_Segs GOSUB Update_Cfg PAUSE 2000 FOR counter = 0 TO 999 GOSUB Show_NLZ_Value PAUSE 100 NEXT Show_Off: config = 0 GOSUB Update_Cfg ' blank display config = %00110001 ' setup for "On" segs5 = 0 segs4 = 0 segs3 = 0 ' "O" segs2 = $F ' "F" segs1 = $F ' "F" GOSUB Update_Segs GOSUB Update_Cfg PAUSE 2000 GOTO Main END ' -----[ Subroutines ]----------------------------------------------------- ' Show value on 7-segment display and blank leading zeros. ' ' Leading zeros are blanked by putting respective digit columns into ' special decode mode (see MC14489 data sheet). Show_NLZ_Value: LOOKDOWN counter, >=[10000, 1000, 100, 10, 0], idx LOOKUP idx, [$01, $21, $31, $39, $3D], config segs5 = counter DIG 4 segs4 = counter DIG 3 segs3 = counter DIG 2 segs2 = counter DIG 1 segs1 = counter DIG 0 GOSUB Update_Segs GOSUB Update_Cfg RETURN ' Update MC14489 decimal point control and segments registers Update_Segs: LOW Enable SHIFTOUT SData, SClock, MSBFIRST, [dpCtrl\4, segs5\4, segs4\4, segs3\4, segs2\4, segs1\4] HIGH Enable RETURN ' Update MC14489 configuration register Update_Cfg: LOW Enable SHIFTOUT SData, SClock, MSBFIRST, [config] HIGH Enable RETURN