I ordered one of this last week and had a program running on it fine for the last 2 days. The program uses a Parallax SX-28 microcontroller and a mini keypad to enter in numbers 0-9, A-F and has random colors when the button is pressed. As I was using the display program tonight the LED controller stoped displaying my characters on it. When rebooting it did show the scrolling up/down LED test pattern so the LEDs are good. How do I get the controller card replaced? Little surprising it only lasted a couple of days.
Thanks.
Timothy Gilmore
’
’ File… Keypad_7SEGLED_4x4_RGBLED.SXB
’ Purpose… Scanning an ET-MINI KEY4x4 http://www.futurlec.com/Mini_Keypad.shtml
’ Original… Original code by Parallax KEYPAD.SXB as seen in SX-KEY HELP MENU
’ Author… Timothy Gilmore
’ E-mail… gilmoret@us.saic.com
’ Started… 02 JUL 2006
’ Updated… 08 OCT 2007
’
’ =========================================================================
’ -------------------------------------------------------------------------
’ Program Description
’ -------------------------------------------------------------------------
’
’ This program demonstrates the scanning of a 4x4 matrix keypad and then displaying
’ the character on a 7 segment display AND 8x8 RGB LED Matrix & controller module.
’ http://www.sparkfun.com/commerce/produc … cts_id=760
’
’
’ Key values (hex):
’
’ C1 C2 C3 C4
’
’ R1 [ 1 ] [ 2 ] [ 3 ] [ 4 ]
’
’ R2 [ 5 ] [ 6 ] [ 7 ] [ 8 ]
’
’ R3 [ 9 ] [ 0 ] [ A ] [ B ]
’
’ R4 [ C ] [ D ] [ E ] [ F ]
’ -------------------------------------------------------------------------
’ Device Settings
’ -------------------------------------------------------------------------
DEVICE SX28, OSCXT1, TURBO, STACKX, OPTIONX
FREQ 4_000_000
’ -------------------------------------------------------------------------
’ IO Pins
’ -------------------------------------------------------------------------
Keys VAR RC ’ keyboard scan port
TRIS_Keys VAR TRIS_C
Col1 VAR Keys.7 ’ column inputs
Col2 VAR Keys.6
Col3 VAR Keys.5
Col4 VAR Keys.4
LEDs VAR RB
TRIS_LEDs VAR TRIS_B
Clock VAR RA.0 ’ Shift clock
DataOut VAR RA.1 ’ Serial Data Out
DataIn VAR RA.2 ’ Serial Data In
ChipSel VAR RA.3 ’ Chip Select
'Futurlec MiniKey
'Connect MiniKey PIN1 to RC.7
'Connect MiniKey PIN2 to RC.6
'Connect MiniKey PIN3 to RC.5
'Connect MiniKey PIN4 to RC.4
'Connect MiniKey PIN8 to RC.3
'Connect MiniKey PIN7 to RC.2
'Connect MiniKey PIN6 to RC.1
'Connect MiniKey PIN5 to RC.0
'Parallax Professional Development Board - 7 Segment display
'Connect 7 Seg DP to RB.7
'Connect 7 Seg G to RB.6
'Connect 7 Seg F to RB.5
'Connect 7 Seg E to RB.4
'Connect 7 Seg D to RB.3
'Connect 7 Seg C to RB.2
'Connect 7 Seg B to RB.1
'Connect 7 Seg A to RB.0
'7 segment display is common ground
'SparkFun 8x8 RGB LED matrix and controller
'Connect RGB display controller CS to RA.3
'Connect RGB display controller DI to RA.2
'Connect RGB display controller DO to RA.1
'Connect RGB display controller SCK to RA.0
'Connect RGB display controller +5V to Vdd
'Connect RGB display controller GND to Vss
’ -------------------------------------------------------------------------
’ Constants
’ -------------------------------------------------------------------------
Yes CON 1
No CON 0
Dash CON %01000000 ’ segment G only
’ -------------------------------------------------------------------------
’ Variables
’ -------------------------------------------------------------------------
theKey VAR Byte ’ from keypad, 0 - 14
row VAR Byte ’ keyboard scan row
temp1 VAR Byte ’ work vars
temp2 VAR Byte
temp3 VAR Byte
temp4 VAR Byte
buf VAR Byte(8)
tmpW1 VAR Word
tmpW2 VAR Word
value VAR Byte
ioByte VAR Byte ’ work byte
ioByte2 VAR Byte ’ work byte
idx VAR Byte ’ work byte
char VAR ioByte ’ current char from message – alias
pixels VAR ioByte2 ’ current pixel data – alias
rows VAR Byte ’ idx.HIGHNIB ’ counter for reading through rows
cols VAR Byte ’ idx.LOWNIB ’ counter for reading through cols
color VAR Byte ’ color for this CHARACTER – you could do more on a pixel (or row or column) basis
'Rand_no VAR Byte
'seed VAR Word
seed VAR Byte
’ =========================================================================
PROGRAM Start
’ =========================================================================
’ -------------------------------------------------------------------------
’ Subroutine Declarations
’ -------------------------------------------------------------------------
GETKEY SUB ’ get key from pad
DELAY SUB 1, 2 ’ delay in milliseconds
doChar SUB
BITVAL FUNC 1, 2, 3 'Thanks to JonnyMac
Load_Char SUB 2, 3 'Thanks to JonnyMac
’ -------------------------------------------------------------------------
’ Program Code
’ -------------------------------------------------------------------------
Start:
char = " " 'clear display with a blank “space” character
doChar
LEDs = Dash ’ dash in 7 segment display
TRIS_LEDs = %00000000 ’ LED pins are 7 segment outputs
Main:
theKey = GETKEY ’ get a key
IF theKey < 16 THEN ’ was a key pressed?
READ ReMap + theKey, theKey ’ yes, remap keypad
READ Digits + theKey, LEDs ’ output to 7 segment display
IF theKey > 9 THEN
theKey = theKey + 65
ELSE
theKey = theKey + 48 ’ Ascii it
ENDIF
Load_Char Char_Maps, theKey
DELAY 100
ENDIF
GOTO Main
’ -------------------------------------------------------------------------
’ Subroutine Code
’ -------------------------------------------------------------------------
’ Use: Load_Char table_name, char_code
’ – moves character data from table into buf()
Load_Char:
tmpW1 = __WPARAM12 ’ table address
tmpW2 = __PARAM3 ’ character (ASCII code)
IF theKey > 57 THEN ’ 9 + 48 = 57
tmpW2 = tmpW2 - 65 ’ z-offset to “0”
ELSE
tmpW2 = tmpW2 - 48
ENDIF
tmpW2 = tmpW2_LSB << 3 ’ x 8
tmpW1 = tmpW1 + tmpW2 ’ add offset to address
FOR temp2 = 0 TO 7
READINC tmpW1, temp1
buf(temp2) = temp1
NEXT
doChar
RETURN
’ Use: value = BITVAL someVal, position
’ – “someVal” can be a byte or word
FUNC BITVAL
IF __PARAMCNT = 2 THEN ’ byte passed?
tmpW1 = __PARAM1 ’ get byte value
temp1 = __PARAM2 ’ get bit position
ELSE ’ word passed
tmpW1 = __WPARAM12 ’ word was passed
temp1 = __PARAM3 ’ get bit position
ENDIF
temp2 = 0 ’ assume cleared
IF temp1 >= 0 THEN ’ position value legal?
IF temp1 <= 15 THEN
tmpW2 = 1 << temp1 ’ create bit mask
tmpW2 = tmpW2 & tmpW1 ’ clear other bits
IF tmpW2 > 0 THEN ’ if not zero
temp2 = 1 ’ bit was 1
ENDIF
ENDIF
ENDIF
RETURN temp2
ENDFUNC
doChar:
LOW ChipSel 'get ready for SPI
PAUSE 1
FOR rows = 0 TO 7 'loop through rows
pixels = buf(rows)
FOR cols = 0 TO 7 'loop cols and make a pixel byte
value = BITVAL pixels, cols
value = value * Color
SHIFTOUT DataIn, Clock, MSBFIRST, value
'if bit for this col/row is 1, then color gets you 1-7 if “on”
'Un-comment to have every LED pixel random
'RANDOM seed
'Rand_no = seed // 7 + 1
'color = Rand_no
NEXT
NEXT
'Un-comment to have every letter random
'RANDOM temp1 ’
'temp2 = temp1 // 7
'temp2 = temp2 + 1
'color = temp2
RANDOM seed
color = seed // 7
color = color + 1
'Hold down on keypad for random color cycling
PAUSE 1
HIGH ChipSel 'latch it
RETURN
’ This routine works by activating each row, then scanning each column.
’ If a particular row/column junction is not active (pressed), the key
’ value is incremented and the scan continues. As soon as a key is found,
’ the routine exits.
’ Use: aByte = GETKEY
’ – scans keyboard and places key value into ‘aByte’
GETKEY:
temp1 = 0 ’ reset keyboard value
row = 4 ’ scan 4 rows
Keys = %00001000 ’ activate first row
TRIS_Keys = %11110000 ’ refresh IO state
DO WHILE row > 0
IF Col1 = Yes THEN EXIT ’ check buttons on column
INC temp1 ’ update key value
IF Col2 = Yes THEN EXIT
INC temp1
IF Col3 = Yes THEN EXIT
INC temp1
IF Col4 = Yes THEN EXIT
INC temp1
Keys = Keys >> 1 ’ select next row
DEC row
LOOP
RETURN temp1
’ Use: DELAY base {, multiplier}
’ – pause for ‘base’ * (optional) ‘multiplier’ milliseconds
DELAY: ’ delay x { * y } ms
temp1 = __PARAM1
IF __PARAMCNT = 1 THEN
temp2 = 1
ELSE
temp2 = __PARAM2
ENDIF
IF temp1 > 0 THEN
IF temp2 > 0 THEN
PAUSE temp1 * temp2
ENDIF
ENDIF
RETURN
’ -------------------------------------------------------------------------
’ DATA
’ -------------------------------------------------------------------------
Char_Maps:
DATA 62,127,99,99,99,99,127,62 '0
DATA 28,30,31,31,28,28,127,127 '1
DATA 30,63,51,56,28,14,127,127 '2
DATA 62,127,99,120,56,99,127,62 '3
DATA 59,59,63,63,56,56,124,124 '4
DATA 127,127,7,63,120,115,127,62 '5
DATA 62,127,99,3,63,99,127,62 '6
DATA 127,127,99,112,56,28,14,7 '7
DATA 62,119,119,62,62,119,119,62 '8
DATA 62,119,119,127,126,112,119,62 '9
DATA 28,62,99,127,127,99,99,99 'A
DATA 63,127,99,63,63,99,127,63 'B
DATA 60,126,103,3,3,103,126,60 'C
DATA 31,63,115,99,99,115,63,31 'D
DATA 127,127,3,63,63,3,127,127 'E
DATA 127,127,3,31,31,3,3,3 'F
’ Matrix to remap keypad values
’ Change values to whatever you want to get displayed.
ReMap:
DATA 1, 2, 3, 4
DATA 5, 6, 7, 8
DATA 9, 0, $A, $B
DATA $C, $D, $E, $F
’ Seven-segment digit maps
Digits:
’ .gfedcba
DATA %00111111 ’ 0
DATA %00000110 ’ 1
DATA %01011011 ’ 2
DATA %01001111 ’ 3
DATA %01100110 ’ 4
DATA %01101101 ’ 5
DATA %01111101 ’ 6
DATA %00000111 ’ 7
DATA %01111111 ’ 8
DATA %01100111 ’ 9
DATA %01110111 ’ A
DATA %01111100 ’ B
DATA %00111001 ’ C
DATA %01011110 ’ D
DATA %01111001 ’ E
DATA %01110001 ’ F