' ========================================================================= ' ' File...... HC4LED.SXB ' Compiler.. SXB Version 1.51.04 ' Purpose... Demonostrate use of HC4LED display module ' Author.... Terry Hitt ' E-mail.... terry@hittconsulting.com ' Started... ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' HC4LED Pinout: ' Pin1 = +5VDC (White wire) ' Pin2 = Gnd ' Pin3 = Blank (Must connect to Gnd to enable display) ' Pin4 = No Connection ' Pin5 = Clock (Connect to RA.0 for this demo program) ' Pin6 = Data (Connect to RA.1 for this demo program) ' ' ' Each segment of the display is addressable, so you can create letters ' and symbols. ' To display custom symbols: ' Set the variables "segments(0)" thru "segments(3)" (segments(0) is on the left) ' simply add the segment values that you want on ' Then use "DisplaySegments" to show the segments on the display ' ' ---4--- ' | | ' 2 8 ' | | ' |---1---| ' | | ' 64 16 ' | | ' --32--- ' ' For example "F" would be 4+2+1+64 = 71 ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX48,OSC32KHZ ',TURBO,STACKX,OPTIONX FREQ 32_000 STACK 16 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Clk PIN RA.0 OUTPUT Dat PIN RA.1 OUTPUT ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- BLANK CON 0 MINUS CON 1 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- index VAR Byte value VAR Word segments VAR Byte (4) ' ========================================================================= PROGRAM Start NOSTARTUP ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- Delay2Sec SUB 0 ' Waits for 2 seconds DisplayValue SUB 1, 2 ' Variable or value as parameter DisplaySegments SUB 4 ' Segment values DisplayArray SUB 0 ' Displays patterns already in segment() array LEDOut SUB 1 ' Shifts out 1 digit ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: DO ' Show custom(non-numeric) message DisplaySegments 91,103,98,79 ' HELP Delay2Sec ' Show leading zero blanking DisplayValue 1 Delay2Sec DisplayValue 12 Delay2Sec DisplayValue 123 Delay2Sec DisplayValue 1234 Delay2Sec ' Show displaying word variable value FOR value = 0 TO 9999 DisplayValue value NEXT Delay2Sec FOR value = -1 TO -999 STEP -1 DisplayValue value PAUSE 20 NEXT Delay2Sec LOOP END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- SUB Delay2Sec PAUSE 2000 RETURN ENDSUB ' ------------------------------------------------------------------------- ' Subroutines to control HC4LED display ' ------------------------------------------------------------------------- SUB DisplayValue holdValue VAR Byte (2) ' Used to save/restore value of variable "value" (need a word variable) holdIndex VAR Byte (1) ' Used to save/restore value of variable index (used to index arrays) isNegative VAR Byte (1) ' 1 if value passed is negative paramW VAR Byte (2) ' Hold parameter (value passed) needed because "holdValue = value" Destroys __PARAMx IF __PARAMCNT = 1 THEN __PARAM2 = 0 ENDIF paramW = __WPARAM12 holdValue = value holdIndex = index value = paramW isNegative = value.15 IF isNegative = 1 THEN value = -value ENDIF PUT segments, BLANK, BLANK, BLANK, BLANK DO WHILE value >= 1000 INC segments(3) value = value - 1000 LOOP DO WHILE value >= 100 INC segments(2) value = value - 100 LOOP DO WHILE value >= 10 INC segments(1) value = value - 10 LOOP segments(0) = value_LSB FOR index = 0 TO 3 READ DigitSegs + segments(index), segments(index) NEXT IF isNegative = 1 THEN segments(3) = MINUS index = 2 ELSE index = 3 ENDIF BlankZeros: IF segments(index) = 126 THEN ' IF digit is Zero... IF isNegative = 1 THEN PUT segments(index), MINUS, BLANK ELSE segments(index) = BLANK ' make it Blank ENDIF ELSE index = 1 ' Set counter to done value ENDIF DJNZ index,BlankZeros DisplayArray index = holdIndex value = holdValue RETURN ENDSUB SUB DisplaySegments PUT segments, __PARAM4, __PARAM3, __PARAM2, __PARAM1 DisplayArray RETURN ENDSUB SUB DisplayArray temp VAR Byte (1) LOW Clk LEDOut segments(0) LEDOut segments(1) LEDOut segments(2) temp = segments(3) >> 1 SHIFTOUT Dat, Clk, MSBFIRST, temp\7 PAUSEUS 5 Dat = segments(3).0 PAUSEUS 5 HIGH Clk PAUSE 2 RETURN ENDSUB SUB LEDOut temp VAR Byte (1) temp = __PARAM1 SHIFTOUT Dat, Clk, MSBFIRST, temp RETURN ENDSUB ' ------------------------------------------------------------------------- ' Data ' ------------------------------------------------------------------------- DigitSegs: DATA 126,24,109,61,27,55,115,28,127,31